Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkgs/native_toolchain_c/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.17.1-wip

* Skip Rust test when no toolchain is installed.

## 0.17.0

* Fix treeshaking on mac.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/native_toolchain_c/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: native_toolchain_c
description: >-
A library to invoke the native C compiler installed on the host machine.
version: 0.17.0
version: 0.17.1-wip
repository: https://github.com/dart-lang/native/tree/main/pkgs/native_toolchain_c

topics:
Expand Down
66 changes: 33 additions & 33 deletions pkgs/native_toolchain_c/test/clinker/rust_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,45 +17,48 @@ Future<void> main() async {
final linkOutputBuilder = LinkOutputBuilder();
final targetArchitecture = Architecture.current;
final targetOS = OS.current;
late final bool rustToolchainInstalled;
late var rustToolchainInstalled = false;
setUpAll(() async {
final tempUri = await tempDirForTest();
final tempUri2 = await tempDirForTest();
staticLib = tempUri.resolve(targetOS.staticlibFileName('libtest'));
final processResult = await Process.run('rustc', [
'--crate-type=staticlib',
'test/clinker/testfiles/linker/test.rs',
'-o',
staticLib.toFilePath(),
]);
rustToolchainInstalled = processResult.exitCode == 0;
try {
final processResult = await Process.run('rustc', [
'--crate-type=staticlib',
'test/clinker/testfiles/linker/test.rs',
'-o',
staticLib.toFilePath(),
]);
rustToolchainInstalled = processResult.exitCode == 0;
} catch (e, s) {
print('$e');
print('$s');
}
if (rustToolchainInstalled) {
await File.fromUri(
staticLib,
).copy(tempUri.resolve('libtest.a').toFilePath());
}
final linkInputBuilder = LinkInputBuilder()
..setupShared(
packageName: 'testpackage',
packageRoot: tempUri,
outputFile: tempUri.resolve('output.json'),
outputDirectoryShared: tempUri2,
)
..setupLink(assets: [], recordedUsesFile: null)
..addExtension(
CodeAssetExtension(
targetOS: targetOS,
targetArchitecture: targetArchitecture,
linkModePreference: LinkModePreference.dynamic,
),
);
} else {
final linkInputBuilder = LinkInputBuilder()
..setupShared(
packageName: 'testpackage',
packageRoot: tempUri,
outputFile: tempUri.resolve('output.json'),
outputDirectoryShared: tempUri2,
)
..setupLink(assets: [], recordedUsesFile: null)
..addExtension(
CodeAssetExtension(
targetOS: targetOS,
targetArchitecture: targetArchitecture,
linkModePreference: LinkModePreference.dynamic,
),
);

linkInput = linkInputBuilder.build();
linkInput = linkInputBuilder.build();
}
});
test('link rust binary with script treeshakes', () async {
if (!rustToolchainInstalled) {
return;
}
final treeshakeOption = LinkerOptions.treeshake(
symbolsToKeep: ['my_other_func'],
);
Expand All @@ -72,12 +75,9 @@ Future<void> main() async {
: false;
expect(symbols, contains('my_other_func'), skip: skipReason);
expect(symbols, isNot(contains('my_func')), skip: skipReason);
});
}, skip: !rustToolchainInstalled);

test('link rust binary without script keeps symbols', () async {
if (!rustToolchainInstalled) {
return;
}
final manualOption = LinkerOptions.manual(
symbolsToKeep: ['my_other_func'],
stripDebug: true,
Expand All @@ -96,7 +96,7 @@ Future<void> main() async {
: false;
expect(symbols, contains('my_other_func'), skip: skipReason);
expect(symbols, contains('my_func'), skip: skipReason);
});
}, skip: !rustToolchainInstalled);
}

Future<String?> _link(
Expand Down
Loading