Skip to content

Commit 49d113b

Browse files
committed
Fix example build on flutter mac
1 parent 1df1e19 commit 49d113b

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

.github/workflows/objective_c.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,10 @@ jobs:
9494
channel: stable
9595
- name: Install dependencies
9696
run: flutter pub get
97-
- name: Build the example app
97+
- name: Build the example app for macos
9898
run: flutter build macos
99+
- name: Build the example app for ios
100+
run: flutter build ios
99101
- name: Check for xcode for analyzer warnings
100102
run: xcodebuild analyze -workspace macos/Runner.xcworkspace -scheme Runner -configuration Debug GCC_TREAT_WARNINGS_AS_ERRORS=YES
101103

pkgs/objective_c/hook/build.dart

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import 'package:native_toolchain_c/src/cbuilder/compiler_resolver.dart';
1212
const objCFlags = ['-x', 'objective-c', '-fobjc-arc'];
1313

1414
String sdkPath = firstLineOfStdout('xcrun', ['--show-sdk-path']);
15-
final cFlags = <String>['-isysroot', sdkPath];
1615

1716
const assetName = 'objective_c.dylib';
1817

@@ -29,7 +28,8 @@ final logger = Logger('')
2928
void main(List<String> args) async {
3029
await build(args, (input, output) async {
3130
const supportedOSs = {OS.iOS, OS.macOS};
32-
if (!supportedOSs.contains(input.config.code.targetOS)) {
31+
final os = input.config.code.targetOS;
32+
if (!supportedOSs.contains(os)) {
3333
// Nothing to do.
3434
return;
3535
}
@@ -42,6 +42,9 @@ void main(List<String> args) async {
4242
final assetPath = input.outputDirectory.resolve(assetName);
4343
final srcDir = Directory.fromUri(input.packageRoot.resolve('src/'));
4444

45+
final arch = input.config.code.targetArchitecture;
46+
final target = '${clangArchName(arch)}-apple-${os.name}';
47+
4548
final cFiles = <String>[];
4649
final mFiles = <String>[];
4750
final hFiles = <String>[];
@@ -56,15 +59,17 @@ void main(List<String> args) async {
5659

5760
cFiles.addAll(extraCFiles.map((f) => input.packageRoot.resolve(f).path));
5861

62+
final cFlags = <String>['-isysroot', sdkPath, '-target', target];
5963
final mFlags = [...cFlags, ...objCFlags];
64+
final linkFlags = cFlags;
6065

6166
final builder = await Builder.create(input, input.packageRoot.path);
6267

6368
final objectFiles = await Future.wait(<Future<String>>[
6469
for (final src in cFiles) builder.buildObject(src, cFlags),
6570
for (final src in mFiles) builder.buildObject(src, mFlags),
6671
]);
67-
await builder.linkLib(objectFiles, assetPath.toFilePath());
72+
await builder.linkLib(objectFiles, assetPath.toFilePath(), linkFlags);
6873

6974
output.dependencies.addAll(cFiles.map(Uri.file));
7075
output.dependencies.addAll(mFiles.map(Uri.file));
@@ -108,11 +113,15 @@ class Builder {
108113
return output;
109114
}
110115

111-
Future<void> linkLib(List<String> objects, String output) => _compile([
116+
Future<void> linkLib(
117+
List<String> objects,
118+
String output,
119+
List<String> flags,
120+
) => _compile([
112121
'-shared',
113122
'-undefined',
114123
'dynamic_lookup',
115-
...cFlags,
124+
...flags,
116125
...objects,
117126
], output);
118127

@@ -138,3 +147,6 @@ String firstLineOfStdout(String cmd, List<String> args) {
138147
.where((line) => line.isNotEmpty)
139148
.first;
140149
}
150+
151+
String clangArchName(Architecture arch) =>
152+
arch == Architecture.x64 ? 'x86_64' : arch.name;

0 commit comments

Comments
 (0)