Skip to content

Commit 76ca835

Browse files
sstricklCommit Queue
authored andcommitted
[dartdev] Add tests for cross compilation.
Separated out from https://dart-review.googlesource.com/c/sdk/+/440224 because cross compilation requires the binaries to have been uploaded and so Windows -> Linux ARM would fail. TEST=pkg/dartdev/test/commands/compile_test.dart Issue: #28617 Change-Id: I0720bf259dbaf6c834e375c5948e22ab4bfbd38d Cq-Include-Trybots: luci.dart.try:pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try,dart-sdk-linux-riscv64-try,dart-sdk-linux-arm64-try,dart-sdk-linux-try,dart-sdk-mac-try,dart-sdk-win-arm64-try,dart-sdk-win-try,dart-sdk-mac-arm64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441200 Commit-Queue: Tess Strickland <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 1223a63 commit 76ca835

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

pkg/dartdev/test/commands/compile_test.dart

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,13 @@ String unsupportedTargetError(Target target) =>
3535
'Unsupported target platform $target';
3636

3737
void defineCompileTests() {
38-
final isRunningOnIA32 = Platform.version.contains('ia32');
38+
final host = Target.current;
39+
// AOT compilation is not available on IA32.
40+
final bool isRunningOnIA32 = host.architecture == Architecture.ia32;
41+
// Cross compilation is not available on 32-bit architectures.
42+
final bool isRunningOn32Bit = isRunningOnIA32 ||
43+
host.architecture == Architecture.arm ||
44+
host.architecture == Architecture.riscv32;
3945

4046
if (Platform.isMacOS) {
4147
test('Compile exe for MacOS signing', () async {
@@ -412,6 +418,65 @@ void defineCompileTests() {
412418
expect(result.exitCode, 0);
413419
}, skip: isRunningOnIA32);
414420

421+
Future<void> basicCrossCompileTest(Target target) async {
422+
final p = project(
423+
mainSrc: 'void main() {print(const String.fromEnvironment("cross"));}');
424+
final inFile = path.canonicalize(path.join(p.dirPath, p.relativeFilePath));
425+
final outFile = path.canonicalize(path.join(p.dirPath, 'myexe'));
426+
final result = await p.run(
427+
[
428+
'compile',
429+
'exe',
430+
'-v',
431+
'--target-os',
432+
target.os.name,
433+
'--target-arch',
434+
target.architecture.name,
435+
'-o',
436+
outFile,
437+
inFile,
438+
],
439+
);
440+
441+
if (result.exitCode != 0) {
442+
print('Subcommand terminated with exit code ${result.exitCode}.');
443+
if (result.stdout.isNotEmpty) {
444+
print('Subcommand stdout:');
445+
print(result.stdout);
446+
}
447+
if (result.stderr.isNotEmpty) {
448+
print('Subcommand stderr:');
449+
print(result.stderr);
450+
}
451+
}
452+
453+
expect(result.stdout,
454+
contains(usingTargetOSMessageForPlatform(target.os.name)));
455+
expect(result.stderr, isNot(contains(unsupportedTargetError(target))));
456+
expect(result.exitCode, 0);
457+
}
458+
459+
final crossCompileOSes = [
460+
OS.linux,
461+
];
462+
463+
final crossCompileArchitectures = [
464+
Architecture.arm,
465+
Architecture.arm64,
466+
Architecture.riscv64,
467+
Architecture.x64,
468+
];
469+
470+
for (final os in crossCompileOSes) {
471+
for (final arch in crossCompileArchitectures) {
472+
if (os == host.os && arch == host.architecture) continue;
473+
final target = Target.fromArchitectureAndOS(arch, os);
474+
test('Compile executable can cross compile to $os $arch',
475+
() async => basicCrossCompileTest(target),
476+
skip: isRunningOn32Bit);
477+
}
478+
}
479+
415480
test('Compile executable cannot compile cross-OS', () async {
416481
final p = project(
417482
mainSrc: 'void main() {print(const String.fromEnvironment("cross"));}');

0 commit comments

Comments
 (0)