From 7566053296651989f1c5ead721ca9429f7655813 Mon Sep 17 00:00:00 2001 From: Sebastian Imlay Date: Tue, 24 Mar 2020 00:53:38 -0700 Subject: [PATCH] Removed lazy_static and regex --- Cargo.toml | 2 -- src/lib.rs | 41 +++++++++++++++++++++++------------------ 2 files changed, 23 insertions(+), 20 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 80a268b..7ee72dd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,5 +15,3 @@ categories = ["development-tools::build-utils"] [dependencies] cc = "1.0.41" -lazy_static = "1.0" -regex = "1.0" diff --git a/src/lib.rs b/src/lib.rs index 1992a36..f95889e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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}; @@ -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(); @@ -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() {