Skip to content

Commit

Permalink
添加window下arm、arm64的交叉编译版本的v8cc
Browse files Browse the repository at this point in the history
  • Loading branch information
chexiongsheng committed Jul 30, 2024
1 parent 41e2dff commit 7a2cf75
Show file tree
Hide file tree
Showing 4 changed files with 256 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ jobs:
- name: Run build script
run: |
cd $GITHUB_WORKSPACE
npm i
bash ./linux_arm64.sh ${{github.event.inputs.v8_revision}}
mv ~/v8/v8/output/v8 ~/v8/v8/output/v8_${{github.event.inputs.v8_revision}}
- uses: actions/upload-artifact@v2
Expand Down Expand Up @@ -301,6 +302,46 @@ jobs:
with:
name: v8_bin
path: ~/v8/v8/output/**/*

build_windows_v8cc_arm64:
name: Windows-v8cc-arm64
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
- name: Run build script
shell: cmd
run: |
cd %GITHUB_WORKSPACE%
call npm i
call .\windows_v8cc_arm64.cmd ${{github.event.inputs.v8_revision}}
- name: Rename
shell: bash
run: |
mv ~/v8/v8/output/v8 ~/v8/v8/output/v8_${{github.event.inputs.v8_revision}}
- uses: actions/upload-artifact@v2
with:
name: v8_bin
path: ~/v8/v8/output/**/*

build_windows_v8cc_arm:
name: Windows-v8cc-arm
runs-on: windows-2019
steps:
- uses: actions/checkout@v2
- name: Run build script
shell: cmd
run: |
cd %GITHUB_WORKSPACE%
call npm i
call .\windows_v8cc_arm.cmd ${{github.event.inputs.v8_revision}}
- name: Rename
shell: bash
run: |
mv ~/v8/v8/output/v8 ~/v8/v8/output/v8_${{github.event.inputs.v8_revision}}
- uses: actions/upload-artifact@v2
with:
name: v8_bin
path: ~/v8/v8/output/**/*

build_macos:
if: github.event.inputs.build_macos == 'true'
Expand Down
68 changes: 68 additions & 0 deletions node-script/add_cross_v8cc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
const fs = require('fs');
const path = require('path')

const v8_path = path.resolve(process.argv[2]);
const v8_version = process.argv[3];
const target_cpu = (process.argv[4] == 'arm' ? 'arm' : 'arm64');

function addV8CC() {
const filepath = path.join(v8_path, 'BUILD.gn')
console.log(`add ${target_cpu} v8cc to ${filepath} ...`);
let context = fs.readFileSync(filepath, 'utf-8');

let v8cc_target = `
v8_executable("v8cc") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
sources = [
"src/snapshot/v8cc.cc",
]
if (v8_control_flow_integrity) {
sources += [ "src/deoptimizer/deoptimizer-cfi-empty.cc" ]
}
configs = [ ":internal_config" ]
deps = [
":v8_base_without_compiler",
":v8_compiler_for_mksnapshot",
":v8_init",
":v8_libbase",
":v8_libplatform",
":v8_maybe_icu",
":v8_shared_internal_headers",
":v8_tracing",
":v8_turboshaft",
"//build/win:default_exe_manifest",
":v8_snapshot",
]
}
`;

if (v8_version == "9.4.146.24") {
v8cc_target = v8cc_target.replace('":v8_turboshaft",', '');
}

const v8_initializers_pos = context.indexOf('v8_source_set("v8_initializers") {');
const v8_init_pos = context.indexOf('v8_source_set("v8_init") {');
const v8_base_without_compiler_pos = context.indexOf('v8_source_set("v8_base_without_compiler") {');
const v8_base_pos = context.indexOf('group("v8_base") {');

let new_context = context.slice(0, v8_initializers_pos);
new_context += `v8_cross_cpu = "${target_cpu}"\n\n`
new_context += context.slice(v8_initializers_pos, v8_init_pos).replace(/v8_current_cpu/g, 'v8_cross_cpu');
new_context += context.slice(v8_init_pos, v8_base_without_compiler_pos);
new_context += context.slice(v8_base_without_compiler_pos, v8_base_pos).replace(/v8_current_cpu/g, 'v8_cross_cpu');
new_context += context.slice(v8_base_pos);
new_context += v8cc_target;
new_context = new_context.replace(/V8_TARGET_ARCH_X64|V8_TARGET_ARCH_IA32/g, target_cpu == 'arm' ? 'V8_TARGET_ARCH_ARM' : 'V8_TARGET_ARCH_ARM64');

fs.writeFileSync(filepath, new_context);

fs.copyFileSync(path.join(__dirname, 'v8cc.cc'), path.join(v8_path, 'src/snapshot/v8cc.cc'));
}

