[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:
Daco Harkes 2024-03-25 15:02:49 +01:00 committed by GitHub
parent 280037f6b1
commit baa54fdd76
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 473 additions and 414 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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],
);
}

View file

@ -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);

View file

@ -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'),
);
}

View file

@ -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();

View file

@ -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>[],
);

View file

@ -54,10 +54,10 @@ dependencies:
async: 2.11.0
unified_analytics: 5.8.8
cli_config: 0.1.2
cli_config: 0.2.0
graphs: 2.3.1
native_assets_builder: 0.5.0
native_assets_cli: 0.4.2
native_assets_builder: 0.6.1
native_assets_cli: 0.5.3
# We depend on very specific internal implementation details of the
# 'test' package, which change between versions, so when upgrading
@ -120,4 +120,4 @@ dartdoc:
# Exclude this package from the hosted API docs.
nodoc: true
# PUBSPEC CHECKSUM: df1d
# PUBSPEC CHECKSUM: ba20

View file

@ -1,24 +0,0 @@
import 'package:native_toolchain_c/native_toolchain_c.dart';
import 'package:logging/logging.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
const packageName = '{{projectName}}';
void main(List<String> args) async {
final buildConfig = await BuildConfig.fromArgs(args);
final buildOutput = BuildOutput();
final cbuilder = CBuilder.library(
name: packageName,
assetId:
'package:$packageName/${packageName}_bindings_generated.dart',
sources: [
'src/$packageName.c',
],
);
await cbuilder.run(
buildConfig: buildConfig,
buildOutput: buildOutput,
logger: Logger('')..onRecord.listen((record) => print(record.message)),
);
await buildOutput.writeToFile(outDir: buildConfig.outDir);
}

View file

@ -0,0 +1,26 @@
import 'package:native_toolchain_c/native_toolchain_c.dart';
import 'package:logging/logging.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
const packageName = '{{projectName}}';
void main(List<String> args) async {
await build(args, (config, output) async {
final packageName = config.packageName;
final cbuilder = CBuilder.library(
name: packageName,
assetName: '${packageName}_bindings_generated.dart',
sources: [
'src/$packageName.c',
],
dartBuildFiles: ['hook/build.dart'],
);
await cbuilder.run(
buildConfig: config,
buildOutput: output,
logger: Logger('')
..level = Level.ALL
..onRecord.listen((record) => print(record.message)),
);
});
}

View file

@ -7,10 +7,10 @@ environment:
sdk: {{dartSdkVersionBounds}}
dependencies:
cli_config: ^0.1.2
cli_config: ^0.2.0
logging: ^1.2.0
native_assets_cli: ^0.4.2
native_toolchain_c: ^0.3.4+1
native_assets_cli: ^0.5.3
native_toolchain_c: ^0.4.1
dev_dependencies:
ffi: ^2.1.0

View file

@ -252,9 +252,9 @@
"templates/package_ffi/.gitignore.tmpl",
"templates/package_ffi/.metadata.tmpl",
"templates/package_ffi/analysis_options.yaml.tmpl",
"templates/package_ffi/build.dart.tmpl",
"templates/package_ffi/CHANGELOG.md.tmpl",
"templates/package_ffi/ffigen.yaml.tmpl",
"templates/package_ffi/hook/build.dart.tmpl",
"templates/package_ffi/lib/projectName_bindings_generated.dart.tmpl",
"templates/package_ffi/lib/projectName.dart.tmpl",
"templates/package_ffi/LICENSE.tmpl",

View file

