@@ -11,19 +11,36 @@ library;
11
11
import 'dart:io' ;
12
12
13
13
import 'package:native_toolchain_c/native_toolchain_c.dart' ;
14
+ import 'package:native_toolchain_c/src/native_toolchain/clang.dart' ;
14
15
import 'package:native_toolchain_c/src/native_toolchain/msvc.dart' ;
15
16
import 'package:native_toolchain_c/src/utils/run_process.dart' ;
16
17
import 'package:test/test.dart' ;
17
18
18
19
import '../helpers.dart' ;
19
20
20
- void main () {
21
+ void main () async {
21
22
if (! Platform .isWindows) {
22
23
// Avoid needing status files on Dart SDK CI.
23
24
return ;
24
25
}
25
26
27
+ final compilers = {
28
+ // Either provided to be MSVC or null which defaults to MSVC.
29
+ msvc: () async => cCompiler,
30
+ // Clang on Windows.
31
+ clang: () async => CCompilerConfig (
32
+ archiver:
33
+ (await llvmAr.defaultResolver! .resolve (logger: logger)).first.uri,
34
+ compiler:
35
+ (await clang.defaultResolver! .resolve (logger: logger)).first.uri,
36
+ linker:
37
+ (await lld.defaultResolver! .resolve (logger: logger)).first.uri,
38
+ )
39
+ };
40
+
26
41
const targets = [
42
+ // TODO(https://github.com/dart-lang/native/issues/170): Support arm64.
43
+ // Architecture.arm64,
27
44
Architecture .ia32,
28
45
Architecture .x64,
29
46
];
@@ -36,86 +53,95 @@ void main() {
36
53
});
37
54
38
55
const dumpbinMachine = {
56
+ Architecture .arm64: 'ARM64' ,
39
57
Architecture .ia32: 'x86' ,
40
58
Architecture .x64: 'x64' ,
41
59
};
42
60
43
61
const optimizationLevels = OptimizationLevel .values;
44
62
var selectOptimizationLevel = 0 ;
63
+ var selectBuildMode = 0 ;
45
64
46
65
final dumpbinFileType = {
47
66
DynamicLoadingBundled (): 'DLL' ,
48
67
StaticLinking (): 'LIBRARY' ,
49
68
};
50
69
51
- for (final linkMode in [DynamicLoadingBundled (), StaticLinking ()]) {
52
- for (final target in targets) {
53
- // Cycle through all optimization levels.
54
- final optimizationLevel = optimizationLevels[selectOptimizationLevel];
55
- selectOptimizationLevel =
56
- (selectOptimizationLevel + 1 ) % optimizationLevels.length;
57
- test ('CBuilder $linkMode library $target $optimizationLevel ' , () async {
58
- final tempUri = await tempDirForTest ();
59
- final tempUri2 = await tempDirForTest ();
60
- final addCUri =
61
- packageUri.resolve ('test/cbuilder/testfiles/add/src/add.c' );
62
- const name = 'add' ;
63
-
64
- final buildInputBuilder = BuildInputBuilder ()
65
- ..setupShared (
66
- packageName: name,
67
- packageRoot: tempUri,
68
- outputFile: tempUri.resolve ('output.json' ),
69
- outputDirectory: tempUri,
70
- outputDirectoryShared: tempUri2,
71
- )
72
- ..config.setupBuild (
73
- linkingEnabled: false ,
74
- dryRun: false ,
75
- )
76
- ..config.setupShared (buildAssetTypes: [CodeAsset .type])
77
- ..config.setupCode (
78
- targetOS: OS .windows,
79
- targetArchitecture: target,
80
- linkModePreference: linkMode == DynamicLoadingBundled ()
81
- ? LinkModePreference .dynamic
82
- : LinkModePreference .static ,
83
- cCompiler: cCompiler,
70
+ for (final compiler in compilers.keys) {
71
+ for (final linkMode in [DynamicLoadingBundled (), StaticLinking ()]) {
72
+ for (final target in targets) {
73
+ // Cycle through all optimization levels.
74
+ final optimizationLevel = optimizationLevels[selectOptimizationLevel];
75
+ selectOptimizationLevel =
76
+ (selectOptimizationLevel + 1 ) % optimizationLevels.length;
77
+ final buildMode = BuildMode .values[selectBuildMode];
78
+ selectBuildMode = (selectBuildMode + 1 ) % BuildMode .values.length;
79
+ test (
80
+ 'CBuilder ${compiler .name } $linkMode library $target '
81
+ ' $optimizationLevel $buildMode ' , () async {
82
+ final tempUri = await tempDirForTest ();
83
+ final tempUri2 = await tempDirForTest ();
84
+ final addCUri =
85
+ packageUri.resolve ('test/cbuilder/testfiles/add/src/add.c' );
86
+ const name = 'add' ;
87
+
88
+ final buildInputBuilder = BuildInputBuilder ()
89
+ ..setupShared (
90
+ packageName: name,
91
+ packageRoot: tempUri,
92
+ outputFile: tempUri.resolve ('output.json' ),
93
+ outputDirectory: tempUri,
94
+ outputDirectoryShared: tempUri2,
95
+ )
96
+ ..config.setupBuild (
97
+ linkingEnabled: false ,
98
+ dryRun: false ,
99
+ )
100
+ ..config.setupShared (buildAssetTypes: [CodeAsset .type])
101
+ ..config.setupCode (
102
+ targetOS: OS .windows,
103
+ targetArchitecture: target,
104
+ linkModePreference: linkMode == DynamicLoadingBundled ()
105
+ ? LinkModePreference .dynamic
106
+ : LinkModePreference .static ,
107
+ cCompiler: await (compilers[compiler]! )(),
108
+ );
109
+
110
+ final buildInput = BuildInput (buildInputBuilder.json);
111
+ final buildOutput = BuildOutputBuilder ();
112
+
113
+ final cbuilder = CBuilder .library (
114
+ name: name,
115
+ assetName: name,
116
+ sources: [addCUri.toFilePath ()],
117
+ optimizationLevel: optimizationLevel,
118
+ buildMode: buildMode,
119
+ );
120
+ await cbuilder.run (
121
+ input: buildInput,
122
+ output: buildOutput,
123
+ logger: logger,
84
124
);
85
125
86
- final buildInput = BuildInput (buildInputBuilder.json);
87
- final buildOutput = BuildOutputBuilder ();
88
-
89
- final cbuilder = CBuilder .library (
90
- name: name,
91
- assetName: name,
92
- sources: [addCUri.toFilePath ()],
93
- optimizationLevel: optimizationLevel,
94
- buildMode: BuildMode .release,
95
- );
96
- await cbuilder.run (
97
- input: buildInput,
98
- output: buildOutput,
99
- logger: logger,
100
- );
101
-
102
- final libUri =
103
- tempUri.resolve (OS .windows.libraryFileName (name, linkMode));
104
- expect (await File .fromUri (libUri).exists (), true );
105
- final result = await runProcess (
106
- executable: dumpbinUri,
107
- arguments: ['/HEADERS' , libUri.toFilePath ()],
108
- logger: logger,
109
- );
110
- expect (result.exitCode, 0 );
111
- final machine =
112
- result.stdout.split ('\n ' ).firstWhere ((e) => e.contains ('machine' ));
113
- expect (machine, contains (dumpbinMachine[target]));
114
- final fileType = result.stdout
115
- .split ('\n ' )
116
- .firstWhere ((e) => e.contains ('File Type' ));
117
- expect (fileType, contains (dumpbinFileType[linkMode]));
118
- });
126
+ final libUri =
127
+ tempUri.resolve (OS .windows.libraryFileName (name, linkMode));
128
+ expect (await File .fromUri (libUri).exists (), true );
129
+ final result = await runProcess (
130
+ executable: dumpbinUri,
131
+ arguments: ['/HEADERS' , libUri.toFilePath ()],
132
+ logger: logger,
133
+ );
134
+ expect (result.exitCode, 0 );
135
+ final machine = result.stdout
136
+ .split ('\n ' )
137
+ .firstWhere ((e) => e.contains ('machine' ));
138
+ expect (machine, contains (dumpbinMachine[target]));
139
+ final fileType = result.stdout
140
+ .split ('\n ' )
141
+ .firstWhere ((e) => e.contains ('File Type' ));
142
+ expect (fileType, contains (dumpbinFileType[linkMode]));
143
+ });
144
+ }
119
145
}
120
146
}
121
147
}
0 commit comments