@@ -11,13 +11,11 @@ import 'package:native_toolchain_c/src/cbuilder/compiler_resolver.dart';
1111
1212const objCFlags = ['-x' , 'objective-c' , '-fobjc-arc' ];
1313
14- String sdkPath = firstLineOfStdout ('xcrun' , ['--show-sdk-path' ]);
15-
1614const assetName = 'objective_c.dylib' ;
1715
1816// TODO(https://github.com/dart-lang/native/issues/2272): Remove this from the
1917// main build.
20- const extraCFiles = ['test/util.c' ];
18+ const testFiles = ['test/util.c' ];
2119
2220final logger = Logger ('' )
2321 ..level = Level .INFO
@@ -33,20 +31,21 @@ void main(List<String> args) async {
3331 }
3432
3533 const supportedOSs = {OS .iOS, OS .macOS};
36- final os = input.config.code.targetOS;
34+ final codeConfig = input.config.code;
35+ final os = codeConfig.targetOS;
3736 if (! supportedOSs.contains (os)) {
3837 // Nothing to do.
3938 return ;
4039 }
4140
42- if (input.config.code .linkModePreference == LinkModePreference .static ) {
41+ if (codeConfig .linkModePreference == LinkModePreference .static ) {
4342 throw UnsupportedError ('LinkModePreference.static is not supported.' );
4443 }
4544
4645 final packageName = input.packageName;
4746 final assetPath = input.outputDirectory.resolve (assetName);
4847 final srcDir = Directory .fromUri (input.packageRoot.resolve ('src/' ));
49- final target = toTargetTriple (input.config.code );
48+ final target = toTargetTriple (codeConfig );
5049
5150 final cFiles = < String > [];
5251 final mFiles = < String > [];
@@ -60,9 +59,15 @@ void main(List<String> args) async {
6059 }
6160 }
6261
63- cFiles.addAll (extraCFiles.map ((f) => input.packageRoot.resolve (f).path));
62+ // Only include the test utils on mac OS. They use memory functions that
63+ // aren't supported on iOS, like mach_vm_region. We don't need them on iOS
64+ // anyway since we only run memory tests on mac.
65+ if (os == OS .macOS) {
66+ cFiles.addAll (testFiles.map ((f) => input.packageRoot.resolve (f).path));
67+ }
6468
65- final cFlags = < String > ['-isysroot' , sdkPath, '-target' , target];
69+ final sysroot = sdkPath (codeConfig);
70+ final cFlags = < String > ['-isysroot' , sysroot, '-target' , target];
6671 final mFlags = [...cFlags, ...objCFlags];
6772 final linkFlags = cFlags;
6873
@@ -142,6 +147,21 @@ class Builder {
142147 }
143148}
144149
150+ String sdkPath (CodeConfig codeConfig) {
151+ final String target;
152+ if (codeConfig.targetOS == OS .iOS) {
153+ if (codeConfig.iOS.targetSdk == IOSSdk .iPhoneOS) {
154+ target = 'iphoneos' ;
155+ } else {
156+ target = 'iphonesimulator' ;
157+ }
158+ } else {
159+ assert (codeConfig.targetOS == OS .macOS);
160+ target = 'macosx' ;
161+ }
162+ return firstLineOfStdout ('xcrun' , ['--show-sdk-path' , '--sdk' , target]);
163+ }
164+
145165String firstLineOfStdout (String cmd, List <String > args) {
146166 final result = Process .runSync (cmd, args);
147167 assert (result.exitCode == 0 );
0 commit comments