@ -15,10 +15,7 @@ import 'package:flutter_tools/src/build_system/build_system.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/isolated/native_assets/android/native_assets.dart';
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, Target;
import 'package:native_assets_cli/native_assets_cli_internal.dart';
import 'package:package_config/package_config_types.dart';
import '../../../src/common.dart';
@ -128,18 +125,20 @@ void main() {
Package('bar', projectUri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSArm64,
path: AssetAbsolutePath(Uri.file('libbar.so')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.arm64,
file: Uri.file('libbar.so'),
),
Asset(
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSX64,
path: AssetAbsolutePath(Uri.file('libbar.so')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.x64,
file: Uri.file('libbar.so'),
),
],
),
@ -237,12 +236,13 @@ void main() {
Package('bar', projectUri),
],
buildResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.androidArm64,
path: AssetAbsolutePath(Uri.file('libbar.so')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.android,
architecture: ArchitectureImpl.arm64,
file: Uri.file('libbar.so'),
),
],
),
@ -382,6 +382,6 @@ class _BuildRunnerWithoutNdk extends FakeNativeAssetsBuildRunner {
});
@override
Future<CCompilerConfig> get ndkCCompilerConfig async =>
Future<CCompilerConfigImpl> get ndkCCompilerConfigImpl async =>
throwToolExit('Android NDK Clang could not be found.');
}

View file

@ -130,18 +130,20 @@ void main() {
final NativeAssetsBuildRunner buildRunner = FakeNativeAssetsBuildRunner(
packagesWithNativeAssetsResult: <Package>[Package('foo', iosEnvironment.buildDir.uri)],
buildResult: FakeNativeAssetsBuilderResult(assets: <native_assets_cli.Asset>[
native_assets_cli.Asset(
id: 'package:foo/foo.dart',
linkMode: native_assets_cli.LinkMode.dynamic,
target: native_assets_cli.Target.iOSArm64,
path: native_assets_cli.AssetAbsolutePath(
Uri.file('foo.framework/foo'),
buildResult: FakeNativeAssetsBuilderResult(
assets: <native_assets_cli.AssetImpl>[
native_assets_cli.NativeCodeAssetImpl(
id: 'package:foo/foo.dart',
linkMode: native_assets_cli.DynamicLoadingBundledImpl(),
os: native_assets_cli.OSImpl.iOS,
architecture: native_assets_cli.ArchitectureImpl.arm64,
file: Uri.file('foo.framework/foo'),
),
)
], dependencies: <Uri>[
Uri.file('src/foo.c'),
]),
],
dependencies: <Uri>[
Uri.file('src/foo.c'),
],
),
);
await NativeAssets(buildRunner: buildRunner).build(iosEnvironment);
@ -191,23 +193,27 @@ void main() {
packagesWithNativeAssetsResult: <Package>[
Package('foo', androidEnvironment.buildDir.uri)
],
buildResult:
FakeNativeAssetsBuilderResult(assets: <native_assets_cli.Asset>[
if (hasAssets)
native_assets_cli.Asset(
id: 'package:foo/foo.dart',
linkMode: native_assets_cli.LinkMode.dynamic,
target: native_assets_cli.Target.androidArm64,
path: native_assets_cli.AssetAbsolutePath(
Uri.file('libfoo.so'),
buildResult: FakeNativeAssetsBuilderResult(
assets: <native_assets_cli.AssetImpl>[
if (hasAssets)
native_assets_cli.NativeCodeAssetImpl(
id: 'package:foo/foo.dart',
linkMode: native_assets_cli.DynamicLoadingBundledImpl(),
os: native_assets_cli.OSImpl.android,
architecture: native_assets_cli.ArchitectureImpl.arm64,
file: Uri.file('libfoo.so'),
),
)
], dependencies: <Uri>[
Uri.file('src/foo.c'),
]),
],
dependencies: <Uri>[
Uri.file('src/foo.c'),
],
),
);
await NativeAssets(buildRunner: buildRunner).build(androidEnvironment);
expect(buildRunner.lastBuildMode, native_assets_cli.BuildMode.release);
expect(
buildRunner.lastBuildMode,
native_assets_cli.BuildModeImpl.release,
);
},
);
}

View file

