blob: 7689613bb5dd452649db0650c15f105afc49f13f [file] [log] [blame]
# Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
# 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("../../build/dart/dart_action.gni")
import("../../utils/compile_platform.gni")
import("../application_snapshot.gni")
import("../create_timestamp.gni")
sdk_outline_dill = "$root_out_dir/ddc_outline.dill"
sdk_full_dill = "$root_out_dir/ddc_platform.dill"
sdk_outline_unsound_dill = "$root_out_dir/ddc_outline_unsound.dill"
sdk_full_unsound_dill = "$root_out_dir/ddc_platform_unsound.dill"
sdk_root = "../../sdk"
pkg_root = "../../pkg"
application_snapshot("dartdevc") {
main_dart = "../../pkg/dev_compiler/bin/dartdevc.dart"
training_args = [
"--dart-sdk-summary",
rebase_path(sdk_outline_dill),
"-o",
"dartdevc.js",
rebase_path("../../pkg/dev_compiler/bin/dartdevc.dart"),
]
training_deps = [ ":ddc_platform" ]
training_inputs = [ sdk_outline_dill ]
}
template("dart2js_compile") {
assert(defined(invoker.main), "Must specify the main file")
main = invoker.main
assert(defined(invoker.out), "Must specify the out file")
out = invoker.out
abs_main = rebase_path(main)
abs_output = rebase_path(out)
prebuilt_dart_action(target_name) {
deps = invoker.deps + [
"../compiler:compile_dart2js_platform",
"../compiler:compile_dart2js_platform_unsound",
]
inputs = [
"$root_out_dir/dart2js_platform.dill",
"$root_out_dir/dart2js_platform_unsound.dill",
"$root_out_dir/dart2js_outline.dill",
"$root_out_dir/dart2js_outline_unsound.dill",
]
outputs = [ out ]
script = "../../pkg/compiler/lib/src/dart2js.dart"
packages = "../../.dart_tool/package_config.json"
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
args = [
"$abs_main",
"-m",
"--invoker=gn_build",
"-o$abs_output",
"--no-source-maps",
"--platform-binaries=" + rebase_path("$root_out_dir"),
]
}
}
dart2js_compile("stack_trace_mapper") {
main = rebase_path("../../pkg/dev_compiler/web/stack_trace_mapper.dart")
out = "$root_out_dir/dev_compiler/build/web/dart_stack_trace_mapper.js"
deps = [ ":ddc_files_stamp" ]
}
# Builds everything needed to run tests with DDC (stable) using test.dart.
group("ddc_stable_test") {
deps = [
":dartdevc",
":ddc_stable_test_local",
"../..:create_sdk",
]
}
# Builds everything needed to run tests with DDC (canary) using test.dart.
group("ddc_canary_test") {
deps = [
":dartdevc",
":ddc_canary_test_local",
"../..:create_sdk",
]
}
# Builds everything needed to run tests with DDC (stable) locally using
# test.dart without --use-sdk.
#
# This is the same as ddc_stable_test, but skips the targets that depend on
# building the Dart VM and create_sdk.
group("ddc_stable_test_local") {
deps = [
":ddc_stable_sdk",
":ddc_stable_test_pkg",
":ddc_stable_unsound_sdk",
]
}
# Builds everything needed to run tests with DDC (stable) locally using
# test.dart without --use-sdk.
#
# This is the same as ddc_stable_test,but skips the targets that depend on
# building the Dart VM and create_sdk.
group("ddc_canary_test_local") {
deps = [
":ddc_canary_sdk",
":ddc_canary_test_pkg",
":ddc_canary_unsound_sdk",
]
}
create_timestamp_file("ddc_files_stamp") {
path = rebase_path("../../pkg/dev_compiler/lib")
output = "$target_gen_dir/ddc_files.stamp"
}
create_timestamp_file("ddc_sdk_patch_stamp") {
path = rebase_path("$sdk_root/lib/_internal/js_dev_runtime")
output = "$target_gen_dir/ddc_sdk_patch_stamp.stamp"
}
# Compiles to JavaScript using DDC (stable) all packages imported in tests.
# TODO(sigmund): generate a js bundle or a module that load these indirectly so
# we can stop referring to this list of packages explicitly in the test_runner.
group("ddc_stable_test_pkg") {
deps = [
":async_helper_stable_js",
":async_helper_stable_unsound_js",
":ddc_test_pkg_outline",
":expect_stable_js",
":expect_stable_unsound_js",
":js_stable_js",
":js_stable_unsound_js",
":meta_stable_js",
":meta_stable_unsound_js",
]
}
# Compiles to JavaScript using DDC (canary) all packages imported in tests.
group("ddc_canary_test_pkg") {
deps = [
":async_helper_canary_js",
":async_helper_canary_unsound_js",
":ddc_test_pkg_outline",
":expect_canary_js",
":expect_canary_unsound_js",
":js_canary_js",
":js_canary_unsound_js",
":meta_canary_js",
":meta_canary_unsound_js",
]
}
group("ddc_test_pkg_outline") {
deps = [
":async_helper_outline",
":async_helper_outline_unsound",
":expect_outline",
":expect_outline_unsound",
":js_outline",
":js_outline_unsound",
":meta_outline",
":meta_outline_unsound",
]
}
template("ddc_compile") {
assert(defined(invoker.package),
"Need 'package' in $target_name (the name of the package)")
assert(defined(invoker.sound_null_safety),
"Need 'sound_null_safety' in $target_name.")
# Determine one of four possible directories for the JavaScript output to be
# generated:
#
# out/gen/ddc
# |- canary/pkg
# |- canary_unsound/pkg
# |- stable/pkg
# |- stable_unsound/pkg
if (invoker.canary) {
js_gen_dir = "$target_gen_dir/canary"
} else {
js_gen_dir = "$target_gen_dir/stable"
}
if (invoker.sound_null_safety) {
platform_dep = ":ddc_platform"
sdk_outline = sdk_outline_dill
js_gen_dir = "$js_gen_dir/pkg"
} else {
platform_dep = ":ddc_platform_unsound"
sdk_outline = sdk_outline_unsound_dill
js_gen_dir = "${js_gen_dir}_unsound/pkg"
}
# Other optional invoker parameters:
# * extra_libraries: entrypoints to include in the module as
# "package:package_name/library_name.dart" (the rule implicitly adds
# the default import "package:package_name/package_name.dart").
# * package_dependencies: the name of other packages this package depends
# on. When providing `name`, a separate `ddc_compile` target
# named `${name}_js` must exist.
# * args: additional args to pass to dartdevc
prebuilt_dart_action(target_name) {
script = "../../pkg/dev_compiler/bin/dartdevc.dart"
module = invoker.package
out_dir = rebase_path("$js_gen_dir")
sdk_path = rebase_path(sdk_outline)
pkg_root = rebase_path("$root_build_dir/../../pkg")
deps = [
":ddc_files_stamp",
platform_dep,
]
inputs = [
sdk_outline,
"$target_gen_dir/ddc_files.stamp",
]
outputs = [
"$js_gen_dir/amd/$module.js",
"$js_gen_dir/amd/$module.js.map",
"$js_gen_dir/ddc/$module.js",
"$js_gen_dir/ddc/$module.js.map",
]
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
args = [
"--no-summarize",
"--multi-root-output-path=$pkg_root",
"--dart-sdk-summary=$sdk_path",
"--modules=amd",
"-o$out_dir/amd/$module.js",
"--modules=ddc",
"-o$out_dir/ddc/$module.js",
"package:$module/$module.dart",
]
if (defined(invoker.extra_libraries)) {
foreach(lib, invoker.extra_libraries) {
args += [ "package:$module/$lib.dart" ]
}
}
if (defined(invoker.package_dependencies)) {
foreach(dep, invoker.package_dependencies) {
deps += [ ":${dep}_js" ]
args += [ "-s$out_dir/$dep.dill" ]
}
}
if (defined(invoker.args)) {
args += invoker.args
}
if (invoker.sound_null_safety) {
args += [ "--sound-null-safety" ]
} else {
args += [ "--no-sound-null-safety" ]
}
if (invoker.canary) {
args += [ "--canary" ]
}
}
}
# Compiles a package to outline .dill file with the "dartdevc" target option.
template("package_kernel_outline") {
assert(defined(invoker.package),
"Need 'package' in $target_name (the name of the package)")
assert(defined(invoker.sound_null_safety),
"Need 'sound_null_safety' in $target_name.")
module = invoker.package
output = "$target_gen_dir/${module}_outline"
if (invoker.sound_null_safety) {
platform_dep = ":ddc_platform"
sdk_outline = rebase_path(sdk_outline_dill)
output = "$output.dill"
} else {
platform_dep = ":ddc_platform_unsound"
sdk_outline = rebase_path(sdk_outline_unsound_dill)
output = "${output}_unsound.dill"
}
package_config =
rebase_path("$root_out_dir/../../.dart_tool/package_config.json")
prebuilt_dart_action(target_name) {
deps = [
"../bazel:kernel_worker_files_stamp",
platform_dep,
]
script = "../bazel/kernel_worker.dart"
outputs = [ output ]
args = [
"--packages-file",
"file:///$package_config",
"--summary-only",
"--target",
"ddc",
"--dart-sdk-summary",
"file:///$sdk_outline",
"--source",
"package:$module/$module.dart",
"--output",
rebase_path(output),
]
if (invoker.sound_null_safety) {
args += [ "--sound-null-safety" ]
} else {
args += [ "--no-sound-null-safety" ]
}
if (defined(invoker.extra_libraries)) {
foreach(lib, invoker.extra_libraries) {
args += [
"--source",
"package:$module/$lib.dart",
]
}
}
}
}
package_kernel_outline("async_helper_outline") {
package = "async_helper"
sound_null_safety = true
}
package_kernel_outline("async_helper_outline_unsound") {
package = "async_helper"
sound_null_safety = false
}
ddc_compile("async_helper_stable_js") {
package = "async_helper"
canary = false
sound_null_safety = true
}
ddc_compile("async_helper_canary_js") {
package = "async_helper"
canary = true
sound_null_safety = true
}
ddc_compile("async_helper_stable_unsound_js") {
package = "async_helper"
canary = false
sound_null_safety = false
}
ddc_compile("async_helper_canary_unsound_js") {
package = "async_helper"
canary = true
sound_null_safety = false
}
package_kernel_outline("expect_outline") {
package = "expect"
extra_libraries = [ "minitest" ]
sound_null_safety = true
}
package_kernel_outline("expect_outline_unsound") {
package = "expect"
extra_libraries = [ "minitest" ]
sound_null_safety = false
}
ddc_compile("expect_stable_js") {
package = "expect"
extra_libraries = [ "minitest" ]
canary = false
sound_null_safety = true
}
ddc_compile("expect_canary_js") {
package = "expect"
extra_libraries = [ "minitest" ]
canary = true
sound_null_safety = true
}
ddc_compile("expect_stable_unsound_js") {
package = "expect"
extra_libraries = [ "minitest" ]
canary = false
sound_null_safety = false
}
ddc_compile("expect_canary_unsound_js") {
package = "expect"
extra_libraries = [ "minitest" ]
canary = true
sound_null_safety = false
}
package_kernel_outline("js_outline") {
package = "js"
extra_libraries = [ "js_util" ]
sound_null_safety = true
}
package_kernel_outline("js_outline_unsound") {
package = "js"
extra_libraries = [ "js_util" ]
sound_null_safety = false
}
ddc_compile("js_stable_js") {
package = "js"
extra_libraries = [ "js_util" ]
canary = false
sound_null_safety = true
}
ddc_compile("js_canary_js") {
package = "js"
extra_libraries = [ "js_util" ]
canary = true
sound_null_safety = true
}
ddc_compile("js_stable_unsound_js") {
package = "js"
extra_libraries = [ "js_util" ]
canary = false
sound_null_safety = false
}
ddc_compile("js_canary_unsound_js") {
package = "js"
extra_libraries = [ "js_util" ]
canary = true
sound_null_safety = false
}
package_kernel_outline("meta_outline") {
package = "meta"
sound_null_safety = true
}
package_kernel_outline("meta_outline_unsound") {
package = "meta"
sound_null_safety = false
}
ddc_compile("meta_stable_js") {
package = "meta"
canary = false
sound_null_safety = true
}
ddc_compile("meta_canary_js") {
package = "meta"
canary = true
sound_null_safety = true
}
ddc_compile("meta_stable_unsound_js") {
package = "meta"
canary = false
sound_null_safety = false
}
ddc_compile("meta_canary_unsound_js") {
package = "meta"
canary = true
sound_null_safety = false
}
template("compile_ddc_platform") {
assert(defined(invoker.sound_null_safety),
"Need 'sound_null_safety' in $target_name.")
compile_platform(target_name) {
single_root_scheme = "org-dartlang-sdk"
single_root_base = rebase_path("$sdk_root/")
libraries_specification_uri = "org-dartlang-sdk:///lib/libraries.json"
args = [
"--target=dartdevc",
"dart:core",
]
if (invoker.sound_null_safety) {
args += [ "--nnbd-strong" ]
outputs = [
sdk_full_dill,
sdk_outline_dill,
]
} else {
args += [ "--nnbd-weak" ]
outputs = [
sdk_full_unsound_dill,
sdk_outline_unsound_dill,
]
}
}
}
compile_ddc_platform("ddc_platform") {
sound_null_safety = true
}
compile_ddc_platform("ddc_platform_unsound") {
sound_null_safety = false
}
# Compiles the DDC SDK JavaScript modules from the platform .dill file.
template("ddc_compile_sdk") {
assert(defined(invoker.sound_null_safety),
"Need 'sound_null_safety' in $target_name.")
# Determine one of four possible directories for the JavaScript output to be
# generated:
#
# out/gen/ddc
# |- canary/sdk
# |- canary_unsound/sdk
# |- stable/sdk
# |- stable_unsound/sdk
if (invoker.canary) {
js_gen_dir = "$target_gen_dir/canary"
} else {
js_gen_dir = "$target_gen_dir/stable"
}
if (invoker.sound_null_safety) {
platform_dep = ":ddc_platform"
platform_input = sdk_full_dill
js_gen_dir = "$js_gen_dir/sdk"
} else {
platform_dep = ":ddc_platform_unsound"
platform_input = sdk_full_unsound_dill
js_gen_dir = "${js_gen_dir}_unsound/sdk"
}
prebuilt_dart_action(target_name) {
deps = [
":ddc_files_stamp",
platform_dep,
]
inputs = [ platform_input ]
outputs = [
"$js_gen_dir/amd/dart_sdk.js",
"$js_gen_dir/amd/dart_sdk.js.map",
"$js_gen_dir/common/dart_sdk.js",
"$js_gen_dir/common/dart_sdk.js.map",
"$js_gen_dir/es6/dart_sdk.js",
"$js_gen_dir/es6/dart_sdk.js.map",
"$js_gen_dir/ddc/dart_sdk.js",
"$js_gen_dir/ddc/dart_sdk.js.map",
]
vm_args = [ "-Dsdk_hash=$sdk_hash" ]
script = "../../pkg/dev_compiler/bin/dartdevc.dart"
args = [
"--multi-root-scheme",
"org-dartlang-sdk",
"--multi-root-output-path",
# This path is intended to point to a version of source files used to
# generate the SDK JavaScript modules.
# The intention is that the source map locations can be linked to the
# orignal source files while running SDK test suites.
# These JavaScript files and source maps are no longer packaged into the
# released SDK.
rebase_path("$target_gen_dir/../../../dart-sdk"),
"--modules",
"amd",
"-o",
rebase_path("$js_gen_dir/amd/dart_sdk.js"),
"--modules",
"common",
"-o",
rebase_path("$js_gen_dir/common/dart_sdk.js"),
"--modules",
"es6",
"-o",
rebase_path("$js_gen_dir/es6/dart_sdk.js"),
"--modules",
"ddc",
"-o",
rebase_path("$js_gen_dir/ddc/dart_sdk.js"),
rebase_path("$platform_input"),
]
if (invoker.sound_null_safety) {
args += [ "--sound-null-safety" ]
} else {
args += [ "--no-sound-null-safety" ]
}
if (invoker.canary) {
args += [ "--canary" ]
}
}
}
ddc_compile_sdk("ddc_stable_sdk") {
canary = false
sound_null_safety = true
}
ddc_compile_sdk("ddc_stable_unsound_sdk") {
canary = false
sound_null_safety = false
}
ddc_compile_sdk("ddc_canary_sdk") {
canary = true
sound_null_safety = true
}
ddc_compile_sdk("ddc_canary_unsound_sdk") {
canary = true
sound_null_safety = false
}