@@ -11,19 +11,36 @@ library;
1111import 'dart:io' ;
1212
1313import 'package:native_toolchain_c/native_toolchain_c.dart' ;
14+ import 'package:native_toolchain_c/src/native_toolchain/clang.dart' ;
1415import 'package:native_toolchain_c/src/native_toolchain/msvc.dart' ;
1516import 'package:native_toolchain_c/src/utils/run_process.dart' ;
1617import 'package:test/test.dart' ;
1718
1819import '../helpers.dart' ;
1920
20- void main () {
21+ void main () async {
2122 if (! Platform .isWindows) {
2223 // Avoid needing status files on Dart SDK CI.
2324 return ;
2425 }
2526
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+
2641 const targets = [
42+ // TODO(https://github.com/dart-lang/native/issues/170): Support arm64.
43+ // Architecture.arm64,
2744 Architecture .ia32,
2845 Architecture .x64,
2946 ];
@@ -36,6 +53,7 @@ void main() {
3653 });
3754
3855 const dumpbinMachine = {
56+ Architecture .arm64: 'ARM64' ,
3957 Architecture .ia32: 'x86' ,
4058 Architecture .x64: 'x64' ,
4159 };
@@ -48,74 +66,79 @@ void main() {
4866 StaticLinking (): 'LIBRARY' ,
4967 };
5068
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,
69+ for (final compiler in compilers.keys) {
70+ for (final linkMode in [DynamicLoadingBundled (), StaticLinking ()]) {
71+ for (final target in targets) {
72+ // Cycle through all optimization levels.
73+ final optimizationLevel = optimizationLevels[selectOptimizationLevel];
74+ selectOptimizationLevel =
75+ (selectOptimizationLevel + 1 ) % optimizationLevels.length;
76+ test (
77+ 'CBuilder ${compiler .name } $linkMode library $target '
78+ ' $optimizationLevel ' , () async {
79+ final tempUri = await tempDirForTest ();
80+ final tempUri2 = await tempDirForTest ();
81+ final addCUri =
82+ packageUri.resolve ('test/cbuilder/testfiles/add/src/add.c' );
83+ const name = 'add' ;
84+
85+ final buildInputBuilder = BuildInputBuilder ()
86+ ..setupShared (
87+ packageName: name,
88+ packageRoot: tempUri,
89+ outputFile: tempUri.resolve ('output.json' ),
90+ outputDirectory: tempUri,
91+ outputDirectoryShared: tempUri2,
92+ )
93+ ..config.setupBuild (
94+ linkingEnabled: false ,
95+ dryRun: false ,
96+ )
97+ ..config.setupShared (buildAssetTypes: [CodeAsset .type])
98+ ..config.setupCode (
99+ targetOS: OS .windows,
100+ targetArchitecture: target,
101+ linkModePreference: linkMode == DynamicLoadingBundled ()
102+ ? LinkModePreference .dynamic
103+ : LinkModePreference .static ,
104+ cCompiler: await (compilers[compiler]! )(),
105+ );
106+
107+ final buildInput = BuildInput (buildInputBuilder.json);
108+ final buildOutput = BuildOutputBuilder ();
109+
110+ final cbuilder = CBuilder .library (
111+ name: name,
112+ assetName: name,
113+ sources: [addCUri.toFilePath ()],
114+ optimizationLevel: optimizationLevel,
115+ buildMode: BuildMode .release,
116+ );
117+ await cbuilder.run (
118+ input: buildInput,
119+ output: buildOutput,
120+ logger: logger,
84121 );
85122
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- });
123+ final libUri =
124+ tempUri.resolve (OS .windows.libraryFileName (name, linkMode));
125+ expect (await File .fromUri (libUri).exists (), true );
126+ final result = await runProcess (
127+ executable: dumpbinUri,
128+ arguments: ['/HEADERS' , libUri.toFilePath ()],
129+ logger: logger,
130+ );
131+ expect (result.exitCode, 0 );
132+ final machine = result.stdout
133+ .split ('\n ' )
134+ .firstWhere ((e) => e.contains ('machine' ));
135+ expect (machine, contains (dumpbinMachine[target]));
136+ final fileType = result.stdout
137+ .split ('\n ' )
138+ .firstWhere ((e) => e.contains ('File Type' ));
139+ expect (fileType, contains (dumpbinFileType[linkMode]));
140+ });
141+ }
119142 }
120143 }
121144}
0 commit comments