[deps] Bump native assets dependencies (#145612)
Roll of a bunch of breaking changes from the native_assets_builder and native_assets_cli upstream. Most notably: * https://github.com/dart-lang/native/pull/946 * https://github.com/dart-lang/native/pull/1018 * https://github.com/dart-lang/native/pull/1019 This PR also updates the template in `flutter create --template=package_ffi` to use the rewritten API. This PR does not change any functionality in Flutter. For reference, the same roll in the Dart SDK: * https://dart-review.googlesource.com/c/sdk/+/357605 * https://dart-review.googlesource.com/c/sdk/+/357623 ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] All existing and new tests are passing. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/wiki/Tree-hygiene#overview [Tree Hygiene]: https://github.com/flutter/flutter/wiki/Tree-hygiene [test-exempt]: https://github.com/flutter/flutter/wiki/Tree-hygiene#tests [Flutter Style Guide]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo [Features we expect every widget to implement]: https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/wiki/Tree-hygiene#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/wiki/Chat
This commit is contained in:
@@ -4,10 +4,7 @@
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||
as native_assets_cli;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||
hide BuildMode;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../android/android_sdk.dart';
|
||||
import '../../../base/common.dart';
|
||||
@@ -30,7 +27,7 @@ Future<Uri?> dryRunNativeAssetsAndroid({
|
||||
return null;
|
||||
}
|
||||
|
||||
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, OS.android);
|
||||
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, OSImpl.android);
|
||||
final Iterable<KernelAsset> nativeAssetPaths =
|
||||
await dryRunNativeAssetsAndroidInternal(
|
||||
fileSystem,
|
||||
@@ -50,20 +47,20 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsAndroidInternal(
|
||||
Uri projectUri,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) async {
|
||||
const OS targetOS = OS.android;
|
||||
const OSImpl targetOS = OSImpl.android;
|
||||
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
||||
linkModePreference: LinkModePreference.dynamic,
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
targetOS: targetOS,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
);
|
||||
ensureNativeAssetsBuildSucceed(dryRunResult);
|
||||
final List<Asset> nativeAssets = dryRunResult.assets;
|
||||
final List<AssetImpl> nativeAssets = dryRunResult.assets;
|
||||
ensureNoLinkModeStatic(nativeAssets);
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||
final Map<Asset, KernelAsset> assetTargetLocations =
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(nativeAssets);
|
||||
return assetTargetLocations.values;
|
||||
}
|
||||
@@ -80,7 +77,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||
required FileSystem fileSystem,
|
||||
required int targetAndroidNdkApi,
|
||||
}) async {
|
||||
const OS targetOS = OS.android;
|
||||
const OSImpl targetOS = OSImpl.android;
|
||||
final Uri buildUri_ = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
if (!await nativeBuildRequired(buildRunner)) {
|
||||
final Uri nativeAssetsYaml = await writeNativeAssetsYaml(
|
||||
@@ -92,21 +89,21 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||
}
|
||||
|
||||
final List<Target> targets = androidArchs.map(_getNativeTarget).toList();
|
||||
final native_assets_cli.BuildMode buildModeCli =
|
||||
final BuildModeImpl buildModeCli =
|
||||
nativeAssetsBuildMode(buildMode);
|
||||
|
||||
globals.logger
|
||||
.printTrace('Building native assets for $targets $buildModeCli.');
|
||||
final List<Asset> nativeAssets = <Asset>[];
|
||||
final List<AssetImpl> nativeAssets = <AssetImpl>[];
|
||||
final Set<Uri> dependencies = <Uri>{};
|
||||
for (final Target target in targets) {
|
||||
final BuildResult result = await buildRunner.build(
|
||||
linkModePreference: LinkModePreference.dynamic,
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
cCompilerConfig: await buildRunner.ndkCCompilerConfig,
|
||||
cCompilerConfig: await buildRunner.ndkCCompilerConfigImpl,
|
||||
targetAndroidNdkApi: targetAndroidNdkApi,
|
||||
);
|
||||
ensureNativeAssetsBuildSucceed(result);
|
||||
@@ -115,7 +112,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||
}
|
||||
ensureNoLinkModeStatic(nativeAssets);
|
||||
globals.logger.printTrace('Building native assets for $targets done.');
|
||||
final Map<Asset, KernelAsset> assetTargetLocations =
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(nativeAssets);
|
||||
await _copyNativeAssetsAndroid(buildUri_, assetTargetLocations, fileSystem);
|
||||
final Uri nativeAssetsUri = await writeNativeAssetsYaml(
|
||||
@@ -127,7 +124,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||
|
||||
Future<void> _copyNativeAssetsAndroid(
|
||||
Uri buildUri,
|
||||
Map<Asset, KernelAsset> assetTargetLocations,
|
||||
Map<AssetImpl, KernelAsset> assetTargetLocations,
|
||||
FileSystem fileSystem,
|
||||
) async {
|
||||
if (assetTargetLocations.isNotEmpty) {
|
||||
@@ -141,9 +138,9 @@ Future<void> _copyNativeAssetsAndroid(
|
||||
final Uri archUri = buildUri.resolve('jniLibs/lib/$jniArchDir/');
|
||||
await fileSystem.directory(archUri).create(recursive: true);
|
||||
}
|
||||
for (final MapEntry<Asset, KernelAsset> assetMapping
|
||||
for (final MapEntry<AssetImpl, KernelAsset> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri source = (assetMapping.key.path as AssetAbsolutePath).uri;
|
||||
final Uri source = assetMapping.key.file!;
|
||||
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
|
||||
final AndroidArch androidArch =
|
||||
_getAndroidArch(assetMapping.value.target);
|
||||
@@ -189,36 +186,37 @@ AndroidArch _getAndroidArch(Target target) {
|
||||
}
|
||||
}
|
||||
|
||||
Map<Asset, KernelAsset> _assetTargetLocations(List<Asset> nativeAssets) {
|
||||
return <Asset, KernelAsset>{
|
||||
for (final Asset asset in nativeAssets)
|
||||
Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||
List<AssetImpl> nativeAssets) {
|
||||
return <AssetImpl, KernelAsset>{
|
||||
for (final AssetImpl 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(Asset asset) {
|
||||
final AssetPath path = asset.path;
|
||||
KernelAsset _targetLocationAndroid(AssetImpl asset) {
|
||||
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (path) {
|
||||
case AssetSystemPath _:
|
||||
kernelAssetPath = KernelAssetSystemPath(path.uri);
|
||||
case AssetInExecutable _:
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystemImpl _:
|
||||
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||
case LookupInExecutableImpl _:
|
||||
kernelAssetPath = KernelAssetInExecutable();
|
||||
case AssetInProcess _:
|
||||
case LookupInProcessImpl _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case AssetAbsolutePath _:
|
||||
final String fileName = path.uri.pathSegments.last;
|
||||
case DynamicLoadingBundledImpl _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
kernelAssetPath = KernelAssetAbsolutePath(Uri(path: fileName));
|
||||
default:
|
||||
throw Exception(
|
||||
'Unsupported asset path type ${path.runtimeType} in asset $asset',
|
||||
'Unsupported asset link mode $linkMode in asset $asset',
|
||||
);
|
||||
}
|
||||
return KernelAsset(
|
||||
id: asset.id,
|
||||
target: asset.target,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||
path: kernelAssetPath,
|
||||
);
|
||||
}
|
||||
@@ -231,17 +229,19 @@ KernelAsset _targetLocationAndroid(Asset asset) {
|
||||
/// assets feature is disabled, or none of the packages have native assets, a
|
||||
/// missing NDK is okay.
|
||||
@override
|
||||
Future<CCompilerConfig> cCompilerConfigAndroid() async {
|
||||
Future<CCompilerConfigImpl> cCompilerConfigAndroid() async {
|
||||
final AndroidSdk? androidSdk = AndroidSdk.locateAndroidSdk();
|
||||
if (androidSdk == null) {
|
||||
throwToolExit('Android SDK could not be found.');
|
||||
}
|
||||
final CCompilerConfig result = CCompilerConfig(
|
||||
cc: _toOptionalFileUri(androidSdk.getNdkClangPath()),
|
||||
ar: _toOptionalFileUri(androidSdk.getNdkArPath()),
|
||||
ld: _toOptionalFileUri(androidSdk.getNdkLdPath()),
|
||||
final CCompilerConfigImpl result = CCompilerConfigImpl(
|
||||
compiler: _toOptionalFileUri(androidSdk.getNdkClangPath()),
|
||||
archiver: _toOptionalFileUri(androidSdk.getNdkArPath()),
|
||||
linker: _toOptionalFileUri(androidSdk.getNdkLdPath()),
|
||||
);
|
||||
if (result.cc == null || result.ar == null || result.ld == null) {
|
||||
if (result.compiler == null ||
|
||||
result.archiver == null ||
|
||||
result.linker == null) {
|
||||
throwToolExit('Android NDK Clang could not be found.');
|
||||
}
|
||||
return result;
|
||||
|
||||
@@ -4,10 +4,7 @@
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||
hide BuildMode;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||
as native_assets_cli;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
@@ -30,7 +27,7 @@ Future<Uri?> dryRunNativeAssetsIOS({
|
||||
return null;
|
||||
}
|
||||
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, OS.iOS);
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, OSImpl.iOS);
|
||||
final Iterable<KernelAsset> assetTargetLocations = await dryRunNativeAssetsIOSInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
@@ -49,16 +46,16 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsIOSInternal(
|
||||
Uri projectUri,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) async {
|
||||
const OS targetOS = OS.iOS;
|
||||
const OSImpl targetOS = OSImpl.iOS;
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
||||
linkModePreference: LinkModePreference.dynamic,
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
targetOS: targetOS,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
);
|
||||
ensureNativeAssetsBuildSucceed(dryRunResult);
|
||||
final List<Asset> nativeAssets = dryRunResult.assets;
|
||||
final List<AssetImpl> nativeAssets = dryRunResult.assets;
|
||||
ensureNoLinkModeStatic(nativeAssets);
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||
return _assetTargetLocations(nativeAssets).values;
|
||||
@@ -81,20 +78,20 @@ Future<List<Uri>> buildNativeAssetsIOS({
|
||||
}
|
||||
|
||||
final List<Target> targets = darwinArchs.map(_getNativeTarget).toList();
|
||||
final native_assets_cli.BuildMode buildModeCli = nativeAssetsBuildMode(buildMode);
|
||||
final BuildModeImpl buildModeCli = nativeAssetsBuildMode(buildMode);
|
||||
|
||||
const OS targetOS = OS.iOS;
|
||||
const OSImpl targetOS = OSImpl.iOS;
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
final IOSSdk iosSdk = _getIOSSdk(environmentType);
|
||||
final IOSSdkImpl iosSdk = _getIOSSdkImpl(environmentType);
|
||||
|
||||
globals.logger.printTrace('Building native assets for $targets $buildModeCli.');
|
||||
final List<Asset> nativeAssets = <Asset>[];
|
||||
final List<AssetImpl> nativeAssets = <AssetImpl>[];
|
||||
final Set<Uri> dependencies = <Uri>{};
|
||||
for (final Target target in targets) {
|
||||
final BuildResult result = await buildRunner.build(
|
||||
linkModePreference: LinkModePreference.dynamic,
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
targetIOSSdk: iosSdk,
|
||||
targetIOSSdkImpl: iosSdk,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
@@ -106,7 +103,8 @@ Future<List<Uri>> buildNativeAssetsIOS({
|
||||
}
|
||||
ensureNoLinkModeStatic(nativeAssets);
|
||||
globals.logger.printTrace('Building native assets for $targets done.');
|
||||
final Map<KernelAssetPath, List<Asset>> fatAssetTargetLocations = _fatAssetTargetLocations(nativeAssets);
|
||||
final Map<KernelAssetPath, List<AssetImpl>> fatAssetTargetLocations =
|
||||
_fatAssetTargetLocations(nativeAssets);
|
||||
await _copyNativeAssetsIOS(
|
||||
buildUri,
|
||||
fatAssetTargetLocations,
|
||||
@@ -115,7 +113,8 @@ Future<List<Uri>> buildNativeAssetsIOS({
|
||||
fileSystem,
|
||||
);
|
||||
|
||||
final Map<Asset, KernelAsset> assetTargetLocations = _assetTargetLocations(nativeAssets);
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(nativeAssets);
|
||||
await writeNativeAssetsYaml(
|
||||
KernelAssets(assetTargetLocations.values),
|
||||
yamlParentDirectory,
|
||||
@@ -124,12 +123,12 @@ Future<List<Uri>> buildNativeAssetsIOS({
|
||||
return dependencies.toList();
|
||||
}
|
||||
|
||||
IOSSdk _getIOSSdk(EnvironmentType environmentType) {
|
||||
IOSSdkImpl _getIOSSdkImpl(EnvironmentType environmentType) {
|
||||
switch (environmentType) {
|
||||
case EnvironmentType.physical:
|
||||
return IOSSdk.iPhoneOs;
|
||||
return IOSSdkImpl.iPhoneOS;
|
||||
case EnvironmentType.simulator:
|
||||
return IOSSdk.iPhoneSimulator;
|
||||
return IOSSdkImpl.iPhoneSimulator;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,11 +144,13 @@ Target _getNativeTarget(DarwinArch darwinArch) {
|
||||
}
|
||||
}
|
||||
|
||||
Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(List<Asset> nativeAssets) {
|
||||
Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(
|
||||
List<AssetImpl> nativeAssets) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<KernelAssetPath, List<Asset>> result = <KernelAssetPath, List<Asset>>{};
|
||||
final Map<KernelAssetPath, List<AssetImpl>> result =
|
||||
<KernelAssetPath, List<AssetImpl>>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
for (final Asset asset in nativeAssets) {
|
||||
for (final AssetImpl asset in nativeAssets) {
|
||||
// Use same target path for all assets with the same id.
|
||||
final KernelAssetPath path = idToPath[asset.id] ??
|
||||
_targetLocationIOS(
|
||||
@@ -157,44 +158,45 @@ Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(List<Asset> nativeAss
|
||||
alreadyTakenNames,
|
||||
).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[path] ??= <Asset>[];
|
||||
result[path] ??= <AssetImpl>[];
|
||||
result[path]!.add(asset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Map<Asset, KernelAsset> _assetTargetLocations(List<Asset> nativeAssets) {
|
||||
Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||
List<AssetImpl> nativeAssets) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
return <Asset, KernelAsset>{
|
||||
for (final Asset asset in nativeAssets)
|
||||
return <AssetImpl, KernelAsset>{
|
||||
for (final AssetImpl asset in nativeAssets)
|
||||
asset: _targetLocationIOS(asset, alreadyTakenNames),
|
||||
};
|
||||
}
|
||||
|
||||
KernelAsset _targetLocationIOS(Asset asset, Set<String> alreadyTakenNames) {
|
||||
final AssetPath path = asset.path;
|
||||
KernelAsset _targetLocationIOS(AssetImpl asset, Set<String> alreadyTakenNames) {
|
||||
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (path) {
|
||||
case AssetSystemPath _:
|
||||
kernelAssetPath = KernelAssetSystemPath(path.uri);
|
||||
case AssetInExecutable _:
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystemImpl _:
|
||||
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||
case LookupInExecutableImpl _:
|
||||
kernelAssetPath = KernelAssetInExecutable();
|
||||
case AssetInProcess _:
|
||||
case LookupInProcessImpl _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case AssetAbsolutePath _:
|
||||
final String fileName = path.uri.pathSegments.last;
|
||||
case DynamicLoadingBundledImpl _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
kernelAssetPath = KernelAssetAbsolutePath(frameworkUri(
|
||||
fileName,
|
||||
alreadyTakenNames,
|
||||
));
|
||||
default:
|
||||
throw Exception(
|
||||
'Unsupported asset path type ${path.runtimeType} in asset $asset',
|
||||
'Unsupported asset link mode $linkMode in asset $asset',
|
||||
);
|
||||
}
|
||||
return KernelAsset(
|
||||
id: asset.id,
|
||||
target: asset.target,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||
path: kernelAssetPath,
|
||||
);
|
||||
}
|
||||
@@ -211,7 +213,7 @@ final KernelAssetPath kernelAssetPath;
|
||||
/// in xcode_backend.dart.
|
||||
Future<void> _copyNativeAssetsIOS(
|
||||
Uri buildUri,
|
||||
Map<KernelAssetPath, List<Asset>> assetTargetLocations,
|
||||
Map<KernelAssetPath, List<AssetImpl>> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
@@ -219,12 +221,11 @@ Future<void> _copyNativeAssetsIOS(
|
||||
if (assetTargetLocations.isNotEmpty) {
|
||||
globals.logger
|
||||
.printTrace('Copying native assets to ${buildUri.toFilePath()}.');
|
||||
for (final MapEntry<KernelAssetPath, List<Asset>> assetMapping
|
||||
for (final MapEntry<KernelAssetPath, List<AssetImpl>> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||
final List<Uri> sources = <Uri>[
|
||||
for (final Asset source in assetMapping.value)
|
||||
(source.path as AssetAbsolutePath).uri
|
||||
for (final AssetImpl source in assetMapping.value) source.file!
|
||||
];
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final File dylibFile = fileSystem.file(targetUri);
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||
hide BuildMode;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/common.dart';
|
||||
import '../../../base/file_system.dart';
|
||||
@@ -29,7 +28,7 @@ Future<Uri?> dryRunNativeAssetsLinux({
|
||||
projectUri: projectUri,
|
||||
flutterTester: flutterTester,
|
||||
fileSystem: fileSystem,
|
||||
os: OS.linux,
|
||||
os: OSImpl.linux,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -44,7 +43,7 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsLinuxInternal(
|
||||
projectUri,
|
||||
flutterTester,
|
||||
buildRunner,
|
||||
OS.linux,
|
||||
OSImpl.linux,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -71,7 +70,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsLinux({
|
||||
/// Flutter expects `clang++` to be on the path on Linux hosts.
|
||||
///
|
||||
/// Search for the accompanying `clang`, `ar`, and `ld`.
|
||||
Future<CCompilerConfig> cCompilerConfigLinux() async {
|
||||
Future<CCompilerConfigImpl> cCompilerConfigLinux() async {
|
||||
const String kClangPlusPlusBinary = 'clang++';
|
||||
const String kClangBinary = 'clang';
|
||||
const String kArBinary = 'llvm-ar';
|
||||
@@ -93,9 +92,9 @@ Future<CCompilerConfig> cCompilerConfigLinux() async {
|
||||
}
|
||||
binaryPaths[binary] = binaryFile.uri;
|
||||
}
|
||||
return CCompilerConfig(
|
||||
ar: binaryPaths[kArBinary],
|
||||
cc: binaryPaths[kClangBinary],
|
||||
ld: binaryPaths[kLdBinary],
|
||||
return CCompilerConfigImpl(
|
||||
archiver: binaryPaths[kArBinary],
|
||||
compiler: binaryPaths[kClangBinary],
|
||||
linker: binaryPaths[kLdBinary],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,7 @@
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||
hide BuildMode;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||
as native_assets_cli;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
@@ -30,7 +27,7 @@ Future<Uri?> dryRunNativeAssetsMacOS({
|
||||
return null;
|
||||
}
|
||||
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, OS.macOS);
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, OSImpl.macOS);
|
||||
final Iterable<KernelAsset> nativeAssetPaths = await dryRunNativeAssetsMacOSInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
@@ -51,22 +48,23 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsMacOSInternal(
|
||||
bool flutterTester,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
) async {
|
||||
const OS targetOS = OS.macOS;
|
||||
const OSImpl targetOS = OSImpl.macOS;
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
||||
linkModePreference: LinkModePreference.dynamic,
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
targetOS: targetOS,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
);
|
||||
ensureNativeAssetsBuildSucceed(dryRunResult);
|
||||
final List<Asset> nativeAssets = dryRunResult.assets;
|
||||
final List<AssetImpl> nativeAssets = dryRunResult.assets;
|
||||
ensureNoLinkModeStatic(nativeAssets);
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||
final Map<Asset, KernelAsset> assetTargetLocations = _assetTargetLocations(
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(
|
||||
nativeAssets,
|
||||
absolutePath,
|
||||
);
|
||||
@@ -90,7 +88,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsMacOS({
|
||||
Uri? yamlParentDirectory,
|
||||
required FileSystem fileSystem,
|
||||
}) async {
|
||||
const OS targetOS = OS.macOS;
|
||||
const OSImpl targetOS = OSImpl.macOS;
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
if (!await nativeBuildRequired(buildRunner)) {
|
||||
final Uri nativeAssetsYaml = await writeNativeAssetsYaml(
|
||||
@@ -104,16 +102,16 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsMacOS({
|
||||
final List<Target> targets = darwinArchs != null
|
||||
? darwinArchs.map(_getNativeTarget).toList()
|
||||
: <Target>[Target.current];
|
||||
final native_assets_cli.BuildMode buildModeCli =
|
||||
final BuildModeImpl buildModeCli =
|
||||
nativeAssetsBuildMode(buildMode);
|
||||
|
||||
globals.logger
|
||||
.printTrace('Building native assets for $targets $buildModeCli.');
|
||||
final List<Asset> nativeAssets = <Asset>[];
|
||||
final List<AssetImpl> nativeAssets = <AssetImpl>[];
|
||||
final Set<Uri> dependencies = <Uri>{};
|
||||
for (final Target target in targets) {
|
||||
final BuildResult result = await buildRunner.build(
|
||||
linkModePreference: LinkModePreference.dynamic,
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
@@ -127,9 +125,9 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsMacOS({
|
||||
ensureNoLinkModeStatic(nativeAssets);
|
||||
globals.logger.printTrace('Building native assets for $targets done.');
|
||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||
final Map<Asset, KernelAsset> assetTargetLocations =
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocations(nativeAssets, absolutePath);
|
||||
final Map<KernelAssetPath, List<Asset>> fatAssetTargetLocations =
|
||||
final Map<KernelAssetPath, List<AssetImpl>> fatAssetTargetLocations =
|
||||
_fatAssetTargetLocations(nativeAssets, absolutePath);
|
||||
if (flutterTester) {
|
||||
await _copyNativeAssetsMacOSFlutterTester(
|
||||
@@ -168,15 +166,15 @@ Target _getNativeTarget(DarwinArch darwinArch) {
|
||||
}
|
||||
}
|
||||
|
||||
Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(
|
||||
List<Asset> nativeAssets,
|
||||
Map<KernelAssetPath, List<AssetImpl>> _fatAssetTargetLocations(
|
||||
List<AssetImpl> nativeAssets,
|
||||
Uri? absolutePath,
|
||||
) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
final Map<KernelAssetPath, List<Asset>> result =
|
||||
<KernelAssetPath, List<Asset>>{};
|
||||
final Map<KernelAssetPath, List<AssetImpl>> result =
|
||||
<KernelAssetPath, List<AssetImpl>>{};
|
||||
final Map<String, KernelAssetPath> idToPath = <String, KernelAssetPath>{};
|
||||
for (final Asset asset in nativeAssets) {
|
||||
for (final AssetImpl asset in nativeAssets) {
|
||||
// Use same target path for all assets with the same id.
|
||||
final KernelAssetPath path = idToPath[asset.id] ??
|
||||
_targetLocationMacOS(
|
||||
@@ -185,39 +183,39 @@ Map<KernelAssetPath, List<Asset>> _fatAssetTargetLocations(
|
||||
alreadyTakenNames,
|
||||
).path;
|
||||
idToPath[asset.id] = path;
|
||||
result[path] ??= <Asset>[];
|
||||
result[path] ??= <AssetImpl>[];
|
||||
result[path]!.add(asset);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Map<Asset, KernelAsset> _assetTargetLocations(
|
||||
List<Asset> nativeAssets,
|
||||
Map<AssetImpl, KernelAsset> _assetTargetLocations(
|
||||
List<AssetImpl> nativeAssets,
|
||||
Uri? absolutePath,
|
||||
) {
|
||||
final Set<String> alreadyTakenNames = <String>{};
|
||||
return <Asset, KernelAsset>{
|
||||
for (final Asset asset in nativeAssets)
|
||||
return <AssetImpl, KernelAsset>{
|
||||
for (final AssetImpl asset in nativeAssets)
|
||||
asset: _targetLocationMacOS(asset, absolutePath, alreadyTakenNames),
|
||||
};
|
||||
}
|
||||
|
||||
KernelAsset _targetLocationMacOS(
|
||||
Asset asset,
|
||||
AssetImpl asset,
|
||||
Uri? absolutePath,
|
||||
Set<String> alreadyTakenNames,
|
||||
) {
|
||||
final AssetPath path = asset.path;
|
||||
final LinkModeImpl linkMode = (asset as NativeCodeAssetImpl).linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (path) {
|
||||
case AssetSystemPath _:
|
||||
kernelAssetPath = KernelAssetSystemPath(path.uri);
|
||||
case AssetInExecutable _:
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystemImpl _:
|
||||
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||
case LookupInExecutableImpl _:
|
||||
kernelAssetPath = KernelAssetInExecutable();
|
||||
case AssetInProcess _:
|
||||
case LookupInProcessImpl _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case AssetAbsolutePath _:
|
||||
final String fileName = path.uri.pathSegments.last;
|
||||
case DynamicLoadingBundledImpl _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
Uri uri;
|
||||
if (absolutePath != null) {
|
||||
// Flutter tester needs full host paths.
|
||||
@@ -231,12 +229,12 @@ KernelAsset _targetLocationMacOS(
|
||||
kernelAssetPath = KernelAssetAbsolutePath(uri);
|
||||
default:
|
||||
throw Exception(
|
||||
'Unsupported asset path type ${path.runtimeType} in asset $asset',
|
||||
'Unsupported asset link mode $linkMode in asset $asset',
|
||||
);
|
||||
}
|
||||
return KernelAsset(
|
||||
id: asset.id,
|
||||
target: asset.target,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||
path: kernelAssetPath,
|
||||
);
|
||||
}
|
||||
@@ -256,7 +254,7 @@ KernelAsset _targetLocationMacOS(
|
||||
/// in macos_assemble.sh.
|
||||
Future<void> _copyNativeAssetsMacOS(
|
||||
Uri buildUri,
|
||||
Map<KernelAssetPath, List<Asset>> assetTargetLocations,
|
||||
Map<KernelAssetPath, List<AssetImpl>> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
@@ -265,12 +263,11 @@ Future<void> _copyNativeAssetsMacOS(
|
||||
globals.logger.printTrace(
|
||||
'Copying native assets to ${buildUri.toFilePath()}.',
|
||||
);
|
||||
for (final MapEntry<KernelAssetPath, List<Asset>> assetMapping
|
||||
for (final MapEntry<KernelAssetPath, List<AssetImpl>> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||
final List<Uri> sources = <Uri>[
|
||||
for (final Asset source in assetMapping.value)
|
||||
(source.path as AssetAbsolutePath).uri,
|
||||
for (final AssetImpl source in assetMapping.value) source.file!,
|
||||
];
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final String name = targetUri.pathSegments.last;
|
||||
@@ -326,7 +323,7 @@ Future<void> _copyNativeAssetsMacOS(
|
||||
/// Code signing is also done here.
|
||||
Future<void> _copyNativeAssetsMacOSFlutterTester(
|
||||
Uri buildUri,
|
||||
Map<KernelAssetPath, List<Asset>> assetTargetLocations,
|
||||
Map<KernelAssetPath, List<AssetImpl>> assetTargetLocations,
|
||||
String? codesignIdentity,
|
||||
BuildMode buildMode,
|
||||
FileSystem fileSystem,
|
||||
@@ -335,12 +332,11 @@ Future<void> _copyNativeAssetsMacOSFlutterTester(
|
||||
globals.logger.printTrace(
|
||||
'Copying native assets to ${buildUri.toFilePath()}.',
|
||||
);
|
||||
for (final MapEntry<KernelAssetPath, List<Asset>> assetMapping
|
||||
for (final MapEntry<KernelAssetPath, List<AssetImpl>> assetMapping
|
||||
in assetTargetLocations.entries) {
|
||||
final Uri target = (assetMapping.key as KernelAssetAbsolutePath).uri;
|
||||
final List<Uri> sources = <Uri>[
|
||||
for (final Asset source in assetMapping.value)
|
||||
(source.path as AssetAbsolutePath).uri,
|
||||
for (final AssetImpl source in assetMapping.value) source.file!,
|
||||
];
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final File dylibFile = fileSystem.file(targetUri);
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
// Shared logic between iOS and macOS implementations of native assets.
|
||||
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||
hide BuildMode;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/common.dart';
|
||||
import '../../../base/file_system.dart';
|
||||
@@ -131,7 +130,7 @@ Future<void> codesignDylib(
|
||||
/// Flutter expects `xcrun` to be on the path on macOS hosts.
|
||||
///
|
||||
/// Use the `clang`, `ar`, and `ld` that would be used if run with `xcrun`.
|
||||
Future<CCompilerConfig> cCompilerConfigMacOS() async {
|
||||
Future<CCompilerConfigImpl> cCompilerConfigMacOS() async {
|
||||
final ProcessResult xcrunResult = await globals.processManager.run(
|
||||
<String>['xcrun', 'clang', '--version'],
|
||||
);
|
||||
@@ -142,10 +141,10 @@ Future<CCompilerConfig> cCompilerConfigMacOS() async {
|
||||
.firstWhere((String s) => s.startsWith('InstalledDir: '))
|
||||
.split(' ')
|
||||
.last;
|
||||
return CCompilerConfig(
|
||||
cc: Uri.file('$installPath/clang'),
|
||||
ar: Uri.file('$installPath/ar'),
|
||||
ld: Uri.file('$installPath/ld'),
|
||||
return CCompilerConfigImpl(
|
||||
compiler: Uri.file('$installPath/clang'),
|
||||
archiver: Uri.file('$installPath/ar'),
|
||||
linker: Uri.file('$installPath/ld'),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
as native_assets_builder show NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_cli/native_assets_cli.dart';
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
import 'package:package_config/package_config_types.dart';
|
||||
|
||||
@@ -46,28 +47,28 @@ abstract class NativeAssetsBuildRunner {
|
||||
/// Runs all [packagesWithNativeAssets] `build.dart` in dry run.
|
||||
Future<DryRunResult> dryRun({
|
||||
required bool includeParentEnvironment,
|
||||
required LinkModePreference linkModePreference,
|
||||
required OS targetOS,
|
||||
required LinkModePreferenceImpl linkModePreference,
|
||||
required OSImpl targetOS,
|
||||
required Uri workingDirectory,
|
||||
});
|
||||
|
||||
/// Runs all [packagesWithNativeAssets] `build.dart`.
|
||||
Future<BuildResult> build({
|
||||
required bool includeParentEnvironment,
|
||||
required BuildMode buildMode,
|
||||
required LinkModePreference linkModePreference,
|
||||
required BuildModeImpl buildMode,
|
||||
required LinkModePreferenceImpl linkModePreference,
|
||||
required Target target,
|
||||
required Uri workingDirectory,
|
||||
CCompilerConfig? cCompilerConfig,
|
||||
CCompilerConfigImpl? cCompilerConfig,
|
||||
int? targetAndroidNdkApi,
|
||||
IOSSdk? targetIOSSdk,
|
||||
IOSSdkImpl? targetIOSSdkImpl,
|
||||
});
|
||||
|
||||
/// The C compiler config to use for compilation.
|
||||
Future<CCompilerConfig> get cCompilerConfig;
|
||||
Future<CCompilerConfigImpl> get cCompilerConfig;
|
||||
|
||||
/// The NDK compiler to use to use for compilation for Android.
|
||||
Future<CCompilerConfig> get ndkCCompilerConfig;
|
||||
Future<CCompilerConfigImpl> get ndkCCompilerConfigImpl;
|
||||
}
|
||||
|
||||
/// Uses `package:native_assets_builder` for its implementation.
|
||||
@@ -125,8 +126,8 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||
@override
|
||||
Future<DryRunResult> dryRun({
|
||||
required bool includeParentEnvironment,
|
||||
required LinkModePreference linkModePreference,
|
||||
required OS targetOS,
|
||||
required LinkModePreferenceImpl linkModePreference,
|
||||
required OSImpl targetOS,
|
||||
required Uri workingDirectory,
|
||||
}) {
|
||||
final PackageLayout packageLayout = PackageLayout.fromPackageConfig(
|
||||
@@ -136,7 +137,7 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||
return _buildRunner.dryRun(
|
||||
includeParentEnvironment: includeParentEnvironment,
|
||||
linkModePreference: linkModePreference,
|
||||
targetOs: targetOS,
|
||||
targetOS: targetOS,
|
||||
workingDirectory: workingDirectory,
|
||||
packageLayout: packageLayout,
|
||||
);
|
||||
@@ -145,13 +146,13 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||
@override
|
||||
Future<BuildResult> build({
|
||||
required bool includeParentEnvironment,
|
||||
required BuildMode buildMode,
|
||||
required LinkModePreference linkModePreference,
|
||||
required BuildModeImpl buildMode,
|
||||
required LinkModePreferenceImpl linkModePreference,
|
||||
required Target target,
|
||||
required Uri workingDirectory,
|
||||
CCompilerConfig? cCompilerConfig,
|
||||
CCompilerConfigImpl? cCompilerConfig,
|
||||
int? targetAndroidNdkApi,
|
||||
IOSSdk? targetIOSSdk,
|
||||
IOSSdkImpl? targetIOSSdkImpl,
|
||||
}) {
|
||||
final PackageLayout packageLayout = PackageLayout.fromPackageConfig(
|
||||
packageConfig,
|
||||
@@ -164,14 +165,14 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||
linkModePreference: linkModePreference,
|
||||
target: target,
|
||||
targetAndroidNdkApi: targetAndroidNdkApi,
|
||||
targetIOSSdk: targetIOSSdk,
|
||||
targetIOSSdk: targetIOSSdkImpl,
|
||||
workingDirectory: workingDirectory,
|
||||
packageLayout: packageLayout,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
late final Future<CCompilerConfig> cCompilerConfig = () {
|
||||
late final Future<CCompilerConfigImpl> cCompilerConfig = () {
|
||||
if (globals.platform.isMacOS || globals.platform.isIOS) {
|
||||
return cCompilerConfigMacOS();
|
||||
}
|
||||
@@ -182,13 +183,13 @@ class NativeAssetsBuildRunnerImpl implements NativeAssetsBuildRunner {
|
||||
return cCompilerConfigWindows();
|
||||
}
|
||||
if (globals.platform.isAndroid) {
|
||||
throwToolExit('Should use ndkCCompilerConfig for Android.');
|
||||
throwToolExit('Should use ndkCCompilerConfigImpl for Android.');
|
||||
}
|
||||
throwToolExit('Unknown target OS.');
|
||||
}();
|
||||
|
||||
@override
|
||||
late final Future<CCompilerConfig> ndkCCompilerConfig = () {
|
||||
late final Future<CCompilerConfigImpl> ndkCCompilerConfigImpl = () {
|
||||
return cCompilerConfigAndroid();
|
||||
}();
|
||||
}
|
||||
@@ -212,14 +213,14 @@ Future<Uri> writeNativeAssetsYaml(
|
||||
}
|
||||
|
||||
/// Select the native asset build mode for a given Flutter build mode.
|
||||
BuildMode nativeAssetsBuildMode(build_info.BuildMode buildMode) {
|
||||
BuildModeImpl nativeAssetsBuildMode(build_info.BuildMode buildMode) {
|
||||
switch (buildMode) {
|
||||
case build_info.BuildMode.debug:
|
||||
return BuildMode.debug;
|
||||
return BuildModeImpl.debug;
|
||||
case build_info.BuildMode.jitRelease:
|
||||
case build_info.BuildMode.profile:
|
||||
case build_info.BuildMode.release:
|
||||
return BuildMode.release;
|
||||
return BuildModeImpl.release;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,10 +295,12 @@ Future<void> ensureNoNativeAssetsOrOsIsSupported(
|
||||
/// https://github.com/dart-lang/sdk/issues/49418.
|
||||
///
|
||||
/// Therefore, ensure all `build.dart` scripts return only dynamic libraries.
|
||||
void ensureNoLinkModeStatic(List<Asset> nativeAssets) {
|
||||
final Iterable<Asset> staticAssets = nativeAssets.where((Asset e) => e.linkMode == LinkMode.static);
|
||||
void ensureNoLinkModeStatic(List<AssetImpl> nativeAssets) {
|
||||
final Iterable<AssetImpl> staticAssets = nativeAssets.where((AssetImpl e) =>
|
||||
e is NativeCodeAssetImpl && e.linkMode == StaticLinkingImpl());
|
||||
if (staticAssets.isNotEmpty) {
|
||||
final String assetIds = staticAssets.map((Asset a) => a.id).toSet().join(', ');
|
||||
final String assetIds =
|
||||
staticAssets.map((AssetImpl a) => a.id).toSet().join(', ');
|
||||
throwToolExit(
|
||||
'Native asset(s) $assetIds have their link mode set to static, '
|
||||
'but this is not yet supported. '
|
||||
@@ -308,7 +311,7 @@ void ensureNoLinkModeStatic(List<Asset> nativeAssets) {
|
||||
|
||||
/// This should be the same for different archs, debug/release, etc.
|
||||
/// It should work for all macOS.
|
||||
Uri nativeAssetsBuildUri(Uri projectUri, OS os) {
|
||||
Uri nativeAssetsBuildUri(Uri projectUri, OSImpl os) {
|
||||
final String buildDir = build_info.getBuildDirectory();
|
||||
return projectUri.resolve('$buildDir/native_assets/$os/');
|
||||
}
|
||||
@@ -455,7 +458,8 @@ Future<Uri?> dryRunNativeAssetsMultipleOSes({
|
||||
final Uri buildUri = buildUriMultiple(projectUri);
|
||||
final Iterable<KernelAsset> nativeAssetPaths = <KernelAsset>[
|
||||
if (targetPlatforms.contains(build_info.TargetPlatform.darwin) ||
|
||||
(targetPlatforms.contains(build_info.TargetPlatform.tester) && OS.current == OS.macOS))
|
||||
(targetPlatforms.contains(build_info.TargetPlatform.tester) &&
|
||||
OSImpl.current == OSImpl.macOS))
|
||||
...await dryRunNativeAssetsMacOSInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
@@ -464,7 +468,8 @@ Future<Uri?> dryRunNativeAssetsMultipleOSes({
|
||||
),
|
||||
if (targetPlatforms.contains(build_info.TargetPlatform.linux_arm64) ||
|
||||
targetPlatforms.contains(build_info.TargetPlatform.linux_x64) ||
|
||||
(targetPlatforms.contains(build_info.TargetPlatform.tester) && OS.current == OS.linux))
|
||||
(targetPlatforms.contains(build_info.TargetPlatform.tester) &&
|
||||
OSImpl.current == OSImpl.linux))
|
||||
...await dryRunNativeAssetsLinuxInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
@@ -473,7 +478,8 @@ Future<Uri?> dryRunNativeAssetsMultipleOSes({
|
||||
),
|
||||
if (targetPlatforms.contains(build_info.TargetPlatform.windows_arm64) ||
|
||||
targetPlatforms.contains(build_info.TargetPlatform.windows_x64) ||
|
||||
(targetPlatforms.contains(build_info.TargetPlatform.tester) && OS.current == OS.windows))
|
||||
(targetPlatforms.contains(build_info.TargetPlatform.tester) &&
|
||||
OSImpl.current == OSImpl.windows))
|
||||
...await dryRunNativeAssetsWindowsInternal(
|
||||
fileSystem,
|
||||
projectUri,
|
||||
@@ -521,7 +527,7 @@ Future<Uri?> dryRunNativeAssetsSingleArchitecture({
|
||||
required Uri projectUri,
|
||||
bool flutterTester = false,
|
||||
required FileSystem fileSystem,
|
||||
required OS os,
|
||||
required OSImpl os,
|
||||
}) async {
|
||||
if (!await nativeBuildRequired(buildRunner)) {
|
||||
return null;
|
||||
@@ -548,24 +554,25 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsSingleArchitectureInternal(
|
||||
Uri projectUri,
|
||||
bool flutterTester,
|
||||
NativeAssetsBuildRunner buildRunner,
|
||||
OS targetOS,
|
||||
OSImpl targetOS,
|
||||
) async {
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS.');
|
||||
|
||||
final DryRunResult dryRunResult = await buildRunner.dryRun(
|
||||
linkModePreference: LinkModePreference.dynamic,
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
targetOS: targetOS,
|
||||
workingDirectory: projectUri,
|
||||
includeParentEnvironment: true,
|
||||
);
|
||||
ensureNativeAssetsBuildSucceed(dryRunResult);
|
||||
final List<Asset> nativeAssets = dryRunResult.assets;
|
||||
final List<AssetImpl> nativeAssets = dryRunResult.assets;
|
||||
ensureNoLinkModeStatic(nativeAssets);
|
||||
globals.logger.printTrace('Dry running native assets for $targetOS done.');
|
||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||
final Map<Asset, KernelAsset> assetTargetLocations = _assetTargetLocationsSingleArchitecture(
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocationsSingleArchitecture(
|
||||
nativeAssets,
|
||||
absolutePath,
|
||||
);
|
||||
@@ -589,7 +596,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsSingleA
|
||||
required FileSystem fileSystem,
|
||||
}) async {
|
||||
final Target target = targetPlatform != null ? _getNativeTarget(targetPlatform) : Target.current;
|
||||
final OS targetOS = target.os;
|
||||
final OSImpl targetOS = target.os;
|
||||
final Uri buildUri = nativeAssetsBuildUri(projectUri, targetOS);
|
||||
final Directory buildDir = fileSystem.directory(buildUri);
|
||||
if (!await buildDir.exists()) {
|
||||
@@ -605,11 +612,11 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsSingleA
|
||||
return (nativeAssetsYaml, <Uri>[]);
|
||||
}
|
||||
|
||||
final BuildMode buildModeCli = nativeAssetsBuildMode(buildMode);
|
||||
final BuildModeImpl buildModeCli = nativeAssetsBuildMode(buildMode);
|
||||
|
||||
globals.logger.printTrace('Building native assets for $target $buildModeCli.');
|
||||
final BuildResult result = await buildRunner.build(
|
||||
linkModePreference: LinkModePreference.dynamic,
|
||||
linkModePreference: LinkModePreferenceImpl.dynamic,
|
||||
target: target,
|
||||
buildMode: buildModeCli,
|
||||
workingDirectory: projectUri,
|
||||
@@ -617,12 +624,13 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsSingleA
|
||||
cCompilerConfig: await buildRunner.cCompilerConfig,
|
||||
);
|
||||
ensureNativeAssetsBuildSucceed(result);
|
||||
final List<Asset> nativeAssets = result.assets;
|
||||
final List<AssetImpl> nativeAssets = result.assets;
|
||||
final Set<Uri> dependencies = result.dependencies.toSet();
|
||||
ensureNoLinkModeStatic(nativeAssets);
|
||||
globals.logger.printTrace('Building native assets for $target done.');
|
||||
final Uri? absolutePath = flutterTester ? buildUri : null;
|
||||
final Map<Asset, KernelAsset> assetTargetLocations = _assetTargetLocationsSingleArchitecture(nativeAssets, absolutePath);
|
||||
final Map<AssetImpl, KernelAsset> assetTargetLocations =
|
||||
_assetTargetLocationsSingleArchitecture(nativeAssets, absolutePath);
|
||||
await _copyNativeAssetsSingleArchitecture(
|
||||
buildUri,
|
||||
assetTargetLocations,
|
||||
@@ -637,12 +645,12 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)> buildNativeAssetsSingleA
|
||||
return (nativeAssetsUri, dependencies.toList());
|
||||
}
|
||||
|
||||
Map<Asset, KernelAsset> _assetTargetLocationsSingleArchitecture(
|
||||
List<Asset> nativeAssets,
|
||||
Map<AssetImpl, KernelAsset> _assetTargetLocationsSingleArchitecture(
|
||||
List<AssetImpl> nativeAssets,
|
||||
Uri? absolutePath,
|
||||
) {
|
||||
return <Asset, KernelAsset>{
|
||||
for (final Asset asset in nativeAssets)
|
||||
return <AssetImpl, KernelAsset>{
|
||||
for (final AssetImpl asset in nativeAssets)
|
||||
asset: _targetLocationSingleArchitecture(
|
||||
asset,
|
||||
absolutePath,
|
||||
@@ -650,18 +658,24 @@ Map<Asset, KernelAsset> _assetTargetLocationsSingleArchitecture(
|
||||
};
|
||||
}
|
||||
|
||||
KernelAsset _targetLocationSingleArchitecture(Asset asset, Uri? absolutePath) {
|
||||
final AssetPath path = asset.path;
|
||||
KernelAsset _targetLocationSingleArchitecture(
|
||||
AssetImpl asset, Uri? absolutePath) {
|
||||
if (asset is! NativeCodeAssetImpl) {
|
||||
throw Exception(
|
||||
'Unsupported asset type ${asset.runtimeType}',
|
||||
);
|
||||
}
|
||||
final LinkModeImpl linkMode = asset.linkMode;
|
||||
final KernelAssetPath kernelAssetPath;
|
||||
switch (path) {
|
||||
case AssetSystemPath _:
|
||||
kernelAssetPath = KernelAssetSystemPath(path.uri);
|
||||
case AssetInExecutable _:
|
||||
switch (linkMode) {
|
||||
case DynamicLoadingSystemImpl _:
|
||||
kernelAssetPath = KernelAssetSystemPath(linkMode.uri);
|
||||
case LookupInExecutableImpl _:
|
||||
kernelAssetPath = KernelAssetInExecutable();
|
||||
case AssetInProcess _:
|
||||
case LookupInProcessImpl _:
|
||||
kernelAssetPath = KernelAssetInProcess();
|
||||
case AssetAbsolutePath _:
|
||||
final String fileName = path.uri.pathSegments.last;
|
||||
case DynamicLoadingBundledImpl _:
|
||||
final String fileName = asset.file!.pathSegments.last;
|
||||
Uri uri;
|
||||
if (absolutePath != null) {
|
||||
// Flutter tester needs full host paths.
|
||||
@@ -675,12 +689,12 @@ KernelAsset _targetLocationSingleArchitecture(Asset asset, Uri? absolutePath) {
|
||||
kernelAssetPath = KernelAssetAbsolutePath(uri);
|
||||
default:
|
||||
throw Exception(
|
||||
'Unsupported asset path type ${path.runtimeType} in asset $asset',
|
||||
'Unsupported asset link mode ${linkMode.runtimeType} in asset $asset',
|
||||
);
|
||||
}
|
||||
return KernelAsset(
|
||||
id: asset.id,
|
||||
target: asset.target,
|
||||
target: Target.fromArchitectureAndOS(asset.architecture!, asset.os),
|
||||
path: kernelAssetPath,
|
||||
);
|
||||
}
|
||||
@@ -727,7 +741,7 @@ Future<void> _copyNativeAssetsSingleArchitecture(
|
||||
buildDir.createSync(recursive: true);
|
||||
}
|
||||
for (final MapEntry<Asset, KernelAsset> assetMapping in assetTargetLocations.entries) {
|
||||
final Uri source = (assetMapping.key.path as AssetAbsolutePath).uri;
|
||||
final Uri source = assetMapping.key.file!;
|
||||
final Uri target = (assetMapping.value.path as KernelAssetAbsolutePath).uri;
|
||||
final Uri targetUri = buildUri.resolveUri(target);
|
||||
final String targetFullPath = targetUri.toFilePath();
|
||||
|
||||
@@ -4,8 +4,7 @@
|
||||
|
||||
import 'package:native_assets_builder/native_assets_builder.dart'
|
||||
hide NativeAssetsBuildRunner;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart'
|
||||
hide BuildMode;
|
||||
import 'package:native_assets_cli/native_assets_cli_internal.dart';
|
||||
|
||||
import '../../../base/file_system.dart';
|
||||
import '../../../build_info.dart';
|
||||
@@ -28,7 +27,7 @@ Future<Uri?> dryRunNativeAssetsWindows({
|
||||
projectUri: projectUri,
|
||||
flutterTester: flutterTester,
|
||||
fileSystem: fileSystem,
|
||||
os: OS.windows,
|
||||
os: OSImpl.windows,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -43,7 +42,7 @@ Future<Iterable<KernelAsset>> dryRunNativeAssetsWindowsInternal(
|
||||
projectUri,
|
||||
flutterTester,
|
||||
buildRunner,
|
||||
OS.windows,
|
||||
OSImpl.windows,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -68,7 +67,7 @@ Future<(Uri? nativeAssetsYaml, List<Uri> dependencies)>
|
||||
);
|
||||
}
|
||||
|
||||
Future<CCompilerConfig> cCompilerConfigWindows() async {
|
||||
Future<CCompilerConfigImpl> cCompilerConfigWindows() async {
|
||||
final VisualStudio visualStudio = VisualStudio(
|
||||
fileSystem: globals.fs,
|
||||
platform: globals.platform,
|
||||
@@ -77,10 +76,10 @@ Future<CCompilerConfig> cCompilerConfigWindows() async {
|
||||
osUtils: globals.os,
|
||||
);
|
||||
|
||||
return CCompilerConfig(
|
||||
cc: _toOptionalFileUri(visualStudio.clPath),
|
||||
ld: _toOptionalFileUri(visualStudio.linkPath),
|
||||
ar: _toOptionalFileUri(visualStudio.libPath),
|
||||
return CCompilerConfigImpl(
|
||||
compiler: _toOptionalFileUri(visualStudio.clPath),
|
||||
linker: _toOptionalFileUri(visualStudio.linkPath),
|
||||
archiver: _toOptionalFileUri(visualStudio.libPath),
|
||||
envScript: _toOptionalFileUri(visualStudio.vcvarsPath),
|
||||
envScriptArgs: <String>[],
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user