Skip to content

Commit

Permalink
Make Dart build script feature-aware (#5264)
Browse files Browse the repository at this point in the history
  • Loading branch information
robertbastian committed Jul 23, 2024
1 parent 3c47d82 commit fb38fc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ffi/dart/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void main(List<String> args) async {

final path = '${config.outDir.path}/icu4x';

await buildLib(target, linkMode, path);
await buildLib(target, linkMode, 'default_components,experimental_components', path);

await BuildOutput(
assets: [
Expand Down
15 changes: 8 additions & 7 deletions ffi/dart/tool/build_libs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,19 @@ import 'dart:io';
Future<void> main(List<String> args) async {
if (args.isEmpty) {
print(
'Usage: ${Platform.script.pathSegments.last} <out_dir> <target:${Target.values}> (<link mode: ${LinkMode.values}>)');
'Usage: ${Platform.script.pathSegments.last} <out_dir> <target:${Target.values}> <link mode: ${LinkMode.values}> <cargo features>');
exit(1);
}
final out = Uri.file(args[0]).toFilePath();
final target = Target.values.firstWhere((t) => t.toString() == args[1]);
final linkMode = LinkMode.values.firstWhere(
(l) => l.toString() == (args.elementAtOrNull(2) ?? 'dynamic'));
final linkMode = LinkMode.values.firstWhere((l) => l.toString() == args[2]);
final cargoFeatures = args.elementAtOrNull(3) ?? 'default_components';

await buildLib(target, linkMode, out);
await buildLib(target, linkMode, cargoFeatures, out);
}

Future<void> buildLib(Target target, LinkMode linkMode, String outName) async {
Future<void> buildLib(
Target target, LinkMode linkMode, String cargoFeatures, String outName) async {
var root = Platform.script.toFilePath().split('ffi')[0];
root = root.substring(0, root.length - 1); // trim trailing slash

Expand Down Expand Up @@ -56,9 +57,9 @@ Future<void> buildLib(Target target, LinkMode linkMode, String outName) async {
'--config=profile.release.codegen-units=1',
'--no-default-features',
if (!isNoStd)
'--features=default_components,compiled_data,buffer_provider,logging,simple_logger',
'--features=compiled_data,buffer_provider,logging,simple_logger,$cargoFeatures',
if (isNoStd)
'--features=default_components,compiled_data,buffer_provider,libc-alloc,panic-handler',
'--features=compiled_data,buffer_provider,libc-alloc,panic-handler,$cargoFeatures',
if (isNoStd) '-Zbuild-std=core,alloc',
if (isNoStd) '-Zbuild-std-features=panic_immediate_abort',
'--target=$rustTarget',
Expand Down

0 comments on commit fb38fc8

Please sign in to comment.