@ -21,35 +21,36 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
this.onBuild,
this.dryRunResult = const FakeNativeAssetsBuilderResult(),
this.buildResult = const FakeNativeAssetsBuilderResult(),
CCompilerConfig? cCompilerConfigResult,
CCompilerConfig? ndkCCompilerConfigResult,
}) : cCompilerConfigResult = cCompilerConfigResult ?? CCompilerConfig(),
ndkCCompilerConfigResult = ndkCCompilerConfigResult ?? CCompilerConfig();
CCompilerConfigImpl? cCompilerConfigResult,
CCompilerConfigImpl? ndkCCompilerConfigImplResult,
}) : cCompilerConfigResult = cCompilerConfigResult ?? CCompilerConfigImpl(),
ndkCCompilerConfigImplResult =
ndkCCompilerConfigImplResult ?? CCompilerConfigImpl();
final native_assets_builder.BuildResult Function(Target)? onBuild;
final native_assets_builder.BuildResult buildResult;
final native_assets_builder.DryRunResult dryRunResult;
final bool hasPackageConfigResult;
final List<Package> packagesWithNativeAssetsResult;
final CCompilerConfig cCompilerConfigResult;
final CCompilerConfig ndkCCompilerConfigResult;
final CCompilerConfigImpl cCompilerConfigResult;
final CCompilerConfigImpl ndkCCompilerConfigImplResult;
int buildInvocations = 0;
int dryRunInvocations = 0;
int hasPackageConfigInvocations = 0;
int packagesWithNativeAssetsInvocations = 0;
BuildMode? lastBuildMode;
BuildModeImpl? lastBuildMode;
@override
Future<native_assets_builder.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,
}) async {
buildInvocations++;
lastBuildMode = buildMode;
@ -59,8 +60,8 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
@override
Future<native_assets_builder.DryRunResult> dryRun({
required bool includeParentEnvironment,
required LinkModePreference linkModePreference,
required OS targetOS,
required LinkModePreferenceImpl linkModePreference,
required OSImpl targetOS,
required Uri workingDirectory,
}) async {
dryRunInvocations++;
@ -80,22 +81,24 @@ class FakeNativeAssetsBuildRunner implements NativeAssetsBuildRunner {
}
@override
Future<CCompilerConfig> get cCompilerConfig async => cCompilerConfigResult;
Future<CCompilerConfigImpl> get cCompilerConfig async =>
cCompilerConfigResult;
@override
Future<CCompilerConfig> get ndkCCompilerConfig async => cCompilerConfigResult;
Future<CCompilerConfigImpl> get ndkCCompilerConfigImpl async =>
cCompilerConfigResult;
}
final class FakeNativeAssetsBuilderResult
implements native_assets_builder.BuildResult {
const FakeNativeAssetsBuilderResult({
this.assets = const <Asset>[],
this.assets = const <AssetImpl>[],
this.dependencies = const <Uri>[],
this.success = true,
});
@override
final List<Asset> assets;
final List<AssetImpl> assets;
@override
final List<Uri> dependencies;

View file

@ -14,9 +14,7 @@ import 'package:flutter_tools/src/resident_devtools_handler.dart';
import 'package:flutter_tools/src/resident_runner.dart';
import 'package:flutter_tools/src/run_hot.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart'
hide BuildMode, Target;
import 'package:native_assets_cli/native_assets_cli_internal.dart'
as native_assets_cli;
hide Target;
import 'package:package_config/package_config.dart';
import 'package:unified_analytics/unified_analytics.dart';
@ -65,12 +63,20 @@ void main() {
Package('bar', fileSystem.currentDirectory.uri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSArm64,
path: AssetAbsolutePath(Uri.file('bar.dylib')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.arm64,
file: Uri.file('bar.dylib'),
),
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.x64,
file: Uri.file('bar.dylib'),
),
],
),
@ -124,12 +130,20 @@ void main() {
Package('bar', fileSystem.currentDirectory.uri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSArm64,
path: AssetAbsolutePath(Uri.file('bar.dylib')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.arm64,
file: Uri.file('bar.dylib'),
),
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.x64,
file: Uri.file('bar.dylib'),
),
],
),

View file

