Skip to content

Commit a88a328

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm] Build dart2native dependencies with the normal "create_sdk" target
This removes special logic for creating the `dart-sdk` we distribute which used to build release and product mode and copied some binaries from the latter into the former, before the SDK was actuallly ready to test and distribute. This changes the GN build rules to build the necessary gen_snapshot/dart_precompiled_runtime product binaries during the normal release build. Normally during --mode=product builds the global build config in //build/config/BUILDCONFIG.gn will set `-fvisibility=false`. => Doing so results in much smaller binaries - because only explicitly exported symbols are visible, the rest can be tree shaken by the linker. Since we are building --mode=release, the `-fvisibility=false` will not be set. In order to set the flag for the 2 special product-mode binaries we need to add -fvisibility=hidden manually, in: * dart_product_config: Which is used for compiling VM sources. * 3rd party double-conversion library * 3rd party boringssl library * 3rd party icu library The upstream CLs are: * BoringSSL: https://dart-review.googlesource.com/c/boringssl_gen/+/150482 * ICU: https://chromium-review.googlesource.com/c/chromium/deps/icu/+/2236407 Issue #42230 Change-Id: I3e47664d9fadb9ed1ad033bb17d46e769442f741 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150524 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Alexander Thomas <[email protected]> Reviewed-by: Zach Anderson <[email protected]>
1 parent 68e1708 commit a88a328

File tree

12 files changed

+194
-199
lines changed

12 files changed

+194
-199
lines changed

pkg/dart2native/bin/dart2native.dart

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ final String dartaotruntime =
1919
path.join(binDir, 'dartaotruntime${executableSuffix}');
2020
final String genSnapshot =
2121
path.join(binDir, 'utils', 'gen_snapshot${executableSuffix}');
22-
final String platformDill =
23-
path.join(sdkDir, 'lib', '_internal', 'vm_platform_strong.dill');
2422
final String productPlatformDill =
2523
path.join(sdkDir, 'lib', '_internal', 'vm_platform_strong_product.dill');
2624

@@ -45,20 +43,8 @@ Future<void> generateNative(
4543
print('Generating AOT kernel dill.');
4644
}
4745

