Skip to content

Commit

Permalink
Fix stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Aug 22, 2024
1 parent bde4c53 commit 9d0061a
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 54 deletions.
54 changes: 41 additions & 13 deletions .github/workflows/intl4x.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,30 +32,32 @@ jobs:
matrix:
sdk: [dev]
os: [ubuntu-latest, windows-latest, macos-latest]
include:
- sdk: dev
run-tests: true

steps:
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
with:
submodules: true

- uses: dart-lang/setup-dart@0a8a0fc875eb934c15d08629302413c671d3f672
with:
sdk: ${{matrix.sdk}}
sdk: ${{ matrix.sdk }}

- run: dart --enable-experiment=native-assets pub get

- run: dart --enable-experiment=native-assets analyze --fatal-infos

- run: dart --enable-experiment=native-assets format --output=none --set-exit-if-changed .
if: ${{matrix.run-tests}}

- run: dart --enable-experiment=native-assets test
if: ${{matrix.run-tests}}

- run: dart --enable-experiment=native-assets test -p chrome
if: ${{matrix.run-tests}}

- name: Compile and run example
run: |
cd example_native
dart --enable-experiment=native-assets pub get
dart --enable-experiment=native-assets build bin/example_native.dart
./bin/example_native.exe
build_fetch:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -84,11 +86,19 @@ jobs:

- run: dart --enable-experiment=native-assets test

- name: Compile and run example
run: |
cd example_native
dart --enable-experiment=native-assets pub get
dart --enable-experiment=native-assets build bin/example_native.dart
./bin/example_native.exe
build_local:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
compiletype: [ dynamic, static ]
runs-on: ${{ matrix.os }}

env:
Expand Down Expand Up @@ -120,7 +130,7 @@ jobs:
cd ffi/dart
dart pub get
cd ../..
dart run ffi/dart/tool/build_libs.dart bin/linux_x64 linux_x64 dynamic icu_collator,icu_datetime,icu_list,icu_decimal,icu_plurals,experimental_components,compiled_data
dart run ffi/dart/tool/build_libs.dart bin/linux_x64 linux_x64 ${{ matrix.compiletype }} icu_collator,icu_datetime,icu_list,icu_decimal,icu_plurals,experimental_components,compiled_data
- name: Build Mac
if: matrix.os == 'macos-latest'
Expand All @@ -132,7 +142,7 @@ jobs:
cd ffi/dart
dart pub get
cd ../..
dart run ffi/dart/tool/build_libs.dart bin/macos_arm64 macos_arm64 dynamic icu_collator,icu_datetime,icu_list,icu_decimal,icu_plurals,experimental_components,compiled_data
dart run ffi/dart/tool/build_libs.dart bin/macos_arm64 macos_arm64 ${{ matrix.compiletype }} icu_collator,icu_datetime,icu_list,icu_decimal,icu_plurals,experimental_components,compiled_data
- name: Build Windows
if: matrix.os == 'windows-latest'
Expand All @@ -144,18 +154,29 @@ jobs:
cd ffi/dart
dart pub get
cd ../..
dart run ffi/dart/tool/build_libs.dart bin/windows_x64 windows_x64 dynamic icu_collator,icu_datetime,icu_list,icu_decimal,icu_plurals,experimental_components,compiled_data
dart run ffi/dart/tool/build_libs.dart bin/windows_x64 windows_x64 ${{ matrix.compiletype }} icu_collator,icu_datetime,icu_list,icu_decimal,icu_plurals,experimental_components,compiled_data
- run: echo "LOCAL_ICU4X_BINARY_DYNAMIC=$(realpath submodules/icu4x/bin/linux_x64)" >> $GITHUB_ENV
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'ubuntu-latest' && ${{ matrix.compiletype }} == 'dynamic'

- run: echo "LOCAL_ICU4X_BINARY_STATIC=$(realpath submodules/icu4x/bin/linux_x64)" >> $GITHUB_ENV
if: matrix.os == 'ubuntu-latest' && ${{ matrix.compiletype }} == 'static'

- run: echo "LOCAL_ICU4X_BINARY_DYNAMIC=$(realpath submodules/icu4x/bin/macos_arm64)" >> $GITHUB_ENV
if: matrix.os == 'macos-latest'
if: matrix.os == 'macos-latest' && ${{ matrix.compiletype }} == 'dynamic'

- run: echo "LOCAL_ICU4X_BINARY_STATIC=$(realpath submodules/icu4x/bin/macos_arm64)" >> $GITHUB_ENV
if: matrix.os == 'macos-latest' && ${{ matrix.compiletype }} == 'static'

