@@ -36,115 +36,126 @@ void main() {
36
36
37
37
const name = 'add' ;
38
38
39
- for (final linkMode in [DynamicLoadingBundled (), StaticLinking ()]) {
40
- for (final targetIOSSdk in IOSSdk .values) {
41
- for (final target in targets) {
42
- if (target == Architecture .x64 && targetIOSSdk == IOSSdk .iPhoneOS) {
43
- continue ;
44
- }
45
-
46
- final libName = OS .iOS.libraryFileName (name, linkMode);
47
- for (final installName in [
48
- null ,
49
- if (linkMode == DynamicLoadingBundled ())
50
- Uri .file ('@executable_path/Frameworks/$libName ' ),
51
- ]) {
52
- test (
53
- 'CBuilder $linkMode library $targetIOSSdk $target '
54
- ' ${installName ?? '' }'
55
- .trim (), () async {
56
- final tempUri = await tempDirForTest ();
57
- final addCUri =
58
- packageUri.resolve ('test/cbuilder/testfiles/add/src/add.c' );
59
- final buildConfig = BuildConfig .build (
60
- outputDirectory: tempUri,
61
- packageName: name,
62
- packageRoot: tempUri,
63
- targetArchitecture: target,
64
- targetOS: OS .iOS,
65
- buildMode: BuildMode .release,
66
- linkModePreference: linkMode == DynamicLoadingBundled ()
67
- ? LinkModePreference .dynamic
68
- : LinkModePreference .static ,
69
- targetIOSSdk: targetIOSSdk,
70
- );
71
- final buildOutput = BuildOutput ();
39
+ for (final language in [Language .c, Language .objectiveC]) {
40
+ for (final linkMode in [DynamicLoadingBundled (), StaticLinking ()]) {
41
+ for (final targetIOSSdk in IOSSdk .values) {
42
+ for (final target in targets) {
43
+ if (target == Architecture .x64 && targetIOSSdk == IOSSdk .iPhoneOS) {
44
+ continue ;
45
+ }
72
46
73
- final cbuilder = CBuilder .library (
74
- name: name,
75
- assetName: name,
76
- sources: [addCUri.toFilePath ()],
77
- installName: installName,
78
- dartBuildFiles: ['hook/build.dart' ],
79
- );
80
- await cbuilder.run (
81
- config: buildConfig,
82
- output: buildOutput,
83
- logger: logger,
84
- );
47
+ final libName = OS .iOS.libraryFileName (name, linkMode);
48
+ for (final installName in [
49
+ null ,
50
+ if (linkMode == DynamicLoadingBundled ())
51
+ Uri .file ('@executable_path/Frameworks/$libName ' ),
52
+ ]) {
53
+ test (
54
+ 'CBuilder $linkMode $language library $targetIOSSdk $target '
55
+ ' ${installName ?? '' }'
56
+ .trim (), () async {
57
+ final tempUri = await tempDirForTest ();
58
+ final sourceUri = switch (language) {
59
+ Language .c =>
60
+ packageUri.resolve ('test/cbuilder/testfiles/add/src/add.c' ),
61
+ Language .objectiveC => packageUri.resolve (
62
+ 'test/cbuilder/testfiles/add_objective_c/src/add.m' ),
63
+ Language () => throw UnimplementedError (),
64
+ };
65
+ final buildConfig = BuildConfig .build (
66
+ outputDirectory: tempUri,
67
+ packageName: name,
68
+ packageRoot: tempUri,
69
+ targetArchitecture: target,
70
+ targetOS: OS .iOS,
71
+ buildMode: BuildMode .release,
72
+ linkModePreference: linkMode == DynamicLoadingBundled ()
73
+ ? LinkModePreference .dynamic
74
+ : LinkModePreference .static ,
75
+ targetIOSSdk: targetIOSSdk,
76
+ );
77
+ final buildOutput = BuildOutput ();
85
78
86
- final libUri = tempUri.resolve (libName);
87
- final objdumpResult = await runProcess (
88
- executable: Uri .file ('objdump' ),
89
- arguments: ['-t' , libUri.path],
90
- logger: logger,
91
- );
92
- expect (objdumpResult.exitCode, 0 );
93
- final machine = objdumpResult.stdout
94
- .split ('\n ' )
95
- .firstWhere ((e) => e.contains ('file format' ));
96
- expect (machine, contains (objdumpFileFormat[target]));
79
+ final cbuilder = CBuilder .library (
80
+ name: name,
81
+ assetName: name,
82
+ sources: [sourceUri.toFilePath ()],
83
+ installName: installName,
84
+ dartBuildFiles: ['hook/build.dart' ],
85
+ language: language,
86
+ );
87
+ await cbuilder.run (
88
+ config: buildConfig,
89
+ output: buildOutput,
90
+ logger: logger,
91
+ );
97
92
98
- final otoolResult = await runProcess (
99
- executable: Uri .file ('otool' ),
100
- arguments: ['-l' , libUri.path],
101
- logger: logger,
102
- );
103
- expect (otoolResult.exitCode, 0 );
104
- if (targetIOSSdk == IOSSdk .iPhoneOS || target == Architecture .x64) {
105
- // The x64 simulator behaves as device, presumably because the
106
- // devices are never x64.
107
- expect (otoolResult.stdout, contains ('LC_VERSION_MIN_IPHONEOS' ));
108
- expect (otoolResult.stdout, isNot (contains ('LC_BUILD_VERSION' )));
109
- } else {
110
- expect (otoolResult.stdout,
111
- isNot (contains ('LC_VERSION_MIN_IPHONEOS' )));
112
- expect (otoolResult.stdout, contains ('LC_BUILD_VERSION' ));
113
- final platform = otoolResult.stdout
93
+ final libUri = tempUri.resolve (libName);
94
+ final objdumpResult = await runProcess (
95
+ executable: Uri .file ('objdump' ),
96
+ arguments: ['-t' , libUri.path],
97
+ logger: logger,
98
+ );
99
+ expect (objdumpResult.exitCode, 0 );
100
+ final machine = objdumpResult.stdout
114
101
.split ('\n ' )
115
- .firstWhere ((e) => e.contains ('platform' ));
116
- const platformIosSimulator = 7 ;
117
- expect (platform, contains (platformIosSimulator.toString ()));
118
- }
102
+ .firstWhere ((e) => e.contains ('file format' ));
103
+ expect (machine, contains (objdumpFileFormat[target]));
119
104
120
- if (linkMode == DynamicLoadingBundled ()) {
121
- final libInstallName = await runOtoolInstallName (libUri, libName);
122
- if (installName == null ) {
123
- // If no install path is passed, we have an absolute path.
124
- final tempName = tempUri.pathSegments.lastWhere ((e) => e != '' );
125
- final pathEnding =
126
- Uri .directory (tempName).resolve (libName).toFilePath ();
127
- expect (Uri .file (libInstallName).isAbsolute, true );
128
- expect (libInstallName, contains (pathEnding));
129
- final targetInstallName =
130
- '@executable_path/Frameworks/$libName ' ;
131
- await runProcess (
132
- executable: Uri .file ('install_name_tool' ),
133
- arguments: [
134
- '-id' ,
135
- targetInstallName,
136
- libUri.toFilePath (),
137
- ],
138
- logger: logger,
139
- );
140
- final libInstallName2 =
141
- await runOtoolInstallName (libUri, libName);
142
- expect (libInstallName2, targetInstallName);
105
+ final otoolResult = await runProcess (
106
+ executable: Uri .file ('otool' ),
107
+ arguments: ['-l' , libUri.path],
108
+ logger: logger,
109
+ );
110
+ expect (otoolResult.exitCode, 0 );
111
+ if (targetIOSSdk == IOSSdk .iPhoneOS ||
112
+ target == Architecture .x64) {
113
+ // The x64 simulator behaves as device, presumably because the
114
+ // devices are never x64.
115
+ expect (otoolResult.stdout, contains ('LC_VERSION_MIN_IPHONEOS' ));
116
+ expect (otoolResult.stdout, isNot (contains ('LC_BUILD_VERSION' )));
143
117
} else {
144
- expect (libInstallName, installName.toFilePath ());
118
+ expect (otoolResult.stdout,
119
+ isNot (contains ('LC_VERSION_MIN_IPHONEOS' )));
120
+ expect (otoolResult.stdout, contains ('LC_BUILD_VERSION' ));
121
+ final platform = otoolResult.stdout
122
+ .split ('\n ' )
123
+ .firstWhere ((e) => e.contains ('platform' ));
124
+ const platformIosSimulator = 7 ;
125
+ expect (platform, contains (platformIosSimulator.toString ()));
126
+ }
127
+
128
+ if (linkMode == DynamicLoadingBundled ()) {
129
+ final libInstallName =
130
+ await runOtoolInstallName (libUri, libName);
131
+ if (installName == null ) {
132
+ // If no install path is passed, we have an absolute path.
133
+ final tempName =
134
+ tempUri.pathSegments.lastWhere ((e) => e != '' );
135
+ final pathEnding =
136
+ Uri .directory (tempName).resolve (libName).toFilePath ();
137
+ expect (Uri .file (libInstallName).isAbsolute, true );
138
+ expect (libInstallName, contains (pathEnding));
139
+ final targetInstallName =
140
+ '@executable_path/Frameworks/$libName ' ;
141
+ await runProcess (
142
+ executable: Uri .file ('install_name_tool' ),
143
+ arguments: [
144
+ '-id' ,
145
+ targetInstallName,
146
+ libUri.toFilePath (),
147
+ ],
148
+ logger: logger,
149
+ );
150
+ final libInstallName2 =
151
+ await runOtoolInstallName (libUri, libName);
152
+ expect (libInstallName2, targetInstallName);
153
+ } else {
154
+ expect (libInstallName, installName.toFilePath ());
155
+ }
145
156
}
146
- }
147
- });
157
+ });
158
+ }
148
159
}
149
160
}
150
161
}
0 commit comments