48-
// Prefer to use the product platform file, if available. Fall back to the
49-
// normal one (this happens if `out/<build-dir>/dart-sdk` is used).
50-
//
51-
// Background information: For the `dart-sdk` we distribute we build release
52-
// and product mode configurations. Then we have an extra bundling step
53-
// which will add product-mode
54-
// gen_snapshot/dartaotruntime/vm_platform_strong_product.dill to the
55-
// release SDK (see tools/bots/dart_sdk.py:CopyAotBinaries)
56-
final String platformFileToUse = File(productPlatformDill).existsSync()
57-
? productPlatformDill
58-
: platformDill;
59-
6046
final kernelResult = await generateAotKernel(dart, genKernel,
61-
platformFileToUse, sourceFile, kernelFile, packages, defines);
47+
productPlatformDill, sourceFile, kernelFile, packages, defines);
6248
if (kernelResult.exitCode != 0) {
6349
stderr.writeln(kernelResult.stdout);
6450
stderr.writeln(kernelResult.stderr);

runtime/BUILD.gn

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,16 @@ config("dart_maybe_product_config") {
4040
# If a DEBUG build has been specified it will be ignored.
4141
config("dart_product_config") {
4242
defines = []
43+
cflags = []
4344
if (!dart_debug) {
4445
defines += [ "PRODUCT" ]
46+
if (is_posix) {
47+
cflags = [
48+
# This is the equivalent from `build/config/BUILDCONFIG.gn` which includes
49+
# `build/config/gcc:symbol_visibility_hidden` in product mode.
50+
"-fvisibility=hidden",
51+
]
52+
}
4553
}
4654
}
4755

runtime/bin/BUILD.gn

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ build_libdart_builtin("libdart_builtin_product") {
6969
extra_configs = [
7070
"..:dart_product_config",
7171
"..:dart_os_config",
72+
"..:dart_arch_config",
7273
]
7374
}
7475

@@ -136,7 +137,11 @@ template("build_elf_loader") {
136137
}
137138

138139
build_elf_loader("elf_loader") {
139-
deps = [ ":libdart_builtin" ]
140+
if (dart_runtime_mode == "release") {
141+
deps = [ ":libdart_builtin_product" ]
142+
} else {
143+
deps = [ ":libdart_builtin" ]
144+
}
140145
}
141146

142147
build_elf_loader("elf_loader_product") {
@@ -512,6 +517,12 @@ dart_io("standalone_dart_io") {
512517
extra_deps = [ ":libdart_builtin" ]
513518
}
514519

520+
dart_io("standalone_dart_io_product") {
521+
extra_configs = [ "..:dart_product_config" ]
522+
extra_sources = []
523+
extra_deps = [ ":libdart_builtin_product" ]
524+
}
525+
515526
gen_snapshot_action("generate_snapshot_bin") {
516527
deps = [ "../vm:vm_platform_stripped" ]
517528
vm_snapshot_data = "$target_gen_dir/vm_snapshot_data.bin"
@@ -732,6 +743,11 @@ action("generate_abi_version_cc_file") {
732743
}
733744

734745
template("dart_executable") {
746+
use_product_mode = dart_runtime_mode == "release"
747+
if (defined(invoker.use_product_mode)) {
748+
use_product_mode = invoker.use_product_mode
749+
}
750+
735751
extra_configs = []
736752
if (defined(invoker.extra_configs)) {
737753
extra_configs += invoker.extra_configs
@@ -761,8 +777,12 @@ template("dart_executable") {
761777
"..:dart_arch_config",
762778
"..:dart_config",
763779
"..:dart_os_config",
764-
"..:dart_maybe_product_config",
765780
] + extra_configs
781+
if (use_product_mode) {
782+
configs += [ "..:dart_product_config" ]
783+
} else {
784+
configs += [ "..:dart_maybe_product_config" ]
785+
}
766786
if (target_os != current_os && target_os == "fuchsia") {
767787
# We already have these in the standalone build, but Fuchsia doesn't
768788
# have them. They are needed for running Fuchsia binaries built for the
@@ -775,12 +795,17 @@ template("dart_executable") {
775795
}
776796

777797
deps = [
778-
":standalone_dart_io",
779-
"//third_party/boringssl",
780-
"//third_party/zlib",
781-
":crashpad",
782-
":generate_abi_version_cc_file",
783-
] + extra_deps
798+
":crashpad",
799+
":generate_abi_version_cc_file",
800+
"//third_party/boringssl",
801+
"//third_party/zlib",
802+
]
803+
if (use_product_mode) {
804+
deps += [ ":standalone_dart_io_product" ]
805+
} else {
806+
deps += [ ":standalone_dart_io" ]
807+
}
808+
deps += extra_deps
784809

785810
defines = extra_defines
786811
if (exclude_kernel_service) {
@@ -888,6 +913,27 @@ dart_executable("dart_precompiled_runtime") {
888913
}
889914
}
890915

916+
dart_executable("dart_precompiled_runtime_product") {
917+
use_product_mode = true
918+
extra_configs = [ "..:dart_precompiled_runtime_config" ]
919+
extra_deps = [
920+
"..:libdart_precompiled_runtime_product",
921+
"../platform:libdart_platform_precompiled_runtime_product",
922+
]
923+
extra_sources = [
924+
"builtin.cc",
925+
"gzip.cc",
926+
"gzip.h",
927+
"loader.cc",
928+
"loader.h",
929+
"main.cc",
930+
"observatory_assets_empty.cc",
931+
"snapshot_empty.cc",
932+
]
933+
934+
extra_deps += [ ":elf_loader_product" ]
935+
}
936+
891937
executable("process_test") {
892938
sources = [ "process_test.cc" ]
893939
}

runtime/configs.gni

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,66 +66,77 @@ _all_configs = [
6666
configs = _jit_config
6767
snapshot = true
6868
compiler = true
69+
is_product = false
6970
},
7071
{
7172
suffix = "_jit_product"
7273
configs = _jit_product_config
7374
snapshot = true
7475
compiler = true
76+
is_product = true
7577
},
7678
{
7779
suffix = "_precompiled_runtime"
7880
configs = _precompiled_runtime_config
7981
snapshot = true
8082
compiler = false
83+
is_product = false
8184
},
8285
{
8386
suffix = "_precompiled_runtime_product"
8487
configs = _precompiled_runtime_product_config
8588
snapshot = true
8689
compiler = false
90+
is_product = true
8791
},
8892
{
8993
suffix = "_precompiler"
9094
configs = _precompiler_config
9195
snapshot = false
9296
compiler = true
97+
is_product = false
9398
},
9499
{
95100
suffix = "_precompiler_product"
96101
configs = _precompiler_product_config
97102
snapshot = false
98103
compiler = true
104+
is_product = true
99105
},
100106
{
101107
suffix = "_precompiler_fuchsia"
102108
configs = _precompiler_fuchsia_config
103109
snapshot = false
104110
compiler = true
111+
is_product = false
105112
},
106113
{
107114
suffix = "_precompiler_product_fuchsia"
108115
configs = _precompiler_product_fuchsia_config
109116
snapshot = false
110117
compiler = true
118+
is_product = true
111119
},
112120
{
113121
suffix = "_precompiler_host_targeting_host"
114122
configs = _precompiler_host_targeting_host_config
115123
snapshot = false
116124
compiler = true
125+
is_product = false
117126
},
118127
{
119128
suffix = "_precompiler_product_host_targeting_host"
120129
configs = _precompiler_product_host_targeting_host_config
121130
snapshot = false
122131
compiler = true
132+
is_product = true
123133
},
124134
{
125135
suffix = "_libfuzzer"
126136
configs = _libfuzzer_config
127137
snapshot = true
128138
compiler = true
139+
is_product = false
129140
},
130141
]
131142

@@ -174,6 +185,14 @@ template("library_for_all_configs") {
174185
if (defined(invoker.extra_deps)) {
175186
extra_deps += invoker.extra_deps
176187
}
188+
extra_product_deps = []
189+
if (defined(invoker.extra_product_deps)) {
190+
extra_product_deps += invoker.extra_product_deps
191+
}
192+
extra_nonproduct_deps = []
193+
if (defined(invoker.extra_nonproduct_deps)) {
194+
extra_nonproduct_deps += invoker.extra_nonproduct_deps
195+
}
177196
foreach(conf, _all_configs) {
178197
target(invoker.target_type, "${target_name}${conf.suffix}") {
179198
forward_variables_from(invoker,
@@ -196,6 +215,11 @@ template("library_for_all_configs") {
196215
}
197216
}
198217
deps = configured_deps + extra_deps
218+
if (conf.is_product) {
219+
deps += extra_product_deps
220+
} else {
221+
deps += extra_nonproduct_deps
222+
}
199223
if (conf.snapshot) {
200224
if (defined(snapshot_sources)) {
201225
sources += snapshot_sources

runtime/third_party/double-conversion/src/BUILD.gn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
# BSD-style license that can be found in the LICENSE file.
44

55
source_set("libdouble_conversion") {
6+
# We are only interested in exposing the exported symbols (for size reasons).
7+
cflags = []
8+
if (is_posix) {
9+
cflags += [ "-fvisibility=hidden" ]
10+
}
11+
612
configs += [
713
"../../..:dart_arch_config",
814
"../../..:dart_config",

runtime/vm/BUILD.gn

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ config("libdart_vm_config") {
6363

6464
library_for_all_configs("libdart_vm") {
6565
target_type = "source_set"
66-
extra_deps = [ "//third_party/icu" ]
66+
extra_product_deps = [
67+
"//third_party/icu:icui18n_hidden_visibility",
68+
"//third_party/icu:icuuc_hidden_visibility",
69+
]
70+
extra_nonproduct_deps = [
71+
"//third_party/icu:icui18n",
72+
"//third_party/icu:icuuc",
73+
]
6774
if (is_fuchsia) {
6875
if (using_fuchsia_sdk) {
6976
extra_deps += [
@@ -147,6 +154,10 @@ library_for_all_configs("libdart_lib") {
147154
template("gen_vm_platform") {
148155
assert(defined(invoker.output_postfix),
149156
"Must define output postfix (e.g., '_strong'")
157+
is_product_flag = dart_runtime_mode == "release"
158+
if (defined(invoker.product_mode)) {
159+
is_product_flag = invoker.product_mode
160+
}
150161
compile_platform(target_name) {
151162
output_postfix = invoker.output_postfix
152163
if (defined(invoker.add_implicit_vm_platform_dependency)) {
@@ -166,7 +177,6 @@ template("gen_vm_platform") {
166177
"$root_out_dir/vm_outline" + output_postfix + ".dill",
167178
]
168179
args = [ "dart:core" ]
169-
is_product_flag = dart_runtime_mode == "release"
170180
allow_causal_async_stacks = !is_product_flag
171181
args += [
172182
"-Ddart.vm.product=$is_product_flag",
@@ -193,6 +203,16 @@ gen_vm_platform("vm_platform") {
193203
output_postfix = "_strong"
194204
}
195205

206+
gen_vm_platform("vm_platform_product") {
207+
add_implicit_vm_platform_dependency = false
208+
exclude_source = false
209+
output_postfix = "_strong_product"
210+
211+
# In Debug mode we use debug binaries for dart2native.
212+
# (see also the "dart_product_config" config)
213+
product_mode = !is_debug
214+
}
215+
196216
gen_vm_platform("vm_platform_stripped") {
197217
add_implicit_vm_platform_dependency = false
198218
exclude_source = true

0 commit comments

Comments
 (0)