Skip to content

Removed lazy_static and regex from cmake-ios branch #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ categories = ["development-tools::build-utils"]

[dependencies]
cc = "1.0.41"
lazy_static = "1.0"
regex = "1.0"
54 changes: 36 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,8 @@

#![deny(missing_docs)]

#[macro_use]
extern crate lazy_static;

extern crate cc;
extern crate regex;

use regex::Regex;
use std::env;
use std::ffi::{OsStr, OsString};
use std::fs::{self, File};
Expand Down Expand Up @@ -81,6 +76,7 @@ pub struct Config {
no_build_target: bool,
verbose_cmake: bool,
verbose_make: bool,
pic: Option<bool>,
}

/// Builds the native library rooted at `path` with the default cmake options.
Expand Down Expand Up @@ -128,9 +124,16 @@ impl Config {
no_build_target: false,
verbose_cmake: false,
verbose_make: false,
pic: None,
}
}

/// Sets flag for PIC. Otherwise use cc::Build platform default
pub fn pic(&mut self, explicit_flag: bool) -> &mut Config {
self.pic = Some(explicit_flag);
self
}

/// Sets the build-tool generator (`-G`) for this compilation.
pub fn generator<T: AsRef<OsStr>>(&mut self, generator: T) -> &mut Config {
self.generator = Some(generator.as_ref().to_owned());
Expand Down Expand Up @@ -351,6 +354,10 @@ impl Config {
c_cfg.static_crt(static_crt);
cxx_cfg.static_crt(static_crt);
}
if let Some(explicit_flag) = self.pic {
c_cfg.pic(explicit_flag);
cxx_cfg.pic(explicit_flag);
}
let c_compiler = c_cfg.get_compiler();
let cxx_compiler = cxx_cfg.get_compiler();
let asm_compiler = c_cfg.get_compiler();
Expand Down Expand Up @@ -1021,22 +1028,22 @@ impl Target for AppleTarget {

fn filter_compiler_args(&self, flags: &mut OsString) {
if let Some(flags_str) = flags.to_str() {
lazy_static! {
static ref ARCH_REGEX: Regex = Regex::new("-arch [^ ]+ ").unwrap();
static ref DEPLOYMENT_TARGET_REGEX: Regex =
Regex::new("-m[\\w-]+-version-min=[\\d.]+ ").unwrap();
static ref SYSROOT_REGEX: Regex = Regex::new("-isysroot [^ ]+ ").unwrap();
}

let mut flags_string = flags_str.to_owned();
flags_string.push(' ');

// These are set by cmake
flags_string = ARCH_REGEX.replace(&flags_string, "").into_owned();
flags_string = DEPLOYMENT_TARGET_REGEX
.replace(&flags_string, "")
.into_owned();
flags_string = SYSROOT_REGEX.replace(&flags_string, "").into_owned();
// The initial version of this logic used the Regex crate and lazy_static.
// Architecture regex: "-arch [^ ]+ "
// Deployment target regex: "-m[\\w-]+-version-min=[\\d.]+ "
// sysroot regex: "-isysroot [^ ]+ "
// The following forloop emulates that set of regular expressions.
for i in flags.to_string_lossy().split(" -") {
if i.starts_with("isysroot")
|| i.starts_with("arch")
|| (i.starts_with("m") && i.contains("-version-min="))
{
flags_string = flags_string.replace(&format!(" -{}", i), "");
}
}

if flags_string.ends_with(' ') {
flags_string.pop();
Expand All @@ -1048,6 +1055,17 @@ impl Target for AppleTarget {
}
}

#[test]
fn test_filter_compiler_args_ios() {
let target = AppleTarget::new("aarch64-apple-ios").unwrap();
let mut input_flags = OsString::from(" -fPIC -m64 -m64 -mios-simulator-version-min=7.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator13.2.sdk -fembed-bitcode -arch aarch64-apple-ios");
target.filter_compiler_args(&mut input_flags);
assert_eq!(
input_flags,
OsString::from(" -fPIC -m64 -m64 -fembed-bitcode")
);
}

fn run(cmd: &mut Command, program: &str) {
println!("running: {:?}", cmd);
let status = match cmd.status() {
Expand Down