Skip to content

Commit

Permalink
[deps] Roll dart-lang/native to new version
Browse files Browse the repository at this point in the history
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
Change-Id: I78f0ece02c337b3b132f161fa7cc5e88db223b57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389500
Commit-Queue: Martin Kustermann <[email protected]>
Reviewed-by: Moritz Sümmermann <[email protected]>
  • Loading branch information
mkustermann authored and Commit Queue committed Nov 4, 2024
1 parent 817882c commit c549a73
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 50 deletions.
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ vars = {
"material_color_utilities_rev": "799b6ba2f3f1c28c67cc7e0b4f18e0c7d7f3c03e",
"mockito_rev": "f72791d3dd5cb2acc4f5c7da065ffe70d2ad1e0b",
# dart-native-interop-team@ is rolling breaking changes manually while the assets features are in experimental.
"native_rev": "659511886501bcce638c3966590df04984909ef0", # disable tools/rev_sdk_deps.dart
"native_rev": "51647776372aa9e1f839efb811aa959fe445c0cf", # disable tools/rev_sdk_deps.dart
"package_config_rev": "bafff8e90be25e1985f7e3ee40ea1d22571a93e6",
"pool_rev": "7bfc71b39742753a88688e56e55a828a2f5dc0bf",
"protobuf_rev": "ccf104dbc36929c0f8708285d5f3a8fae206343e",
Expand Down
44 changes: 33 additions & 11 deletions pkg/dartdev/lib/src/commands/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import 'package:dartdev/src/utils.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/native_assets_cli_internal.dart';
import 'package:native_assets_cli/code_assets_builder.dart';
import 'package:native_assets_cli/data_assets_builder.dart';
import 'package:path/path.dart' as path;
import 'package:vm/target_os.dart'; // For possible --target-os values.

Expand Down Expand Up @@ -141,13 +142,25 @@ class BuildCommand extends DartdevCommand {
dartExecutable: Uri.file(sdk.dart),
logger: logger(verbose),
);

final cCompilerConfig = getCCompilerConfig();

final buildResult = await nativeAssetsBuildRunner.build(
configCreator: () => BuildConfigBuilder()
..setupCodeConfig(
linkModePreference: LinkModePreference.dynamic,
targetArchitecture: target.architecture,
targetMacOSVersion: targetMacOSVersion,
cCompilerConfig: cCompilerConfig,
),
configValidator: (config) async => [
...await validateDataAssetBuildConfig(config),
...await validateCodeAssetBuildConfig(config),
],
workingDirectory: workingDirectory,
target: target,
linkModePreference: LinkModePreference.dynamic,
targetOS: target.os,
buildMode: BuildMode.release,
includeParentEnvironment: true,
targetMacOSVersion: targetMacOSVersion,
linkingEnabled: true,
supportedAssetTypes: [
CodeAsset.type,
Expand All @@ -157,10 +170,10 @@ class BuildCommand extends DartdevCommand {
...await validateCodeAssetBuildOutput(config, output),
],
applicationAssetValidator: (assets) async => [
...await validateCodeAssetsInApplication(assets),
...await validateCodeAssetInApplication(assets),
],
);
if (!buildResult.success) {
if (buildResult == null) {
stderr.writeln('Native assets build failed.');
return 255;
}
Expand Down Expand Up @@ -192,15 +205,24 @@ class BuildCommand extends DartdevCommand {

// Start linking here.
final linkResult = await nativeAssetsBuildRunner.link(
configCreator: () => LinkConfigBuilder()
..setupCodeConfig(
targetArchitecture: target.architecture,
linkModePreference: LinkModePreference.dynamic,
targetMacOSVersion: targetMacOSVersion,
cCompilerConfig: cCompilerConfig,
),
configValidator: (config) async => [
...await validateDataAssetLinkConfig(config),
...await validateCodeAssetLinkConfig(config),
],
resourceIdentifiers:
recordUseEnabled ? Uri.file(recordedUsagesPath!) : null,
workingDirectory: workingDirectory,
target: target,
linkModePreference: LinkModePreference.dynamic,
targetOS: target.os,
buildMode: BuildMode.release,
includeParentEnvironment: true,
buildResult: buildResult,
targetMacOSVersion: targetMacOSVersion,
supportedAssetTypes: [
CodeAsset.type,
],
Expand All @@ -209,11 +231,11 @@ class BuildCommand extends DartdevCommand {
...await validateCodeAssetLinkOutput(config, output),
],
applicationAssetValidator: (assets) async => [
...await validateCodeAssetsInApplication(assets),
...await validateCodeAssetInApplication(assets),
],
);

if (!linkResult.success) {
if (linkResult == null) {
stderr.writeln('Native assets link failed.');
return 255;
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/dartdev/lib/src/commands/compile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -552,8 +552,8 @@ Remove debugging information from the output and save it separately to the speci
return 255;
}
} else {
final (success, assets) = await compileNativeAssetsJit(verbose: verbose);
if (!success) {
final assets = await compileNativeAssetsJit(verbose: verbose);
if (assets == null) {
stderr.writeln('Native assets build failed.');
return 255;
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/dartdev/lib/src/commands/run.dart
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,15 @@ class RunCommand extends DartdevCommand {
}
} else {
final runPackageName = getPackageForCommand(mainCommand);
final (success, assets) = await compileNativeAssetsJitYamlFile(
final assetsYamlFileUri = await compileNativeAssetsJitYamlFile(
verbose: verbose,
runPackageName: runPackageName,
);
if (!success) {
if (assetsYamlFileUri == null) {
log.stderr('Error: Compiling native assets failed.');
return errorExitCode;
}
nativeAssets = assets?.toFilePath();
nativeAssets = assetsYamlFileUri.toFilePath();
}

final String? residentCompilerInfoFileArg =
Expand Down
6 changes: 3 additions & 3 deletions pkg/dartdev/lib/src/commands/test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ Run "${runner!.executableName} help" to see global options.''');
return DartdevCommand.errorExitCode;
}
} else {
final (success, assets) =
final assetsYamlFileUri =
await compileNativeAssetsJitYamlFile(verbose: verbose);
if (!success) {
if (assetsYamlFileUri == null) {
log.stderr('Error: Compiling native assets failed.');
return DartdevCommand.errorExitCode;
}
nativeAssets = assets?.toFilePath();
nativeAssets = assetsYamlFileUri.toFilePath();
}

try {
Expand Down
78 changes: 58 additions & 20 deletions pkg/dartdev/lib/src/native_assets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import 'package:dartdev/src/sdk.dart';
import 'package:dartdev/src/utils.dart';
import 'package:logging/logging.dart';
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:native_assets_cli/native_assets_cli_internal.dart';

import 'core.dart';
Expand All @@ -17,7 +19,7 @@ import 'core.dart';
///
/// If provided, only native assets of all transitive dependencies of
/// [runPackageName] are built.
Future<(bool success, List<EncodedAsset> assets)> compileNativeAssetsJit({
Future<List<EncodedAsset>?> compileNativeAssetsJit({
required bool verbose,
String? runPackageName,
}) async {
Expand All @@ -32,10 +34,10 @@ Future<(bool success, List<EncodedAsset> assets)> compileNativeAssetsJit({
// `getExecutableForCommand` later.
final result = await Process.run(sdk.dart, ['pub', 'get']);
if (result.exitCode != 0) {
return (true, <EncodedAsset>[]);
return null;
}
} else {
return (true, <EncodedAsset>[]);
return null;
}
}
final nativeAssetsBuildRunner = NativeAssetsBuildRunner(
Expand All @@ -46,17 +48,26 @@ Future<(bool success, List<EncodedAsset> assets)> compileNativeAssetsJit({
final target = Target.current;
final targetMacOSVersion =
target.os == OS.macOS ? minimumSupportedMacOSVersion : null;
final cCompilerConfig = getCCompilerConfig();
final buildResult = await nativeAssetsBuildRunner.build(
configCreator: () => BuildConfigBuilder()
..setupCodeConfig(
targetArchitecture: target.architecture,
// When running in JIT mode, only dynamic libraries are supported.
linkModePreference: LinkModePreference.dynamic,
targetMacOSVersion: targetMacOSVersion,
cCompilerConfig: cCompilerConfig,
),
configValidator: (config) async => [
...await validateCodeAssetBuildConfig(config),
...await validateDataAssetBuildConfig(config),
],
workingDirectory: workingDirectory,
// When running in JIT mode, only the host OS needs to be build.
target: target,
// When running in JIT mode, only dynamic libraries are supported.
linkModePreference: LinkModePreference.dynamic,
targetOS: target.os,
// Dart has no concept of release vs debug, default to release.
buildMode: BuildMode.release,
includeParentEnvironment: true,
runPackageName: runPackageName,
targetMacOSVersion: targetMacOSVersion,
linkingEnabled: false,
supportedAssetTypes: [
CodeAsset.type,
Expand All @@ -66,14 +77,11 @@ Future<(bool success, List<EncodedAsset> assets)> compileNativeAssetsJit({
...await validateCodeAssetBuildOutput(config, output),
],
applicationAssetValidator: (assets) async => [
...await validateCodeAssetsInApplication(assets),
...await validateCodeAssetInApplication(assets),
],
);

return (
buildResult.success,
buildResult.encodedAssets,
);
if (buildResult == null) return null;
return buildResult.encodedAssets;
}

/// Compiles all native assets for host OS in JIT mode, and creates the
Expand All @@ -83,17 +91,15 @@ Future<(bool success, List<EncodedAsset> assets)> compileNativeAssetsJit({
/// [runPackageName] are built.
///
/// Used in `dart run` and `dart test`.
Future<(bool success, Uri? nativeAssetsYaml)> compileNativeAssetsJitYamlFile({
Future<Uri?> compileNativeAssetsJitYamlFile({
required bool verbose,
String? runPackageName,
}) async {
final (success, assets) = await compileNativeAssetsJit(
final assets = await compileNativeAssetsJit(
verbose: verbose,
runPackageName: runPackageName,
);
if (!success) {
return (false, null);
}
if (assets == null) return null;
final codeAssets = assets
.where((e) => e.type == CodeAsset.type)
.map(CodeAsset.fromEncoded)
Expand All @@ -118,7 +124,7 @@ Future<(bool success, Uri? nativeAssetsYaml)> compileNativeAssetsJitYamlFile({
${kernelAssets.toNativeAssetsFile()}''';
final assetFile = File(assetsUri.toFilePath());
await assetFile.writeAsString(nativeAssetsYaml);
return (true, assetsUri);
return assetsUri;
}

KernelAsset _targetLocation(CodeAsset asset) {
Expand Down Expand Up @@ -199,3 +205,35 @@ Logger logger(bool verbose) => Logger('')
log.trace(record.message);
}
});

CCompilerConfig? getCCompilerConfig() {
// Specifically for running our tests on Dart CI with the test runner, we
// recognize specific variables to setup the C Compiler configuration.
final env = Platform.environment;
final cc = env['DART_HOOK_TESTING_C_COMPILER__CC'];
final ar = env['DART_HOOK_TESTING_C_COMPILER__AR'];
final ld = env['DART_HOOK_TESTING_C_COMPILER__LD'];
final envScript = env['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT'];
final envScriptArgs =
env['DART_HOOK_TESTING_C_COMPILER__ENV_SCRIPT_ARGUMENTS']
?.split(' ')
.map((arg) => arg.trim())
.where((arg) => arg.isNotEmpty)
.toList();
final hasEnvScriptArgs = envScriptArgs != null && envScriptArgs.isNotEmpty;

if (cc != null ||
ar != null ||
ld != null ||
envScript != null ||
hasEnvScriptArgs) {
return CCompilerConfig(
archiver: ar != null ? Uri.file(ar) : null,
compiler: cc != null ? Uri.file(cc) : null,
envScript: envScript != null ? Uri.file(envScript) : null,
envScriptArgs: hasEnvScriptArgs ? envScriptArgs : null,
linker: ld != null ? Uri.file(ld) : null,
);
}
return null;
}
2 changes: 1 addition & 1 deletion pkg/dartdev/test/native_assets/build_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import 'dart:io';

import 'package:native_assets_cli/native_assets_cli_internal.dart';
import 'package:native_assets_cli/code_assets_builder.dart';
import 'package:test/test.dart';

import '../utils.dart';
Expand Down
8 changes: 2 additions & 6 deletions pkg/dartdev/test/native_assets/compile_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,8 @@ void main(List<String> args) {
logger: logger,
expectExitCodeZero: false,
);
expect(
result.stderr,
contains(
'Native assets build failed.',
),
);
expect(result.stderr,
contains('Building assets for package:native_add failed.'));
expect(result.exitCode, 255);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:logging/logging.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/code_assets.dart';
import 'package:native_toolchain_c/native_toolchain_c.dart';

void main(List<String> arguments) async {
Expand Down
4 changes: 2 additions & 2 deletions pkg/record_use/test_data/drop_dylib_recording/hook/link.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'dart:convert';
import 'dart:io';

import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_assets_cli/code_assets.dart';
import 'package:record_use/record_use.dart';

final callIdAdd = const Identifier(
Expand All @@ -32,7 +32,7 @@ void main(List<String> arguments) async {
final usages =
RecordedUsages.fromJson(jsonDecode(string) as Map<String, dynamic>);

final codeAssets = config.codeAssets.all;
final codeAssets = config.codeAssets;
print('Received assets: ${codeAssets.map((a) => a.id).join(', ')}.');

final symbols = <String>{};
Expand Down

0 comments on commit c549a73

Please sign in to comment.