(function() {
addV8CC();
})();
72 changes: 72 additions & 0 deletions windows_v8cc_arm.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
set VERSION=%1

cd /d %USERPROFILE%
echo =====[ Getting Depot Tools ]=====
powershell -command "Invoke-WebRequest https://storage.googleapis.com/chrome-infra/depot_tools.zip -O depot_tools.zip"
7z x depot_tools.zip -o*
set PATH=%CD%\depot_tools;%PATH%
set GYP_MSVS_VERSION=2019
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
call gclient

cd depot_tools
call git reset --hard 8d16d4a
cd ..
set DEPOT_TOOLS_UPDATE=0


mkdir v8
cd v8

echo =====[ Fetching V8 ]=====
call fetch v8
cd v8
call git checkout refs/tags/%VERSION%
@REM cd test\test262\data
call git config --system core.longpaths true
@REM call git restore *
@REM cd ..\..\..\
call gclient sync

if "%VERSION%"=="10.6.194" (
echo =====[ patch 10.6.194 ]=====
node %~dp0\node-script\do-gitpatch.js -p %GITHUB_WORKSPACE%\patches\win_msvc_v10.6.194.patch
)

if "%VERSION%"=="11.8.172" (
echo =====[ patch 10.6.194 ]=====
node %~dp0\node-script\do-gitpatch.js -p %GITHUB_WORKSPACE%\patches\remove_uchar_include_v11.8.172.patch
node %~dp0\node-script\do-gitpatch.js -p %GITHUB_WORKSPACE%\patches\win_dll_v11.8.172.patch"
)

if "%VERSION%"=="9.4.146.24" (
echo =====[ patch jinja for python3.10+ ]=====
cd third_party\jinja2
node %~dp0\node-script\do-gitpatch.js -p %GITHUB_WORKSPACE%\patches\jinja_v9.4.146.24.patch
cd ..\..
)

@REM echo =====[ Patching V8 ]=====
@REM node %GITHUB_WORKSPACE%\CRLF2LF.js %GITHUB_WORKSPACE%\patches\builtins-puerts.patches
@REM call git apply --cached --reject %GITHUB_WORKSPACE%\patches\builtins-puerts.patches
@REM call git checkout -- .

@REM issue #4
node %~dp0\node-script\do-gitpatch.js -p %GITHUB_WORKSPACE%\patches\intrin.patch

echo =====[ add ArrayBuffer_New_Without_Stl ]=====
node %~dp0\node-script\add_arraybuffer_new_without_stl.js .

node %~dp0\node-script\add_cross_v8cc.js . %VERSION% arm

echo =====[ Building V8 ]=====
if not "%VERSION%"=="9.4.146.24" (
call gn gen out.gn\x86.release -args="target_os=""win"" target_cpu=""x86"" v8_use_external_startup_data=false v8_enable_i18n_support=false is_debug=false v8_static_library=true is_clang=false strip_debug_info=true symbol_level=0 v8_enable_pointer_compression=false v8_enable_sandbox=false"
) else (
call gn gen out.gn\x86.release -args="target_os=""win"" target_cpu=""x86"" v8_use_external_startup_data=false v8_enable_i18n_support=false is_debug=false v8_static_library=true is_clang=false strip_debug_info=true symbol_level=0 v8_enable_pointer_compression=false"
)

call ninja -v -C out.gn\x86.release v8cc