- run: echo ("LOCAL_ICU4X_BINARY_DYNAMIC=" + (Get-Item submodules\icu4x\bin\windows_x64).FullName -replace '/', '\') >> $env:GITHUB_ENV
if: matrix.os == 'windows-latest'
if: matrix.os == 'windows-latest' && ${{ matrix.compiletype }} == 'dynamic'

- run: echo ("LOCAL_ICU4X_BINARY_STATIC=" + (Get-Item submodules\icu4x\bin\windows_x64).FullName -replace '/', '\') >> $env:GITHUB_ENV
if: matrix.os == 'windows-latest' && ${{ matrix.compiletype }} == 'static'

- run: echo $LOCAL_ICU4X_BINARY_DYNAMIC

- run: echo $LOCAL_ICU4X_BINARY_STATIC

- name: Display structure of downloaded files
run: ls -R
Expand All @@ -169,3 +190,10 @@ jobs:
run: |
cd pkgs/intl4x
dart --enable-experiment=native-assets test
- name: Compile and run example
run: |
cd pkgs/intl4x/example_native
dart --enable-experiment=native-assets pub get
dart --enable-experiment=native-assets build bin/example_native.dart
./bin/example_native.exe
101 changes: 60 additions & 41 deletions pkgs/intl4x/hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -240,31 +240,16 @@ Future<BuildResult> buildLib(
final datagenFileUri = config.outputDirectory.resolve('datagen');
final postcardFileUri = config.outputDirectory.resolve('postcard');
if (!config.dryRun) {
final rustTarget = _asRustTarget(
config.targetOS,
config.dryRun ? null : config.targetArchitecture!,
config.targetOS == OS.iOS &&
config.targetIOSSdk == IOSSdk.iPhoneSimulator,
);
final isNoStd =
_isNoStdTarget((config.targetOS, config.targetArchitecture));

if (!isNoStd) {
final rustArguments = ['target', 'add', rustTarget];
final rustup = await Process.run(
final rustArguments = ['target', 'add', asRustTarget(config)];
await runProcess(
'rustup',
rustArguments,
workingDirectory: workingDirectory,
);

if (rustup.exitCode != 0) {
throw ProcessException(
'rustup',
rustArguments,
rustup.stderr.toString(),
rustup.exitCode,
);
}
}
final tempDir = await Directory.systemTemp.createTemp();

Expand Down Expand Up @@ -298,35 +283,26 @@ Future<BuildResult> buildLib(
if (isNoStd) '--features=${noStdFeatures.join(',')}',
if (isNoStd) '-Zbuild-std=core,alloc',
if (isNoStd) '-Zbuild-std-features=panic_immediate_abort',
'--target=$rustTarget',
'--target=${asRustTarget(config)}',
'--target-dir=${tempDir.path}'
];
final cargo = await Process.run(
await runProcess(
'cargo',
arguments,
workingDirectory: workingDirectory,
);

if (cargo.exitCode != 0) {
throw ProcessException(
'cargo',
arguments,
cargo.stderr.toString(),
cargo.exitCode,
);
}

final builtPath = path.join(
tempDir.path,
rustTarget,
asRustTarget(config),
'release',
libFileName,
);
await copyFile(builtPath, libFileUri);

if (config.linkingEnabled) {
final postcardPath = path.join(tempDir.path, 'full.postcard');
await Process.run(
await runProcess(
'cargo',
[
'run',
Expand All @@ -341,26 +317,31 @@ Future<BuildResult> buildLib(
);
await copyFile(postcardPath, postcardFileUri);

final datagenPath = path.join(tempDir.path, 'datagen');
final datagenPath = path.join(
tempDir.path,
asRustTarget(config),
'release',
'icu4x-datagen',
);
final datagenDirectory = path.join(workingDirectory, 'provider/datagen');
await Process.run(
await runProcess(
'rustup',
['target', 'add', 'aarch64-unknown-linux-gnu'],
['target', 'add', asRustTarget(config)],
workingDirectory: datagenDirectory,
);
await Process.run(
await runProcess(
'cargo',
[
'build',
'--release',
'--bin',
'icu4x-datagen',
...['--bin', 'icu4x-datagen'],
'--no-default-features',
...[
'--features',
'bin,blob_exporter,blob_input,rayon,experimental_components'
],
...['--target', 'aarch64-unknown-linux-gnu']
...['--target', asRustTarget(config)],
'--target-dir=${tempDir.path}'
],
workingDirectory: datagenDirectory,
);
Expand All @@ -374,6 +355,15 @@ Future<BuildResult> buildLib(
);
}

String asRustTarget(BuildConfig config) {
final rustTarget = _asRustTarget(
config.targetOS,
config.dryRun ? null : config.targetArchitecture!,
config.targetOS == OS.iOS && config.targetIOSSdk == IOSSdk.iPhoneSimulator,
);
return rustTarget;
}

String _asRustTarget(OS os, Architecture? architecture, bool isSimulator) {
if (os == OS.iOS && architecture == Architecture.arm64 && isSimulator) {
return 'aarch64-apple-ios-sim';
Expand Down Expand Up @@ -416,10 +406,39 @@ extension on BuildConfig {
buildStatic ? targetOS.staticlibFileName : targetOS.dylibFileName;
}

Future<void> copyFile(String path, Uri libFileUri) async {
final file = File(path);
Future<void> copyFile(String from, Uri to) async {
final file = File(from);
if (!(await file.exists())) {
throw FileSystemException('File does not exist.', path);
throw FileSystemException('File does not exist.', from);
}
await file.copy(to.toFilePath(windows: Platform.isWindows));
}

Future<void> runProcess(
String executable,
List<String> arguments, {
required String workingDirectory,
bool dryRun = false,
}) async {
print('----------');
print('Running `$executable $arguments` in $workingDirectory');
if (!dryRun) {
final processResult = await Process.run(
executable,
arguments,
workingDirectory: workingDirectory,
);
print('stdout:');
print(processResult.stdout);
if ((processResult.stderr as String).isNotEmpty) {
print('stderr:');
print(processResult.stderr);
}
if (processResult.exitCode != 0) {
throw ProcessException(executable, arguments, '', processResult.exitCode);
}
} else {
print('Not running, as --dry-run is set.');
}
await file.copy(libFileUri.toFilePath(windows: Platform.isWindows));
print('==========');
}

0 comments on commit 9d0061a

Please sign in to comment.