-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
distrib: Add new tools distribution for mksnapshot (see #3734)
- Loading branch information
1 parent
8f4a474
commit 5607a4d
Showing
5 changed files
with
359 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
CONTENTS | ||
-------- | ||
|
||
Debug Contains the Debug build of tools. | ||
|
||
Release Contains the Release build of tools. | ||
|
||
|
||
IMPORTANT NOTE | ||
-------------- | ||
|
||
CEF/Chromium builds are created using the following host architectures: | ||
|
||
- Linux: x86-64 (Intel/AMD) | ||
- Windows: x86-64 (Intel/AMD) | ||
- MacOS: ARM64 (Apple Silicon) | ||
|
||
Binaries in this tools package must be run on the supported host OS/architecture | ||
even in cases where the output targets a different architecture. | ||
|
||
For example, files targeting a MacOS 64-bit (Intel) application must be created | ||
on a MacOS ARM64 (Apple Silicon) host system using the MacOS 64-bit (Intel) | ||
tools distribution. | ||
|
||
|
||
USAGE | ||
----- | ||
|
||
Start with the required host system and the tools distribution that matches your | ||
application's target OS/architecture and CEF version. | ||
|
||
Custom V8 Snapshots | ||
|
||
Custom startup snapshots [https://v8.dev/blog/custom-startup-snapshots] can be | ||
used to speed up V8/JavaScript load time in the renderer process. With CEF this | ||
works as follows: | ||
|
||
1. Generate a single JavaScript file that contains custom startup data. For | ||
example, using https://github.com/atom/electron-link. | ||
|
||
2. Execute the `run_mksnapshot` script to create a `v8_context_snapshot.bin` | ||
file containing the custom data in addition to the default V8 data. | ||
|
||
Example: | ||
% run_mksnapshot Release /path/to/snapshot.js | ||
|
||
Note that bin file names include an architecture component on MacOS | ||
(e.g. `v8_context_snapshot.[arm64|x86_64].bin`) | ||
|
||
3. Replace the existing `v8_context_snapshot.bin` file in the installation | ||
folder or app bundle. | ||
|
||
4. Run the application and verify in DevTools that the custom startup data | ||
exists. For example, electron-link adds a global `snapshotResult` object. | ||
|
||
Please visit the CEF Website for additional usage information. | ||
|
||
https://bitbucket.org/chromiumembedded/cef/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
@echo off | ||
:: Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights | ||
:: reserved. Use of this source code is governed by a BSD-style license | ||
:: that can be found in the LICENSE file. | ||
|
||
set RC= | ||
|
||
setlocal | ||
|
||
if not "%1" == "Debug" ( | ||
if not "%1" == "Release" ( | ||
echo Usage: run_mksnapshot.bat [Debug^|Release] path\to\snapshot.js | ||
set ERRORLEVEL=1 | ||
goto end | ||
) | ||
) | ||
|
||
set SCRIPT_DIR=%~dp0 | ||
set BIN_DIR=%SCRIPT_DIR%%~1 | ||
|
||
if not exist "%BIN_DIR%" ( | ||
echo %BIN_DIR% directory not found | ||
set ERRORLEVEL=1 | ||
goto end | ||
) | ||
|
||
set CMD_FILE=mksnapshot_cmd.txt | ||
|
||
if not exist "%BIN_DIR%\%CMD_FILE%" ( | ||
echo %BIN_DIR%\%CMD_FILE% file not found | ||
set ERRORLEVEL=1 | ||
goto end | ||
) | ||
|
||
cd "%BIN_DIR%" | ||
|
||
:: Read %CMD_FILE% into a local variable. | ||
set /p CMDLINE=<%CMD_FILE% | ||
|
||
:: Generate snapshot_blob.bin. | ||
echo Running mksnapshot... | ||
call mksnapshot %CMDLINE% %2 | ||
|
||
set OUT_FILE=v8_context_snapshot.bin | ||
|
||
:: Generate v8_context_snapshot.bin. | ||
echo Running v8_context_snapshot_generator... | ||
call v8_context_snapshot_generator --output_file=%OUT_FILE% | ||
|
||
if not exist "%BIN_DIR%\%OUT_FILE%" ( | ||
echo Failed | ||
set ERRORLEVEL=1 | ||
goto end | ||
) | ||
|
||
echo Success! Created %BIN_DIR%\%OUT_FILE% | ||
|
||
:end | ||
endlocal & set RC=%ERRORLEVEL% | ||
goto omega | ||
|
||
:returncode | ||
exit /B %RC% | ||
|
||
:omega | ||
call :returncode %RC% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/bin/bash | ||
# Copyright (c) 2024 The Chromium Embedded Framework Authors. All rights | ||
# reserved. Use of this source code is governed by a BSD-style license | ||
# that can be found in the LICENSE file. | ||
|
||
if [ "$1" != "Debug" ] && [ "$1" != "Release" ]; then | ||
echo 'Usage: run_mksnapshot.sh [Debug|Release] /path/to/snapshot.js' | ||
exit 1 | ||
fi | ||
|
||
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )" | ||
BIN_DIR=$SCRIPT_DIR/$1 | ||
|
||
if [ ! -d "$BIN_DIR" ]; then | ||
echo "$BIN_DIR directory not found." | ||
exit 1 | ||
fi | ||
|
||
CMD_FILE=mksnapshot_cmd.txt | ||
|
||
if [ ! -f "$BIN_DIR/$CMD_FILE" ]; then | ||
echo "$BIN_DIR/$CMD_FILE file not found." | ||
exit 1 | ||
fi | ||
|
||
pushd "$BIN_DIR" > /dev/null | ||
|
||
# Read $CMD_FILE into an argument array. | ||
IFS=' ' read -r -a args < $CMD_FILE | ||
|
||
if [ "$(uname)" == "Darwin" ]; then | ||
# Execution of tools binaries downloaded on MacOS may be blocked | ||
# by Apple Security settings with a message like "<binary> can't | ||
# be opened because Apple cannot check it for malicious software." | ||
# Remove that block here. | ||
xattr -c ./mksnapshot | ||
xattr -c ./v8_context_snapshot_generator | ||
fi | ||
|
||
# Generate snapshot_blob.bin. | ||
echo 'Running mksnapshot...' | ||
./mksnapshot "${args[@]}" "${@:2}" | ||
|
||
# Determine the architecture suffix, if any. | ||
suffix='' | ||
if [ "$(uname)" == "Darwin" ]; then | ||
value='--target_arch=arm64' | ||
if [[ " ${args[*]} " =~ [[:space:]]${value}[[:space:]] ]]; then | ||
suffix='.arm64' | ||
else | ||
suffix='.x86_64' | ||
fi | ||
fi | ||
|
||
OUT_FILE=v8_context_snapshot${suffix}.bin | ||
|
||
# Generate v8_context_snapshot.bin. | ||
echo 'Running v8_context_snapshot_generator...' | ||
./v8_context_snapshot_generator --output_file=$OUT_FILE | ||
|
||
popd > /dev/null | ||
|
||
if [ -f "$BIN_DIR/$OUT_FILE" ]; then | ||
echo "Success! Created $BIN_DIR/$OUT_FILE" | ||
else | ||
echo "Failed" | ||
exit 1 | ||
fi |
Oops, something went wrong.