@ -15,7 +15,7 @@ import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/isolated/native_assets/ios/native_assets.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart'
hide BuildMode, Target;
hide Target;
import 'package:native_assets_cli/native_assets_cli_internal.dart'
as native_assets_cli;
import 'package:package_config/package_config_types.dart';
@ -127,18 +127,20 @@ void main() {
Package('bar', projectUri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSArm64,
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.arm64,
file: Uri.file('libbar.dylib'),
),
Asset(
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSX64,
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.x64,
file: Uri.file('libbar.dylib'),
),
],
),
@ -265,12 +267,13 @@ void main() {
Package('bar', projectUri),
],
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: target,
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
linkMode: DynamicLoadingBundledImpl(),
os: target.os,
architecture: target.architecture,
file: Uri.file('${target.architecture}/libbar.dylib'),
),
],
),

View file

@ -18,9 +18,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/isolated/native_assets/linux/native_assets.dart';
import 'package:flutter_tools/src/isolated/native_assets/native_assets.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart'
hide BuildMode, Target;
import 'package:native_assets_cli/native_assets_cli_internal.dart'
as native_assets_cli;
hide Target;
import 'package:package_config/package_config_types.dart';
import '../../../src/common.dart';
@ -165,18 +163,20 @@ void main() {
Package('bar', projectUri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.linuxX64,
path: AssetAbsolutePath(Uri.file('libbar.so')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.linux,
architecture: ArchitectureImpl.x64,
file: Uri.file('libbar.so'),
),
Asset(
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.linuxArm64,
path: AssetAbsolutePath(Uri.file('libbar.so')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.linux,
architecture: ArchitectureImpl.arm64,
file: Uri.file('libbar.so'),
),
],
),
@ -284,12 +284,13 @@ void main() {
Package('bar', projectUri),
],
buildResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.linuxX64,
path: AssetAbsolutePath(dylibAfterCompiling.uri),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.linux,
architecture: ArchitectureImpl.x64,
file: dylibAfterCompiling.uri,
),
],
),
@ -337,18 +338,20 @@ void main() {
Package('bar', projectUri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.static,
target: native_assets_cli.Target.macOSArm64,
path: AssetAbsolutePath(Uri.file('bar.a')),
linkMode: StaticLinkingImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.arm64,
file: Uri.file('bar.a'),
),
Asset(
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.static,
target: native_assets_cli.Target.macOSX64,
path: AssetAbsolutePath(Uri.file('bar.a')),
linkMode: StaticLinkingImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.x64,
file: Uri.file('bar.a'),
),
],
),
@ -460,12 +463,13 @@ void main() {
);
final NativeAssetsBuildRunner runner =
NativeAssetsBuildRunnerImpl(projectUri, packageConfig, fileSystem, logger);
final CCompilerConfig result = await runner.cCompilerConfig;
expect(result.cc, Uri.file('/some/path/to/clang'));
final CCompilerConfigImpl result = await runner.cCompilerConfig;
expect(result.compiler, Uri.file('/some/path/to/clang'));
});
}
class _BuildRunnerWithoutClang extends FakeNativeAssetsBuildRunner {
@override
Future<CCompilerConfig> get cCompilerConfig async => throwToolExit('Failed to find clang++ on the PATH.');
Future<CCompilerConfigImpl> get cCompilerConfig async =>
throwToolExit('Failed to find clang++ on the PATH.');
}

View file