md output\v8\Bin\Win\arm
copy /Y out.gn\x86.release\v8cc.exe output\v8\Bin\Win\arm\
75 changes: 75 additions & 0 deletions windows_v8cc_arm64.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
set VERSION=%1

cd /d %USERPROFILE%
echo =====[ Getting Depot Tools ]=====
powershell -command "Invoke-WebRequest https://storage.googleapis.com/chrome-infra/depot_tools.zip -O depot_tools.zip"
7z x depot_tools.zip -o*
set PATH=%CD%\depot_tools;%PATH%
set GYP_MSVS_VERSION=2019
set DEPOT_TOOLS_WIN_TOOLCHAIN=0
call gclient

cd depot_tools
call git reset --hard 8d16d4a
cd ..
set DEPOT_TOOLS_UPDATE=0


mkdir v8
cd v8

echo =====[ Fetching V8 ]=====
call fetch v8
cd v8
call git checkout refs/tags/%VERSION%
@REM cd test\test262\data
call git config --system core.longpaths true
@REM call git restore *
@REM cd ..\..\..\
call gclient sync

@REM echo =====[ Patching V8 ]=====
@REM node %GITHUB_WORKSPACE%\CRLF2LF.js %GITHUB_WORKSPACE%\patches\builtins-puerts.patches
@REM call git apply --cached --reject %GITHUB_WORKSPACE%\patches\builtins-puerts.patches
@REM call git checkout -- .

if "%VERSION%"=="10.6.194" (
echo =====[ patch 10.6.194 ]=====
node %~dp0\node-script\do-gitpatch.js -p %GITHUB_WORKSPACE%\patches\win_msvc_v10.6.194.patch
)

if "%VERSION%"=="11.8.172" (
echo =====[ patch 10.6.194 ]=====
node %~dp0\node-script\do-gitpatch.js -p %GITHUB_WORKSPACE%\patches\remove_uchar_include_v11.8.172.patch
node %~dp0\node-script\do-gitpatch.js -p %GITHUB_WORKSPACE%\patches\win_dll_v11.8.172.patch"
)

if "%VERSION%"=="9.4.146.24" (
echo =====[ patch jinja for python3.10+ ]=====
cd third_party\jinja2
node %~dp0\node-script\do-gitpatch.js -p %GITHUB_WORKSPACE%\patches\jinja_v9.4.146.24.patch
cd ..\..
)

echo =====[ add ArrayBuffer_New_Without_Stl ]=====
node %~dp0\node-script\add_arraybuffer_new_without_stl.js .

node %~dp0\node-script\add_cross_v8cc.js . %VERSION% arm64

echo =====[ Building V8 ]=====
if "%VERSION%"=="11.8.172" (
call gn gen out.gn\x64.release -args="target_os=""win"" target_cpu=""x64"" v8_use_external_startup_data=false v8_enable_i18n_support=false is_debug=false v8_static_library=true is_clang=false strip_debug_info=true symbol_level=0 v8_enable_pointer_compression=false v8_enable_sandbox=false v8_enable_maglev=false"
)

if "%VERSION%"=="10.6.194" (
call gn gen out.gn\x64.release -args="target_os=""win"" target_cpu=""x64"" v8_use_external_startup_data=false v8_enable_i18n_support=false is_debug=false v8_static_library=true is_clang=false strip_debug_info=true symbol_level=0 v8_enable_pointer_compression=false v8_enable_sandbox=false"
)

if "%VERSION%"=="9.4.146.24" (
call gn gen out.gn\x64.release -args="target_os=""win"" target_cpu=""x64"" v8_use_external_startup_data=false v8_enable_i18n_support=false is_debug=false v8_static_library=true is_clang=false strip_debug_info=true symbol_level=0 v8_enable_pointer_compression=false"
)

call ninja -v -C out.gn\x64.release v8cc

md output\v8\Bin\Win\arm64
copy /Y out.gn\x64.release\v8cc.exe output\v8\Bin\Win\arm64\

0 comments on commit 7a2cf75

Please sign in to comment.