Skip to content

Commit

Permalink
Removed lazy_static and regex
Browse files Browse the repository at this point in the history
  • Loading branch information
simlay committed Mar 24, 2020
1 parent 49c1f3c commit 7566053
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
2 changes: 0 additions & 2 deletions Cargo.toml
Expand Up @@ -15,5 +15,3 @@ categories = ["development-tools::build-utils"]

[dependencies]
cc = "1.0.41"
lazy_static = "1.0"
regex = "1.0"
41 changes: 23 additions & 18 deletions src/lib.rs
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 @@ -1033,22 +1028,21 @@ 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 @@ -1060,6 +1054,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

0 comments on commit 7566053

Please sign in to comment.