From 25421083e8be79ec6e64fd06ff3a2a6399f2f0f8 Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Wed, 11 Dec 2024 21:20:58 +0100 Subject: [PATCH] [native_assets_cli] Move `targetOS` to `CodeConfig` (#1806) Next refactoring in: * https://github.com/dart-lang/native/issues/1738 We move `config.targetOS` to `config.codeConfig.targetOS`. Other asset types might not get access on the target OS. This will require a manual roll into dartdev and flutter tools due to the targetOS now having to be passed in via `setupCodeConfig` instead of the base config. The native assets builder will still emit the same JSON if code assets are supported. Since both Dart and Flutter support code assets currently, this will not break anything. Once data assets for web in Flutter are added, all existing build hooks that assume code assets are always supported will break. --- pkgs/native_assets_builder/CHANGELOG.md | 2 + .../lib/src/build_runner/build_runner.dart | 4 - .../build_runner_reusability_test.dart | 3 +- .../concurrency_shared_test_helper.dart | 10 +- .../build_runner/concurrency_test_helper.dart | 2 +- .../test/build_runner/helpers.dart | 8 +- .../native_dynamic_linking_test.dart | 2 +- .../test/test_data/transformer_test.dart | 2 +- .../fail_on_os_sdk_version/hook/build.dart | 6 +- .../hook/link.dart | 6 +- pkgs/native_assets_cli/CHANGELOG.md | 2 + .../example/build/local_asset/hook/build.dart | 2 +- pkgs/native_assets_cli/lib/code_assets.dart | 1 + .../lib/native_assets_cli.dart | 1 - pkgs/native_assets_cli/lib/src/api/build.dart | 2 +- .../lib/src/code_assets/code_asset.dart | 3 +- .../lib/src/code_assets/config.dart | 13 +- .../lib/src/{ => code_assets}/os.dart | 0 .../lib/src/code_assets/testing.dart | 2 +- .../lib/src/code_assets/validation.dart | 8 +- pkgs/native_assets_cli/lib/src/config.dart | 9 +- .../lib/src/model/build_config_CHANGELOG.md | 8 ++ pkgs/native_assets_cli/lib/src/target.dart | 2 +- pkgs/native_assets_cli/lib/test.dart | 2 - .../test/api/build_test.dart | 1 - .../test/build_config_test.dart | 6 - .../native_assets_cli/test/checksum_test.dart | 136 ++++++++++++------ .../test/code_assets/config_test.dart | 6 +- .../test/code_assets/validation_test.dart | 52 ++++--- .../test/data_assets/validation_test.dart | 1 - .../test/example/local_asset_test.dart | 9 +- .../test/example/native_add_library_test.dart | 9 +- .../example/native_dynamic_linking_test.dart | 2 +- .../test/link_config_test.dart | 3 - .../test/validation_test.dart | 1 - .../lib/src/cbuilder/cbuilder.dart | 9 +- .../lib/src/cbuilder/clinker.dart | 8 +- .../lib/src/cbuilder/compiler_resolver.dart | 14 +- .../lib/src/cbuilder/ctool.dart | 2 +- .../lib/src/cbuilder/run_cbuilder.dart | 30 ++-- .../cbuilder/cbuilder_build_failure_test.dart | 2 +- .../cbuilder/cbuilder_cross_android_test.dart | 2 +- .../cbuilder/cbuilder_cross_ios_test.dart | 4 +- .../cbuilder_cross_linux_host_test.dart | 2 +- .../cbuilder_cross_macos_host_test.dart | 4 +- .../cbuilder_cross_windows_host_test.dart | 2 +- .../test/cbuilder/cbuilder_test.dart | 30 ++-- .../test/cbuilder/compiler_resolver_test.dart | 11 +- .../test/cbuilder/objective_c_test.dart | 2 +- .../test/clinker/build_testfiles.dart | 2 +- .../test/clinker/objects_test.dart | 2 +- .../test/clinker/throws_test.dart | 2 +- .../test/clinker/treeshake_helper.dart | 2 +- 53 files changed, 251 insertions(+), 205 deletions(-) rename pkgs/native_assets_cli/lib/src/{ => code_assets}/os.dart (100%) diff --git a/pkgs/native_assets_builder/CHANGELOG.md b/pkgs/native_assets_builder/CHANGELOG.md index 97f2bf472..d10ec539d 100644 --- a/pkgs/native_assets_builder/CHANGELOG.md +++ b/pkgs/native_assets_builder/CHANGELOG.md @@ -2,6 +2,8 @@ - Removed support for dry run (Flutter no long requires it). - Various fixes to caching. +- **Breaking change** `BuildConfig.targetOS` is now only provided if + `buildAssetTypes` contains the code asset. ## 0.9.0 diff --git a/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart b/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart index b3a20931f..8f86b49f9 100644 --- a/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart +++ b/pkgs/native_assets_builder/lib/src/build_runner/build_runner.dart @@ -92,7 +92,6 @@ class NativeAssetsBuildRunner { required BuildConfigValidator configValidator, required BuildValidator buildValidator, required ApplicationAssetValidator applicationAssetValidator, - required OS targetOS, required Uri workingDirectory, PackageLayout? packageLayout, String? runPackageName, @@ -121,7 +120,6 @@ class NativeAssetsBuildRunner { final configBuilder = configCreator() ..setupHookConfig( - targetOS: targetOS, buildAssetTypes: buildAssetTypes, packageName: package.name, packageRoot: packageLayout.packageRoot(package.name), @@ -197,7 +195,6 @@ class NativeAssetsBuildRunner { required LinkConfigCreator configCreator, required LinkConfigValidator configValidator, required LinkValidator linkValidator, - required OS targetOS, required Uri workingDirectory, required ApplicationAssetValidator applicationAssetValidator, PackageLayout? packageLayout, @@ -220,7 +217,6 @@ class NativeAssetsBuildRunner { for (final package in buildPlan) { final configBuilder = configCreator() ..setupHookConfig( - targetOS: targetOS, buildAssetTypes: buildAssetTypes, packageName: package.name, packageRoot: packageLayout.packageRoot(package.name), diff --git a/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart b/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart index d279a12ae..aa7356a6c 100644 --- a/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart +++ b/pkgs/native_assets_builder/test/build_runner/build_runner_reusability_test.dart @@ -30,12 +30,12 @@ void main() async { BuildConfigBuilder configCreator() => BuildConfigBuilder() ..setupCodeConfig( targetArchitecture: Architecture.current, + targetOS: OS.current, linkModePreference: LinkModePreference.dynamic, ); await buildRunner.build( configCreator: configCreator, - targetOS: OS.current, workingDirectory: packageUri, linkingEnabled: false, buildAssetTypes: [], @@ -45,7 +45,6 @@ void main() async { ); await buildRunner.build( configCreator: configCreator, - targetOS: OS.current, workingDirectory: packageUri, linkingEnabled: false, buildAssetTypes: [], diff --git a/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test_helper.dart b/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test_helper.dart index e741bfa13..d31b8c434 100644 --- a/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test_helper.dart +++ b/pkgs/native_assets_builder/test/build_runner/concurrency_shared_test_helper.dart @@ -20,8 +20,14 @@ void main(List args) async { logger: logger, dartExecutable: dartExecutable, ).build( - configCreator: BuildConfigBuilder.new, - targetOS: target.os, + // Set up the code config, so that the builds for different targets are + // in different directories. + configCreator: () => BuildConfigBuilder() + ..setupCodeConfig( + targetArchitecture: target.architecture, + targetOS: target.os, + linkModePreference: LinkModePreference.dynamic, + ), workingDirectory: packageUri, linkingEnabled: false, buildAssetTypes: [DataAsset.type], diff --git a/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart b/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart index 9a680232b..75d2cb096 100644 --- a/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart +++ b/pkgs/native_assets_builder/test/build_runner/concurrency_test_helper.dart @@ -28,11 +28,11 @@ void main(List args) async { configCreator: () => BuildConfigBuilder() ..setupCodeConfig( targetArchitecture: Architecture.current, + targetOS: OS.current, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: dartCICompilerConfig, targetMacOSVersion: OS.current == OS.macOS ? defaultMacOSVersion : null, ), - targetOS: OS.current, workingDirectory: packageUri, linkingEnabled: false, buildAssetTypes: [CodeAsset.type, DataAsset.type], diff --git a/pkgs/native_assets_builder/test/build_runner/helpers.dart b/pkgs/native_assets_builder/test/build_runner/helpers.dart index 275ec9c9a..6be66afea 100644 --- a/pkgs/native_assets_builder/test/build_runner/helpers.dart +++ b/pkgs/native_assets_builder/test/build_runner/helpers.dart @@ -59,6 +59,7 @@ Future build( if (buildAssetTypes.contains(CodeAsset.type)) { configBuilder.setupCodeConfig( targetArchitecture: target?.architecture ?? Architecture.current, + targetOS: targetOS, linkModePreference: linkModePreference, cCompilerConfig: cCompilerConfig ?? dartCICompilerConfig, targetIOSSdk: targetIOSSdk, @@ -71,7 +72,6 @@ Future build( return configBuilder; }, configValidator: configValidator, - targetOS: targetOS, workingDirectory: packageUri, packageLayout: packageLayout, runPackageName: runPackageName, @@ -124,6 +124,7 @@ Future link( if (buildAssetTypes.contains(CodeAsset.type)) { configBuilder.setupCodeConfig( targetArchitecture: target?.architecture ?? Architecture.current, + targetOS: target?.os ?? OS.current, linkModePreference: linkModePreference, cCompilerConfig: cCompilerConfig ?? dartCICompilerConfig, targetIOSSdk: targetIOSSdk, @@ -136,7 +137,6 @@ Future link( return configBuilder; }, configValidator: configValidator, - targetOS: target?.os ?? OS.current, workingDirectory: packageUri, packageLayout: packageLayout, buildResult: buildResult, @@ -185,6 +185,7 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( configCreator: () => BuildConfigBuilder() ..setupCodeConfig( targetArchitecture: target?.architecture ?? Architecture.current, + targetOS: target?.os ?? OS.current, linkModePreference: linkModePreference, cCompilerConfig: cCompilerConfig ?? dartCICompilerConfig, targetIOSSdk: targetIOSSdk, @@ -193,7 +194,6 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( targetAndroidNdkApi: targetAndroidNdkApi, ), configValidator: buildConfigValidator, - targetOS: target?.os ?? OS.current, workingDirectory: packageUri, packageLayout: packageLayout, runPackageName: runPackageName, @@ -217,6 +217,7 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( configCreator: () => LinkConfigBuilder() ..setupCodeConfig( targetArchitecture: target?.architecture ?? Architecture.current, + targetOS: target?.os ?? OS.current, linkModePreference: linkModePreference, cCompilerConfig: cCompilerConfig, targetIOSSdk: targetIOSSdk, @@ -225,7 +226,6 @@ Future<(BuildResult?, LinkResult?)> buildAndLink( targetAndroidNdkApi: targetAndroidNdkApi, ), configValidator: linkConfigValidator, - targetOS: target?.os ?? OS.current, workingDirectory: packageUri, packageLayout: packageLayout, buildResult: buildResult, diff --git a/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart b/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart index a2b167d12..2e35c3b13 100644 --- a/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart +++ b/pkgs/native_assets_builder/test/test_data/native_dynamic_linking_test.dart @@ -34,7 +34,6 @@ void main() async { ..setupHookConfig( packageName: name, packageRoot: testPackageUri, - targetOS: OS.current, buildAssetTypes: [CodeAsset.type], ) ..setupBuildConfig(dryRun: false, linkingEnabled: false) @@ -44,6 +43,7 @@ void main() async { ) ..setupCodeConfig( targetArchitecture: Architecture.current, + targetOS: OS.current, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: cCompiler, ); diff --git a/pkgs/native_assets_builder/test/test_data/transformer_test.dart b/pkgs/native_assets_builder/test/test_data/transformer_test.dart index c965e136d..05d2b868c 100644 --- a/pkgs/native_assets_builder/test/test_data/transformer_test.dart +++ b/pkgs/native_assets_builder/test/test_data/transformer_test.dart @@ -49,7 +49,6 @@ void main() async { ..setupHookConfig( packageName: packageName, packageRoot: packageUri, - targetOS: OS.current, buildAssetTypes: [DataAsset.type], ) ..setupBuildConfig(dryRun: false, linkingEnabled: false) @@ -59,6 +58,7 @@ void main() async { ) ..setupCodeConfig( targetArchitecture: architecture, + targetOS: OS.current, linkModePreference: LinkModePreference.dynamic, ); diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/hook/build.dart b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/hook/build.dart index 177b2d794..d774f5e13 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/hook/build.dart +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version/hook/build.dart @@ -14,7 +14,7 @@ const minMacOSVersionForThisPackage = 13; void main(List arguments) async { await build(arguments, (config, output) async { - if (config.targetOS == OS.android) { + if (config.codeConfig.targetOS == OS.android) { if (config.codeConfig.targetAndroidNdkApi! < minNdkApiVersionForThisPackage) { throw UnsupportedError( @@ -22,7 +22,7 @@ void main(List arguments) async { 'least Android NDK API level $minNdkApiVersionForThisPackage.', ); } - } else if (config.targetOS == OS.iOS) { + } else if (config.codeConfig.targetOS == OS.iOS) { final iosVersion = config.codeConfig.targetIOSVersion; // iosVersion is nullable to deal with version skew. if (iosVersion != null && iosVersion < minIosVersionForThisPackage) { @@ -31,7 +31,7 @@ void main(List arguments) async { 'least iOS version $minIosVersionForThisPackage.', ); } - } else if (config.targetOS == OS.macOS) { + } else if (config.codeConfig.targetOS == OS.macOS) { final macosVersion = config.codeConfig.targetMacOSVersion; // macosVersion is nullable to deal with version skew. if (macosVersion != null && diff --git a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/hook/link.dart b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/hook/link.dart index 27aec5e37..a4603499f 100644 --- a/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/hook/link.dart +++ b/pkgs/native_assets_builder/test_data/fail_on_os_sdk_version_linker/hook/link.dart @@ -14,7 +14,7 @@ const minMacOSVersionForThisPackage = 13; void main(List arguments) async { await link(arguments, (config, output) async { - if (config.targetOS == OS.android) { + if (config.codeConfig.targetOS == OS.android) { if (config.codeConfig.targetAndroidNdkApi! < minNdkApiVersionForThisPackage) { throw UnsupportedError( @@ -22,7 +22,7 @@ void main(List arguments) async { 'least Android NDK API level $minNdkApiVersionForThisPackage.', ); } - } else if (config.targetOS == OS.iOS) { + } else if (config.codeConfig.targetOS == OS.iOS) { final iosVersion = config.codeConfig.targetIOSVersion; // iosVersion is nullable to deal with version skew. if (iosVersion != null && iosVersion < minIosVersionForThisPackage) { @@ -31,7 +31,7 @@ void main(List arguments) async { 'least iOS version $minIosVersionForThisPackage.', ); } - } else if (config.targetOS == OS.macOS) { + } else if (config.codeConfig.targetOS == OS.macOS) { final macosVersion = config.codeConfig.targetMacOSVersion; // macosVersion is nullable to deal with version skew. if (macosVersion != null && diff --git a/pkgs/native_assets_cli/CHANGELOG.md b/pkgs/native_assets_cli/CHANGELOG.md index 20a84d7d7..4d01bed7a 100644 --- a/pkgs/native_assets_cli/CHANGELOG.md +++ b/pkgs/native_assets_cli/CHANGELOG.md @@ -9,6 +9,8 @@ it can be controlled in the build hook together with the `OptimizationLevel`. Most likely, every package should ship with `release`. `BuildMode.debug` should only be used while developing the package locally. +- **Breaking change** Move `HookConfig.targetOS` to `CodeConfig`. `DataAsset`s + and other asset types might now support varying on the target OS. - **Breaking change**: Change the behavior of `testBuildHook` and `testCodeBuildHook`; instead of defining tests, these methods should now be called from within tests. diff --git a/pkgs/native_assets_cli/example/build/local_asset/hook/build.dart b/pkgs/native_assets_cli/example/build/local_asset/hook/build.dart index 3e61c0c4a..9547ac51b 100644 --- a/pkgs/native_assets_cli/example/build/local_asset/hook/build.dart +++ b/pkgs/native_assets_cli/example/build/local_asset/hook/build.dart @@ -38,7 +38,7 @@ Future main(List args) async { name: 'asset.txt', file: assetPath, linkMode: DynamicLoadingBundled(), - os: config.targetOS, + os: config.codeConfig.targetOS, architecture: // ignore: deprecated_member_use config.dryRun ? null : config.codeConfig.targetArchitecture, diff --git a/pkgs/native_assets_cli/lib/code_assets.dart b/pkgs/native_assets_cli/lib/code_assets.dart index 0e84016a7..82c32b6d5 100644 --- a/pkgs/native_assets_cli/lib/code_assets.dart +++ b/pkgs/native_assets_cli/lib/code_assets.dart @@ -32,3 +32,4 @@ export 'src/code_assets/link_mode.dart' LookupInProcess, StaticLinking; export 'src/code_assets/link_mode_preference.dart' show LinkModePreference; +export 'src/code_assets/os.dart' show OS; diff --git a/pkgs/native_assets_cli/lib/native_assets_cli.dart b/pkgs/native_assets_cli/lib/native_assets_cli.dart index a484fe804..be4d880a3 100644 --- a/pkgs/native_assets_cli/lib/native_assets_cli.dart +++ b/pkgs/native_assets_cli/lib/native_assets_cli.dart @@ -21,4 +21,3 @@ export 'src/config.dart' LinkOutputBuilder; export 'src/encoded_asset.dart' show EncodedAsset; export 'src/metadata.dart'; -export 'src/os.dart' show OS; diff --git a/pkgs/native_assets_cli/lib/src/api/build.dart b/pkgs/native_assets_cli/lib/src/api/build.dart index c033a8c58..cd7cc063f 100644 --- a/pkgs/native_assets_cli/lib/src/api/build.dart +++ b/pkgs/native_assets_cli/lib/src/api/build.dart @@ -82,7 +82,7 @@ import '../validation.dart'; /// name: 'asset.txt', /// file: assetPath, /// linkMode: DynamicLoadingBundled(), -/// os: config.targetOS, +/// os: config.codeConfig.targetOS, /// architecture: config.codeConfig.targetArchitecture, /// ), /// ); diff --git a/pkgs/native_assets_cli/lib/src/code_assets/code_asset.dart b/pkgs/native_assets_cli/lib/src/code_assets/code_asset.dart index dcfeaf4ff..4a65875ae 100644 --- a/pkgs/native_assets_cli/lib/src/code_assets/code_asset.dart +++ b/pkgs/native_assets_cli/lib/src/code_assets/code_asset.dart @@ -5,12 +5,11 @@ import '../config.dart'; import '../encoded_asset.dart'; import '../json_utils.dart'; -import '../os.dart'; import '../utils/json.dart'; import '../utils/map.dart'; - import 'architecture.dart'; import 'link_mode.dart'; +import 'os.dart'; /// A code asset which respects the native application binary interface (ABI). /// diff --git a/pkgs/native_assets_cli/lib/src/code_assets/config.dart b/pkgs/native_assets_cli/lib/src/code_assets/config.dart index f9a3d97e8..6f749a106 100644 --- a/pkgs/native_assets_cli/lib/src/code_assets/config.dart +++ b/pkgs/native_assets_cli/lib/src/code_assets/config.dart @@ -4,12 +4,12 @@ import '../config.dart'; import '../json_utils.dart'; - import 'architecture.dart'; import 'c_compiler_config.dart'; import 'code_asset.dart'; import 'ios_sdk.dart'; import 'link_mode_preference.dart'; +import 'os.dart'; /// Extension to the [BuildConfig] providing access to configuration specific to /// code assets (only available if code assets are supported). @@ -48,6 +48,9 @@ class CodeConfig { final int? targetAndroidNdkApi; final IOSSdk? targetIOSSdk; + /// The operating system being compiled for. + final OS targetOS; + CodeConfig(HookConfig config) : linkModePreference = LinkModePreference.fromString( config.json.string(_linkModePreferenceKey)), @@ -56,6 +59,7 @@ class CodeConfig { ? null : Architecture.fromString(config.json.string(_targetArchitectureKey, validValues: Architecture.values.map((a) => a.name))), + targetOS = OS.fromString(config.json.string(_targetOSConfigKey)), cCompiler = switch (config.json.optionalMap(_compilerKey)) { final Map map => CCompilerConfig.fromJson(map), null => CCompilerConfig(), @@ -121,6 +125,7 @@ extension type CodeAssetLinkOutputBuilderAdd._(LinkOutputBuilder _output) { extension CodeAssetBuildConfigBuilder on HookConfigBuilder { void setupCodeConfig({ required Architecture? targetArchitecture, + required OS targetOS, required LinkModePreference linkModePreference, CCompilerConfig? cCompilerConfig, int? targetIOSVersion, @@ -131,6 +136,7 @@ extension CodeAssetBuildConfigBuilder on HookConfigBuilder { if (targetArchitecture != null) { json[_targetArchitectureKey] = targetArchitecture.toString(); } + json[_targetOSConfigKey] = targetOS.toString(); json[_linkModePreferenceKey] = linkModePreference.toString(); if (cCompilerConfig != null) { json[_compilerKey] = cCompilerConfig.toJson(); @@ -170,9 +176,10 @@ extension CodeAssetLinkOutput on LinkOutput { } const String _compilerKey = 'c_compiler'; +const String _linkModePreferenceKey = 'link_mode_preference'; +const String _targetAndroidNdkApiKey = 'target_android_ndk_api'; const String _targetArchitectureKey = 'target_architecture'; const String _targetIOSSdkKey = 'target_ios_sdk'; -const String _linkModePreferenceKey = 'link_mode_preference'; const String _targetIOSVersionKey = 'target_ios_version'; const String _targetMacOSVersionKey = 'target_macos_version'; -const String _targetAndroidNdkApiKey = 'target_android_ndk_api'; +const String _targetOSConfigKey = 'target_os'; diff --git a/pkgs/native_assets_cli/lib/src/os.dart b/pkgs/native_assets_cli/lib/src/code_assets/os.dart similarity index 100% rename from pkgs/native_assets_cli/lib/src/os.dart rename to pkgs/native_assets_cli/lib/src/code_assets/os.dart diff --git a/pkgs/native_assets_cli/lib/src/code_assets/testing.dart b/pkgs/native_assets_cli/lib/src/code_assets/testing.dart index 25f3741f1..3d2648273 100644 --- a/pkgs/native_assets_cli/lib/src/code_assets/testing.dart +++ b/pkgs/native_assets_cli/lib/src/code_assets/testing.dart @@ -42,6 +42,7 @@ Future testCodeBuildHook({ linkModePreference: linkModePreference ?? LinkModePreference.dynamic, cCompilerConfig: cCompiler, targetArchitecture: targetArchitecture ?? Architecture.current, + targetOS: targetOS ?? OS.current, targetIOSSdk: targetIOSSdk, targetIOSVersion: targetIOSVersion, targetMacOSVersion: targetMacOSVersion, @@ -58,7 +59,6 @@ Future testCodeBuildHook({ await check(config, output); }, - targetOS: targetOS, buildAssetTypes: buildAssetTypes, linkingEnabled: linkingEnabled, ); diff --git a/pkgs/native_assets_cli/lib/src/code_assets/validation.dart b/pkgs/native_assets_cli/lib/src/code_assets/validation.dart index 8361824b5..b01dcc559 100644 --- a/pkgs/native_assets_cli/lib/src/code_assets/validation.dart +++ b/pkgs/native_assets_cli/lib/src/code_assets/validation.dart @@ -12,7 +12,7 @@ Future validateCodeAssetBuildConfig( BuildConfig config) async => _validateCodeConfig( 'BuildConfig', - config.targetOS, + config.codeConfig.targetOS, // ignore: deprecated_member_use_from_same_package config.dryRun, config.codeConfig, @@ -20,7 +20,7 @@ Future validateCodeAssetBuildConfig( Future validateCodeAssetLinkConfig(LinkConfig config) async => _validateCodeConfig( - 'LinkConfig', config.targetOS, false, config.codeConfig); + 'LinkConfig', config.codeConfig.targetOS, false, config.codeConfig); ValidationErrors _validateCodeConfig( String configName, OS targetOS, bool dryRun, CodeConfig codeConfig) { @@ -169,9 +169,9 @@ void _validateCodeAssets( } final os = codeAsset.os; - if (config.targetOS != os) { + if (codeConfig.targetOS != os) { final error = 'CodeAsset "$id" has a os "$os", which ' - 'is not the target os "${config.targetOS}".'; + 'is not the target os "${codeConfig.targetOS}".'; errors.add(error); } diff --git a/pkgs/native_assets_cli/lib/src/config.dart b/pkgs/native_assets_cli/lib/src/config.dart index 27d66de18..ff1912306 100644 --- a/pkgs/native_assets_cli/lib/src/config.dart +++ b/pkgs/native_assets_cli/lib/src/config.dart @@ -10,10 +10,10 @@ import 'package:pub_semver/pub_semver.dart'; import 'api/deprecation_messages.dart'; import 'code_assets/architecture.dart'; +import 'code_assets/os.dart'; import 'encoded_asset.dart'; import 'json_utils.dart'; import 'metadata.dart'; -import 'os.dart'; import 'utils/datetime.dart'; import 'utils/json.dart'; @@ -61,9 +61,6 @@ sealed class HookConfig { /// another. For this it is convenient to know the packageRoot. final Uri packageRoot; - /// The operating system being compiled for. - final OS targetOS; - /// The asset types that the invoker of this hook supports. final List buildAssetTypes; @@ -80,7 +77,6 @@ sealed class HookConfig { outputDirectoryShared = json.path(_outDirSharedConfigKey), packageRoot = json.path(_packageRootConfigKey), packageName = json.string(_packageNameConfigKey), - targetOS = OS.fromString(json.string(_targetOSConfigKey)), buildAssetTypes = json.optionalStringList(_buildAssetTypesKey) ?? json.optionalStringList(_supportedAssetTypesKey) ?? const []; @@ -97,12 +93,10 @@ sealed class HookConfigBuilder { void setupHookConfig({ required Uri packageRoot, required String packageName, - required OS targetOS, required List buildAssetTypes, }) { json[_packageNameConfigKey] = packageName; json[_packageRootConfigKey] = packageRoot.toFilePath(); - json[_targetOSConfigKey] = targetOS.toString(); json[_buildAssetTypesKey] = buildAssetTypes; json[_supportedAssetTypesKey] = buildAssetTypes; } @@ -135,7 +129,6 @@ sealed class HookConfigBuilder { } } -const _targetOSConfigKey = 'target_os'; // TODO: Bump min-SDK constraint to 3.7 and remove once stable. const _buildModeConfigKeyDeprecated = 'build_mode'; const _metadataConfigKey = 'metadata'; diff --git a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md index 77c5947e0..c460ecc8a 100644 --- a/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md +++ b/pkgs/native_assets_cli/lib/src/model/build_config_CHANGELOG.md @@ -3,6 +3,14 @@ - `BuildConfig.supportedAssetTypes` renamed to `BuildConfig.buildAssetTypes`. Compatibility with older SDKs: Look for the old key. Compatibility with older hooks: Also provide the old hook in the config. +- `BuildConfig.targetOS` is now only provided if `buildAssetTypes` contains the + code asset. + Compatibility with older SDKs: Fine, they always provide it. + Compatibility with older hooks: Currently, no embedders call hooks without + support for code assets. Once they do (data assets on web), existing hooks + will break. Mitigation: Update existing hooks to check for `buildAssetTypes` + and/or change `CBuilder` to be a no-op if `buildAssetTypes` does not contain + code assets. - `BuildConfig.outputDirectoryShared` for sharing between hook invocations. Compatibility with older SDKs: Create a sibling dir next to the output directory. This does not facilitate caching, but should not break the hook. diff --git a/pkgs/native_assets_cli/lib/src/target.dart b/pkgs/native_assets_cli/lib/src/target.dart index fc595fed6..39cc5687e 100644 --- a/pkgs/native_assets_cli/lib/src/target.dart +++ b/pkgs/native_assets_cli/lib/src/target.dart @@ -6,7 +6,7 @@ import 'dart:ffi' show Abi; import 'dart:io'; import 'code_assets/architecture.dart'; -import 'os.dart'; +import 'code_assets/os.dart'; final class Target implements Comparable { final Abi abi; diff --git a/pkgs/native_assets_cli/lib/test.dart b/pkgs/native_assets_cli/lib/test.dart index 21deb2490..e18210a4b 100644 --- a/pkgs/native_assets_cli/lib/test.dart +++ b/pkgs/native_assets_cli/lib/test.dart @@ -30,7 +30,6 @@ Future testBuildHook({ required FutureOr Function(List arguments) mainMethod, required FutureOr Function(BuildConfig config, BuildOutput output) check, - OS? targetOS, List? buildAssetTypes, bool? linkingEnabled, }) async { @@ -53,7 +52,6 @@ Future testBuildHook({ ..setupHookConfig( packageRoot: Directory.current.uri, packageName: _readPackageNameFromPubspec(), - targetOS: targetOS ?? OS.current, buildAssetTypes: buildAssetTypes ?? [], ) ..setupBuildConfig( diff --git a/pkgs/native_assets_cli/test/api/build_test.dart b/pkgs/native_assets_cli/test/api/build_test.dart index b10d9adb1..aa2801b37 100644 --- a/pkgs/native_assets_cli/test/api/build_test.dart +++ b/pkgs/native_assets_cli/test/api/build_test.dart @@ -34,7 +34,6 @@ void main() async { ..setupHookConfig( packageRoot: tempUri, packageName: packageName, - targetOS: OS.iOS, buildAssetTypes: ['foo'], ) ..setupBuildConfig( diff --git a/pkgs/native_assets_cli/test/build_config_test.dart b/pkgs/native_assets_cli/test/build_config_test.dart index 61fdf685a..10e844ab0 100644 --- a/pkgs/native_assets_cli/test/build_config_test.dart +++ b/pkgs/native_assets_cli/test/build_config_test.dart @@ -40,7 +40,6 @@ void main() async { ..setupHookConfig( packageName: packageName, packageRoot: packageRootUri, - targetOS: OS.android, buildAssetTypes: ['my-asset-type'], ) ..setupBuildConfig( @@ -73,7 +72,6 @@ void main() async { 'package_name': packageName, 'package_root': packageRootUri.toFilePath(), 'supported_asset_types': ['my-asset-type'], - 'target_os': 'android', 'version': latestVersion.toString(), }; @@ -85,7 +83,6 @@ void main() async { expect(config.packageName, packageName); expect(config.packageRoot, packageRootUri); - expect(config.targetOS, OS.android); expect(config.buildAssetTypes, ['my-asset-type']); expect(config.linkingEnabled, false); @@ -98,7 +95,6 @@ void main() async { ..setupHookConfig( packageName: packageName, packageRoot: packageRootUri, - targetOS: OS.android, buildAssetTypes: ['my-asset-type'], ) ..setupBuildConfig( @@ -121,7 +117,6 @@ void main() async { 'package_name': packageName, 'package_root': packageRootUri.toFilePath(), 'supported_asset_types': ['my-asset-type'], - 'target_os': 'android', 'version': latestVersion.toString(), }; @@ -133,7 +128,6 @@ void main() async { expect(config.packageName, packageName); expect(config.packageRoot, packageRootUri); - expect(config.targetOS, OS.android); expect(config.buildAssetTypes, ['my-asset-type']); expect(config.linkingEnabled, true); diff --git a/pkgs/native_assets_cli/test/checksum_test.dart b/pkgs/native_assets_cli/test/checksum_test.dart index aee34b710..3b2376d28 100644 --- a/pkgs/native_assets_cli/test/checksum_test.dart +++ b/pkgs/native_assets_cli/test/checksum_test.dart @@ -14,21 +14,31 @@ void main() { final configs = []; final checksums = []; for (final os in [OS.linux, OS.macOS]) { - for (final packageName in ['foo', 'bar']) { - for (final assetType in [CodeAsset.type, DataAsset.type]) { - for (final dryRun in [true, false]) { - for (final linking in [true, false]) { - final builder = BuildConfigBuilder() - ..setupHookConfig( - packageRoot: Uri.file('foo'), - packageName: packageName, - targetOS: os, - buildAssetTypes: [assetType], - ) - ..setupBuildConfig(dryRun: dryRun, linkingEnabled: linking); - configs - .add(const JsonEncoder.withIndent(' ').convert(builder.json)); - checksums.add(builder.computeChecksum()); + for (final architecture in [Architecture.arm64, Architecture.x64]) { + for (final packageName in ['foo', 'bar']) { + for (final assetType in [CodeAsset.type, DataAsset.type]) { + for (final dryRun in [true, false]) { + for (final linking in [true, false]) { + final builder = BuildConfigBuilder() + ..setupHookConfig( + packageRoot: Uri.file('foo'), + packageName: packageName, + buildAssetTypes: [assetType], + ) + ..setupBuildConfig( + dryRun: dryRun, + linkingEnabled: linking, + ) + ..setupCodeConfig( + targetArchitecture: architecture, + targetOS: os, + linkModePreference: LinkModePreference.dynamic, + ); + configs.add( + const JsonEncoder.withIndent(' ').convert(builder.json), + ); + checksums.add(builder.computeChecksum()); + } } } } @@ -42,38 +52,70 @@ void main() { // needing to update this list). final expectedChecksums = [ - '4cfa5fbd14f8d73d04014ee5b453b000', - '365e989ba01bac43d654981fec67205d', - '2191c07f18b5ef13999eb6f8356ae02e', - '257890f33b84d191746a378fb0db4eba', - 'c22d663cde074a6722c2d5253b8e0619', - 'f520e2f4fd0f2fd76da0c6c18db9559b', - '7cc71dd803c24a424db70444002df999', - 'a5774f32e91551e8dfdcc3f63e45f3ed', - '0f361f3a5072f66f68eb4d7a7e4b92d6', - '5cc8e330ea24c647a1dbf2d82497c73c', - '97b5dbdf7a76cf5839de3bd0cac63b6d', - 'ccc846104ddc0dbd700190638b756435', - '0fca1f77969d6e24602cf44c28695c2b', - '683be025644ff73c5eba9d1f99f9808c', - '7a6982964efcf50507669706e31bdab5', - 'd2b17c98c64e750d8bd2ed5beb907401', - 'de3ac273831822414783f0d72acf9d82', - '09c17c21bd277ea2709c35205a2fdfa6', - 'f07b3399888444bc2b7fa837c0c1dddb', - '6e92bc3271d65229793d8bd1ed4e00be', - 'd353ae01cf04e201180edf8c5e4dac37', - '25044b641a83b33860cf8f79154652bb', - 'afc5e24300cf70245146148111b8a746', - '8023595c2343952c02e2aa47f6ee809f', - '226d39440aa5380bbcf71fb9a804a4b0', - '26cab023910889c0c96cbba2bb04ad97', - '32bea1c49326ae259fe97a6fc7b1e08d', - 'a0cccc3aa7069efc86a84b0299dba682', - '28280ef1dfe5e5922eb97577e8a85c40', - '69595125d5987c952355903deaa87684', - 'b5328455769192919339d0e6158d728d', - 'ed827ce888b9929ba83e04af8d5b7a37', + 'd666127fab5478b736d505c0cbd2e08e', + '5d5cf5cf7916bd7adc26f5d5611f23ec', + '29cb9cf638acac26c1e7eb20bf4e359a', + '2214edee21375319f5612344dfe6acbc', + '40b61c96feff406659bc35e24875744b', + 'a0492f5322cea695e3bc1522d66a20ce', + '9f5269a2c0c663023af449e77ac39980', + 'c9add26b586b1fb897f9ff0d2edb235d', + '95ec14e605b3519f00ea8816b328e0ad', + 'fc5792f6beb3c0e0f7894537a3fa4850', + 'bbf84c44fb1ce09636a70d3e9a8590be', + '9c83dfb94b98c6f4ec79cbabc95e6198', + 'af8712f4857423f455d2912c55fe6766', + '99d1eba44f3e914b58768c210d139cc1', + '12cc255c3fc076d3550ac32b43166631', + '2188cca31e8306cbacb9c3d799b5513c', + '65ad5d4fb66745aad4e5a2969a1e45b1', + '29da0a967b9cfd5e4d21d61c97d2a99e', + 'efef4a8ab871ed05a9358a2e4d6d4e03', + '672a07ce5b6f82204ba92b45c287781c', + '4bcdd217687c15fb108dc9a9b8f8537c', + 'c0593c4282d42a659d66d8b72e44b2a6', + 'dd428de57da1d45149f4ff8a27fa3ea0', + 'c04f80b8be73bcfe435c586ef8a979bc', + '1056f2bf80b3c1979952af1e62e34576', + 'b7d943b4bab492e10c582bdd58aced0e', + 'ed56d7afbd306393c3206685e6d1ba81', + '1463940666f69e3b132f3766570ef83b', + '5451c1a2a24bc5e1206b245b028e0078', + '5f2c169a71039d3d6b2ae74e3c2723d7', + '67759625e5a0908dabcaeeb2b1264f84', + '921b2b7012548949e9b465addccc2e71', + '94bc85e935634df06e208ac8ab9643d3', + 'ee4cd19fc3ac5d4a85ceaf2e80e44682', + '661bf4e49dff3c104784a0d75cf45204', + '0b3529f1337b3759e97733095a868d29', + '1522580f1e96c5ea5dc68ca7a720adee', + '5c08a30f498edf9962c8ff20a1ab4fba', + '69f4f6640eba043f4df2e6f109f07b90', + '62db9da306210856e44bb7f8a75a15fd', + '125f6fa99282a3b7e8937030a3aa2c6d', + '1cf817dd1a1710bfacb82ef71da94e4f', + '1eccd6e8e62985cb9955db4fd8c22d2f', + '4becc04d3263f2b362dd76c0e0eb6d7b', + '74ecd3c74beb88f2f7f02921a8de1143', + 'ad6bf3865f8addf4233e3a83192f5464', + 'edf54995d97ad818449f09d9b2fc86e2', + '89014c91ebb4075bdea2d52f2d35b4ae', + 'cb59b4041a0a7bbf636ed4e3b30d06be', + '3dd69a72235c9b45e1f85c143e8f97bc', + 'b08bec82fca775aeec2e4f400b20a4a0', + '79381e4fd8c1191f2fceb7ad30b3fd64', + 'b8e5434a62d4b0a381363dca1152a0d5', + 'f70e0798fa96df0b6e1d14d69fd0deaa', + '3d807e9c6306c16f2ee61a32e8081e2f', + '0646eefc0cfd913506051f0c8a900983', + 'b5adb85aeaf88a23e7bafd29e63c03ac', + '7b269c3e21fe9e29285daba8c370073f', + '1a47af48f1e3158000d44ef59ab597da', + '2665c64ac2a9d919fff7420c0e770db3', + '27c0acf56ef48f3855fc20ea8810ff8d', + '2a9a03940008cdd6f9231f1f54dd94bf', + '86d87e3cb682646e5d1158898ed7913f', + '6a7b30ccd5a35694c515d22f165be589', ]; printOnFailure('final expectedChecksums = ['); printOnFailure(checksums.map((e) => " '$e',").join('\n')); diff --git a/pkgs/native_assets_cli/test/code_assets/config_test.dart b/pkgs/native_assets_cli/test/code_assets/config_test.dart index b205e5b40..fe7943afa 100644 --- a/pkgs/native_assets_cli/test/code_assets/config_test.dart +++ b/pkgs/native_assets_cli/test/code_assets/config_test.dart @@ -91,7 +91,6 @@ void main() async { ..setupHookConfig( packageName: packageName, packageRoot: packageRootUri, - targetOS: OS.android, buildAssetTypes: [CodeAsset.type], ) ..setupBuildConfig( @@ -103,6 +102,7 @@ void main() async { outputDirectoryShared: outputDirectoryShared, ) ..setupCodeConfig( + targetOS: OS.android, targetArchitecture: null, // not available in dry run cCompilerConfig: null, // not available in dry run linkModePreference: LinkModePreference.preferStatic, @@ -116,7 +116,6 @@ void main() async { ..setupHookConfig( packageName: packageName, packageRoot: packageRootUri, - targetOS: OS.android, buildAssetTypes: [CodeAsset.type], ) ..setupBuildConfig( @@ -128,6 +127,7 @@ void main() async { outputDirectoryShared: outputDirectoryShared, ) ..setupCodeConfig( + targetOS: OS.android, targetArchitecture: Architecture.arm64, targetAndroidNdkApi: 30, linkModePreference: LinkModePreference.preferStatic, @@ -148,7 +148,6 @@ void main() async { ..setupHookConfig( packageName: packageName, packageRoot: packageRootUri, - targetOS: OS.android, buildAssetTypes: [CodeAsset.type], ) ..setupLinkConfig(assets: assets) @@ -158,6 +157,7 @@ void main() async { recordedUsesFile: null, ) ..setupCodeConfig( + targetOS: OS.android, targetArchitecture: Architecture.arm64, targetAndroidNdkApi: 30, linkModePreference: LinkModePreference.preferStatic, diff --git a/pkgs/native_assets_cli/test/code_assets/validation_test.dart b/pkgs/native_assets_cli/test/code_assets/validation_test.dart index 4365f1712..09aa23571 100644 --- a/pkgs/native_assets_cli/test/code_assets/validation_test.dart +++ b/pkgs/native_assets_cli/test/code_assets/validation_test.dart @@ -29,12 +29,11 @@ void main() { await Directory.fromUri(tempUri).delete(recursive: true); }); - BuildConfigBuilder makeBuildConfigBuilder({OS os = OS.iOS}) { + BuildConfigBuilder makeBuildConfigBuilder() { final configBuilder = BuildConfigBuilder() ..setupHookConfig( packageName: packageName, packageRoot: tempUri, - targetOS: os, buildAssetTypes: [CodeAsset.type], ) ..setupBuildConfig( @@ -48,12 +47,14 @@ void main() { return configBuilder; } - BuildConfig makeCodeBuildConfig( - {LinkModePreference linkModePreference = LinkModePreference.dynamic}) { + BuildConfig makeCodeBuildConfig({ + LinkModePreference linkModePreference = LinkModePreference.dynamic, + OS os = OS.iOS, + }) { final builder = makeBuildConfigBuilder() ..setupCodeConfig( + targetOS: os, targetArchitecture: Architecture.arm64, - targetIOSSdk: IOSSdk.iPhoneOS, linkModePreference: linkModePreference, ); return BuildConfig(builder.json); @@ -66,7 +67,7 @@ void main() { package: config.packageName, name: 'foo.dylib', architecture: config.codeConfig.targetArchitecture, - os: config.targetOS, + os: config.codeConfig.targetOS, linkMode: DynamicLoadingBundled(), )); final errors = await validateCodeAssetBuildOutput( @@ -93,7 +94,7 @@ void main() { name: 'foo.dart', file: assetFile.uri, linkMode: linkMode, - os: config.targetOS, + os: config.codeConfig.targetOS, architecture: config.codeConfig.targetArchitecture, ), ); @@ -119,7 +120,7 @@ void main() { name: 'foo.dart', file: assetFile.uri, linkMode: DynamicLoadingBundled(), - os: config.targetOS, + os: config.codeConfig.targetOS, architecture: Architecture.x64, ), ); @@ -144,7 +145,7 @@ void main() { name: 'foo.dart', file: assetFile.uri, linkMode: DynamicLoadingBundled(), - os: config.targetOS, + os: config.codeConfig.targetOS, ), ); final errors = await validateCodeAssetBuildOutput( @@ -185,7 +186,7 @@ void main() { test('duplicate dylib name', () async { final config = makeCodeBuildConfig(); final outputBuilder = BuildOutputBuilder(); - final fileName = config.targetOS.dylibFileName('foo'); + final fileName = config.codeConfig.targetOS.dylibFileName('foo'); final assetFile = File.fromUri(outDirUri.resolve(fileName)); await assetFile.writeAsBytes([1, 2, 3]); outputBuilder.codeAssets.addAll([ @@ -194,7 +195,7 @@ void main() { name: 'src/foo.dart', file: assetFile.uri, linkMode: DynamicLoadingBundled(), - os: config.targetOS, + os: config.codeConfig.targetOS, architecture: config.codeConfig.targetArchitecture, ), CodeAsset( @@ -202,7 +203,7 @@ void main() { name: 'src/bar.dart', file: assetFile.uri, linkMode: DynamicLoadingBundled(), - os: config.targetOS, + os: config.codeConfig.targetOS, architecture: config.codeConfig.targetArchitecture, ), ]); @@ -216,10 +217,12 @@ void main() { group('BuildConfig.codeConfig validation', () { test('Missing targetIOSVersion', () async { - final builder = makeBuildConfigBuilder(os: OS.iOS) + final builder = makeBuildConfigBuilder() ..setupCodeConfig( - targetArchitecture: Architecture.arm64, - linkModePreference: LinkModePreference.dynamic); + targetOS: OS.iOS, + targetArchitecture: Architecture.arm64, + linkModePreference: LinkModePreference.dynamic, + ); final errors = await validateCodeAssetBuildConfig(BuildConfig(builder.json)); expect( @@ -232,20 +235,24 @@ void main() { contains('BuildConfig.codeConfig.targetIOSSdk was missing'))); }); test('Missing targetAndroidNdkApi', () async { - final builder = makeBuildConfigBuilder(os: OS.android) + final builder = makeBuildConfigBuilder() ..setupCodeConfig( - targetArchitecture: Architecture.arm64, - linkModePreference: LinkModePreference.dynamic); + targetOS: OS.android, + targetArchitecture: Architecture.arm64, + linkModePreference: LinkModePreference.dynamic, + ); expect( await validateCodeAssetBuildConfig(BuildConfig(builder.json)), contains(contains( 'BuildConfig.codeConfig.targetAndroidNdkApi was missing'))); }); test('Missing targetMacOSVersion', () async { - final builder = makeBuildConfigBuilder(os: OS.macOS) + final builder = makeBuildConfigBuilder() ..setupCodeConfig( - targetArchitecture: Architecture.arm64, - linkModePreference: LinkModePreference.dynamic); + targetOS: OS.macOS, + targetArchitecture: Architecture.arm64, + linkModePreference: LinkModePreference.dynamic, + ); expect( await validateCodeAssetBuildConfig(BuildConfig(builder.json)), contains(contains( @@ -253,8 +260,9 @@ void main() { }); test('Nonexisting compiler/archiver/linker/envScript', () async { final nonExistent = outDirUri.resolve('foo baz'); - final builder = makeBuildConfigBuilder(os: OS.linux) + final builder = makeBuildConfigBuilder() ..setupCodeConfig( + targetOS: OS.linux, targetArchitecture: Architecture.arm64, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: CCompilerConfig( diff --git a/pkgs/native_assets_cli/test/data_assets/validation_test.dart b/pkgs/native_assets_cli/test/data_assets/validation_test.dart index 422b2e6c9..f38180203 100644 --- a/pkgs/native_assets_cli/test/data_assets/validation_test.dart +++ b/pkgs/native_assets_cli/test/data_assets/validation_test.dart @@ -34,7 +34,6 @@ void main() { ..setupHookConfig( packageName: packageName, packageRoot: tempUri, - targetOS: OS.iOS, buildAssetTypes: [DataAsset.type]) ..setupBuildConfig( linkingEnabled: false, diff --git a/pkgs/native_assets_cli/test/example/local_asset_test.dart b/pkgs/native_assets_cli/test/example/local_asset_test.dart index 5c9de1312..ce57a4b62 100644 --- a/pkgs/native_assets_cli/test/example/local_asset_test.dart +++ b/pkgs/native_assets_cli/test/example/local_asset_test.dart @@ -44,7 +44,6 @@ void main() async { ..setupHookConfig( packageRoot: testPackageUri, packageName: name, - targetOS: OS.current, buildAssetTypes: [CodeAsset.type], ) ..setupBuildRunConfig( @@ -52,9 +51,11 @@ void main() async { outputDirectoryShared: outputDirectoryShared) ..setupBuildConfig(linkingEnabled: false, dryRun: dryRun) ..setupCodeConfig( - targetArchitecture: dryRun ? null : Architecture.current, - linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: dryRun ? null : cCompiler); + targetOS: OS.current, + targetArchitecture: dryRun ? null : Architecture.current, + linkModePreference: LinkModePreference.dynamic, + cCompilerConfig: dryRun ? null : cCompiler, + ); final buildConfigUri = testTempUri.resolve('build_config.json'); await File.fromUri(buildConfigUri) diff --git a/pkgs/native_assets_cli/test/example/native_add_library_test.dart b/pkgs/native_assets_cli/test/example/native_add_library_test.dart index 3d9c9b14c..2a3415901 100644 --- a/pkgs/native_assets_cli/test/example/native_add_library_test.dart +++ b/pkgs/native_assets_cli/test/example/native_add_library_test.dart @@ -44,7 +44,6 @@ void main() async { ..setupHookConfig( packageRoot: testPackageUri, packageName: name, - targetOS: OS.current, buildAssetTypes: [CodeAsset.type], ) ..setupBuildRunConfig( @@ -52,9 +51,11 @@ void main() async { outputDirectoryShared: outputDirectoryShared) ..setupBuildConfig(linkingEnabled: false, dryRun: dryRun) ..setupCodeConfig( - targetArchitecture: dryRun ? null : Architecture.current, - linkModePreference: LinkModePreference.dynamic, - cCompilerConfig: dryRun ? null : cCompiler); + targetOS: OS.current, + targetArchitecture: dryRun ? null : Architecture.current, + linkModePreference: LinkModePreference.dynamic, + cCompilerConfig: dryRun ? null : cCompiler, + ); final buildConfigUri = testTempUri.resolve('build_config.json'); await File.fromUri(buildConfigUri) diff --git a/pkgs/native_assets_cli/test/example/native_dynamic_linking_test.dart b/pkgs/native_assets_cli/test/example/native_dynamic_linking_test.dart index 64b3f50de..f90d91f15 100644 --- a/pkgs/native_assets_cli/test/example/native_dynamic_linking_test.dart +++ b/pkgs/native_assets_cli/test/example/native_dynamic_linking_test.dart @@ -48,7 +48,6 @@ void main() async { ..setupHookConfig( packageRoot: testPackageUri, packageName: name, - targetOS: OS.current, buildAssetTypes: [CodeAsset.type], ) ..setupBuildRunConfig( @@ -57,6 +56,7 @@ void main() async { ) ..setupBuildConfig(linkingEnabled: false, dryRun: dryRun) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: dryRun ? null : Architecture.current, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: dryRun ? null : cCompiler, diff --git a/pkgs/native_assets_cli/test/link_config_test.dart b/pkgs/native_assets_cli/test/link_config_test.dart index dc87cc772..2cf9616ea 100644 --- a/pkgs/native_assets_cli/test/link_config_test.dart +++ b/pkgs/native_assets_cli/test/link_config_test.dart @@ -33,7 +33,6 @@ void main() async { ..setupHookConfig( packageName: packageName, packageRoot: packageRootUri, - targetOS: OS.android, buildAssetTypes: ['asset-type-1', 'asset-type-2'], ) ..setupLinkConfig(assets: assets) @@ -53,7 +52,6 @@ void main() async { 'package_name': packageName, 'package_root': packageRootUri.toFilePath(), 'supported_asset_types': ['asset-type-1', 'asset-type-2'], - 'target_os': 'android', 'version': latestVersion.toString(), }; expect(config.json, expectedConfigJson); @@ -64,7 +62,6 @@ void main() async { expect(config.packageName, packageName); expect(config.packageRoot, packageRootUri); - expect(config.targetOS, OS.android); expect(config.buildAssetTypes, ['asset-type-1', 'asset-type-2']); expect(config.encodedAssets, assets); }); diff --git a/pkgs/native_assets_cli/test/validation_test.dart b/pkgs/native_assets_cli/test/validation_test.dart index 8a45a1b96..fae2834d1 100644 --- a/pkgs/native_assets_cli/test/validation_test.dart +++ b/pkgs/native_assets_cli/test/validation_test.dart @@ -34,7 +34,6 @@ void main() { ..setupHookConfig( packageName: packageName, packageRoot: tempUri, - targetOS: OS.iOS, buildAssetTypes: ['my-asset-type'], ) ..setupBuildConfig( diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart index 9fda6b34f..c2e3c0a34 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/cbuilder.dart @@ -126,9 +126,10 @@ class CBuilder extends CTool implements Builder { await Directory.fromUri(outDir).create(recursive: true); final linkMode = getLinkMode(linkModePreference ?? config.codeConfig.linkModePreference); - final libUri = - outDir.resolve(config.targetOS.libraryFileName(name, linkMode)); - final exeUri = outDir.resolve(config.targetOS.executableFileName(name)); + final libUri = outDir + .resolve(config.codeConfig.targetOS.libraryFileName(name, linkMode)); + final exeUri = + outDir.resolve(config.codeConfig.targetOS.executableFileName(name)); final sources = [ for (final source in this.sources) packageRoot.resolveUri(Uri.file(source)), @@ -188,7 +189,7 @@ class CBuilder extends CTool implements Builder { name: assetName!, file: libUri, linkMode: linkMode, - os: config.targetOS, + os: config.codeConfig.targetOS, architecture: // ignore: deprecated_member_use config.dryRun ? null : config.codeConfig.targetArchitecture, diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart index aa804863e..425944630 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/clinker.dart @@ -51,7 +51,7 @@ class CLinker extends CTool implements Linker { required LinkOutputBuilder output, required Logger? logger, }) async { - if (OS.current != OS.linux || config.targetOS != OS.linux) { + if (OS.current != OS.linux || config.codeConfig.targetOS != OS.linux) { throw UnsupportedError('Currently, only linux is supported for this ' 'feature. See also https://github.com/dart-lang/native/issues/1376'); } @@ -60,8 +60,8 @@ class CLinker extends CTool implements Linker { await Directory.fromUri(outDir).create(recursive: true); final linkMode = getLinkMode(linkModePreference ?? config.codeConfig.linkModePreference); - final libUri = - outDir.resolve(config.targetOS.libraryFileName(name, linkMode)); + final libUri = outDir + .resolve(config.codeConfig.targetOS.libraryFileName(name, linkMode)); final sources = [ for (final source in this.sources) packageRoot.resolveUri(Uri.file(source)), @@ -104,7 +104,7 @@ class CLinker extends CTool implements Linker { name: assetName!, file: libUri, linkMode: linkMode, - os: config.targetOS, + os: config.codeConfig.targetOS, architecture: config.codeConfig.targetArchitecture, )); } diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart index 149b64df2..3e4854764 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/compiler_resolver.dart @@ -20,14 +20,12 @@ import '../tool/tool_instance.dart'; // TODO(dacoharkes): This should support alternatives. // For example use Clang or MSVC on Windows. class CompilerResolver { - final HookConfig hookConfig; final CodeConfig codeConfig; final Logger? logger; final OS hostOS; final Architecture hostArchitecture; CompilerResolver({ - required this.hookConfig, required this.codeConfig, required this.logger, OS? hostOS, // Only visible for testing. @@ -49,7 +47,7 @@ class CompilerResolver { return result; } - final targetOS = hookConfig.targetOS; + final targetOS = codeConfig.targetOS; final targetArchitecture = codeConfig.targetArchitecture; final errorMessage = "No tools configured on host '${hostOS}_$hostArchitecture' with target " @@ -60,7 +58,7 @@ class CompilerResolver { /// Select the right compiler for cross compiling to the specified target. Tool? _selectCompiler() { - final targetOS = hookConfig.targetOS; + final targetOS = codeConfig.targetOS; final targetArch = codeConfig.targetArchitecture; // TODO(dacoharkes): Support falling back on other tools. @@ -135,7 +133,7 @@ class CompilerResolver { return result; } - final targetOS = hookConfig.targetOS; + final targetOS = codeConfig.targetOS; final targetArchitecture = codeConfig.targetArchitecture; final errorMessage = "No tools configured on host '${hostOS}_$hostArchitecture' with target " @@ -146,7 +144,7 @@ class CompilerResolver { /// Select the right archiver for cross compiling to the specified target. Tool? _selectArchiver() { - final targetOS = hookConfig.targetOS; + final targetOS = codeConfig.targetOS; final targetArchitecture = codeConfig.targetArchitecture; // TODO(dacoharkes): Support falling back on other tools. @@ -224,7 +222,7 @@ class CompilerResolver { } Future resolveLinker() async { - final targetOS = hookConfig.targetOS; + final targetOS = codeConfig.targetOS; final targetArchitecture = codeConfig.targetArchitecture; // First, check if the launcher provided a direct path to the compiler. var result = await _tryLoadLinkerFromConfig(); @@ -261,7 +259,7 @@ class CompilerResolver { /// Select the right compiler for cross compiling to the specified target. Tool? _selectLinker() { - final targetOS = hookConfig.targetOS; + final targetOS = codeConfig.targetOS; final targetArchitecture = codeConfig.targetArchitecture; if (targetOS == OS.macOS || targetOS == OS.iOS) return appleLd; diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart index 13e9ff0ad..4234337e2 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/ctool.dart @@ -18,7 +18,7 @@ abstract class CTool { /// Name of the library or executable to build or link. /// - /// The filename will be decided by [LinkConfig.targetOS] and + /// The filename will be decided by [CodeConfig.targetOS] and /// [OSLibraryNaming.libraryFileName] or /// [OSLibraryNaming.executableFileName]. /// diff --git a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart index a4b8197c1..23d61225c 100644 --- a/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart +++ b/pkgs/native_toolchain_c/lib/src/cbuilder/run_cbuilder.dart @@ -76,7 +76,7 @@ class RunCBuilder { .whereType() .length == 1) { - if (config.targetOS == OS.windows && cppLinkStdLib != null) { + if (codeConfig.targetOS == OS.windows && cppLinkStdLib != null) { throw ArgumentError.value( cppLinkStdLib, 'cppLinkStdLib', @@ -85,8 +85,8 @@ class RunCBuilder { } } - late final _resolver = CompilerResolver( - hookConfig: config, codeConfig: codeConfig, logger: logger); + late final _resolver = + CompilerResolver(codeConfig: codeConfig, logger: logger); Future compiler() async => await _resolver.resolveCompiler(); @@ -139,7 +139,7 @@ class RunCBuilder { } final IOSSdk? targetIosSdk; - if (config.targetOS == OS.iOS) { + if (codeConfig.targetOS == OS.iOS) { targetIosSdk = codeConfig.targetIOSSdk; } else { targetIosSdk = null; @@ -149,7 +149,7 @@ class RunCBuilder { // invoking clang. Mimic that behavior here. // See https://github.com/dart-lang/native/issues/171. final int? targetAndroidNdkApi; - if (config.targetOS == OS.android) { + if (codeConfig.targetOS == OS.android) { final minimumApi = codeConfig.targetArchitecture == Architecture.riscv64 ? 35 : 21; targetAndroidNdkApi = max(codeConfig.targetAndroidNdkApi!, minimumApi); @@ -158,9 +158,9 @@ class RunCBuilder { } final targetIOSVersion = - config.targetOS == OS.iOS ? codeConfig.targetIOSVersion : null; + codeConfig.targetOS == OS.iOS ? codeConfig.targetIOSVersion : null; final targetMacOSVersion = - config.targetOS == OS.macOS ? codeConfig.targetMacOSVersion : null; + codeConfig.targetOS == OS.macOS ? codeConfig.targetMacOSVersion : null; final architecture = codeConfig.targetArchitecture; final sourceFiles = sources.map((e) => e.toFilePath()).toList(); @@ -219,24 +219,24 @@ class RunCBuilder { await runProcess( executable: toolInstance.uri, arguments: [ - if (config.targetOS == OS.android) ...[ + if (codeConfig.targetOS == OS.android) ...[ '--target=' '${androidNdkClangTargetFlags[architecture]!}' '${targetAndroidNdkApi!}', '--sysroot=${androidSysroot(toolInstance).toFilePath()}', ], - if (config.targetOS == OS.macOS) + if (codeConfig.targetOS == OS.macOS) '--target=${appleClangMacosTargetFlags[architecture]!}', - if (config.targetOS == OS.iOS) + if (codeConfig.targetOS == OS.iOS) '--target=${appleClangIosTargetFlags[architecture]![targetIosSdk]!}', if (targetIOSVersion != null) '-mios-version-min=$targetIOSVersion', if (targetMacOSVersion != null) '-mmacos-version-min=$targetMacOSVersion', - if (config.targetOS == OS.iOS) ...[ + if (codeConfig.targetOS == OS.iOS) ...[ '-isysroot', (await iosSdk(targetIosSdk!, logger: logger)).toFilePath(), ], - if (config.targetOS == OS.macOS) ...[ + if (codeConfig.targetOS == OS.macOS) ...[ '-isysroot', (await macosSdk(logger: logger)).toFilePath(), ], @@ -280,14 +280,14 @@ class RunCBuilder { '-x', 'c++', '-l', - cppLinkStdLib ?? defaultCppLinkStdLib[config.targetOS]! + cppLinkStdLib ?? defaultCppLinkStdLib[codeConfig.targetOS]! ], if (optimizationLevel != OptimizationLevel.unspecified) optimizationLevel.clangFlag(), ...linkerOptions?.preSourcesFlags(toolInstance.tool, sourceFiles) ?? [], // Support Android 15 page size by default, can be overridden by // passing [flags]. - if (config.targetOS == OS.android) '-Wl,-z,max-page-size=16384', + if (codeConfig.targetOS == OS.android) '-Wl,-z,max-page-size=16384', ...flags, for (final MapEntry(key: name, :value) in defines.entries) if (value == null) '-D$name' else '-D$name=$value', @@ -314,7 +314,7 @@ class RunCBuilder { ...linkerOptions?.postSourcesFlags(toolInstance.tool, sourceFiles) ?? [], if (executable != null || dynamicLibrary != null) ...[ - if (config.targetOS case OS.android || OS.linux) + if (codeConfig.targetOS case OS.android || OS.linux) // During bundling code assets are all placed in the same directory. // Setting this rpath allows the binary to find other code assets // it is linked against. diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart index 164dde262..7e906878d 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_build_failure_test.dart @@ -34,13 +34,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: cCompiler, diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart index 6b3002c75..cb8e80201 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_android_test.dart @@ -149,13 +149,13 @@ Future buildLib( buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.android, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.android, targetArchitecture: targetArchitecture, cCompilerConfig: cCompiler, targetAndroidNdkApi: androidNdkApi, diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart index 29e78e72f..90e358aa5 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_ios_test.dart @@ -75,13 +75,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.iOS, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.iOS, targetArchitecture: target, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic @@ -233,13 +233,13 @@ Future buildLib( buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.iOS, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.iOS, targetArchitecture: targetArchitecture, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart index c39d398d0..d0be152b7 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_linux_host_test.dart @@ -47,13 +47,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.linux, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.linux, targetArchitecture: target, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart index 129c8bec3..9df36f3ad 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_macos_host_test.dart @@ -62,13 +62,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.macOS, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.macOS, targetArchitecture: target, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic @@ -163,13 +163,13 @@ Future buildLib( buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.macOS, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.macOS, targetArchitecture: targetArchitecture, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart index 6c9532653..92109a604 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_cross_windows_host_test.dart @@ -66,13 +66,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.windows, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.windows, targetArchitecture: target, linkModePreference: linkMode == DynamicLoadingBundled() ? LinkModePreference.dynamic diff --git a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart index 4b0a30793..3873a5b85 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/cbuilder_test.dart @@ -48,13 +48,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, @@ -97,7 +97,7 @@ void main() { (message) => message.contains(helloWorldCUri.toFilePath()), ); - switch ((buildConfig.targetOS, pic)) { + switch ((buildConfig.codeConfig.targetOS, pic)) { case (OS.windows, _) || (_, null): expect(compilerInvocation, isNot(contains('-fPIC'))); expect(compilerInvocation, isNot(contains('-fPIE'))); @@ -130,13 +130,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: dryRun, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: dryRun ? null : cCompiler, @@ -172,7 +172,7 @@ void main() { final compilerInvocation = logMessages.singleWhere( (message) => message.contains(addCUri.toFilePath()), ); - switch ((buildConfig.targetOS, pic)) { + switch ((buildConfig.codeConfig.targetOS, pic)) { case (OS.windows, _) || (_, null): expect(compilerInvocation, isNot(contains('-fPIC'))); expect(compilerInvocation, isNot(contains('-fPIE'))); @@ -231,13 +231,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, @@ -250,7 +250,7 @@ void main() { final buildConfig = BuildConfig(buildConfigBuilder.json); final buildOutput = BuildOutputBuilder(); - final flag = switch (buildConfig.targetOS) { + final flag = switch (buildConfig.codeConfig.targetOS) { OS.windows => '/DFOO=USER_FLAG', _ => '-DFOO=USER_FLAG', }; @@ -298,13 +298,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, @@ -354,13 +354,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, @@ -373,7 +373,7 @@ void main() { final buildConfig = BuildConfig(buildConfigBuilder.json); final buildOutput = BuildOutputBuilder(); - final stdFlag = switch (buildConfig.targetOS) { + final stdFlag = switch (buildConfig.codeConfig.targetOS) { OS.windows => '/std:$std', _ => '-std=$std', }; @@ -422,13 +422,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, @@ -441,7 +441,7 @@ void main() { final buildConfig = BuildConfig(buildConfigBuilder.json); final buildOutput = BuildOutputBuilder(); - final defaultStdLibLinkFlag = switch (buildConfig.targetOS) { + final defaultStdLibLinkFlag = switch (buildConfig.codeConfig.targetOS) { OS.windows => null, OS.linux => '-l stdc++', OS.macOS => '-l c++', @@ -495,13 +495,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, @@ -522,7 +522,7 @@ void main() { buildMode: BuildMode.release, ); - if (buildConfig.targetOS == OS.windows) { + if (buildConfig.codeConfig.targetOS == OS.windows) { await expectLater( () => cbuilder.run( config: buildConfig, @@ -579,13 +579,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, @@ -680,13 +680,13 @@ Future testDefines({ buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, // Ignored by executables. linkModePreference: LinkModePreference.dynamic, diff --git a/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart b/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart index b4c1ddf01..929312368 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/compiler_resolver_test.dart @@ -46,13 +46,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: 'dummy', packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: CCompilerConfig( @@ -67,10 +67,8 @@ void main() { outputDirectoryShared: tempUri2, ); final buildConfig = BuildConfig(buildConfigBuilder.json); - final resolver = CompilerResolver( - hookConfig: buildConfig, - codeConfig: buildConfig.codeConfig, - logger: logger); + final resolver = + CompilerResolver(codeConfig: buildConfig.codeConfig, logger: logger); final compiler = await resolver.resolveCompiler(); final archiver = await resolver.resolveArchiver(); expect(compiler.uri, buildConfig.codeConfig.cCompiler.compiler); @@ -85,13 +83,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: 'dummy', packageRoot: tempUri, - targetOS: OS.windows, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.windows, targetArchitecture: Architecture.arm64, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: cCompiler, @@ -104,7 +102,6 @@ void main() { final buildConfig = BuildConfig(buildConfigBuilder.json); final resolver = CompilerResolver( - hookConfig: buildConfig, codeConfig: buildConfig.codeConfig, logger: logger, hostOS: OS.android, // This is never a host. diff --git a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart index 23f8fe9ca..e251080a2 100644 --- a/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart +++ b/pkgs/native_toolchain_c/test/cbuilder/objective_c_test.dart @@ -40,13 +40,13 @@ void main() { buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: OS.current, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: OS.current, targetArchitecture: Architecture.current, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: cCompiler, diff --git a/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart b/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart index fe183eb09..2dbc32946 100644 --- a/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart +++ b/pkgs/native_toolchain_c/test/clinker/build_testfiles.dart @@ -30,13 +30,13 @@ Future buildTestArchive( buildAssetTypes: [CodeAsset.type], packageName: name, packageRoot: tempUri, - targetOS: os, ) ..setupBuildConfig( linkingEnabled: false, dryRun: false, ) ..setupCodeConfig( + targetOS: os, targetArchitecture: architecture, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: cCompiler, diff --git a/pkgs/native_toolchain_c/test/clinker/objects_test.dart b/pkgs/native_toolchain_c/test/clinker/objects_test.dart index d080e984a..0797b194c 100644 --- a/pkgs/native_toolchain_c/test/clinker/objects_test.dart +++ b/pkgs/native_toolchain_c/test/clinker/objects_test.dart @@ -36,12 +36,12 @@ Future main() async { buildAssetTypes: [CodeAsset.type], packageName: 'testpackage', packageRoot: tempUri, - targetOS: os, ) ..setupLinkConfig( assets: [], ) ..setupCodeConfig( + targetOS: os, targetArchitecture: architecture, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: cCompiler, diff --git a/pkgs/native_toolchain_c/test/clinker/throws_test.dart b/pkgs/native_toolchain_c/test/clinker/throws_test.dart index 149f09001..9a1c2a633 100644 --- a/pkgs/native_toolchain_c/test/clinker/throws_test.dart +++ b/pkgs/native_toolchain_c/test/clinker/throws_test.dart @@ -27,12 +27,12 @@ Future main() async { buildAssetTypes: [CodeAsset.type], packageName: 'testpackage', packageRoot: tempUri, - targetOS: os, ) ..setupLinkConfig( assets: [], ) ..setupCodeConfig( + targetOS: os, targetArchitecture: Architecture.x64, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: cCompiler, diff --git a/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart b/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart index 322d9ba04..d8d55c88b 100644 --- a/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart +++ b/pkgs/native_toolchain_c/test/clinker/treeshake_helper.dart @@ -66,12 +66,12 @@ Future runTests(List architectures) async { buildAssetTypes: [CodeAsset.type], packageName: 'testpackage', packageRoot: tempUri, - targetOS: os, ) ..setupLinkConfig( assets: [], ) ..setupCodeConfig( + targetOS: os, targetArchitecture: architecture, linkModePreference: LinkModePreference.dynamic, cCompilerConfig: cCompiler,