From da14b16ef37349e955b36d09fd75214086b7e375 Mon Sep 17 00:00:00 2001 From: asiva Date: Tue, 22 Oct 2024 17:39:27 +0000 Subject: [PATCH] [Web/DDC] - Convert the kernel_worker and dartdevc snapshots to an AOT snapshot Converts kernel_worker.dart.snapshot and dartdevc.dart.snapshot to AOT snapshots. Fixes tests and paths in the code accordingly. TESTS=ci Change-Id: Ib99b2a3343e23252c3a6b5295b0d20f0f486aede Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381388 Reviewed-by: Nicholas Shahan Commit-Queue: Siva Annamalai --- CHANGELOG.md | 11 ++- .../tool/modular_test_suite_helper.dart | 24 ++++++- .../expression_compiler_worker_shared.dart | 27 ++++++-- pkg/dev_compiler/test/macros/macros_test.dart | 42 ++++++++---- pkg/dev_compiler/test/modular_helpers.dart | 29 ++++++-- pkg/dev_compiler/test/worker/worker_test.dart | 46 ++++++++----- pkg/dev_compiler/tool/ddb | 10 ++- pkg/dynamic_modules/test/runner/ddc.dart | 8 +-- pkg/dynamic_modules/test/runner/util.dart | 8 ++- .../lib/src/compiler_configuration.dart | 13 ++-- sdk/BUILD.gn | 67 +++++++++++++------ tests/macro_build/ddc_lt_test.dart | 4 +- tests/macro_build/tester/tester.dart | 8 +++ utils/bazel/BUILD.gn | 19 ++++++ utils/ddc/BUILD.gn | 65 +++++++++++++++--- 15 files changed, 293 insertions(+), 88 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84a41e67df4..a2148d90ae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,7 +31,7 @@ main() { } ``` -###### Dart to Javascript Compiler (dart2js) +#### Dart to Javascript Compiler (dart2js) - The dart2js compiler which is invoked when the command 'dart compile js' is used has been switched to use an AOT snapshot @@ -39,6 +39,15 @@ main() { [#53576]: https://github.com/dart-lang/sdk/issues/53576 +#### Dart Development Compiler (dartdevc) + +- The dartdevc compiler and kernel_worker utility have been switched to use + an AOT snapshot instead of a JIT snapshot, the SDK build still includes a + JIT snapshot of these tools as package build/build_web_compiler depends + on it. The AOT snapshot can be used as follows to run DDC + /bin/dartaotruntime /bin/snapshots/dartdevc_aot.dart.snapshot + +[#53576]: https://github.com/dart-lang/sdk/issues/53576 ## 3.6.0 diff --git a/pkg/compiler/tool/modular_test_suite_helper.dart b/pkg/compiler/tool/modular_test_suite_helper.dart index bad5d08e220..c12f7a9299c 100644 --- a/pkg/compiler/tool/modular_test_suite_helper.dart +++ b/pkg/compiler/tool/modular_test_suite_helper.dart @@ -20,12 +20,14 @@ import 'package:modular_test/src/runner.dart'; import 'package:modular_test/src/suite.dart'; import 'package:modular_test/src/steps/macro_precompile_aot.dart'; import 'package:modular_test/src/steps/util.dart'; +import 'package:path/path.dart' as p; String packageConfigJsonPath = ".dart_tool/package_config.json"; Uri sdkRoot = Platform.script.resolve("../../../"); Uri packageConfigUri = sdkRoot.resolve(packageConfigJsonPath); late Options _options; late String _dart2jsScript; +late String _kernelWorkerAotScript; late String _kernelWorkerScript; const dillSummaryId = DataId("summary.dill"); @@ -118,8 +120,22 @@ abstract class CFEStep extends IOModularStep { sources = getSources(module); } + var isAot = File(_kernelWorkerAotScript).existsSync(); + var script = _kernelWorkerAotScript; + var sdkPath = p.dirname(p.dirname(Platform.resolvedExecutable)); + var executable = p.absolute( + sdkPath, + 'bin', + Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime', + ); + if (!isAot) { + // This can be removed once we stop supporting ia32 architecture. + script = _kernelWorkerScript; + executable = Platform.resolvedExecutable; + } + List args = [ - _kernelWorkerScript, + script, '--sound-null-safety', ...stepArguments, '--exclude-non-sources', @@ -140,8 +156,8 @@ abstract class CFEStep extends IOModularStep { ...(flags.expand((String flag) => ['--enable-experiment', flag])), ]; - var result = await runProcess( - Platform.resolvedExecutable, args, root.toFilePath(), _options.verbose); + var result = + await runProcess(executable, args, root.toFilePath(), _options.verbose); checkExitCode(result, this, module, _options.verbose); } @@ -635,6 +651,8 @@ Future resolveScripts(Options options) async { _options = options; _dart2jsScript = await resolve( 'package:compiler/src/dart2js.dart', 'snapshots/dart2js.dart.snapshot'); + _kernelWorkerAotScript = await resolve('utils/bazel/kernel_worker.dart', + 'snapshots/kernel_worker_aot.dart.snapshot'); _kernelWorkerScript = await resolve('utils/bazel/kernel_worker.dart', 'snapshots/kernel_worker.dart.snapshot'); } diff --git a/pkg/dev_compiler/test/expression_compiler/expression_compiler_worker_shared.dart b/pkg/dev_compiler/test/expression_compiler/expression_compiler_worker_shared.dart index 7b2b3cd779b..e3dc4bbea95 100644 --- a/pkg/dev_compiler/test/expression_compiler/expression_compiler_worker_shared.dart +++ b/pkg/dev_compiler/test/expression_compiler/expression_compiler_worker_shared.dart @@ -1191,15 +1191,28 @@ class DDCKernelGenerator { static final dart = Platform.resolvedExecutable; static final sdkPath = computePlatformBinariesLocation(forceBuildDir: true).toFilePath(); - - static final dartdevc = - p.join(sdkPath, 'dart-sdk', 'bin', 'snapshots', 'dartdevc.dart.snapshot'); - static final kernelWorker = p.join( - sdkPath, 'dart-sdk', 'bin', 'snapshots', 'kernel_worker.dart.snapshot'); + static var dartExecutable = p.join( + sdkPath, + 'dart-sdk', + 'bin', + Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime', + ); + static var dartdevc = p.join( + sdkPath, 'dart-sdk', 'bin', 'snapshots', 'dartdevc_aot.dart.snapshot'); + static var kernelWorker = p.join(sdkPath, 'dart-sdk', 'bin', 'snapshots', + 'kernel_worker_aot.dart.snapshot'); DDCKernelGenerator(this.config, this.verbose); Future generate() async { + if (!File(dartdevc).existsSync()) { + // This can be removed once we stop supporting ia32 architecture. + dartdevc = p.join( + sdkPath, 'dart-sdk', 'bin', 'snapshots', 'dartdevc.dart.snapshot'); + kernelWorker = p.join(sdkPath, 'dart-sdk', 'bin', 'snapshots', + 'kernel_worker.dart.snapshot'); + dartExecutable = Platform.resolvedExecutable; + } Directory.fromUri(config.outputPath).createSync(); // generate summaries @@ -1238,7 +1251,7 @@ class DDCKernelGenerator { if (!config.soundNullSafety) '--no-sound-null-safety', ]; - return runProcess(dart, args, config.rootPath, verbose); + return runProcess(dartExecutable, args, config.rootPath, verbose); } Future _generateFullDill(ModuleConfiguration module) async { @@ -1270,7 +1283,7 @@ class DDCKernelGenerator { '--no-summarize', ]; - return await runProcess(dart, args, config.rootPath, verbose); + return await runProcess(dartExecutable, args, config.rootPath, verbose); } } diff --git a/pkg/dev_compiler/test/macros/macros_test.dart b/pkg/dev_compiler/test/macros/macros_test.dart index 381f8169bd3..9030479d1d6 100644 --- a/pkg/dev_compiler/test/macros/macros_test.dart +++ b/pkg/dev_compiler/test/macros/macros_test.dart @@ -9,6 +9,7 @@ import 'package:dev_compiler/ddc.dart' as ddc; import 'package:frontend_server/compute_kernel.dart'; import 'package:macros/src/bootstrap.dart'; import 'package:macros/src/executor/serialization.dart'; +import 'package:path/path.dart' as p; import 'package:test/test.dart'; Directory tmp = Directory.systemTemp.createTempSync('ddc_worker_test'); @@ -22,12 +23,14 @@ String _resolvePath(String executableRelativePath) { void main() { group('DDC: Macros', timeout: Timeout(Duration(minutes: 2)), () { late File testMacroDart; - late File bootstrapDillFileVm; + late String bootstrapDillPathVm; + late String bootstrapAotPathVm; late File bootstrapDillFileDdc; late Uri testMacroUri; late File packageConfig; late List ddcArgs; late List executableArgs; + late String dartAot; final applyTestMacroDart = file('apply_test_macro.dart'); final testMacroJS = file('test_macro.js'); @@ -99,20 +102,32 @@ macro class TestMacro implements ClassDeclarationsMacro { 'lib/_internal/vm_platform_strong_product.dill')); var ddcPlatformDill = File(_resolvePath('../' 'lib/_internal/ddc_outline.dill')); - bootstrapDillFileVm = file('bootstrap.dart.dill'); + bootstrapDillPathVm = 'bootstrap.dart.dill'; var bootstrapResult = await computeKernel([ '--enable-experiment=macros', '--no-summary', '--no-summary-only', '--target=vm', '--dart-sdk-summary=${productPlatformDill.uri}', - '--output=${bootstrapDillFileVm.path}', + '--output=$bootstrapDillPathVm', '--source=${bootstrapFile.uri}', '--source=${testMacroDart.uri}', '--packages-file=${packageConfig.uri}', ]); expect(bootstrapResult.succeeded, true); + // Compile the macro to vm AOT executable to be run by the CFE. + bootstrapAotPathVm = 'bootstrap.dart.exe'; + var bootstrapAotResult = Process.runSync(Platform.resolvedExecutable, [ + 'compile', + 'exe', + '--enable-experiment=macros', + '-o', + bootstrapAotPathVm, + bootstrapFile.path, + ]); + expect(bootstrapAotResult.exitCode, EXIT_CODE_OK); + // Compile the macro to ddc dill for the ddc build. bootstrapDillFileDdc = file('bootstrap_ddc.dart.dill'); var bootstrapResultDdc = await computeKernel([ @@ -146,11 +161,6 @@ void main() { _resolvePath('../../ddc_outline.dill'), '--packages=${packageConfig.uri}', ]; - - executableArgs = [ - _resolvePath('../../gen/dartdevc.dart.snapshot'), - ...ddcArgs - ]; }); tearDown(() { @@ -175,7 +185,7 @@ void main() { await ddc.internalMain([ ...ddcArgs, '--precompiled-macro', - '${bootstrapDillFileVm.path};$testMacroUri', + '$bootstrapDillPathVm;$testMacroUri', '--no-source-map', '--no-summarize', '-s', @@ -193,7 +203,15 @@ void main() { }); test('compile using dartdevc snapshot', () { - var result = Process.runSync(Platform.executable, [ + executableArgs = [ + _resolvePath('snapshots/dartdevc_aot.dart.snapshot'), + ...ddcArgs + ]; + + dartAot = p.absolute(p.dirname(Platform.resolvedExecutable), + Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime'); + + var result = Process.runSync(dartAot, [ ...executableArgs, '--no-source-map', '-o', @@ -207,10 +225,10 @@ void main() { expect(testMacroJS.existsSync(), isTrue); expect(testMacroSummary.existsSync(), isTrue); - result = Process.runSync(Platform.executable, [ + result = Process.runSync(dartAot, [ ...executableArgs, '--precompiled-macro', - '${bootstrapDillFileVm.path};$testMacroUri', + '$bootstrapAotPathVm;$testMacroUri', '--no-source-map', '--no-summarize', '-s', diff --git a/pkg/dev_compiler/test/modular_helpers.dart b/pkg/dev_compiler/test/modular_helpers.dart index ced49b111ff..e0b6b0bea2c 100644 --- a/pkg/dev_compiler/test/modular_helpers.dart +++ b/pkg/dev_compiler/test/modular_helpers.dart @@ -12,6 +12,7 @@ import 'package:modular_test/src/runner.dart'; import 'package:modular_test/src/steps/macro_precompile_aot.dart'; import 'package:modular_test/src/steps/util.dart'; import 'package:modular_test/src/suite.dart'; +import 'package:path/path.dart' as p; String packageConfigJsonPath = '.dart_tool/package_config.json'; Uri sdkRoot = Platform.script.resolve('../../../'); @@ -19,6 +20,7 @@ Uri packageConfigUri = sdkRoot.resolve(packageConfigJsonPath); late Options _options; late String _dartdevcScript; late String _kernelWorkerScript; +late String _dartExecutable; const dillId = DataId('dill'); const jsId = DataId('js'); @@ -120,7 +122,7 @@ class SourceToSummaryDillStep implements IOModularStep { ]; var result = await runProcess( - Platform.resolvedExecutable, args, root.toFilePath(), _options.verbose); + _dartExecutable, args, root.toFilePath(), _options.verbose); checkExitCode(result, this, module, _options.verbose); } @@ -219,7 +221,7 @@ class DDCStep implements IOModularStep { '$output', ]; var result = await runProcess( - Platform.resolvedExecutable, args, root.toFilePath(), _options.verbose); + _dartExecutable, args, root.toFilePath(), _options.verbose); checkExitCode(result, this, module, _options.verbose); } @@ -337,8 +339,23 @@ Future resolveScripts(Options options) async { return result; } - _dartdevcScript = await resolve( - 'pkg/dev_compiler/bin/dartdevc.dart', 'snapshots/dartdevc.dart.snapshot'); - _kernelWorkerScript = await resolve('utils/bazel/kernel_worker.dart', - 'snapshots/kernel_worker.dart.snapshot'); + _dartdevcScript = await resolve('pkg/dev_compiler/bin/dartdevc.dart', + 'snapshots/dartdevc_aot.dart.snapshot'); + if (File(_dartdevcScript).existsSync()) { + _kernelWorkerScript = await resolve('utils/bazel/kernel_worker.dart', + 'snapshots/kernel_worker_aot.dart.snapshot'); + var sdkPath = p.dirname(p.dirname(Platform.resolvedExecutable)); + _dartExecutable = p.absolute( + sdkPath, + 'bin', + Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime', + ); + } else { + // This can be removed once we stop supporting ia32 architecture. + _dartdevcScript = await resolve('pkg/dev_compiler/bin/dartdevc.dart', + 'snapshots/dartdevc.dart.snapshot'); + _kernelWorkerScript = await resolve('utils/bazel/kernel_worker.dart', + 'snapshots/kernel_worker.dart.snapshot'); + _dartExecutable = Platform.resolvedExecutable; + } } diff --git a/pkg/dev_compiler/test/worker/worker_test.dart b/pkg/dev_compiler/test/worker/worker_test.dart index 5e341162495..bf18fe92868 100644 --- a/pkg/dev_compiler/test/worker/worker_test.dart +++ b/pkg/dev_compiler/test/worker/worker_test.dart @@ -8,6 +8,7 @@ import 'dart:io'; import 'package:bazel_worker/bazel_worker.dart'; import 'package:bazel_worker/testing.dart'; +import 'package:path/path.dart' as p; import 'package:test/test.dart'; Directory tmp = Directory.systemTemp.createTempSync('ddc_worker_test'); @@ -20,8 +21,21 @@ String _resolvePath(String executableRelativePath) { void main() { var baseArgs = []; + var sdkPath = p.dirname(Platform.executable); + var dartAotRuntime = p.absolute( + sdkPath, + Platform.isWindows + ? 'dart_precompiled_runtime_product.exe' + : 'dart_precompiled_runtime_product'); + if (!File(dartAotRuntime).existsSync()) { + dartAotRuntime = p.absolute( + sdkPath, + Platform.isWindows + ? 'dart_precompiled_runtime.exe' + : 'dart_precompiled_runtime'); + } final executableArgs = [ - _resolvePath('gen/dartdevc.dart.snapshot'), + _resolvePath('gen/dartdevc_aot.dart.snapshot'), '--sound-null-safety', '--dart-sdk-summary', _resolvePath('ddc_outline.dill'), @@ -54,7 +68,7 @@ void main() { test('can compile in worker mode', () async { var args = executableArgs.toList()..add('--persistent_worker'); - var process = await Process.start(Platform.executable, args); + var process = await Process.start(dartAotRuntime, args); var messageGrouper = AsyncMessageGrouper(process.stdout); var request = WorkRequest(); @@ -97,7 +111,7 @@ void main() { test('can compile in basic mode', () { var args = executableArgs.toList()..addAll(compilerArgs); - var result = Process.runSync(Platform.executable, args); + var result = Process.runSync(dartAotRuntime, args); expect(result.exitCode, EXIT_CODE_OK); expect(result.stdout, isEmpty); @@ -109,7 +123,7 @@ void main() { var args = List.from(executableArgs) ..add('--does-not-exist') ..addAll(compilerArgs); - var result = Process.runSync(Platform.executable, args); + var result = Process.runSync(dartAotRuntime, args); expect(result.exitCode, 64); expect(result.stdout, @@ -123,7 +137,7 @@ void main() { ..add('--does-not-exist') ..add('--ignore-unrecognized-flags') ..addAll(compilerArgs); - var result = Process.runSync(Platform.executable, args); + var result = Process.runSync(dartAotRuntime, args); expect(result.exitCode, EXIT_CODE_OK); expect(result.stdout, isEmpty); @@ -135,7 +149,7 @@ void main() { argsFile.createSync(); argsFile.writeAsStringSync(compilerArgs.join('\n')); var args = executableArgs.toList()..add('@${argsFile.path}'); - var process = await Process.start(Platform.executable, args); + var process = await Process.start(dartAotRuntime, args); await stderr.addStream(process.stderr); var futureProcessOutput = process.stdout.map(utf8.decode).toList(); @@ -149,7 +163,7 @@ void main() { ..add('--modules') ..add('ddc') ..addAll(compilerArgs); - var result = Process.runSync(Platform.executable, args); + var result = Process.runSync(dartAotRuntime, args); expect(result.exitCode, EXIT_CODE_OK); expect(result.stdout, isEmpty); @@ -187,7 +201,7 @@ void main() { test('can compile in basic mode', () { var result = Process.runSync( - Platform.executable, + dartAotRuntime, executableArgs + baseArgs + [ @@ -203,7 +217,7 @@ void main() { expect(greetingSummary.existsSync(), isTrue); result = Process.runSync( - Platform.executable, + dartAotRuntime, executableArgs + baseArgs + [ @@ -223,7 +237,7 @@ void main() { test('reports error on overlapping summaries', () { var result = Process.runSync( - Platform.executable, + dartAotRuntime, executableArgs + baseArgs + [ @@ -239,7 +253,7 @@ void main() { expect(greetingSummary.existsSync(), isTrue); result = Process.runSync( - Platform.executable, + dartAotRuntime, executableArgs + baseArgs + [ @@ -255,7 +269,7 @@ void main() { expect(greeting2Summary.existsSync(), isTrue); result = Process.runSync( - Platform.executable, + dartAotRuntime, executableArgs + baseArgs + [ @@ -289,7 +303,7 @@ void main() { test('incorrect usage', () { var result = Process.runSync( - Platform.executable, + dartAotRuntime, executableArgs + baseArgs + [ @@ -304,7 +318,7 @@ void main() { test('compile errors', () { badFileDart.writeAsStringSync('main() => "hello world"'); var result = Process.runSync( - Platform.executable, + dartAotRuntime, executableArgs + baseArgs + [ @@ -340,7 +354,7 @@ void main() { test('works if part and library supplied', () { var result = Process.runSync( - Platform.executable, + dartAotRuntime, executableArgs + baseArgs + [ @@ -359,7 +373,7 @@ void main() { test('works if part is not supplied', () { var result = Process.runSync( - Platform.executable, + dartAotRuntime, executableArgs + baseArgs + [ diff --git a/pkg/dev_compiler/tool/ddb b/pkg/dev_compiler/tool/ddb index 4f7eedc32e3..1d0701871f3 100755 --- a/pkg/dev_compiler/tool/ddb +++ b/pkg/dev_compiler/tool/ddb @@ -170,6 +170,12 @@ void main(List args) async { // your path. var dartBinary = Platform.resolvedExecutable; var dartSdk = p.dirname(p.dirname(dartBinary)); + var dartAotBinary = p.absolute( + dartSdk, + 'bin', + Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime' + ); + var execBinary = debug ? dartBinary : dartAotBinary; // In debug mode (`-d`), we run from the `pkg/dev_compiler` sources. We // determine the location via this actual script (i.e., `-d` assumes @@ -216,10 +222,10 @@ void main(List args) async { p.join(ddcPath, 'bin', 'dartdevc.dart'), ] else // Use built snapshot. - p.join(dartSdk, 'bin', 'snapshots', 'dartdevc.dart.snapshot'), + p.join(dartSdk, 'bin', 'snapshots', 'dartdevc_aot.dart.snapshot'), ...ddcArgs, ]; - var process = await startProcess('DDC', dartBinary, args); + var process = await startProcess('DDC', execBinary, args); if (await process.exitCode != 0) exit(await process.exitCode); } diff --git a/pkg/dynamic_modules/test/runner/ddc.dart b/pkg/dynamic_modules/test/runner/ddc.dart index 2e80e86319e..8df6c5a13e0 100644 --- a/pkg/dynamic_modules/test/runner/ddc.dart +++ b/pkg/dynamic_modules/test/runner/ddc.dart @@ -63,7 +63,7 @@ class DdcExecutor implements TargetExecutor { var testDir = _tmp.uri.resolve(testName).toFilePath(); var args = [ '--packages=${repoRoot.toFilePath()}/.dart_tool/package_config.json', - ddcSnapshot.toFilePath(), + ddcAotSnapshot.toFilePath(), '--modules=ddc', '--no-summarize', '--no-source-map', @@ -85,7 +85,7 @@ class DdcExecutor implements TargetExecutor { '-o', '$source.js', ]; - await runProcess(Platform.resolvedExecutable, args, testDir, _logger, + await runProcess(dartAotBin.toFilePath(), args, testDir, _logger, 'compile $testName/$source'); } @@ -95,7 +95,7 @@ class DdcExecutor implements TargetExecutor { var testDir = _tmp.uri.resolve(testName).toFilePath(); var args = [ '--packages=${repoRoot.toFilePath()}/.dart_tool/package_config.json', - kernelWOrkerSnapshot.toFilePath(), + kernelWOrkerAotSnapshot.toFilePath(), '--summary-only', '--target', 'ddc', @@ -112,7 +112,7 @@ class DdcExecutor implements TargetExecutor { '$source.dill', ]; - await runProcess(Platform.resolvedExecutable, args, testDir, _logger, + await runProcess(dartAotBin.toFilePath(), args, testDir, _logger, 'sumarize $testName/$source'); } diff --git a/pkg/dynamic_modules/test/runner/util.dart b/pkg/dynamic_modules/test/runner/util.dart index 952bc4e708a..b721b8605aa 100644 --- a/pkg/dynamic_modules/test/runner/util.dart +++ b/pkg/dynamic_modules/test/runner/util.dart @@ -65,9 +65,11 @@ String _d8Path = (() { Uri d8Uri = repoRoot.resolve(_d8Path); Uri _dartBin = Uri.file(Platform.resolvedExecutable); -Uri ddcSnapshot = _dartBin.resolve('snapshots/dartdevc.dart.snapshot'); -Uri kernelWOrkerSnapshot = - _dartBin.resolve('snapshots/kernel_worker.dart.snapshot'); +Uri dartAotBin = _dartBin + .resolve(Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime'); +Uri ddcAotSnapshot = _dartBin.resolve('snapshots/dartdevc_aot.dart.snapshot'); +Uri kernelWOrkerAotSnapshot = + _dartBin.resolve('snapshots/kernel_worker_aot.dart.snapshot'); Uri buildRootUri = repoRoot.resolve(buildFolder); Uri ddcSdkOutline = buildRootUri.resolve('ddc_outline.dill'); Uri ddcSdkJs = buildRootUri.resolve('gen/utils/ddc/stable/sdk/ddc/dart_sdk.js'); diff --git a/pkg/test_runner/lib/src/compiler_configuration.dart b/pkg/test_runner/lib/src/compiler_configuration.dart index 9ebb610fe4c..67bc57669be 100644 --- a/pkg/test_runner/lib/src/compiler_configuration.dart +++ b/pkg/test_runner/lib/src/compiler_configuration.dart @@ -635,6 +635,8 @@ class DevCompilerConfiguration extends CompilerConfiguration { /// the canary and null safety modes. final String buildOptionsDir; + bool get _isIA32 => _configuration.architecture == Architecture.ia32; + DevCompilerConfiguration(super.configuration) : _soundNullSafety = configuration.nnbdMode == NnbdMode.strong, buildOptionsDir = [ @@ -650,7 +652,7 @@ class DevCompilerConfiguration extends CompilerConfiguration { @override String computeCompilerPath() { if (_enableHostAsserts && _useSdk) { - // When [_useSdk] is true, ddc is compiled into a snapshot that was + // When [_useSdk] is true, ddc is compiled into an AOT snapshot that was // built without assertions enabled. The VM cannot make such snapshot run // with assertions later. These two flags could be used together if we // also build sdk snapshots with assertions enabled. @@ -660,9 +662,9 @@ class DevCompilerConfiguration extends CompilerConfiguration { // spawn as a subprocess is a Dart VM. // Internally the [DevCompilerCompilationCommand] will prepend the snapshot // or Dart library entrypoint that is executed by the VM. - // This will change once we update the DDC to use AOT instead of a snapshot. var dir = _useSdk ? '${_configuration.buildDirectory}/dart-sdk' : 'sdk'; - return '$dir/bin/dart$executableExtension'; + var executable = _useSdk && !_isIA32 ? 'dartaotruntime' : 'dart'; + return '$dir/bin/$executable$executableExtension'; } @override @@ -741,8 +743,11 @@ class DevCompilerConfiguration extends CompilerConfiguration { args.add("$summary=$package"); } + final snapshotName = + !_isIA32 ? 'dartdevc_aot.dart.snapshot' : 'dartdevc.dart.snapshot'; var compilerPath = _useSdk && !_enableHostAsserts - ? '${_configuration.buildDirectory}/dart-sdk/bin/snapshots/dartdevc.dart.snapshot' + ? '${_configuration.buildDirectory}/dart-sdk/bin/snapshots/' + '$snapshotName' : Repository.uri.resolve('pkg/dev_compiler/bin/dartdevc.dart').path; var command = DevCompilerCompilationCommand(outputFile, bootstrapDependencies(), computeCompilerPath(), args, environment, diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 93cf0222172..937593d5035 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -47,14 +47,16 @@ declare_args() { # ........dart2js.dart.snapshot (JIT snapshot only on ia32) # ........dart2wasm_product.snapshot (if not on ia32) # ........dartdev.dart.snapshot (app-jit snapshot or kernel dill file) -# ........dartdevc.dart.snapshot +# ........dartdevc_aot.dart.snapshot (AOT snapshot, if not on ia32) +# ........dartdevc.dart.snapshot (JIT snapshot only on ia32) # ........dds.dart.snapshot # ........dart_tooling_daemon.dart.snapshot # ........frontend_server_aot.dart.snapshot (AOT snapshot, if not on ia32) # ........frontend_server.dart.snapshot (JIT snapshot only on ia32) # ........gen_kernel_aot.dart.snapshot (if not on ia32) # ........kernel-service.dart.snapshot -# ........kernel_worker.dart.snapshot +# ........kernel_worker_aot.dart.snapshot (JIT snapshot only on ia32) +# ........kernel_worker.dart.snapshot (AOT snapshot, it not ia32) # ......resources/ # ........dartdoc/ # ..........resources/ @@ -152,26 +154,51 @@ if (dart_dynamic_modules) { ] ] } -_full_sdk_snapshots = _platform_sdk_snapshots + [ - [ - "dartdevc", - "../utils/ddc:dartdevc", - ], - [ - "kernel_worker", - "../utils/bazel:kernel_worker", - ], - ] +# AOT snapshots are not supported on the ia32 architecture, we continue +# to use JIT snapshots on that architecture, the conditional code below +# accounts for this. if (dart_target_arch != "ia32" && dart_target_arch != "x86") { - _full_sdk_snapshots += [ [ - "dart2js_aot", - "../utils/compiler:dart2js_sdk_aot", - ] ] + _full_sdk_snapshots = + _platform_sdk_snapshots + [ + [ + "dart2js_aot", + "../utils/compiler:dart2js_sdk_aot", + ], + [ + "dartdevc_aot", + "../utils/ddc:dartdevc_aot", + ], + [ + "kernel_worker_aot", + "../utils/bazel:kernel_worker_aot", + ], + + # Remove these JIT snapshot in Dart SDK version 3.7 + # Please see https://github.com/dart-lang/build/pull/3742 for details. + [ + "dartdevc", + "../utils/ddc:dartdevc", + ], + [ + "kernel_worker", + "../utils/bazel:kernel_worker", + ], + ] } else { - _full_sdk_snapshots += [ [ - "dart2js", - "../utils/compiler:dart2js", - ] ] + _full_sdk_snapshots = _platform_sdk_snapshots + [ + [ + "dart2js", + "../utils/compiler:dart2js", + ], + [ + "dartdevc", + "../utils/ddc:dartdevc", + ], + [ + "kernel_worker", + "../utils/bazel:kernel_worker", + ], + ] } # Libraries that go under lib/ diff --git a/tests/macro_build/ddc_lt_test.dart b/tests/macro_build/ddc_lt_test.dart index 0befc02c10d..f254ff8f6bf 100644 --- a/tests/macro_build/ddc_lt_test.dart +++ b/tests/macro_build/ddc_lt_test.dart @@ -7,8 +7,8 @@ import 'tester/tester.dart'; void main() { testMacroBuild([ r'$DART pub get', - r'$DART ' - r'$DART_SDK_OUT/dart-sdk/bin/snapshots/dartdevc.dart.snapshot ' + r'$DARTAOTRUNTIME ' + r'$DART_SDK_OUT/dart-sdk/bin/snapshots/dartdevc_aot.dart.snapshot ' '-Dtest_runner.configuration=ddc-linux-chrome ' '--enable-experiment=macros ' '--sound-null-safety ' diff --git a/tests/macro_build/tester/tester.dart b/tests/macro_build/tester/tester.dart index 097a0490ed3..0fc0db41c29 100644 --- a/tests/macro_build/tester/tester.dart +++ b/tests/macro_build/tester/tester.dart @@ -47,6 +47,13 @@ Future testMacroBuild(List commands) async { final dartSdkPath = Directory.current.path; final dartPath = Platform.resolvedExecutable; + final dartAotPath = p.absolute(dartSdkOutDirectory, 'dart-sdk/bin', + Platform.isWindows ? 'dartaotruntime.exe' : 'dartaotruntime'); + + if (!File(dartAotPath).existsSync()) { + fail('This test is not supported on SDK configurations that do not have ' + 'an AOT runtime'); + } // TODO(davidmorgan): run on more platforms. final configuration = String.fromEnvironment('test_runner.configuration'); @@ -72,6 +79,7 @@ runner to ensure they are built and not stale: } final commandParts = command .replaceAll(r'$DART_SDK', dartSdkPath) + .replaceAll(r'$DARTAOTRUNTIME', dartAotPath) .replaceAll(r'$DART', dartPath) .split(' ') .map((c) => c.replaceAll(r'$SPACE', ' ')) diff --git a/utils/bazel/BUILD.gn b/utils/bazel/BUILD.gn index 143febeac89..4e6526f290a 100644 --- a/utils/bazel/BUILD.gn +++ b/utils/bazel/BUILD.gn @@ -2,9 +2,28 @@ # for details. All rights reserved. Use of this source code is governed by a # BSD-style license that can be found in the LICENSE file. +import("../../runtime/runtime_args.gni") +import("../../sdk_args.gni") +import("../aot_snapshot.gni") import("../application_snapshot.gni") import("../create_timestamp.gni") +aot_snapshot("kernel_worker_aot") { + main_dart = "kernel_worker.dart" + name = "kernel_worker_aot" + output = "$root_gen_dir/kernel_worker_aot.dart.snapshot" + + # dartaotruntime has dart_product_config applied to it, + # so it is built in product mode in both release and + # product builds, and is only built in debug mode in debug + # builds. The following line ensures that the dartaotruntime + # and frontend_server_aot snapshot in an SDK build are + # always compatible with each other. + force_product_mode = !dart_debug +} + +# Generation of this JIT snapshot can be removed in Dart SDK version 3.7 +# Please see https://github.com/dart-lang/build/pull/3742 for more details application_snapshot("kernel_worker") { main_dart = "kernel_worker.dart" training_args = [ "--help" ] diff --git a/utils/ddc/BUILD.gn b/utils/ddc/BUILD.gn index 7127fd39f80..9c6f1473319 100644 --- a/utils/ddc/BUILD.gn +++ b/utils/ddc/BUILD.gn @@ -3,7 +3,10 @@ # BSD-style license that can be found in the LICENSE file. import("../../build/dart/dart_action.gni") +import("../../runtime/runtime_args.gni") +import("../../sdk_args.gni") import("../../utils/compile_platform.gni") +import("../aot_snapshot.gni") import("../application_snapshot.gni") import("../create_timestamp.gni") @@ -15,6 +18,20 @@ sdk_full_unsound_dill = "$root_out_dir/ddc_platform_unsound.dill" sdk_root = "../../sdk" pkg_root = "../../pkg" +aot_snapshot("dartdevc_aot") { + main_dart = "../../pkg/dev_compiler/bin/dartdevc.dart" + name = "dartdevc_aot" + output = "$root_gen_dir/dartdevc_aot.dart.snapshot" + + # dartaotruntime has dart_product_config applied to it, + # so it is built in product mode in both release and + # product builds, and is only built in debug mode in debug + # builds. The following line ensures that the dartaotruntime + # and dartdevc_aot snapshot in an SDK build are + # always compatible with each other. + force_product_mode = !dart_debug +} + application_snapshot("dartdevc") { main_dart = "../../pkg/dev_compiler/bin/dartdevc.dart" @@ -346,19 +363,31 @@ template("package_kernel_outline") { package_kernel_outline("expect_outline") { package = "expect" - extra_libraries = [ "async_helper", "legacy/minitest", "legacy/async_minitest" ] + extra_libraries = [ + "async_helper", + "legacy/minitest", + "legacy/async_minitest", + ] sound_null_safety = true } package_kernel_outline("expect_outline_unsound") { package = "expect" - extra_libraries = [ "async_helper", "legacy/minitest", "legacy/async_minitest" ] + extra_libraries = [ + "async_helper", + "legacy/minitest", + "legacy/async_minitest", + ] sound_null_safety = false } ddc_compile("expect_stable_js") { package = "expect" - extra_libraries = [ "async_helper", "legacy/minitest", "legacy/async_minitest" ] + extra_libraries = [ + "async_helper", + "legacy/minitest", + "legacy/async_minitest", + ] canary = false modules = [ "amd", @@ -369,7 +398,11 @@ ddc_compile("expect_stable_js") { ddc_compile("expect_canary_js") { package = "expect" - extra_libraries = [ "async_helper", "legacy/minitest", "legacy/async_minitest" ] + extra_libraries = [ + "async_helper", + "legacy/minitest", + "legacy/async_minitest", + ] canary = true modules = [ "amd" ] sound_null_safety = true @@ -377,7 +410,11 @@ ddc_compile("expect_canary_js") { ddc_compile("expect_canary_ddc_js") { package = "expect" - extra_libraries = [ "async_helper", "legacy/minitest", "legacy/async_minitest" ] + extra_libraries = [ + "async_helper", + "legacy/minitest", + "legacy/async_minitest", + ] canary = true modules = [ "ddc" ] sound_null_safety = true @@ -385,7 +422,11 @@ ddc_compile("expect_canary_ddc_js") { ddc_compile("expect_stable_unsound_js") { package = "expect" - extra_libraries = [ "async_helper", "legacy/minitest", "legacy/async_minitest" ] + extra_libraries = [ + "async_helper", + "legacy/minitest", + "legacy/async_minitest", + ] canary = false modules = [ "amd", @@ -396,7 +437,11 @@ ddc_compile("expect_stable_unsound_js") { ddc_compile("expect_canary_unsound_js") { package = "expect" - extra_libraries = [ "async_helper", "legacy/minitest", "legacy/async_minitest" ] + extra_libraries = [ + "async_helper", + "legacy/minitest", + "legacy/async_minitest", + ] canary = true modules = [ "amd" ] sound_null_safety = false @@ -404,7 +449,11 @@ ddc_compile("expect_canary_unsound_js") { ddc_compile("expect_canary_unsound_ddc_js") { package = "expect" - extra_libraries = [ "async_helper", "legacy/minitest", "legacy/async_minitest" ] + extra_libraries = [ + "async_helper", + "legacy/minitest", + "legacy/async_minitest", + ] canary = true modules = [ "ddc" ] sound_null_safety = false