From e73fca260f38d21aaa403a0f3511cd6a89dba6da Mon Sep 17 00:00:00 2001 From: Moritz Date: Thu, 13 Jun 2024 14:59:28 +0200 Subject: [PATCH] Fix dependencies in intl4x (#849) * Fix dependencies in intl4x * Adapt version in pubspec * Swtich to real version --- pkgs/intl4x/CHANGELOG.md | 4 + pkgs/intl4x/hook/build.dart | 183 ++++++++++++++++++++---------------- pkgs/intl4x/pubspec.yaml | 6 +- 3 files changed, 107 insertions(+), 86 deletions(-) diff --git a/pkgs/intl4x/CHANGELOG.md b/pkgs/intl4x/CHANGELOG.md index 9c64489d..3d446163 100644 --- a/pkgs/intl4x/CHANGELOG.md +++ b/pkgs/intl4x/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.9.1 + +- Small fixes in imports + ## 0.9.0 - Update for `icu4x` and `build.dart` changes. diff --git a/pkgs/intl4x/hook/build.dart b/pkgs/intl4x/hook/build.dart index d7d9568d..82d0fba3 100644 --- a/pkgs/intl4x/hook/build.dart +++ b/pkgs/intl4x/hook/build.dart @@ -17,7 +17,7 @@ void main(List args) async { final buildMode = switch (Platform.environment['ICU4X_BUILD_MODE']) { 'local' => LocalMode(), 'checkout' => CheckoutMode(config), - 'fetch' || null => FetchMode(), + 'fetch' || null => FetchMode(config), String() => throw ArgumentError(''' @@ -36,7 +36,7 @@ Unknown build mode for icu4x. Set the `ICU4X_BUILD_MODE` environment variable wi name: assetId, linkMode: DynamicLoadingBundled(), architecture: config.targetArchitecture, - os: OS.current, + os: config.targetOS, file: builtLibrary, )); @@ -70,20 +70,27 @@ sealed class BuildMode { } final class FetchMode implements BuildMode { + final BuildConfig config; + + FetchMode(this.config); + @override Future build() async { // TODO: Get a nicer CDN than a generated link to a privately owned repo. - final request = await HttpClient().getUrl(Uri.parse( - 'https://nightly.link/mosuem/i18n/workflows/intl4x_artifacts/main/lib-$platformName-latest.zip')); + final uri = Uri.parse( + 'https://nightly.link/mosuem/i18n/workflows/intl4x_artifacts/main/lib-$platformName-latest.zip'); + final request = await HttpClient().getUrl(uri); final response = await request.close(); - + if (response.statusCode != 200) { + throw ArgumentError('The request to $uri failed'); + } final zippedDynamicLibrary = File(path.join(Directory.systemTemp.path, 'tmp.zip')); zippedDynamicLibrary.createSync(); await response.pipe(zippedDynamicLibrary.openWrite()); - final directory = await Directory.systemTemp.createTemp(); - final dynamicLibrary = File.fromUri(directory.uri.resolve('icu4xlib')); + final dynamicLibrary = + File.fromUri(config.outputDirectory.resolve('icu4xlib')); await dynamicLibrary.create(); unzipFirstFile(input: zippedDynamicLibrary, output: dynamicLibrary); return dynamicLibrary.uri; @@ -136,92 +143,101 @@ final class CheckoutMode implements BuildMode { } Future buildLib(BuildConfig config, String workingDirectory) async { - final rustTarget = _asRustTarget( - config.targetOS, - 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( - 'rustup', - rustArguments, - workingDirectory: workingDirectory, + final dylibFileName = + config.targetOS.dylibFileName(crateName.replaceAll('-', '_')); + final dylibFileUri = config.outputDirectory.resolve(dylibFileName); + 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 (rustup.exitCode != 0) { - throw ProcessException( + if (!isNoStd) { + final rustArguments = ['target', 'add', rustTarget]; + final rustup = await Process.run( 'rustup', rustArguments, - rustup.stderr.toString(), - rustup.exitCode, + workingDirectory: workingDirectory, ); - } - } - final stdFeatures = [ - 'default_components', - 'compiled_data', - 'buffer_provider', - 'logging', - 'simple_logger', - 'experimental_components', - ]; - final noStdFeatures = [ - 'default_components', - 'compiled_data', - 'buffer_provider', - 'libc-alloc', - 'panic-handler', - 'experimental_components', - ]; - final tempDir = Directory.systemTemp.createTempSync(); - final linkModeType = config.linkModePreference == LinkModePreference.static - ? 'staticlib' - : 'cdylib'; - final arguments = [ - if (isNoStd) '+nightly', - 'rustc', - '-p=$crateName', - '--crate-type=$linkModeType', - '--release', - '--config=profile.release.panic="abort"', - '--config=profile.release.codegen-units=1', - '--no-default-features', - if (!isNoStd) '--features=${stdFeatures.join(',')}', - if (isNoStd) '--features=${noStdFeatures.join(',')}', - if (isNoStd) '-Zbuild-std=core,alloc', - if (isNoStd) '-Zbuild-std-features=panic_immediate_abort', - '--target=$rustTarget', - '--target-dir=${tempDir.path}' - ]; - final cargo = await Process.run( - 'cargo', - arguments, - workingDirectory: workingDirectory, - ); - - if (cargo.exitCode != 0) { - throw ProcessException( + if (rustup.exitCode != 0) { + throw ProcessException( + 'rustup', + rustArguments, + rustup.stderr.toString(), + rustup.exitCode, + ); + } + } + final tempDir = await Directory.systemTemp.createTemp(); + + final stdFeatures = [ + 'default_components', + 'compiled_data', + 'buffer_provider', + 'logging', + 'simple_logger', + 'experimental_components', + ]; + final noStdFeatures = [ + 'default_components', + 'compiled_data', + 'buffer_provider', + 'libc-alloc', + 'panic-handler', + 'experimental_components', + ]; + final linkModeType = config.linkModePreference == LinkModePreference.static + ? 'staticlib' + : 'cdylib'; + final arguments = [ + if (isNoStd) '+nightly', + 'rustc', + '-p=$crateName', + '--crate-type=$linkModeType', + '--release', + '--config=profile.release.panic="abort"', + '--config=profile.release.codegen-units=1', + '--no-default-features', + if (!isNoStd) '--features=${stdFeatures.join(',')}', + if (isNoStd) '--features=${noStdFeatures.join(',')}', + if (isNoStd) '-Zbuild-std=core,alloc', + if (isNoStd) '-Zbuild-std-features=panic_immediate_abort', + '--target=$rustTarget', + '--target-dir=${tempDir.path}' + ]; + final cargo = await Process.run( 'cargo', arguments, - cargo.stderr.toString(), - cargo.exitCode, + workingDirectory: workingDirectory, ); - } - final dylibFilePath = path.join( - tempDir.path, - rustTarget, - 'release', - config.targetOS.dylibFileName(crateName.replaceAll('-', '_')), - ); - if (!File(dylibFilePath).existsSync()) { - throw FileSystemException('Building the dylib failed', dylibFilePath); + if (cargo.exitCode != 0) { + throw ProcessException( + 'cargo', + arguments, + cargo.stderr.toString(), + cargo.exitCode, + ); + } + + final builtPath = path.join( + tempDir.path, + rustTarget, + 'release', + dylibFileName, + ); + final file = File(builtPath); + if (!(await file.exists())) { + throw FileSystemException('Building the dylib failed', builtPath); + } + await file.copy(dylibFileUri.path); } - return Uri.file(dylibFilePath); + return dylibFileUri; } String _asRustTarget(OS os, Architecture? architecture, bool isSimulator) { @@ -249,7 +265,8 @@ String _asRustTarget(OS os, Architecture? architecture, bool isSimulator) { (OS.windows, Architecture.arm64) => 'aarch64-pc-windows-msvc', (OS.windows, Architecture.ia32) => 'i686-pc-windows-msvc', (OS.windows, Architecture.x64) => 'x86_64-pc-windows-msvc', - (_, _) => throw UnimplementedError('Target not available for rust'), + (_, _) => throw UnimplementedError( + 'Target ${(os, architecture)} not available for rust'), }; } diff --git a/pkgs/intl4x/pubspec.yaml b/pkgs/intl4x/pubspec.yaml index 09af2d6d..85647277 100644 --- a/pkgs/intl4x/pubspec.yaml +++ b/pkgs/intl4x/pubspec.yaml @@ -1,7 +1,7 @@ name: intl4x description: >- A lightweight modular library for internationalization (i18n) functionality. -version: 0.9.0 +version: 0.9.1 repository: https://github.com/dart-lang/i18n/tree/main/pkgs/intl4x platforms: web: @@ -17,16 +17,16 @@ environment: sdk: ">=3.3.0 <4.0.0" dependencies: + archive: ^3.4.10 ffi: ^2.1.0 js: ^0.7.1 meta: ^1.12.0 native_assets_cli: ^0.6.0 + path: ^1.9.0 dev_dependencies: - archive: ^3.4.10 args: ^2.4.2 collection: ^1.18.0 dart_flutter_team_lints: ^3.1.0 lints: ^4.0.0 - path: ^1.9.0 test: ^1.22.1