From dec31cbab6c5bd44eb577761c386dcc732ded95b Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Thu, 3 Apr 2025 07:42:31 +0200 Subject: [PATCH] [native_assets] Roll dependencies (#166282) Updating the dart-lang/native dependencies to the ones published today. No functional changes, but `CodeAsset` does not expose an `architecture` and `os ` anymore (https://github.com/dart-lang/native/issues/2127). Instead these should be taken from what is passed in for the `CodeConfig`. This PR refactors the `DartBuildResult` to carry around the `Target` with `CodeAsset`s as `FlutterCodeAsset`s. (This PR avoid refactoring relevant code due to https://github.com/flutter/flutter/pull/164094 already refactoring this code.) --- .../link_hook/hook/build.dart | 2 +- .../link_hook/hook/link.dart | 6 +- dev/integration_tests/link_hook/pubspec.yaml | 6 +- .../native_assets/android/native_assets.dart | 27 +++-- .../native_assets/ios/native_assets.dart | 53 +++++---- .../native_assets/macos/native_assets.dart | 62 +++++----- .../isolated/native_assets/native_assets.dart | 108 +++++++++++------- .../lib/src/update_packages_pins.dart | 4 +- packages/flutter_tools/pubspec.yaml | 6 +- .../templates/package_ffi/pubspec.yaml.tmpl | 4 +- .../isolated/native_assets_test.dart | 9 +- .../isolated/native_assets_test_utils.dart | 2 +- 12 files changed, 158 insertions(+), 131 deletions(-) diff --git a/dev/integration_tests/link_hook/hook/build.dart b/dev/integration_tests/link_hook/hook/build.dart index b5090b3e5c..fe9590690e 100644 --- a/dev/integration_tests/link_hook/hook/build.dart +++ b/dev/integration_tests/link_hook/hook/build.dart @@ -9,7 +9,7 @@ import 'package:native_toolchain_c/native_toolchain_c.dart'; void main(List args) async { await build(args, (BuildInput input, BuildOutputBuilder output) async { - if (!input.config.buildAssetTypes.contains(CodeAsset.type)) { + if (!input.config.buildCodeAssets) { return; } diff --git a/dev/integration_tests/link_hook/hook/link.dart b/dev/integration_tests/link_hook/hook/link.dart index 9ef56a6a1a..b94a02e22b 100644 --- a/dev/integration_tests/link_hook/hook/link.dart +++ b/dev/integration_tests/link_hook/hook/link.dart @@ -6,7 +6,7 @@ import 'package:native_assets_cli/code_assets.dart'; void main(List args) async { await link(args, (LinkInput input, LinkOutputBuilder output) async { - if (!input.config.buildAssetTypes.contains(CodeAsset.type)) { + if (!input.config.buildCodeAssets) { return; } final CodeAsset asset = input.assets.code.single; @@ -17,8 +17,8 @@ void main(List args) async { // Change the asset id to something that is used. name: '${packageName}_bindings_generated.dart', linkMode: asset.linkMode, - os: asset.os, - architecture: asset.architecture, + os: input.config.code.targetOS, + architecture: input.config.code.targetArchitecture, file: asset.file, ), ); diff --git a/dev/integration_tests/link_hook/pubspec.yaml b/dev/integration_tests/link_hook/pubspec.yaml index 2116c1b6c1..dfac7e28b0 100644 --- a/dev/integration_tests/link_hook/pubspec.yaml +++ b/dev/integration_tests/link_hook/pubspec.yaml @@ -7,8 +7,8 @@ environment: dependencies: logging: 1.3.0 - native_assets_cli: 0.12.0 - native_toolchain_c: 0.9.0 + native_assets_cli: 0.13.0 + native_toolchain_c: 0.10.0 async: 2.13.0 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" collection: 1.19.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" @@ -68,4 +68,4 @@ dev_dependencies: webkit_inspection_protocol: 1.2.1 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" yaml_edit: 2.2.2 # THIS LINE IS AUTOGENERATED - TO UPDATE USE "flutter update-packages --force-upgrade" -# PUBSPEC CHECKSUM: 2038 +# PUBSPEC CHECKSUM: a861 diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart index b960e69179..d23ffd4653 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/android/native_assets.dart @@ -10,6 +10,7 @@ import '../../../android/gradle_utils.dart'; import '../../../base/common.dart'; import '../../../base/file_system.dart'; import '../../../build_info.dart'; +import '../native_assets.dart'; int targetAndroidNdkApi(Map environmentDefines) { return int.parse(environmentDefines[kMinSdkVersion] ?? minSdkVersion); @@ -17,7 +18,7 @@ int targetAndroidNdkApi(Map environmentDefines) { Future copyNativeCodeAssetsAndroid( Uri buildUri, - Map assetTargetLocations, + Map assetTargetLocations, FileSystem fileSystem, ) async { assert(assetTargetLocations.isNotEmpty); @@ -28,8 +29,8 @@ Future copyNativeCodeAssetsAndroid( final Uri archUri = buildUri.resolve('jniLibs/lib/$jniArchDir/'); await fileSystem.directory(archUri).create(recursive: true); } - for (final MapEntry assetMapping in assetTargetLocations.entries) { - final Uri source = assetMapping.key.file!; + for (final MapEntry assetMapping in assetTargetLocations.entries) { + final Uri source = assetMapping.key.codeAsset.file!; final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri; final AndroidArch androidArch = _getAndroidArch(assetMapping.value.target.architecture); final String jniArchDir = androidArch.archName; @@ -62,16 +63,18 @@ AndroidArch _getAndroidArch(Architecture architecture) { }; } -Map assetTargetLocationsAndroid(List nativeAssets) { - return { - for (final CodeAsset asset in nativeAssets) asset: _targetLocationAndroid(asset), +Map assetTargetLocationsAndroid( + List nativeAssets, +) { + return { + for (final FlutterCodeAsset asset in nativeAssets) asset: _targetLocationAndroid(asset), }; } /// Converts the `path` of [asset] as output from a `build.dart` invocation to /// the path used inside the Flutter app bundle. -KernelAsset _targetLocationAndroid(CodeAsset asset) { - final LinkMode linkMode = asset.linkMode; +KernelAsset _targetLocationAndroid(FlutterCodeAsset asset) { + final LinkMode linkMode = asset.codeAsset.linkMode; final KernelAssetPath kernelAssetPath; switch (linkMode) { case DynamicLoadingSystem _: @@ -81,16 +84,12 @@ KernelAsset _targetLocationAndroid(CodeAsset asset) { case LookupInProcess _: kernelAssetPath = KernelAssetInProcess(); case DynamicLoadingBundled _: - final String fileName = asset.file!.pathSegments.last; + final String fileName = asset.codeAsset.file!.pathSegments.last; kernelAssetPath = KernelAssetAbsolutePath(Uri(path: fileName)); default: throw Exception('Unsupported asset link mode $linkMode in asset $asset'); } - return KernelAsset( - id: asset.id, - target: Target.fromArchitectureAndOS(asset.architecture, asset.os), - path: kernelAssetPath, - ); + return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath); } /// Looks the NDK clang compiler tools. diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart index 703b93e903..1014c22cc2 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/ios/native_assets.dart @@ -8,6 +8,7 @@ import 'package:native_assets_cli/code_assets_builder.dart'; import '../../../base/file_system.dart'; import '../../../build_info.dart'; import '../macos/native_assets_host.dart'; +import '../native_assets.dart'; // TODO(dcharkes): Fetch minimum iOS version from somewhere. https://github.com/flutter/flutter/issues/145104 const int targetIOSVersion = 12; @@ -28,40 +29,41 @@ Architecture getNativeIOSArchitecture(DarwinArch darwinArch) { }; } -Map> fatAssetTargetLocationsIOS(List nativeAssets) { +Map> fatAssetTargetLocationsIOS( + List nativeAssets, +) { final Set alreadyTakenNames = {}; - final Map> result = >{}; + final Map> result = + >{}; final Map idToPath = {}; - for (final CodeAsset asset in nativeAssets) { + for (final FlutterCodeAsset asset in nativeAssets) { // Use same target path for all assets with the same id. + final String assetId = asset.codeAsset.id; final KernelAssetPath path = - idToPath[asset.id] ?? _targetLocationIOS(asset, alreadyTakenNames).path; - idToPath[asset.id] = path; - result[path] ??= []; + idToPath[assetId] ?? _targetLocationIOS(asset, alreadyTakenNames).path; + idToPath[assetId] = path; + result[path] ??= []; result[path]!.add(asset); } return result; } -Map assetTargetLocationsIOS(List nativeAssets) { +Map assetTargetLocationsIOS(List nativeAssets) { final Set alreadyTakenNames = {}; final Map idToPath = {}; - final Map result = {}; - for (final CodeAsset asset in nativeAssets) { + final Map result = {}; + for (final FlutterCodeAsset asset in nativeAssets) { + final String assetId = asset.codeAsset.id; final KernelAssetPath path = - idToPath[asset.id] ?? _targetLocationIOS(asset, alreadyTakenNames).path; - idToPath[asset.id] = path; - result[asset] = KernelAsset( - id: asset.id, - target: Target.fromArchitectureAndOS(asset.architecture, asset.os), - path: path, - ); + idToPath[assetId] ?? _targetLocationIOS(asset, alreadyTakenNames).path; + idToPath[assetId] = path; + result[asset] = KernelAsset(id: assetId, target: asset.target, path: path); } return result; } -KernelAsset _targetLocationIOS(CodeAsset asset, Set alreadyTakenNames) { - final LinkMode linkMode = asset.linkMode; +KernelAsset _targetLocationIOS(FlutterCodeAsset asset, Set alreadyTakenNames) { + final LinkMode linkMode = asset.codeAsset.linkMode; final KernelAssetPath kernelAssetPath; switch (linkMode) { case DynamicLoadingSystem _: @@ -71,16 +73,12 @@ KernelAsset _targetLocationIOS(CodeAsset asset, Set alreadyTakenNames) { case LookupInProcess _: kernelAssetPath = KernelAssetInProcess(); case DynamicLoadingBundled _: - final String fileName = asset.file!.pathSegments.last; + final String fileName = asset.codeAsset.file!.pathSegments.last; kernelAssetPath = KernelAssetAbsolutePath(frameworkUri(fileName, alreadyTakenNames)); default: throw Exception('Unsupported asset link mode $linkMode in asset $asset'); } - return KernelAsset( - id: asset.id, - target: Target.fromArchitectureAndOS(asset.architecture, asset.os), - path: kernelAssetPath, - ); + return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath); } /// Copies native assets into a framework per dynamic library. @@ -97,7 +95,7 @@ KernelAsset _targetLocationIOS(CodeAsset asset, Set alreadyTakenNames) { /// in xcode_backend.dart. Future copyNativeCodeAssetsIOS( Uri buildUri, - Map> assetTargetLocations, + Map> assetTargetLocations, String? codesignIdentity, BuildMode buildMode, FileSystem fileSystem, @@ -106,11 +104,12 @@ Future copyNativeCodeAssetsIOS( final Map oldToNewInstallNames = {}; final List<(File, String, Directory)> dylibs = <(File, String, Directory)>[]; - for (final MapEntry> assetMapping + for (final MapEntry> assetMapping in assetTargetLocations.entries) { final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri; final List sources = [ - for (final CodeAsset source in assetMapping.value) fileSystem.file(source.file), + for (final FlutterCodeAsset source in assetMapping.value) + fileSystem.file(source.codeAsset.file), ]; final Uri targetUri = buildUri.resolveUri(target); final File dylibFile = fileSystem.file(targetUri); diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart index 89c511b10b..441a46f18c 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/macos/native_assets.dart @@ -7,6 +7,7 @@ import 'package:native_assets_cli/code_assets_builder.dart'; import '../../../base/file_system.dart'; import '../../../build_info.dart'; +import '../native_assets.dart'; import 'native_assets_host.dart'; // TODO(dcharkes): Fetch minimum MacOS version from somewhere. https://github.com/flutter/flutter/issues/145104 @@ -21,50 +22,49 @@ Architecture getNativeMacOSArchitecture(DarwinArch darwinArch) { }; } -Map> fatAssetTargetLocationsMacOS( - List nativeAssets, +Map> fatAssetTargetLocationsMacOS( + List nativeAssets, Uri? absolutePath, ) { final Set alreadyTakenNames = {}; - final Map> result = >{}; + final Map> result = + >{}; final Map idToPath = {}; - for (final CodeAsset asset in nativeAssets) { + for (final FlutterCodeAsset asset in nativeAssets) { // Use same target path for all assets with the same id. + final String assetId = asset.codeAsset.id; final KernelAssetPath path = - idToPath[asset.id] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path; - idToPath[asset.id] = path; - result[path] ??= []; + idToPath[assetId] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path; + idToPath[assetId] = path; + result[path] ??= []; result[path]!.add(asset); } return result; } -Map assetTargetLocationsMacOS( - List nativeAssets, +Map assetTargetLocationsMacOS( + List nativeAssets, Uri? absolutePath, ) { final Set alreadyTakenNames = {}; final Map idToPath = {}; - final Map result = {}; - for (final CodeAsset asset in nativeAssets) { + final Map result = {}; + for (final FlutterCodeAsset asset in nativeAssets) { + final String assetId = asset.codeAsset.id; final KernelAssetPath path = - idToPath[asset.id] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path; - idToPath[asset.id] = path; - result[asset] = KernelAsset( - id: asset.id, - target: Target.fromArchitectureAndOS(asset.architecture, asset.os), - path: path, - ); + idToPath[assetId] ?? _targetLocationMacOS(asset, absolutePath, alreadyTakenNames).path; + idToPath[assetId] = path; + result[asset] = KernelAsset(id: assetId, target: asset.target, path: path); } return result; } KernelAsset _targetLocationMacOS( - CodeAsset asset, + FlutterCodeAsset asset, Uri? absolutePath, Set alreadyTakenNames, ) { - final LinkMode linkMode = asset.linkMode; + final LinkMode linkMode = asset.codeAsset.linkMode; final KernelAssetPath kernelAssetPath; switch (linkMode) { case DynamicLoadingSystem _: @@ -74,7 +74,7 @@ KernelAsset _targetLocationMacOS( case LookupInProcess _: kernelAssetPath = KernelAssetInProcess(); case DynamicLoadingBundled _: - final String fileName = asset.file!.pathSegments.last; + final String fileName = asset.codeAsset.file!.pathSegments.last; Uri uri; if (absolutePath != null) { // Flutter tester needs full host paths. @@ -89,11 +89,7 @@ KernelAsset _targetLocationMacOS( default: throw Exception('Unsupported asset link mode $linkMode in asset $asset'); } - return KernelAsset( - id: asset.id, - target: Target.fromArchitectureAndOS(asset.architecture, asset.os), - path: kernelAssetPath, - ); + return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath); } /// Copies native assets into a framework per dynamic library. @@ -113,7 +109,7 @@ KernelAsset _targetLocationMacOS( /// in macos_assemble.sh. Future copyNativeCodeAssetsMacOS( Uri buildUri, - Map> assetTargetLocations, + Map> assetTargetLocations, String? codesignIdentity, BuildMode buildMode, FileSystem fileSystem, @@ -123,11 +119,12 @@ Future copyNativeCodeAssetsMacOS( final Map oldToNewInstallNames = {}; final List<(File, String, Directory)> dylibs = <(File, String, Directory)>[]; - for (final MapEntry> assetMapping + for (final MapEntry> assetMapping in assetTargetLocations.entries) { final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri; final List sources = [ - for (final CodeAsset source in assetMapping.value) fileSystem.file(source.file), + for (final FlutterCodeAsset source in assetMapping.value) + fileSystem.file(source.codeAsset.file), ]; final Uri targetUri = buildUri.resolveUri(target); final String name = targetUri.pathSegments.last; @@ -201,7 +198,7 @@ Future copyNativeCodeAssetsMacOS( /// Code signing is also done here. Future copyNativeCodeAssetsMacOSFlutterTester( Uri buildUri, - Map> assetTargetLocations, + Map> assetTargetLocations, String? codesignIdentity, BuildMode buildMode, FileSystem fileSystem, @@ -211,11 +208,12 @@ Future copyNativeCodeAssetsMacOSFlutterTester( final Map oldToNewInstallNames = {}; final List<(File, String)> dylibs = <(File, String)>[]; - for (final MapEntry> assetMapping + for (final MapEntry> assetMapping in assetTargetLocations.entries) { final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri; final List sources = [ - for (final CodeAsset source in assetMapping.value) fileSystem.file(source.file), + for (final FlutterCodeAsset source in assetMapping.value) + fileSystem.file(source.codeAsset.file), ]; final Uri targetUri = buildUri.resolveUri(target); final File dylibFile = fileSystem.file(targetUri); diff --git a/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart b/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart index 1f30b9d931..8971da9ee9 100644 --- a/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart +++ b/packages/flutter_tools/lib/src/isolated/native_assets/native_assets.dart @@ -34,35 +34,63 @@ import 'windows/native_assets.dart'; final class DartBuildResult { const DartBuildResult(this.codeAssets, this.dependencies); - const DartBuildResult.empty() : codeAssets = const [], dependencies = const []; + const DartBuildResult.empty() + : codeAssets = const [], + dependencies = const []; factory DartBuildResult.fromJson(Map json) { final List dependencies = [ for (final Object? encodedUri in json['dependencies']! as List) Uri.parse(encodedUri! as String), ]; - final List codeAssets = [ + final List codeAssets = [ for (final Object? json in json['code_assets']! as List) - CodeAsset.fromEncoded(EncodedAsset.fromJson(json! as Map)), + FlutterCodeAsset( + codeAsset: CodeAsset.fromEncoded( + EncodedAsset.fromJson( + (json! as Map)['asset']! as Map, + ), + ), + target: Target.fromString((json as Map)['target']! as String), + ), ]; return DartBuildResult(codeAssets, dependencies); } - final List codeAssets; + final List codeAssets; final List dependencies; Map toJson() => { 'dependencies': [for (final Uri dep in dependencies) dep.toString()], - 'code_assets': [for (final CodeAsset code in codeAssets) code.encode().toJson()], + 'code_assets': [ + for (final FlutterCodeAsset code in codeAssets) + { + 'asset': code.codeAsset.encode().toJson(), + 'target': code.target.toString(), + }, + ], }; /// The files that eventually should be bundled with the app. List get filesToBeBundled => [ - for (final CodeAsset code in codeAssets) - if (code.linkMode is DynamicLoadingBundled) code.file!, + for (final FlutterCodeAsset code in codeAssets) + if (code.codeAsset.linkMode is DynamicLoadingBundled) code.codeAsset.file!, ]; } +/// A [CodeAsset] for a specific [target]. +/// +/// Flutter builds [CodeAsset]s for multiple architectures (on MacOS and iOS). +/// This class distinguishes the (otherwise identical) [codeAsset]s on different +/// [target]s. These are then later combined into a single [KernelAsset] before +/// being added to the native assets manifest. +class FlutterCodeAsset { + FlutterCodeAsset({required this.codeAsset, required this.target}); + + final CodeAsset codeAsset; + final Target target; +} + /// Invokes the build of all transitive Dart packages and prepares code assets /// to be included in the native build. Future runFlutterSpecificDartBuild({ @@ -122,7 +150,7 @@ Future installCodeAssets({ final BuildMode buildMode = _getBuildMode(environmentDefines, flutterTester); final String? codesignIdentity = environmentDefines[kCodesignIdentity]; - final Map assetTargetLocations = assetTargetLocationsForOS( + final Map assetTargetLocations = assetTargetLocationsForOS( targetOS, dartBuildResult.codeAssets, flutterTester, @@ -379,18 +407,18 @@ Uri nativeAssetsBuildUri(Uri projectUri, OS os) { return projectUri.resolve('$buildDir/native_assets/$os/'); } -Map _assetTargetLocationsWindowsLinux( - List assets, +Map _assetTargetLocationsWindowsLinux( + List assets, Uri? absolutePath, ) { - return { - for (final CodeAsset asset in assets) + return { + for (final FlutterCodeAsset asset in assets) asset: _targetLocationSingleArchitecture(asset, absolutePath), }; } -KernelAsset _targetLocationSingleArchitecture(CodeAsset asset, Uri? absolutePath) { - final LinkMode linkMode = asset.linkMode; +KernelAsset _targetLocationSingleArchitecture(FlutterCodeAsset asset, Uri? absolutePath) { + final LinkMode linkMode = asset.codeAsset.linkMode; final KernelAssetPath kernelAssetPath; switch (linkMode) { case DynamicLoadingSystem _: @@ -400,7 +428,7 @@ KernelAsset _targetLocationSingleArchitecture(CodeAsset asset, Uri? absolutePath case LookupInProcess _: kernelAssetPath = KernelAssetInProcess(); case DynamicLoadingBundled _: - final String fileName = asset.file!.pathSegments.last; + final String fileName = asset.codeAsset.file!.pathSegments.last; Uri uri; if (absolutePath != null) { // Flutter tester needs full host paths. @@ -415,16 +443,12 @@ KernelAsset _targetLocationSingleArchitecture(CodeAsset asset, Uri? absolutePath default: throw Exception('Unsupported asset link mode ${linkMode.runtimeType} in asset $asset'); } - return KernelAsset( - id: asset.id, - target: Target.fromArchitectureAndOS(asset.architecture, asset.os), - path: kernelAssetPath, - ); + return KernelAsset(id: asset.codeAsset.id, target: asset.target, path: kernelAssetPath); } -Map assetTargetLocationsForOS( +Map assetTargetLocationsForOS( OS targetOS, - List codeAssets, + List codeAssets, bool flutterTester, Uri buildUri, ) { @@ -450,7 +474,7 @@ Future _copyNativeCodeAssetsForOS( Uri buildUri, BuildMode buildMode, FileSystem fileSystem, - Map assetTargetLocations, + Map assetTargetLocations, String? codesignIdentity, bool flutterTester, ) async { @@ -458,9 +482,10 @@ Future _copyNativeCodeAssetsForOS( // If a code asset that use a linking mode of [LookupInProcess], // [LookupInExecutable] or [DynamicLoadingSystem] do not have anything to // bundle as part of the app. - assetTargetLocations = { - for (final CodeAsset codeAsset in assetTargetLocations.keys) - if (codeAsset.linkMode is DynamicLoadingBundled) codeAsset: assetTargetLocations[codeAsset]!, + assetTargetLocations = { + for (final FlutterCodeAsset codeAsset in assetTargetLocations.keys) + if (codeAsset.codeAsset.linkMode is DynamicLoadingBundled) + codeAsset: assetTargetLocations[codeAsset]!, }; if (assetTargetLocations.isEmpty) { @@ -468,7 +493,7 @@ Future _copyNativeCodeAssetsForOS( } globals.logger.printTrace('Copying native assets to ${buildUri.toFilePath()}.'); - final List codeAssets = assetTargetLocations.keys.toList(); + final List codeAssets = assetTargetLocations.keys.toList(); switch (targetOS) { case OS.windows: case OS.linux: @@ -533,7 +558,7 @@ Future _runDartBuild({ : architectures.toList().toString(); globals.logger.printTrace('Building native assets for $targetOS $architectureString.'); - final List assets = []; + final List codeAssets = []; final Set dependencies = {}; final EnvironmentType? environmentType; @@ -566,13 +591,14 @@ Future _runDartBuild({ final MacOSCodeConfig? macOSConfig = targetOS == OS.macOS ? MacOSCodeConfig(targetVersion: targetMacOSVersion) : null; for (final Architecture architecture in architectures) { + final Target target = Target.fromArchitectureAndOS(architecture, targetOS!); final BuildResult? buildResult = await buildRunner.build( extensions: [ CodeAssetExtension( targetArchitecture: architecture, linkModePreference: LinkModePreference.dynamic, cCompiler: cCompilerConfig, - targetOS: targetOS!, + targetOS: targetOS, android: androidConfig, iOS: iosConfig, macOS: macOSConfig, @@ -585,7 +611,7 @@ Future _runDartBuild({ } dependencies.addAll(buildResult.dependencies); if (!linkingEnabled) { - assets.addAll(buildResult.encodedAssets); + codeAssets.addAll(_filterCodeAssets(buildResult.encodedAssets, target)); } else { final LinkResult? linkResult = await buildRunner.link( extensions: [ @@ -604,20 +630,24 @@ Future _runDartBuild({ if (linkResult == null) { _throwNativeAssetsLinkFailed(); } - assets.addAll(linkResult.encodedAssets); + codeAssets.addAll(_filterCodeAssets(linkResult.encodedAssets, target)); dependencies.addAll(linkResult.dependencies); } } - final List codeAssets = - assets - .where((EncodedAsset asset) => asset.type == CodeAsset.type) - .map(CodeAsset.fromEncoded) - .toList(); globals.logger.printTrace('Building native assets for $targetOS $architectureString done.'); return DartBuildResult(codeAssets, dependencies.toList()); } +List _filterCodeAssets(List assets, Target target) => + assets + .where((EncodedAsset asset) => asset.isCodeAsset) + .map( + (EncodedAsset encodedAsset) => + FlutterCodeAsset(codeAsset: encodedAsset.asCodeAsset, target: target), + ) + .toList(); + List _architecturesForOS( TargetPlatform targetPlatform, OS targetOS, @@ -676,7 +706,7 @@ Architecture _getNativeArchitecture(TargetPlatform targetPlatform) { Future _copyNativeCodeAssetsToBundleOnWindowsLinux( Uri buildUri, - Map assetTargetLocations, + Map assetTargetLocations, BuildMode buildMode, FileSystem fileSystem, ) async { @@ -686,8 +716,8 @@ Future _copyNativeCodeAssetsToBundleOnWindowsLinux( if (!buildDir.existsSync()) { buildDir.createSync(recursive: true); } - for (final MapEntry assetMapping in assetTargetLocations.entries) { - final Uri source = assetMapping.key.file!; + for (final MapEntry assetMapping in assetTargetLocations.entries) { + final Uri source = assetMapping.key.codeAsset.file!; final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri; final Uri targetUri = buildUri.resolveUri(target); final String targetFullPath = targetUri.toFilePath(); diff --git a/packages/flutter_tools/lib/src/update_packages_pins.dart b/packages/flutter_tools/lib/src/update_packages_pins.dart index 6157159bae..a6b1978633 100644 --- a/packages/flutter_tools/lib/src/update_packages_pins.dart +++ b/packages/flutter_tools/lib/src/update_packages_pins.dart @@ -25,9 +25,9 @@ const Map kManuallyPinnedDependencies = { 'flutter_template_images': '5.0.0', // Must always exactly match flutter_tools template. 'google_mobile_ads': '5.1.0', // https://github.com/flutter/flutter/issues/156912 'native_assets_builder': - '0.12.0', // Under active development with breaking changes until 1.0.0. Manually rolled by @dcharkes. + '0.13.0', // Under active development with breaking changes until 1.0.0. Manually rolled by @dcharkes. 'native_assets_cli': - '0.12.0', // Under active development with breaking changes until 1.0.0. Manually rolled by @dcharkes. + '0.13.0', // Under active development with breaking changes until 1.0.0. Manually rolled by @dcharkes. 'material_color_utilities': '0.11.1', // Keep pinned to latest until 1.0.0. 'leak_tracker': '10.0.9', // https://github.com/flutter/devtools/issues/3951 'leak_tracker_testing': '3.0.1', // https://github.com/flutter/devtools/issues/3951 diff --git a/packages/flutter_tools/pubspec.yaml b/packages/flutter_tools/pubspec.yaml index bddced1435..3ff5c3b21d 100644 --- a/packages/flutter_tools/pubspec.yaml +++ b/packages/flutter_tools/pubspec.yaml @@ -55,8 +55,8 @@ dependencies: unified_analytics: 7.0.1 graphs: 2.3.2 - native_assets_builder: 0.12.0 - native_assets_cli: 0.12.0 + native_assets_builder: 0.13.0 + native_assets_cli: 0.13.0 # We depend on very specific internal implementation details of the # 'test' package, which change between versions, so when upgrading @@ -122,4 +122,4 @@ dartdoc: # Exclude this package from the hosted API docs. nodoc: true -# PUBSPEC CHECKSUM: 2b6e +# PUBSPEC CHECKSUM: 5070 diff --git a/packages/flutter_tools/templates/package_ffi/pubspec.yaml.tmpl b/packages/flutter_tools/templates/package_ffi/pubspec.yaml.tmpl index a3e9abd7c4..63209e9e85 100644 --- a/packages/flutter_tools/templates/package_ffi/pubspec.yaml.tmpl +++ b/packages/flutter_tools/templates/package_ffi/pubspec.yaml.tmpl @@ -8,8 +8,8 @@ environment: dependencies: logging: ^1.2.0 - native_assets_cli: ^0.12.0 - native_toolchain_c: ^0.9.0 + native_assets_cli: ^0.13.0 + native_toolchain_c: ^0.10.0 dev_dependencies: ffi: ^2.1.3 diff --git a/packages/flutter_tools/test/general.shard/isolated/native_assets_test.dart b/packages/flutter_tools/test/general.shard/isolated/native_assets_test.dart index b14befe960..3dfbf712fc 100644 --- a/packages/flutter_tools/test/general.shard/isolated/native_assets_test.dart +++ b/packages/flutter_tools/test/general.shard/isolated/native_assets_test.dart @@ -254,10 +254,11 @@ void main() { ), ), ); - expect(result.codeAssets.map((CodeAsset c) => c.file!.toString()).toList()..sort(), [ - directSoFile.uri.toString(), - linkedSoFile.uri.toString(), - ]); + expect( + result.codeAssets.map((FlutterCodeAsset c) => c.codeAsset.file!.toString()).toList() + ..sort(), + [directSoFile.uri.toString(), linkedSoFile.uri.toString()], + ); }, ); } diff --git a/packages/flutter_tools/test/integration.shard/isolated/native_assets_test_utils.dart b/packages/flutter_tools/test/integration.shard/isolated/native_assets_test_utils.dart index cff658911e..1e6ae1e0ab 100644 --- a/packages/flutter_tools/test/integration.shard/isolated/native_assets_test_utils.dart +++ b/packages/flutter_tools/test/integration.shard/isolated/native_assets_test_utils.dart @@ -189,7 +189,7 @@ void main(List args) async { await build(args, (input, output) async { final packageName = input.packageName; - if (!input.config.buildAssetTypes.contains(CodeAsset.type)) { + if (!input.config.buildCodeAssets) { return; } final builders = [