4444
4545#![ deny( missing_docs) ]
4646
47- #[ macro_use]
48- extern crate lazy_static;
49-
5047extern crate cc;
51- extern crate regex;
5248
53- use regex:: Regex ;
5449use std:: env;
5550use std:: ffi:: { OsStr , OsString } ;
5651use std:: fs:: { self , File } ;
@@ -1033,22 +1028,21 @@ impl Target for AppleTarget {
10331028
10341029 fn filter_compiler_args ( & self , flags : & mut OsString ) {
10351030 if let Some ( flags_str) = flags. to_str ( ) {
1036- lazy_static ! {
1037- static ref ARCH_REGEX : Regex = Regex :: new( "-arch [^ ]+ " ) . unwrap( ) ;
1038- static ref DEPLOYMENT_TARGET_REGEX : Regex =
1039- Regex :: new( "-m[\\ w-]+-version-min=[\\ d.]+ " ) . unwrap( ) ;
1040- static ref SYSROOT_REGEX : Regex = Regex :: new( "-isysroot [^ ]+ " ) . unwrap( ) ;
1041- }
1042-
10431031 let mut flags_string = flags_str. to_owned ( ) ;
10441032 flags_string. push ( ' ' ) ;
1045-
10461033 // These are set by cmake
1047- flags_string = ARCH_REGEX . replace ( & flags_string, "" ) . into_owned ( ) ;
1048- flags_string = DEPLOYMENT_TARGET_REGEX
1049- . replace ( & flags_string, "" )
1050- . into_owned ( ) ;
1051- flags_string = SYSROOT_REGEX . replace ( & flags_string, "" ) . into_owned ( ) ;
1034+ // The initial version of this logic used the Regex crate and lazy_static.
1035+ // Architecture regex: "-arch [^ ]+ "
1036+ // Deployment target regex: "-m[\\w-]+-version-min=[\\d.]+ "
1037+ // sysroot regex: "-isysroot [^ ]+ "
1038+ // The following forloop emulates that set of regular expressions.
1039+ for i in flags. to_string_lossy ( ) . split ( " -" ) {
1040+ if ( i. starts_with ( "isysroot" ) || i. starts_with ( "arch" ) )
1041+ || ( i. starts_with ( "m" ) && i. contains ( "-version-min=" ) )
1042+ {
1043+ flags_string = flags_string. replace ( & format ! ( " -{}" , i) , "" ) ;
1044+ }
1045+ }
10521046
10531047 if flags_string. ends_with ( ' ' ) {
10541048 flags_string. pop ( ) ;
@@ -1060,6 +1054,17 @@ impl Target for AppleTarget {
10601054 }
10611055}
10621056
1057+ #[ test]
1058+ fn test_filter_compiler_args_ios ( ) {
1059+ let target = AppleTarget :: new ( "aarch64-apple-ios" ) . unwrap ( ) ;
1060+ 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" ) ;
1061+ target. filter_compiler_args ( & mut input_flags) ;
1062+ assert_eq ! (
1063+ input_flags,
1064+ OsString :: from( " -fPIC -m64 -m64 -fembed-bitcode" )
1065+ ) ;
1066+ }
1067+
10631068fn run ( cmd : & mut Command , program : & str ) {
10641069 println ! ( "running: {:?}" , cmd) ;
10651070 let status = match cmd. status ( ) {
0 commit comments