@ -16,7 +16,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/isolated/native_assets/macos/native_assets.dart';
import 'package:flutter_tools/src/isolated/native_assets/native_assets.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart'
hide BuildMode, Target;
hide Target;
import 'package:native_assets_cli/native_assets_cli_internal.dart'
as native_assets_cli;
import 'package:package_config/package_config_types.dart';
@ -146,18 +146,20 @@ void main() {
Package('bar', projectUri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSArm64,
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.arm64,
file: Uri.file('libbar.dylib'),
),
Asset(
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.macOSX64,
path: AssetAbsolutePath(Uri.file('libbar.dylib')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.x64,
file: Uri.file('libbar.dylib'),
),
],
),
@ -302,12 +304,13 @@ void main() {
Package('bar', projectUri),
],
onBuild: (native_assets_cli.Target target) => FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: target,
path: AssetAbsolutePath(Uri.file('${target.architecture}/libbar.dylib')),
linkMode: DynamicLoadingBundledImpl(),
os: target.os,
architecture: target.architecture,
file: Uri.file('${target.architecture}/libbar.dylib'),
),
],
),
@ -355,18 +358,20 @@ void main() {
Package('bar', projectUri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.static,
target: native_assets_cli.Target.macOSArm64,
path: AssetAbsolutePath(Uri.file('bar.a')),
linkMode: StaticLinkingImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.arm64,
file: Uri.file('bar.a'),
),
Asset(
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.static,
target: native_assets_cli.Target.macOSX64,
path: AssetAbsolutePath(Uri.file('bar.a')),
linkMode: StaticLinkingImpl(),
os: OSImpl.macOS,
architecture: ArchitectureImpl.x64,
file: Uri.file('bar.a'),
),
],
),
@ -479,9 +484,9 @@ InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault
fileSystem,
logger,
);
final CCompilerConfig result = await runner.cCompilerConfig;
final CCompilerConfigImpl result = await runner.cCompilerConfig;
expect(
result.cc,
result.compiler,
Uri.file(
'/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang',
),

View file

@ -17,9 +17,7 @@ import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/isolated/native_assets/native_assets.dart';
import 'package:flutter_tools/src/isolated/native_assets/windows/native_assets.dart';
import 'package:native_assets_cli/native_assets_cli_internal.dart'
hide BuildMode, Target;
import 'package:native_assets_cli/native_assets_cli_internal.dart'
as native_assets_cli;
hide Target;
import 'package:package_config/package_config_types.dart';
import '../../../src/common.dart';
@ -145,12 +143,13 @@ void main() {
Package('bar', projectUri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.windowsX64,
path: AssetAbsolutePath(Uri.file('bar.dll')),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.windows,
architecture: ArchitectureImpl.x64,
file: Uri.file('bar.dll'),
),
],
),
@ -255,12 +254,13 @@ void main() {
Package('bar', projectUri),
],
buildResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.dynamic,
target: native_assets_cli.Target.windowsX64,
path: AssetAbsolutePath(dylibAfterCompiling.uri),
linkMode: DynamicLoadingBundledImpl(),
os: OSImpl.windows,
architecture: ArchitectureImpl.x64,
file: dylibAfterCompiling.uri,
),
],
),
@ -308,12 +308,13 @@ void main() {
Package('bar', projectUri),
],
dryRunResult: FakeNativeAssetsBuilderResult(
assets: <Asset>[
Asset(
assets: <AssetImpl>[
NativeCodeAssetImpl(
id: 'package:bar/bar.dart',
linkMode: LinkMode.static,
target: native_assets_cli.Target.windowsX64,
path: AssetAbsolutePath(Uri.file(OS.windows.staticlibFileName('bar'))),
linkMode: StaticLinkingImpl(),
os: OSImpl.windows,
architecture: ArchitectureImpl.x64,
file: Uri.file(OSImpl.windows.staticlibFileName('bar')),
),
],
),
@ -492,10 +493,19 @@ void main() {
fileSystem,
logger,
);
final CCompilerConfig result = await runner.cCompilerConfig;
expect(result.cc?.toFilePath(), msvcBinDir.childFile('cl.exe').uri.toFilePath());
expect(result.ar?.toFilePath(), msvcBinDir.childFile('lib.exe').uri.toFilePath());
expect(result.ld?.toFilePath(), msvcBinDir.childFile('link.exe').uri.toFilePath());
final CCompilerConfigImpl result = await runner.cCompilerConfig;
expect(
result.compiler?.toFilePath(),
msvcBinDir.childFile('cl.exe').uri.toFilePath(),
);
expect(
result.archiver?.toFilePath(),
msvcBinDir.childFile('lib.exe').uri.toFilePath(),
);
expect(
result.linker?.toFilePath(),
msvcBinDir.childFile('link.exe').uri.toFilePath(),
);
expect(result.envScript, isNotNull);
expect(result.envScriptArgs, isNotNull);
});

View file

