Skip to content

Commit 4341e37

Browse files
authored
[objective_c] Fix older XCode builds (#2866)
1 parent 49661db commit 4341e37

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

.github/workflows/objective_c.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,20 @@ jobs:
8787
defaults:
8888
run:
8989
working-directory: pkgs/objective_c/example/flutter_app
90+
strategy:
91+
fail-fast: false
92+
matrix:
93+
xcode_version: ["16.1", "26.1.1"]
94+
ios_version: ["18.1"]
9095
steps:
9196
- uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3
9297
- uses: subosito/flutter-action@fd55f4c5af5b953cc57a2be44cb082c8f6635e8e
9398
with:
9499
channel: stable
100+
- name: Select the XCode version
101+
run: sudo xcode-select -switch /Applications/Xcode_${{ matrix.xcode_version }}.app/Contents/Developer
102+
- name: Install iOS SDK
103+
run: xcodebuild -downloadPlatform iOS -buildVersion ${{ matrix.ios_version }}
95104
- name: Install dependencies
96105
run: flutter pub get
97106
- name: Build the example app for macos

pkgs/objective_c/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 9.2.2
2+
3+
- Fix a [bug](https://github.com/dart-lang/http/issues/1861) where the build
4+
failed on older versions of XCode.
5+
16
## 9.2.1
27

38
- Fix [bug](https://github.com/dart-lang/native/issues/2824) where the build

pkgs/objective_c/hook/build.dart

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@ import 'package:native_toolchain_c/src/cbuilder/compiler_resolver.dart';
1111

1212
const objCFlags = ['-x', 'objective-c', '-fobjc-arc'];
1313

14-
String sdkPath = firstLineOfStdout('xcrun', ['--show-sdk-path']);
15-
1614
const 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

2220
final 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+
145165
String firstLineOfStdout(String cmd, List<String> args) {
146166
final result = Process.runSync(cmd, args);
147167
assert(result.exitCode == 0);

pkgs/objective_c/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
name: objective_c
66
description: 'A library to access Objective C from Flutter that acts as a support library for package:ffigen.'
7-
version: 9.2.1
7+
version: 9.2.2
88
repository: https://github.com/dart-lang/native/tree/main/pkgs/objective_c
99
issue_tracker: https://github.com/dart-lang/native/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aobjective_c
1010

0 commit comments

Comments
 (0)