Skip to content

Commit

Permalink
[deps] Roll dart-lang/native
Browse files Browse the repository at this point in the history
This CL refactors the native assets implementation in Dartdev:

* It introduces a `DartNativeAssetsBuilder` that wraps all logic.
* The code now explicitly searches for a package config, and invokes
  `pub get` if that file does not exist but a pubspec does.
  (For most `dartdev` commands, `pub get` was already running later
  implicitly.)
* The code now explicitly searches for a `runPackageName` and skips
  building native assets if a package name cannot be found.

Change-Id: Ib5562fc64c3a756c99fee2e2daa763eb6fb1e855
Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-arm64-try,pkg-win-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404583
Commit-Queue: Daco Harkes <[email protected]>
Reviewed-by: Hossein Yousefi <[email protected]>
Reviewed-by: Ben Konyi <[email protected]>
  • Loading branch information
dcharkes authored and Commit Queue committed Jan 21, 2025
1 parent eba7e49 commit e1eade6
Show file tree
Hide file tree
Showing 8 changed files with 372 additions and 331 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ vars = {
"markdown_rev": "19aaded4300d24bedcbf52ade792b203ddf030b0",
"material_color_utilities_rev": "799b6ba2f3f1c28c67cc7e0b4f18e0c7d7f3c03e",
# dart-native-interop-team@ is rolling breaking changes manually while the assets features are in experimental.
"native_rev": "d1d9aa5e62d239580b8bf17e36db6d47c308fc89", # disable tools/rev_sdk_deps.dart
"native_rev": "3ed5d3d07246cd792693584c2c42216739a634b7", # disable tools/rev_sdk_deps.dart
"protobuf_rev": "b7dd58cdbd879beee4c3fbf8ee80fce8e97bad26",
"pub_rev": "710265bae23ad5860f33287fba10b5c369f19a93", # disable tools/rev_sdk_deps.dart
"shelf_rev": "bf799519cda2898a7c5af06dcfdd5fe6443afd79",
Expand Down
95 changes: 12 additions & 83 deletions pkg/dartdev/lib/src/commands/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@ import 'package:dartdev/src/commands/compile.dart';
import 'package:dartdev/src/experiments.dart';
import 'package:dartdev/src/native_assets_bundling.dart';
import 'package:dartdev/src/sdk.dart';
import 'package:dartdev/src/utils.dart';
import 'package:file/local.dart';
import 'package:front_end/src/api_prototype/compiler_options.dart'
show Verbosity;
import 'package:native_assets_builder/native_assets_builder.dart';
import 'package:native_assets_cli/code_assets_builder.dart';
import 'package:native_assets_cli/data_assets_builder.dart';
import 'package:package_config/package_config.dart' as package_config;
import 'package:path/path.dart' as path;
import 'package:vm/target_os.dart'; // For possible --target-os values.

Expand Down Expand Up @@ -132,61 +127,23 @@ class BuildCommand extends DartdevCommand {
}
await outputDir.create(recursive: true);

// Start native asset generation here.
stdout.writeln('Building native assets.');
final packageConfig = await findPackageConfigUri(sourceUri);
final runPackageName = await findRootPackageName(sourceUri);
final workingDirectory = Directory.current.uri;
final packageLayout = PackageLayout.fromPackageConfig(
LocalFileSystem(),
await package_config.loadPackageConfigUri(packageConfig!),
packageConfig,
final packageConfig = await DartNativeAssetsBuilder.ensurePackageConfig(
sourceUri,
);
final target = Target.current;
final macOSConfig = target.os == OS.macOS
? MacOSConfig(targetVersion: minimumSupportedMacOSVersion)
: null;
final nativeAssetsBuildRunner = NativeAssetsBuildRunner(
fileSystem: const LocalFileSystem(),
dartExecutable: Uri.file(sdk.dart),
logger: logger(verbose),
final runPackageName = await DartNativeAssetsBuilder.findRootPackageName(
sourceUri,
);

final cCompilerConfig = getCCompilerConfig();

final buildResult = await nativeAssetsBuildRunner.build(
inputCreator: () => BuildInputBuilder()
..config.setupCode(
targetOS: target.os,
linkModePreference: LinkModePreference.dynamic,
targetArchitecture: target.architecture,
macOS: macOSConfig,
cCompiler: cCompilerConfig,
),
inputValidator: (config) async => [
...await validateDataAssetBuildInput(config),
...await validateCodeAssetBuildInput(config),
],
workingDirectory: workingDirectory,
packageLayout: packageLayout,
runPackageName: runPackageName,
linkingEnabled: true,
buildAssetTypes: [
CodeAsset.type,
],
buildValidator: (config, output) async => [
...await validateDataAssetBuildOutput(config, output),
...await validateCodeAssetBuildOutput(config, output),
],
applicationAssetValidator: (assets) async => [
...await validateCodeAssetInApplication(assets),
],
final builder = DartNativeAssetsBuilder(
packageConfigUri: packageConfig!,
runPackageName: runPackageName!,
verbose: verbose,
);
final buildResult = await builder.buildNativeAssetsAOT();
if (buildResult == null) {
stderr.writeln('Native assets build failed.');
return 255;
}
// End native asset generation here.

final tempDir = Directory.systemTemp.createTempSync();
try {
Expand All @@ -211,38 +168,10 @@ class BuildCommand extends DartdevCommand {
recordedUsagesFile: recordedUsagesPath,
);

// Start linking here.
final linkResult = await nativeAssetsBuildRunner.link(
inputCreator: () => LinkInputBuilder()
..config.setupCode(
targetOS: target.os,
targetArchitecture: target.architecture,
linkModePreference: LinkModePreference.dynamic,
macOS: macOSConfig,
cCompiler: cCompilerConfig,
),
inputValidator: (config) async => [
...await validateDataAssetLinkInput(config),
...await validateCodeAssetLinkInput(config),
],
resourceIdentifiers:
recordUseEnabled ? Uri.file(recordedUsagesPath!) : null,
workingDirectory: workingDirectory,
runPackageName: runPackageName,
packageLayout: packageLayout,
final linkResult = await builder.linkNativeAssetsAOT(
recordedUsagesPath: recordedUsagesPath,
buildResult: buildResult,
buildAssetTypes: [
CodeAsset.type,
],
linkValidator: (config, output) async => [
...await validateDataAssetLinkOutput(config, output),
...await validateCodeAssetLinkOutput(config, output),
],
applicationAssetValidator: (assets) async => [
...await validateCodeAssetInApplication(assets),
],
);

if (linkResult == null) {
stderr.writeln('Native assets link failed.');
return 255;
Expand All @@ -265,7 +194,7 @@ Use linkMode as dynamic library instead.""");
if (allAssets.isNotEmpty) {
final kernelAssets = await bundleNativeAssets(
allAssets,
target,
builder.target,
outputUri,
relocatable: true,
verbose: true,
Expand Down
44 changes: 28 additions & 16 deletions pkg/dartdev/lib/src/commands/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -558,23 +558,35 @@ Remove debugging information from the output and save it separately to the speci
return compileErrorExitCode;
}

if (!nativeAssetsExperimentEnabled) {
if (await warnOnNativeAssets()) {
return 255;
}
} else {
final assets = await compileNativeAssetsJit(
verbose: verbose,
runPackageName: await findRootPackageName(Directory.current.uri),
final packageConfig = await DartNativeAssetsBuilder.ensurePackageConfig(
Directory.current.uri,
);
if (packageConfig != null) {
final runPackageName = await DartNativeAssetsBuilder.findRootPackageName(
Directory.current.uri,
);
if (assets == null) {
stderr.writeln('Native assets build failed.');
return 255;
}
if (assets.isNotEmpty) {
stderr.writeln(
"'dart compile' does currently not support native assets.");
return 255;
if (runPackageName != null) {
final builder = DartNativeAssetsBuilder(
packageConfigUri: packageConfig,
runPackageName: runPackageName,
verbose: verbose,
);
if (!nativeAssetsExperimentEnabled) {
if (await builder.warnOnNativeAssets()) {
return 255;
}
} else {
final assets = await builder.compileNativeAssetsJit();
if (assets == null) {
stderr.writeln('Native assets build failed.');
return 255;
}
if (assets.isNotEmpty) {
stderr.writeln(
"'dart compile' does currently not support native assets.");
return 255;
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/dartdev/lib/src/commands/language_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ For more information about the server's capabilities and configuration, see:
sdk.analysisServerSnapshot,
args,
packageConfigOverride: null,
useExecProcess : false,
useExecProcess: false,
);
return 0;
} catch (e, st) {
Expand Down
40 changes: 26 additions & 14 deletions pkg/dartdev/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -371,22 +371,34 @@ class RunCommand extends DartdevCommand {
}

String? nativeAssets;
if (!nativeAssetsExperimentEnabled) {
if (await warnOnNativeAssets()) {
return errorExitCode;
}
} else {
final packageConfig = await DartNativeAssetsBuilder.ensurePackageConfig(
Directory.current.uri,
);
if (packageConfig != null) {
final runPackageName = getPackageForCommand(mainCommand) ??
await findRootPackageName(Directory.current.uri);
final assetsYamlFileUri = await compileNativeAssetsJitYamlFile(
verbose: verbose,
runPackageName: runPackageName,
);
if (assetsYamlFileUri == null) {
log.stderr('Error: Compiling native assets failed.');
return errorExitCode;
await DartNativeAssetsBuilder.findRootPackageName(
Directory.current.uri,
);
if (runPackageName != null) {
final builder = DartNativeAssetsBuilder(
packageConfigUri: packageConfig,
runPackageName: runPackageName,
verbose: verbose,
);
if (!nativeAssetsExperimentEnabled) {
if (await builder.warnOnNativeAssets()) {
return errorExitCode;
}
} else {
final assetsYamlFileUri =
await builder.compileNativeAssetsJitYamlFile();
if (assetsYamlFileUri == null) {
log.stderr('Error: Compiling native assets failed.');
return errorExitCode;
}
nativeAssets = assetsYamlFileUri.toFilePath();
}
}
nativeAssets = assetsYamlFileUri.toFilePath();
}

final String? residentCompilerInfoFileArg =
Expand Down
38 changes: 25 additions & 13 deletions pkg/dartdev/lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,33 @@ Run "${runner!.executableName} help" to see global options.''');
final args = argResults!;

String? nativeAssets;
if (!nativeAssetsExperimentEnabled) {
if (await warnOnNativeAssets()) {
return DartdevCommand.errorExitCode;
}
} else {
final assetsYamlFileUri =
await compileNativeAssetsJitYamlFile(
verbose: verbose,
runPackageName: await findRootPackageName(Directory.current.uri),
final packageConfig = await DartNativeAssetsBuilder.ensurePackageConfig(
Directory.current.uri,
);
if (packageConfig != null) {
final runPackageName = await DartNativeAssetsBuilder.findRootPackageName(
Directory.current.uri,
);
if (assetsYamlFileUri == null) {
log.stderr('Error: Compiling native assets failed.');
return DartdevCommand.errorExitCode;
if (runPackageName != null) {
final builder = DartNativeAssetsBuilder(
packageConfigUri: packageConfig,
runPackageName: runPackageName,
verbose: verbose,
);
if (!nativeAssetsExperimentEnabled) {
if (await builder.warnOnNativeAssets()) {
return DartdevCommand.errorExitCode;
}
} else {
final assetsYamlFileUri =
await builder.compileNativeAssetsJitYamlFile();
if (assetsYamlFileUri == null) {
log.stderr('Error: Compiling native assets failed.');
return DartdevCommand.errorExitCode;
}
nativeAssets = assetsYamlFileUri.toFilePath();
}
}
nativeAssets = assetsYamlFileUri.toFilePath();
}

try {
Expand Down
Loading

0 comments on commit e1eade6

Please sign in to comment.