@ -227,16 +227,17 @@ void main() {
testWithoutContext('flutter build $buildSubcommand error on static libraries', () async {
await inTempDir((Directory tempDirectory) async {
final Directory packageDirectory = await createTestProject(packageName, tempDirectory);
final File buildDotDart = packageDirectory.childFile('build.dart');
final File buildDotDart =
packageDirectory.childDirectory('hook').childFile('build.dart');
final String buildDotDartContents = await buildDotDart.readAsString();
// Overrides the build to output static libraries.
final String buildDotDartContentsNew = buildDotDartContents.replaceFirst(
'final buildConfig = await BuildConfig.fromArgs(args);',
'await build(args, (config, output) async {',
'''
final buildConfig = await BuildConfig.fromArgs([
'-D${LinkModePreference.configKey}=${LinkModePreference.static}',
await build([
'-D${LinkModePreferenceImpl.configKey}=${LinkModePreferenceImpl.static}',
...args,
]);
], (config, output) async {
''',
);
expect(buildDotDartContentsNew, isNot(buildDotDartContents));
@ -344,7 +345,7 @@ void expectDylibIsBundledIos(Directory appDirectory, String buildMode) {
/// Sample path: build/linux/x64/release/bundle/lib/libmy_package.so
void expectDylibIsBundledLinux(Directory appDirectory, String buildMode) {
// Linux does not support cross compilation, so always only check current architecture.
final String architecture = Architecture.current.dartPlatform;
final String architecture = ArchitectureImpl.current.dartPlatform;
final Directory appBundle = appDirectory
.childDirectory('build')
.childDirectory(hostOs)
@ -354,7 +355,8 @@ void expectDylibIsBundledLinux(Directory appDirectory, String buildMode) {
expect(appBundle, exists);
final Directory dylibsFolder = appBundle.childDirectory('lib');
expect(dylibsFolder, exists);
final File dylib = dylibsFolder.childFile(OS.linux.dylibFileName(packageName));
final File dylib =
dylibsFolder.childFile(OSImpl.linux.dylibFileName(packageName));
expect(dylib, exists);
}
@ -363,7 +365,7 @@ void expectDylibIsBundledLinux(Directory appDirectory, String buildMode) {
/// Sample path: build\windows\x64\runner\Debug\my_package_example.exe
void expectDylibIsBundledWindows(Directory appDirectory, String buildMode) {
// Linux does not support cross compilation, so always only check current architecture.
final String architecture = Architecture.current.dartPlatform;
final String architecture = ArchitectureImpl.current.dartPlatform;
final Directory appBundle = appDirectory
.childDirectory('build')
.childDirectory(hostOs)
@ -371,7 +373,8 @@ void expectDylibIsBundledWindows(Directory appDirectory, String buildMode) {
.childDirectory('runner')
.childDirectory(buildMode.upperCaseFirst());
expect(appBundle, exists);
final File dylib = appBundle.childFile(OS.windows.dylibFileName(packageName));
final File dylib =
appBundle.childFile(OSImpl.windows.dylibFileName(packageName));
expect(dylib, exists);
}
@ -401,7 +404,8 @@ void expectDylibIsBundledAndroid(Directory appDirectory, String buildMode) {
if (buildMode != 'debug') {
expect(archDir.childFile('libapp.so'), exists);
}
final File dylib = archDir.childFile(OS.android.dylibFileName(packageName));
final File dylib =
archDir.childFile(OSImpl.android.dylibFileName(packageName));
expect(dylib, exists);
}
}
@ -424,14 +428,14 @@ void expectDylibIsBundledWithFrameworks(Directory appDirectory, String buildMode
void expectCCompilerIsConfigured(Directory appDirectory) {
final Directory nativeAssetsBuilderDir = appDirectory.childDirectory('.dart_tool/native_assets_builder/');
for (final Directory subDir in nativeAssetsBuilderDir.listSync().whereType<Directory>()) {
final File config = subDir.childFile('config.yaml');
final File config = subDir.childFile('config.json');
expect(config, exists);
final String contents = config.readAsStringSync();
// Dry run does not pass compiler info.
if (contents.contains('dry_run: true')) {
if (contents.contains('"dry_run": true')) {
continue;
}
expect(contents, contains('cc: '));
expect(contents, contains('"cc": '));
}
}