Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: rename the v8 context snapshot on arm64 macOS builds #26202

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,9 @@ step-electron-dist-build: &step-electron-dist-build
if [ x"$MAS_BUILD" == x"true" ]; then
target_os=mac_mas
fi
if [ "$TARGET_ARCH" == "arm64" ]; then
target_cpu=arm64
fi
elif [ "`uname`" == "Linux" ]; then
target_os=linux
if [ x"$TARGET_ARCH" == x ]; then
Expand Down
10 changes: 5 additions & 5 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,10 @@ if (is_mac) {
action("fake_v8_context_snapshot_generator") {
script = "build/fake_v8_context_snapshot_generator.py"
args = [
rebase_path("$root_out_dir/v8_context_snapshot.bin"),
rebase_path("$root_out_dir/fake/v8_context_snapshot.bin"),
rebase_path("$root_out_dir/$v8_context_snapshot_filename"),
rebase_path("$root_out_dir/fake/$v8_context_snapshot_filename"),
]
outputs = [ "$root_out_dir/fake/v8_context_snapshot.bin" ]
outputs = [ "$root_out_dir/fake/$v8_context_snapshot_filename" ]
}

bundle_data("electron_framework_resources") {
Expand All @@ -700,10 +700,10 @@ if (is_mac) {
public_deps += [ "//v8" ]
if (use_v8_context_snapshot) {
if (use_prebuilt_v8_context_snapshot) {
sources += [ "$root_out_dir/fake/v8_context_snapshot.bin" ]
sources += [ "$root_out_dir/fake/$v8_context_snapshot_filename" ]
public_deps += [ ":fake_v8_context_snapshot_generator" ]
} else {
sources += [ "$root_out_dir/v8_context_snapshot.bin" ]
sources += [ "$root_out_dir/$v8_context_snapshot_filename" ]
public_deps += [ "//tools/v8_context_snapshot" ]
}
} else {
Expand Down
1 change: 1 addition & 0 deletions patches/chromium/.patches
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,4 @@ worker_feat_add_hook_to_notify_script_ready.patch
cherry-pick-2f5b8357dca2.patch
fix_use_electron_generated_resources.patch
chore_expose_v8_initialization_isolate_callbacks.patch
rename_the_v8_context_snapshot_on_arm64_macos_builds.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Samuel Attard <samuel.r.attard@gmail.com>
Date: Wed, 21 Oct 2020 13:13:00 -0700
Subject: rename the v8 context snapshot on arm64 macOS builds

This is done so that the arm64 and x64 v8 context snapshots can
live side by side in a universal app build of a Chromium based
application. All other files can be Mach-O universal binaries
generated using "lipo" but these snapshot files have to be uniquely
named so that both can exist in the Resources folder at the same time
and the correct one is chosen at runtime.

Bug: 1142017
Change-Id: I8449b72ba3a36e7ce69b9d9ec7768bd80ecc3e3a

diff --git a/android_webview/BUILD.gn b/android_webview/BUILD.gn
index a07040de159b5a060c30cc5d9b16c82686f12363..c616d7cd872349d8ead7d6605b437d7330a22034 100644
--- a/android_webview/BUILD.gn
+++ b/android_webview/BUILD.gn
@@ -792,7 +792,7 @@ if (android_64bit_target_cpu) {
"32-bit targets shouldn't have secondary abi")
arch_suffix = "32"
if (use_v8_context_snapshot) {
- renaming_sources = [ "$_secondary_abi_out_dir/v8_context_snapshot.bin" ]
+ renaming_sources = [ "$_secondary_abi_out_dir/$v8_context_snapshot_filename" ]
renaming_destinations = [ "v8_context_snapshot_$arch_suffix.bin" ]
} else {
renaming_sources = [ "$_secondary_abi_out_dir/snapshot_blob.bin" ]
diff --git a/chrome/BUILD.gn b/chrome/BUILD.gn
index 56f5ff4c628daa7f42f4c84c9a4b98f3f250a2b0..15f7a164662b9e90fa43eb893d743182e05b48fa 100644
--- a/chrome/BUILD.gn
+++ b/chrome/BUILD.gn
@@ -772,7 +772,7 @@ if (is_win) {
if (v8_use_external_startup_data) {
public_deps += [ "//v8" ]
if (use_v8_context_snapshot) {
- sources += [ "$root_out_dir/v8_context_snapshot.bin" ]
+ sources += [ "$root_out_dir/$v8_context_snapshot_filename" ]
public_deps += [ "//tools/v8_context_snapshot" ]
} else {
sources += [ "$root_out_dir/snapshot_blob.bin" ]
diff --git a/chrome/installer/mini_installer/BUILD.gn b/chrome/installer/mini_installer/BUILD.gn
index 7c7af8c0d9487abcd82ecd9d2d5b1ab4b737148b..df39ea145cc6b05775db7fbfb680fce892b8941a 100644
--- a/chrome/installer/mini_installer/BUILD.gn
+++ b/chrome/installer/mini_installer/BUILD.gn
@@ -228,7 +228,7 @@ template("generate_mini_installer") {
if (v8_use_external_startup_data) {
deps += [ "//v8" ]
if (use_v8_context_snapshot) {
- inputs += [ "$root_out_dir/v8_context_snapshot.bin" ]
+ inputs += [ "$root_out_dir/$v8_context_snapshot_filename" ]
deps += [ "//tools/v8_context_snapshot" ]
} else {
inputs += [ "$root_out_dir/snapshot_blob.bin" ]
diff --git a/content/browser/BUILD.gn b/content/browser/BUILD.gn
index fcf6229f4d530c56b7c65fe6898c00a8a566dc1a..b3115bab5c08106072e28a9f01304f688d51f72b 100644
--- a/content/browser/BUILD.gn
+++ b/content/browser/BUILD.gn
@@ -43,6 +43,7 @@ source_set("browser") {
configs += [
"//build/config:precompiled_headers",
"//content:content_implementation",
+ "//tools/v8_context_snapshot:use_v8_context_snapshot",
"//v8:external_startup_data",
]
defines = []
diff --git a/content/browser/v8_snapshot_files.cc b/content/browser/v8_snapshot_files.cc
index d557c41a38e17c61e1b91d3daa47ea17e13a6a9e..43c93e3f50290d2aef230083a4bcebf307ef0c6e 100644
--- a/content/browser/v8_snapshot_files.cc
+++ b/content/browser/v8_snapshot_files.cc
@@ -13,7 +13,7 @@ std::map<std::string, base::FilePath> GetV8SnapshotFilesToPreload() {
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#if defined(USE_V8_CONTEXT_SNAPSHOT)
return {{kV8ContextSnapshotDataDescriptor,
- base::FilePath(FILE_PATH_LITERAL("v8_context_snapshot.bin"))}};
+ base::FilePath(FILE_PATH_LITERAL(V8_CONTEXT_SNAPSHOT_FILENAME))}};
#else
return {{kV8SnapshotDataDescriptor,
base::FilePath(FILE_PATH_LITERAL("snapshot_blob.bin"))}};
diff --git a/content/shell/BUILD.gn b/content/shell/BUILD.gn
index 578e4341247e112440b13080b45ac5e854635bd2..74c1e0f29db065985920756ae057e255d76e51c2 100644
--- a/content/shell/BUILD.gn
+++ b/content/shell/BUILD.gn
@@ -547,7 +547,7 @@ if (is_mac) {
if (v8_use_external_startup_data) {
public_deps += [ "//v8" ]
if (use_v8_context_snapshot) {
- sources += [ "$root_out_dir/v8_context_snapshot.bin" ]
+ sources += [ "$root_out_dir/$v8_context_snapshot_filename" ]
public_deps += [ "//tools/v8_context_snapshot" ]
} else {
sources += [ "$root_out_dir/snapshot_blob.bin" ]
diff --git a/gin/BUILD.gn b/gin/BUILD.gn
index 9ec6eb1b898bc87d066bdc75867ff624f7ef1f50..dfc59c17382f8463e82185032d977a1868c71985 100644
--- a/gin/BUILD.gn
+++ b/gin/BUILD.gn
@@ -85,7 +85,10 @@ component("gin") {
frameworks = [ "CoreFoundation.framework" ]
}

- configs += [ "//v8:external_startup_data" ]
+ configs += [
+ "//tools/v8_context_snapshot:use_v8_context_snapshot",
+ "//v8:external_startup_data",
+ ]
}

executable("gin_shell") {
diff --git a/gin/v8_initializer.cc b/gin/v8_initializer.cc
index 51fe2fa000e47ced3661ba581c52dceba93447fe..07d970b84b770b06019dc1de441cf108d67b1782 100644
--- a/gin/v8_initializer.cc
+++ b/gin/v8_initializer.cc
@@ -76,7 +76,9 @@ const char kSnapshotFileName32[] = "snapshot_blob_32.bin";
#endif

#else // defined(OS_ANDROID)
-const char kV8ContextSnapshotFileName[] = "v8_context_snapshot.bin";
+#if defined(USE_V8_CONTEXT_SNAPSHOT)
+const char kV8ContextSnapshotFileName[] = V8_CONTEXT_SNAPSHOT_FILENAME;
+#endif
const char kSnapshotFileName[] = "snapshot_blob.bin";
#endif // defined(OS_ANDROID)

@@ -86,7 +88,12 @@ const char* GetSnapshotFileName(
case V8Initializer::V8SnapshotFileType::kDefault:
return kSnapshotFileName;
case V8Initializer::V8SnapshotFileType::kWithAdditionalContext:
+#if defined(USE_V8_CONTEXT_SNAPSHOT)
return kV8ContextSnapshotFileName;
+#else
+ NOTREACHED();
+ return nullptr;
+#endif
}
NOTREACHED();
return nullptr;
diff --git a/headless/BUILD.gn b/headless/BUILD.gn
index aeab3dc3ad08688b7a7af191b43e20845da72091..d2ab76aed326d246c8f8d550ff709b84b56e45d3 100644
--- a/headless/BUILD.gn
+++ b/headless/BUILD.gn
@@ -471,7 +471,7 @@ component("headless_non_renderer") {
if (v8_use_external_startup_data) {
public_deps += [ "//v8" ]
if (use_v8_context_snapshot) {
- data += [ "$root_out_dir/v8_context_snapshot.bin" ]
+ data += [ "$root_out_dir/$v8_context_snapshot_filename" ]
data_deps += [ "//tools/v8_context_snapshot" ]
} else {
data += [ "$root_out_dir/snapshot_blob.bin" ]
diff --git a/tools/v8_context_snapshot/BUILD.gn b/tools/v8_context_snapshot/BUILD.gn
index 2f20f684d89021dcd0e64421a0553a3e4a66334d..7662cc8ee83e39709eee6e0919c85370fedbb983 100644
--- a/tools/v8_context_snapshot/BUILD.gn
+++ b/tools/v8_context_snapshot/BUILD.gn
@@ -21,14 +21,17 @@ group("v8_context_snapshot") {
if (use_v8_context_snapshot) {
public_deps = [ ":generate_v8_context_snapshot" ]
if (!is_android) {
- data = [ "$root_out_dir/v8_context_snapshot.bin" ]
+ data = [ "$root_out_dir/$v8_context_snapshot_filename" ]
}
}
}

config("use_v8_context_snapshot") {
if (use_v8_context_snapshot) {
- defines = [ "USE_V8_CONTEXT_SNAPSHOT" ]
+ defines = [
+ "USE_V8_CONTEXT_SNAPSHOT",
+ "V8_CONTEXT_SNAPSHOT_FILENAME=\"$v8_context_snapshot_filename\"",
+ ]
}
}

@@ -36,7 +39,7 @@ if (use_v8_context_snapshot) {
if (is_android && enable_java_templates) {
android_assets("v8_context_snapshot_assets") {
deps = [ ":v8_context_snapshot" ]
- renaming_sources = [ "$root_out_dir/v8_context_snapshot.bin" ]
+ renaming_sources = [ "$root_out_dir/$v8_context_snapshot_filename" ]
if (current_cpu == "arm" || current_cpu == "x86" ||
current_cpu == "mipsel") {
renaming_destinations = [ "v8_context_snapshot_32.bin" ]
@@ -49,7 +52,7 @@ if (use_v8_context_snapshot) {

action("generate_v8_context_snapshot") {
script = "//build/gn_run_binary.py"
- output_file = "$root_out_dir/v8_context_snapshot.bin"
+ output_file = "$root_out_dir/$v8_context_snapshot_filename"
output_path = rebase_path(output_file, root_build_dir)

args = [
diff --git a/tools/v8_context_snapshot/v8_context_snapshot.gni b/tools/v8_context_snapshot/v8_context_snapshot.gni
index 6a6f477ad3f543680cd6485bdf6b0e82d567012c..7f485e135cef8e3f0c01ede28b4cfe76067bc624 100644
--- a/tools/v8_context_snapshot/v8_context_snapshot.gni
+++ b/tools/v8_context_snapshot/v8_context_snapshot.gni
@@ -18,6 +18,18 @@ declare_args() {
!is_chromeos && !is_android && !is_chromecast && !is_fuchsia &&
!(host_os == "mac" && current_cpu == "x86") &&
(v8_target_cpu == target_cpu || is_msan) && !(is_win && host_os != "win")
+
+ # We use a different filename for arm64 macOS builds so that the arm64 and
+ # x64 snapshots can live side-by-side in a universal macOS app.
+ if (is_mac) {
+ if (v8_target_cpu == "x64") {
+ v8_context_snapshot_filename = "v8_context_snapshot.x86_64.bin"
+ } else if (v8_target_cpu == "arm64") {
+ v8_context_snapshot_filename = "v8_context_snapshot.arm64.bin"
+ }
+ } else {
+ v8_context_snapshot_filename = "v8_context_snapshot.bin"
+ }
}

# We cannot use V8 context snapshot, if V8 doesn't use snapshot files.
3 changes: 3 additions & 0 deletions script/verify-mksnapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import glob
import os
import platform
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -31,6 +32,8 @@ def main():
subprocess.check_call(mkargs + [ SNAPSHOT_SOURCE ], cwd=app_path)
print('ok mksnapshot successfully created snapshot_blob.bin.')
context_snapshot = 'v8_context_snapshot.bin'
if platform.system() == 'Darwin':
context_snapshot = 'v8_context_snapshot.x86_64.bin'
context_snapshot_path = os.path.join(app_path, context_snapshot)
gen_binary = get_binary_path('v8_context_snapshot_generator', \
app_path)
Expand Down