44
44
45
45
#![ deny( missing_docs) ]
46
46
47
- #[ macro_use]
48
- extern crate lazy_static;
49
-
50
47
extern crate cc;
51
- extern crate regex;
52
48
53
- use regex:: Regex ;
54
49
use std:: env;
55
50
use std:: ffi:: { OsStr , OsString } ;
56
51
use std:: fs:: { self , File } ;
@@ -1033,22 +1028,21 @@ impl Target for AppleTarget {
1033
1028
1034
1029
fn filter_compiler_args ( & self , flags : & mut OsString ) {
1035
1030
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
-
1043
1031
let mut flags_string = flags_str. to_owned ( ) ;
1044
1032
flags_string. push ( ' ' ) ;
1045
-
1046
1033
// 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
+ }
1052
1046
1053
1047
if flags_string. ends_with ( ' ' ) {
1054
1048
flags_string. pop ( ) ;
@@ -1060,6 +1054,17 @@ impl Target for AppleTarget {
1060
1054
}
1061
1055
}
1062
1056
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
+
1063
1068
fn run ( cmd : & mut Command , program : & str ) {
1064
1069
println ! ( "running: {:?}" , cmd) ;
1065
1070
let status = match cmd. status ( ) {
0 commit comments