diff --git a/.github/workflows/build_v8.yml b/.github/workflows/build_v8.yml new file mode 100644 index 0000000..fe461f6 --- /dev/null +++ b/.github/workflows/build_v8.yml @@ -0,0 +1,237 @@ +name: build v8 + +on: + workflow_dispatch: + inputs: + tag_date: + description: 'tag date' + required: true + +#https://docs.google.com/document/d/1oFPHyNb_eXg6NzrE6xJDNPdJrHMZvx0LqsD6wpbd9vY/edit#heading=h.4tfb7x3beh2l +#libwee8按设计只支持wasm,不支持js,但8.4.371.19版本尚未移除js功能,还能用,如果升级v8版本要注意 +#libmonolith会稳妥一些,但静态库大小会大些 +env: + VERSION: 8.4.371.19 + +jobs: + build_android_arm_v8: + name: Android (arm64-v8a) + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Run build script + run: | + cd $GITHUB_WORKSPACE + sh ./android_armv8.sh ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: ~/v8/v8/output/**/* + + build_android_arm_v7: + name: Android (armeabi-v7a) + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Run build script + run: | + cd $GITHUB_WORKSPACE + sh ./android_armv7.sh ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: ~/v8/v8/output/**/* + + build_android_x86_64: + name: Android (x86_64) + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Run build script + run: | + cd $GITHUB_WORKSPACE + sh ./android_x64.sh ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: ~/v8/v8/output/**/* + + build_linux: + name: Linux + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - name: Run build script + run: | + cd $GITHUB_WORKSPACE + sh ./linux.sh ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: ~/v8/v8/output/**/* + + build_windows: + name: Windows + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - name: Run build script + shell: cmd + run: | + cd %GITHUB_WORKSPACE% + call .\windows_64.cmd ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: v8/v8/output/**/* + + - uses: actions/upload-artifact@v2 + with: + name: v8_bin_win64 + path: v8/v8/output/**/* + + build_windows_md: + name: Windows-MD + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - name: Run build script + shell: cmd + run: | + cd %GITHUB_WORKSPACE% + call .\windows_64MD.cmd ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: v8/v8/output/**/* + + build_windows_md_dll: + name: Windows-MD-DLL + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - name: Run build script + shell: cmd + run: | + cd %GITHUB_WORKSPACE% + call .\windows_64MD_DLL.cmd ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: v8/v8/output/**/* + + build_windows_32: + name: Windows-32 + runs-on: windows-2019 + steps: + - uses: actions/checkout@v2 + - name: Run build script + shell: cmd + run: | + cd %GITHUB_WORKSPACE% + call .\windows_32.cmd ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: v8/v8/output/**/* + + build_macos: + name: macOS + runs-on: macos-10.15 + steps: + - uses: actions/checkout@v2 + - name: Use Xcode 12.0 to use SDK 10.15 + run: sudo xcode-select -switch "/Applications/Xcode_12.app" + - name: Run build script + run: | + cd $GITHUB_WORKSPACE + sh ./macos.sh ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: ~/v8/v8/output/**/* + + build_macos_dll: + name: macOS-DLL + runs-on: macos-10.15 + steps: + - uses: actions/checkout@v2 + - name: Use Xcode 12.0 to use SDK 10.15 + run: sudo xcode-select -switch "/Applications/Xcode_12.app" + - name: Run build script + run: | + cd $GITHUB_WORKSPACE + sh ./macos_DLL.sh ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: ~/v8/v8/output/**/* + + build_ios: + name: iOS + runs-on: macos-10.15 + steps: + - uses: actions/checkout@v2 + - name: Use Xcode 12.0 to use SDK 10.15 + run: sudo xcode-select -switch "/Applications/Xcode_12.app" + - name: Run build script + run: | + cd $GITHUB_WORKSPACE + sh ./ios.sh ${{env.VERSION}} + - uses: actions/upload-artifact@v2 + with: + name: v8_bin + path: ~/v8/v8/output/**/* + + #build_ios_simulator: + # name: iOS simulator + # runs-on: macos-10.15 + # steps: + # - uses: actions/checkout@v2 + # - name: Use Xcode 12.0 to use SDK 10.15 + # run: sudo xcode-select -switch "/Applications/Xcode_12.app" + # - name: Run build script + # run: | + # cd $GITHUB_WORKSPACE + # sh ./ios_simulator.sh ${{env.VERSION}} + # - uses: actions/upload-artifact@v2 + # with: + # name: v8_bin + # path: ~/v8/v8/output/**/* + + publish: + runs-on: ubuntu-latest + needs: [build_android_arm_v8,build_android_arm_v7,build_android_x86_64,build_linux,build_windows,build_windows_md,build_windows_32,build_macos,build_ios,build_windows_md_dll,build_macos_dll] + steps: + - uses: actions/download-artifact@v1 + with: + name: v8_bin + path: v8_bin/ + + - name: Create Release Asset + run: | + cd v8_bin/ && tar cvfz ../v8_bin_${{env.VERSION}}.tgz v8 && cd - + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: V8_${{env.VERSION}}_${{ github.event.inputs.tag_date }} + release_name: V8_${{env.VERSION}}_${{ github.event.inputs.tag_date }} + draft: false + prerelease: false + + - name: Upload V8 + #id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./v8_bin_${{env.VERSION}}.tgz + asset_name: v8_bin_${{env.VERSION}}.tgz + asset_content_type: application/tgz + + diff --git a/CRLF2LF.js b/CRLF2LF.js new file mode 100644 index 0000000..9a9d943 --- /dev/null +++ b/CRLF2LF.js @@ -0,0 +1,4 @@ +const fs = require('fs'); +var file = process.argv[2]; + +fs.writeFileSync(file, fs.readFileSync(file, {encoding: 'utf-8'}).toString().replace(/\r\n/g, '\n')); diff --git a/android_armv7.sh b/android_armv7.sh new file mode 100644 index 0000000..10e251a --- /dev/null +++ b/android_armv7.sh @@ -0,0 +1,64 @@ +VERSION=$1 +[ -z "$GITHUB_WORKSPACE" ] && GITHUB_WORKSPACE="$( cd "$( dirname "$0" )"/.. && pwd )" + +sudo apt-get install -y \ + pkg-config \ + git \ + subversion \ + curl \ + wget \ + build-essential \ + python \ + xz-utils \ + zip + +cd ~ +echo "=====[ Getting Depot Tools ]=====" +git clone -q https://chromium.googlesource.com/chromium/tools/depot_tools.git +export PATH=$(pwd)/depot_tools:$PATH +gclient + + +mkdir v8 +cd v8 + +echo "=====[ Fetching V8 ]=====" +fetch v8 +echo "target_os = ['android']" >> .gclient +cd ~/v8/v8 +./build/install-build-deps-android.sh +git checkout refs/tags/$VERSION +gclient sync + + +# echo "=====[ Patching V8 ]=====" +# git apply --cached $GITHUB_WORKSPACE/patch/builtins-puerts.patch +# git checkout -- . + +echo "=====[ Building V8 ]=====" +python ./tools/dev/v8gen.py arm.release -vv -- ' +target_os = "android" +target_cpu = "arm" +is_debug = false +v8_enable_i18n_support= false +v8_target_cpu = "arm" +use_goma = false +v8_use_snapshot = true +v8_use_external_startup_data = true +v8_static_library = true +strip_absolute_paths_from_debug_symbols = false +strip_debug_info = false +symbol_level=1 +use_custom_libcxx=false +use_custom_libcxx_for_host=true +' +ninja -C out.gn/arm.release -t clean +ninja -C out.gn/arm.release wee8 +third_party/android_ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin/strip -g -S -d --strip-debug --verbose out.gn/arm.release/obj/libwee8.a + +node $GITHUB_WORKSPACE/genBlobHeader.js "android armv7" out.gn/arm.release/snapshot_blob.bin + +mkdir -p output/v8/Lib/Android/armeabi-v7a +cp out.gn/arm.release/obj/libwee8.a output/v8/Lib/Android/armeabi-v7a/ +mkdir -p output/v8/Inc/Blob/Android/armv7a +cp SnapshotBlob.h output/v8/Inc/Blob/Android/armv7a/ diff --git a/android_armv8.sh b/android_armv8.sh new file mode 100644 index 0000000..3088cce --- /dev/null +++ b/android_armv8.sh @@ -0,0 +1,64 @@ +VERSION=$1 +[ -z "$GITHUB_WORKSPACE" ] && GITHUB_WORKSPACE="$( cd "$( dirname "$0" )"/.. && pwd )" + +sudo apt-get install -y \ + pkg-config \ + git \ + subversion \ + curl \ + wget \ + build-essential \ + python \ + xz-utils \ + zip + +cd ~ +echo "=====[ Getting Depot Tools ]=====" +git clone -q https://chromium.googlesource.com/chromium/tools/depot_tools.git +export PATH=$(pwd)/depot_tools:$PATH +gclient + + +mkdir v8 +cd v8 + +echo "=====[ Fetching V8 ]=====" +fetch v8 +echo "target_os = ['android']" >> .gclient +cd ~/v8/v8 +./build/install-build-deps-android.sh +git checkout refs/tags/$VERSION +gclient sync + + +# echo "=====[ Patching V8 ]=====" +# git apply --cached $GITHUB_WORKSPACE/patch/builtins-puerts.patch +# git checkout -- . + +echo "=====[ Building V8 ]=====" +python ./tools/dev/v8gen.py arm64.release -vv -- ' +target_os = "android" +target_cpu = "arm64" +is_debug = false +v8_enable_i18n_support= false +v8_target_cpu = "arm64" +use_goma = false +v8_use_snapshot = true +v8_use_external_startup_data = true +v8_static_library = true +strip_debug_info = false +symbol_level=1 +use_custom_libcxx=false +use_custom_libcxx_for_host=true +v8_enable_pointer_compression=false +' +ninja -C out.gn/arm64.release -t clean +ninja -C out.gn/arm64.release wee8 +third_party/android_ndk/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/aarch64-linux-android/bin/strip -g -S -d --strip-debug --verbose out.gn/arm64.release/obj/libwee8.a + +node $GITHUB_WORKSPACE/genBlobHeader.js "android arm64" out.gn/arm64.release/snapshot_blob.bin + +mkdir -p output/v8/Lib/Android/arm64-v8a +cp out.gn/arm64.release/obj/libwee8.a output/v8/Lib/Android/arm64-v8a/ +mkdir -p output/v8/Inc/Blob/Android/arm64 +cp SnapshotBlob.h output/v8/Inc/Blob/Android/arm64/ diff --git a/android_x64.sh b/android_x64.sh new file mode 100644 index 0000000..97e18dc --- /dev/null +++ b/android_x64.sh @@ -0,0 +1,64 @@ +VERSION=$1 +[ -z "$GITHUB_WORKSPACE" ] && GITHUB_WORKSPACE="$( cd "$( dirname "$0" )"/.. && pwd )" + +sudo apt-get install -y \ + pkg-config \ + git \ + subversion \ + curl \ + wget \ + build-essential \ + python \ + xz-utils \ + zip + +cd ~ +echo "=====[ Getting Depot Tools ]=====" +git clone -q https://chromium.googlesource.com/chromium/tools/depot_tools.git +export PATH=$(pwd)/depot_tools:$PATH +gclient + + +mkdir v8 +cd v8 + +echo "=====[ Fetching V8 ]=====" +fetch v8 +echo "target_os = ['android']" >> .gclient +cd ~/v8/v8 +./build/install-build-deps-android.sh +git checkout refs/tags/$VERSION +gclient sync + + +# echo "=====[ Patching V8 ]=====" +# git apply --cached $GITHUB_WORKSPACE/patch/builtins-puerts.patch +# git checkout -- . + +echo "=====[ Building V8 ]=====" +python ./tools/dev/v8gen.py x64.release -vv -- ' +target_os = "android" +target_cpu = "x64" +is_debug = false +v8_enable_i18n_support= false +v8_target_cpu = "x64" +use_goma = false +v8_use_snapshot = true +v8_use_external_startup_data = true +v8_static_library = true +strip_debug_info = false +symbol_level=1 +use_custom_libcxx=false +use_custom_libcxx_for_host=true +v8_enable_pointer_compression=false +' +ninja -C out.gn/x64.release -t clean +ninja -C out.gn/x64.release wee8 +third_party/android_ndk/toolchains/x86_64-4.9/prebuilt/linux-x86_64/x86_64-linux-android/bin/strip -g -S -d --strip-debug --verbose out.gn/x64.release/obj/libwee8.a + +node $GITHUB_WORKSPACE/genBlobHeader.js "android x64" out.gn/x64.release/snapshot_blob.bin + +mkdir -p output/v8/Lib/Android/x64 +cp out.gn/x64.release/obj/libwee8.a output/v8/Lib/Android/x64/ +mkdir -p output/v8/Inc/Blob/Android/x64 +cp SnapshotBlob.h output/v8/Inc/Blob/Android/x64/ diff --git a/genBlobHeader.js b/genBlobHeader.js new file mode 100644 index 0000000..958f4ef --- /dev/null +++ b/genBlobHeader.js @@ -0,0 +1,34 @@ +const fs = require('fs'); + +const nativeBlobPerfix = "#pragma once\n\n#include \n\nstatic const uint8_t NativesBlobCode[] = {\n"; + +const snapshotBlobPerfix = "#pragma once\n\n#include \n\nstatic const uint8_t SnapshotBlobCode[] = {\n"; + +var platform = process.argv[2]; + +var blobPath = process.argv[3]; + +var output = process.argv[4] || "./"; + +var context = "//" + platform + "\n"; + +context += blobPath.includes("snapshot_blob.bin") ? snapshotBlobPerfix : nativeBlobPerfix; + +output += blobPath.includes("snapshot_blob.bin") ? "SnapshotBlob.h" : "NativesBlob.h"; + +var binary = fs.readFileSync(blobPath); + +var buff = Buffer.from(binary, 'binary'); + +const kLineSize = 15; + +for(var i = 0; i < buff.length; ++i) { + context += "0x" + buff.slice(i, i+1).toString('hex') + ", "; + if ( (i + 1) % kLineSize == 0) { + context += "\n"; + } +} + +context += "};\n"; + +fs.writeFileSync(output, context, 'utf8'); diff --git a/ios.sh b/ios.sh new file mode 100644 index 0000000..488dbed --- /dev/null +++ b/ios.sh @@ -0,0 +1,45 @@ +VERSION=$1 +[ -z "$GITHUB_WORKSPACE" ] && GITHUB_WORKSPACE="$( cd "$( dirname "$0" )"/.. && pwd )" + +cd ~ +echo "=====[ Getting Depot Tools ]=====" +git clone -q https://chromium.googlesource.com/chromium/tools/depot_tools.git +export PATH=$(pwd)/depot_tools:$PATH +gclient + +mkdir v8 +cd v8 + +echo "=====[ Fetching V8 ]=====" +fetch v8 +echo "target_os = ['ios']" >> .gclient +cd ~/v8/v8 +git checkout refs/tags/$VERSION +gclient sync + +# echo "=====[ Patching V8 ]=====" +# git apply --cached $GITHUB_WORKSPACE/patch/builtins-puerts.patch +# git checkout -- . + +echo "=====[ Building V8 ]=====" +python ./tools/dev/v8gen.py arm64.release -vv -- ' +v8_use_external_startup_data = true +v8_use_snapshot = true +v8_enable_i18n_support = false +is_debug = false +v8_static_library = true +ios_enable_code_signing = false +target_os = "ios" +target_cpu = "arm64" +v8_enable_pointer_compression = false +' +ninja -C out.gn/arm64.release -t clean +ninja -C out.gn/arm64.release wee8 +strip -S out.gn/arm64.release/obj/libwee8.a + +node $GITHUB_WORKSPACE/genBlobHeader.js "ios arm64" out.gn/arm64.release/snapshot_blob.bin + +mkdir -p output/v8/Lib/iOS/arm64 +cp out.gn/arm64.release/obj/libwee8.a output/v8/Lib/iOS/arm64/ +mkdir -p output/v8/Inc/Blob/iOS/arm64 +cp SnapshotBlob.h output/v8/Inc/Blob/iOS/arm64/ diff --git a/ios_bitcode.sh b/ios_bitcode.sh new file mode 100644 index 0000000..e5b1e05 --- /dev/null +++ b/ios_bitcode.sh @@ -0,0 +1,51 @@ +VERSION=$1 +[ -z "$GITHUB_WORKSPACE" ] && GITHUB_WORKSPACE="$( cd "$( dirname "$0" )"/.. && pwd )" + +cd ~ +echo "=====[ Getting Depot Tools ]=====" +git clone -q https://chromium.googlesource.com/chromium/tools/depot_tools.git +export PATH=$(pwd)/depot_tools:$PATH +gclient + + +mkdir v8 +cd v8 + +echo "=====[ Fetching V8 ]=====" +fetch v8 +echo "target_os = ['ios']" >> .gclient +cd ~/v8/v8 +git checkout refs/tags/$VERSION +gclient sync + + +echo "=====[ Patching V8 ]=====" +# git apply --cached $GITHUB_WORKSPACE/patch/builtins-puerts.patch +git apply --cached $GITHUB_WORKSPACE/patch/bitcode.patch +git checkout -- . + +echo "=====[ Building V8 ]=====" +python ./tools/dev/v8gen.py arm64.release -vv -- ' +v8_use_external_startup_data = true +v8_use_snapshot = true +v8_enable_i18n_support = false +is_debug = false +v8_static_library = true +ios_enable_code_signing = false +target_os = "ios" +target_cpu = "arm64" +v8_enable_pointer_compression = false +use_xcode_clang = true +enable_ios_bitcode = true +symbol_level = 0 +' +ninja -C out.gn/arm64.release -t clean +ninja -C out.gn/arm64.release wee8 +strip -S out.gn/arm64.release/obj/libwee8.a + +node $GITHUB_WORKSPACE/genBlobHeader.js "ios arm64(bitcode)" out.gn/arm64.release/snapshot_blob.bin + +mkdir -p output/v8/Lib/iOS/bitcode +cp out.gn/arm64.release/obj/libwee8.a output/v8/Lib/iOS/bitcode/ +mkdir -p output/v8/Inc/Blob/iOS/bitcode +cp SnapshotBlob.h output/v8/Inc/Blob/iOS/bitcode/ diff --git a/ios_simulator.sh b/ios_simulator.sh new file mode 100644 index 0000000..e408339 --- /dev/null +++ b/ios_simulator.sh @@ -0,0 +1,47 @@ +VERSION=$1 +[ -z "$GITHUB_WORKSPACE" ] && GITHUB_WORKSPACE="$( cd "$( dirname "$0" )"/.. && pwd )" + +cd ~ +echo "=====[ Getting Depot Tools ]=====" +git clone -q https://chromium.googlesource.com/chromium/tools/depot_tools.git +export PATH=$(pwd)/depot_tools:$PATH +gclient + + +mkdir v8 +cd v8 + +echo "=====[ Fetching V8 ]=====" +fetch v8 +echo "target_os = ['ios']" >> .gclient +cd ~/v8/v8 +git checkout refs/tags/$VERSION +gclient sync + + +# echo "=====[ Patching V8 ]=====" +# git apply --cached $GITHUB_WORKSPACE/patch/builtins-puerts.patch +# git checkout -- . + +echo "=====[ Building V8 ]=====" +python ./tools/dev/v8gen.py x64.release -vv -- ' +v8_use_external_startup_data = true +v8_use_snapshot = true +v8_enable_i18n_support = false +is_debug = false +v8_static_library = true +ios_enable_code_signing = false +target_os = "ios" +target_cpu = "x64" +v8_enable_pointer_compression = false +' +ninja -C out.gn/x64.release -t clean +ninja -C out.gn/x64.release wee8 +strip -S out.gn/x64.release/obj/libwee8.a + +node $GITHUB_WORKSPACE/genBlobHeader.js "ios x64" out.gn/x64.release/snapshot_blob.bin + +mkdir -p output/v8/Lib/iOS/x64 +cp out.gn/x64.release/obj/libwee8.a output/v8/Lib/iOS/x64/ +mkdir -p output/v8/Inc/Blob/iOS/x64 +cp SnapshotBlob.h output/v8/Inc/Blob/iOS/x64/ diff --git a/linux.sh b/linux.sh new file mode 100644 index 0000000..1bd1568 --- /dev/null +++ b/linux.sh @@ -0,0 +1,48 @@ +VERSION=$1 +[ -z "$GITHUB_WORKSPACE" ] && GITHUB_WORKSPACE="$( cd "$( dirname "$0" )"/.. && pwd )" + +cd ~ +echo "=====[ Getting Depot Tools ]=====" +git clone -q https://chromium.googlesource.com/chromium/tools/depot_tools.git +export PATH=$(pwd)/depot_tools:$PATH +gclient + + +mkdir v8 +cd v8 + +echo "=====[ Fetching V8 ]=====" +fetch v8 +echo "target_os = ['linux']" >> .gclient +cd ~/v8/v8 +git checkout refs/tags/$VERSION +gclient sync + +# echo "=====[ Patching V8 ]=====" +# git apply --cached $GITHUB_WORKSPACE/patch/builtins-puerts.patch +# git checkout -- . + + +echo "=====[ Building V8 ]=====" +python ./tools/dev/v8gen.py x64.release -vv -- ' +is_debug = false +v8_enable_i18n_support= false +v8_use_snapshot = true +v8_use_external_startup_data = true +v8_static_library = true +strip_debug_info = true +symbol_level=0 +libcxx_abi_unstable = false +v8_enable_pointer_compression=false +' + +ninja -C out.gn/x64.release -t clean +ninja -C out.gn/x64.release wee8 + +node $GITHUB_WORKSPACE/genBlobHeader.js "linux" out.gn/x64.release/snapshot_blob.bin + +mkdir -p output/v8/Lib/Linux +cp out.gn/x64.release/obj/libwee8.a output/v8/Lib/Linux/ +mkdir -p output/v8/Inc/Blob/Linux +cp SnapshotBlob.h output/v8/Inc/Blob/Linux/ + diff --git a/macos.sh b/macos.sh new file mode 100644 index 0000000..c0a5295 --- /dev/null +++ b/macos.sh @@ -0,0 +1,45 @@ +VERSION=$1 +[ -z "$GITHUB_WORKSPACE" ] && GITHUB_WORKSPACE="$( cd "$( dirname "$0" )"/.. && pwd )" + +cd ~ +echo "=====[ Getting Depot Tools ]=====" +git clone -q https://chromium.googlesource.com/chromium/tools/depot_tools.git +export PATH=$(pwd)/depot_tools:$PATH +gclient + + +mkdir v8 +cd v8 + +echo "=====[ Fetching V8 ]=====" +fetch v8 +echo "target_os = ['mac']" >> .gclient +cd ~/v8/v8 +git checkout refs/tags/$VERSION +gclient sync + +# echo "=====[ Patching V8 ]=====" +# git apply --cached $GITHUB_WORKSPACE/patch/builtins-puerts.patch +# git checkout -- . + +echo "=====[ Building V8 ]=====" +python ./tools/dev/v8gen.py x64.release -vv -- ' +is_debug = false +v8_enable_i18n_support= false +v8_use_snapshot = true +v8_use_external_startup_data = true +v8_static_library = true +strip_debug_info = true +symbol_level=0 +libcxx_abi_unstable = false +v8_enable_pointer_compression=false +' +ninja -C out.gn/x64.release -t clean +ninja -C out.gn/x64.release wee8 + +node $GITHUB_WORKSPACE/genBlobHeader.js "osx 64" out.gn/x64.release/snapshot_blob.bin + +mkdir -p output/v8/Lib/macOS +cp out.gn/x64.release/obj/libwee8.a output/v8/Lib/macOS/ +mkdir -p output/v8/Inc/Blob/macOS +cp SnapshotBlob.h output/v8/Inc/Blob/macOS/ diff --git a/macos_DLL.sh b/macos_DLL.sh new file mode 100644 index 0000000..77640f6 --- /dev/null +++ b/macos_DLL.sh @@ -0,0 +1,44 @@ +VERSION=$1 +[ -z "$GITHUB_WORKSPACE" ] && GITHUB_WORKSPACE="$( cd "$( dirname "$0" )"/.. && pwd )" + +cd ~ +echo "=====[ Getting Depot Tools ]=====" +git clone -q https://chromium.googlesource.com/chromium/tools/depot_tools.git +export PATH=$(pwd)/depot_tools:$PATH +gclient + + +mkdir v8 +cd v8 + +echo "=====[ Fetching V8 ]=====" +fetch v8 +echo "target_os = ['mac']" >> .gclient +cd ~/v8/v8 +git checkout refs/tags/$VERSION +gclient sync + +# echo "=====[ Patching V8 ]=====" +# git apply --cached $GITHUB_WORKSPACE/patch/builtins-puerts.patch +# git checkout -- . + +echo "=====[ Building V8 ]=====" +python ./tools/dev/v8gen.py x64.release -vv -- ' +is_debug = false +v8_enable_i18n_support= false +v8_use_snapshot = true +v8_use_external_startup_data = true +is_component_build = true +strip_debug_info = true +symbol_level=0 +libcxx_abi_unstable = false +v8_enable_pointer_compression=false +' +ninja -C out.gn/x64.release -t clean +ninja -C out.gn/x64.release v8 + +mkdir -p output/v8/Lib/macOSdylib +cp out.gn/x64.release/libv8.dylib output/v8/Lib/macOSdylib/ +cp out.gn/x64.release/libv8_libplatform.dylib output/v8/Lib/macOSdylib/ +cp out.gn/x64.release/libv8_libbase.dylib output/v8/Lib/macOSdylib/ +cp out.gn/x64.release/libchrome_zlib.dylib output/v8/Lib/macOSdylib/ diff --git a/patch/allocation.h.patch b/patch/allocation.h.patch new file mode 100644 index 0000000..c27d50f --- /dev/null +++ b/patch/allocation.h.patch @@ -0,0 +1,12 @@ +diff --git a/src/utils/allocation.h b/src/utils/allocation.h +index 2cdd12242e..64b0f07350 100644 +--- a/src/utils/allocation.h ++++ b/src/utils/allocation.h +@@ -35,6 +35,7 @@ class V8_EXPORT_PRIVATE Malloced { + + template + T* NewArray(size_t size) { ++ size = (size == 0) ? 1 : size; + T* result = new (std::nothrow) T[size]; + if (result == nullptr) { + V8::GetCurrentPlatform()->OnCriticalMemoryPressure(); diff --git a/patch/bitcode.patch b/patch/bitcode.patch new file mode 100644 index 0000000..892f285 --- /dev/null +++ b/patch/bitcode.patch @@ -0,0 +1,13 @@ +diff --git a/BUILD.gn b/BUILD.gn +index 167e63503c..881c340c70 100644 +--- a/BUILD.gn ++++ b/BUILD.gn +@@ -562,7 +562,7 @@ config("toolchain") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + defines = [] +- cflags = [] ++ cflags = ["-Wno-error"] + ldflags = [] + + if (v8_current_cpu == "arm") { diff --git a/patch/builtins-puerts.patch b/patch/builtins-puerts.patch new file mode 100644 index 0000000..143db3c --- /dev/null +++ b/patch/builtins-puerts.patch @@ -0,0 +1,231 @@ +diff --git a/.gitignore b/.gitignore +index ffbf9ce355..c408c7d7c7 100644 +--- a/.gitignore ++++ b/.gitignore +@@ -104,3 +104,5 @@ turbo*.dot + turbo*.json + v8.ignition_dispatches_table.json + ++build.sh ++puerts +\ No newline at end of file +diff --git a/include/v8.h b/include/v8.h +index 18d72f1630..af2144ac99 100644 +--- a/include/v8.h ++++ b/include/v8.h +@@ -38,6 +38,9 @@ + */ + namespace v8 { + ++namespace Puerts { ++ class FunctionCallbackInfo; ++} + class AccessorSignature; + class Array; + class ArrayBuffer; +@@ -307,6 +310,7 @@ class Local { + template + friend class MaybeLocal; + template friend class FunctionCallbackInfo; ++ friend class Puerts::FunctionCallbackInfo; + template friend class PropertyCallbackInfo; + friend class String; + friend class Object; +@@ -12038,6 +12042,69 @@ size_t SnapshotCreator::AddData(Local object) { + */ + + ++namespace Puerts { ++ ++ typedef void (*CallbackFunction)(v8::Isolate* Isolate, const v8::Puerts::FunctionCallbackInfo& Info, void* Self, int ParamLen, int64_t UserData); ++ ++ struct FunctionInfo { ++ bool isStatic; ++ CallbackFunction callback; ++ void* bindData; ++ }; ++ class FunctionCallbackInfo { ++ class ReturnValue { ++ protected: ++ internal::Address* value_; ++ bool* is_return_value_setted_; ++ public: ++ ReturnValue(internal::Address* slot, bool* isReturnValueSetted) ++ : value_(slot), is_return_value_setted_(isReturnValueSetted) {} ++ internal::Address* Get() ++ { ++ return value_; ++ } ++ void Set(const Local handle); ++ }; ++ private: ++ internal::Address* return_value_; ++ bool* is_return_value_setted_; ++ internal::Address* values_; ++ int length_; ++ public: ++ FunctionCallbackInfo( ++ internal::Address* address, ++ internal::Address* returnValue, ++ bool* isReturnValueSetted, ++ int length ++ ) { ++ this->values_ = address; ++ this->length_ = length; ++ return_value_ = returnValue; ++ is_return_value_setted_ = isReturnValueSetted; ++ } ++ FunctionCallbackInfo( ++ v8::Local address, ++ int length ++ ) { ++ this->values_ = reinterpret_cast(*address); ++ this->length_ = length; ++ } ++ ReturnValue GetReturnValue() const { ++ return ReturnValue(return_value_, is_return_value_setted_); ++ } ++ int Length() const { ++ return length_; ++ } ++ Local operator[](int i) const { ++ #ifdef V8_REVERSE_JSARGS ++ return Local(reinterpret_cast(values_ + i)); ++ #else ++ return Local(reinterpret_cast(values_ - i)); ++ #endif ++ } ++ }; ++} ++ + } // namespace v8 + + #endif // INCLUDE_V8_H_ +diff --git a/src/api/api.cc b/src/api/api.cc +index 93780bceec..0b600916ad 100644 +--- a/src/api/api.cc ++++ b/src/api/api.cc +@@ -11181,6 +11181,12 @@ void InvokeFinalizationRegistryCleanupFromTask( + #undef CALLBACK_SETTER + + } // namespace internal ++ ++void Puerts::FunctionCallbackInfo::ReturnValue::Set(const v8::Local handle) { ++ *is_return_value_setted_ = true; ++ *value_ = *reinterpret_cast(*handle); ++} ++ + } // namespace v8 + + #undef TRACE_BS +diff --git a/src/builtins/builtins-api.cc b/src/builtins/builtins-api.cc +index 6eb6f87c74..bcbe8c8c58 100644 +--- a/src/builtins/builtins-api.cc ++++ b/src/builtins/builtins-api.cc +@@ -309,5 +309,74 @@ BUILTIN(HandleApiCallAsConstructor) { + return HandleApiCallAsFunctionOrConstructor(isolate, true, args); + } + ++ ++V8_WARN_UNUSED_RESULT MaybeHandle PuertsCallHandler( ++ internal::Isolate* isolate, ++ internal::JSObject puertsThis, ++ BuiltinArguments& args ++) { ++ Puerts::FunctionInfo* functionInfo = (Puerts::FunctionInfo*)Foreign::cast( ++ JSObject::cast(puertsThis.GetEmbedderField(0)).GetEmbedderField(0) ++ ).foreign_address(); ++ ++ int argLength = args.length() - 1; ++ internal::Address returnValue = 0; ++ bool isReturnValueSetted = false; ++ Puerts::FunctionCallbackInfo callbackInfo( ++ args.address_of_arg_at(1), ++ &returnValue, ++ &isReturnValueSetted, ++ argLength ++ ); ++ ++ functionInfo->callback( ++ reinterpret_cast(isolate), ++ callbackInfo, ++ functionInfo->isStatic ? nullptr : reinterpret_cast( ++ internal::Internals::ReadExternalPointerField( ++ isolate, ++ args.at(0)->ptr(), ++ internal::Internals::kJSObjectHeaderSize ++ ) ++ ), ++ argLength, ++ (int64_t)functionInfo->bindData ++ ); ++ RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); ++ ++ if (isReturnValueSetted) { ++ return MaybeHandle(internal::Object(returnValue), isolate); ++ ++ } else { ++ return isolate->factory()->undefined_value(); ++ } ++ ++} ++ ++BUILTIN(ApiPuertsCallback) { ++ HandleScope scope(isolate); ++ Handle callbackFun = args.target(); ++ RETURN_RESULT_OR_FAILURE( ++ isolate, ++ PuertsCallHandler( ++ isolate, ++ JSObject::cast(callbackFun->shared().function_data()), ++ args ++ ) ++ ); ++} ++ ++BUILTIN(ApiPuertsMakeCallback) { ++ Handle internalized_name = args.at(1); ++ ++ NewFunctionArgs funArgs = NewFunctionArgs::ForBuiltinWithoutPrototype( ++ internalized_name, Builtins::kApiPuertsCallback, LanguageMode::kStrict); ++ Handle fun = isolate->factory()->NewFunction(funArgs); ++ fun->shared().set_native(true); ++ fun->shared().DontAdaptArguments(); ++ fun->shared().set_function_data(*args.at(2), WriteBarrierMode::UPDATE_WRITE_BARRIER); ++ ++ return *fun; ++} + } // namespace internal + } // namespace v8 +diff --git a/src/builtins/builtins-definitions.h b/src/builtins/builtins-definitions.h +index 84ddf55f6f..5df968e57d 100644 +--- a/src/builtins/builtins-definitions.h ++++ b/src/builtins/builtins-definitions.h +@@ -792,6 +792,8 @@ namespace internal { + TFJ(StringPrototypeTrimStart, kDontAdaptArgumentsSentinel) \ + /* ES6 #sec-string.raw */ \ + CPP(StringRaw) \ ++ CPP(ApiPuertsCallback) \ ++ CPP(ApiPuertsMakeCallback) \ + \ + /* Symbol */ \ + /* ES #sec-symbol-constructor */ \ +diff --git a/src/init/bootstrapper.cc b/src/init/bootstrapper.cc +index f4049e328e..5b41e1ceed 100644 +--- a/src/init/bootstrapper.cc ++++ b/src/init/bootstrapper.cc +@@ -1917,6 +1917,14 @@ void Genesis::InitializeGlobal(Handle global_object, + SimpleInstallFunction(isolate_, string_fun, "raw", Builtins::kStringRaw, 1, + false); + ++ // === zombie === ++ ++ Handle puerts_object = ++ factory->NewJSObject(isolate_->object_function(), AllocationType::kOld); ++ JSObject::AddProperty(isolate_, global, "PuertsV8", puerts_object, DONT_ENUM); ++ ++ SimpleInstallFunction(isolate_, puerts_object, "makeCallback", Builtins::kApiPuertsMakeCallback, 1, false); ++ + // Create the %StringPrototype% + Handle prototype = Handle::cast( + factory->NewJSObject(string_fun, AllocationType::kOld)); diff --git a/patch_array_new.js b/patch_array_new.js new file mode 100644 index 0000000..ace9e62 --- /dev/null +++ b/patch_array_new.js @@ -0,0 +1,7 @@ +const fs = require('fs'); + +var lines = fs.readFileSync(process.argv[2], 'utf-8'); + +lines = lines.replace("T* NewArray(size_t size) {", "T* NewArray(size_t size) {\n size = (size == 0) ? 1 : size;"); + +fs.writeFileSync(process.argv[2], lines); diff --git a/rep.js b/rep.js new file mode 100644 index 0000000..5c524a3 --- /dev/null +++ b/rep.js @@ -0,0 +1,9 @@ +const fs = require('fs'); + +var lines = fs.readFileSync(process.argv[2], 'utf-8').split(/[\n\r]/); + +for(var i = 0; i < lines.length; i++) { + lines[i] = lines[i].replace("configs = [ \":static_crt\" ]", "configs = [ \":dynamic_crt\" ]"); +} + +fs.writeFileSync(process.argv[2], lines.join('\n')); diff --git a/windows_32.cmd b/windows_32.cmd new file mode 100644 index 0000000..0c536ea --- /dev/null +++ b/windows_32.cmd @@ -0,0 +1,42 @@ +set VERSION=%1 + +cd %HOMEPATH% +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 + + +mkdir v8 +cd v8 + +echo =====[ Fetching V8 ]===== +call fetch v8 +cd v8 +call git checkout refs/tags/%VERSION% +cd test\test262\data +call git config --system core.longpaths true +call git restore * +cd ..\..\..\ +call gclient sync + +@REM echo =====[ Patching V8 ]===== +@REM node %GITHUB_WORKSPACE%\CRLF2LF.js %GITHUB_WORKSPACE%\patch\builtins-puerts.patch +@REM call git apply --cached --reject %GITHUB_WORKSPACE%\patch\builtins-puerts.patch +@REM call git checkout -- . + +echo =====[ Building V8 ]===== +call gn gen out.gn\x86.release -args="target_os=""win"" target_cpu=""x86"" v8_use_external_startup_data=true 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 -C out.gn\x86.release -t clean +call ninja -C out.gn\x86.release wee8 + +node %~dp0\genBlobHeader.js "window x86" out.gn\x86.release\snapshot_blob.bin + +md output\v8\Lib\Win32 +copy /Y out.gn\x86.release\obj\wee8.lib output\v8\Lib\Win32\ +md output\v8\Inc\Blob\Win32 +copy SnapshotBlob.h output\v8\Inc\Blob\Win32\ diff --git a/windows_64.cmd b/windows_64.cmd new file mode 100644 index 0000000..6d956b6 --- /dev/null +++ b/windows_64.cmd @@ -0,0 +1,45 @@ +set VERSION=%1 + +cd %HOMEPATH% +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 + + +mkdir v8 +cd v8 + +echo =====[ Fetching V8 ]===== +call fetch v8 +cd v8 +call git checkout refs/tags/%VERSION% +cd test\test262\data +call git config --system core.longpaths true +call git restore * +cd ..\..\..\ +call gclient sync + +@REM echo =====[ Patching V8 ]===== +@REM node %GITHUB_WORKSPACE%\CRLF2LF.js %GITHUB_WORKSPACE%\patch\builtins-puerts.patch +@REM call git apply --cached --reject %GITHUB_WORKSPACE%\patch\builtins-puerts.patch +@REM call git checkout -- . + +echo =====[ Building V8 ]===== +call gn gen out.gn\x64.release -args="target_os=""win"" target_cpu=""x64"" v8_use_external_startup_data=true 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 -C out.gn\x64.release -t clean +call ninja -C out.gn\x64.release wee8 + +node %~dp0\genBlobHeader.js "window x64" out.gn\x64.release\snapshot_blob.bin + +md output\v8\Lib\Win64 +copy /Y out.gn\x64.release\obj\wee8.lib output\v8\Lib\Win64\ +md output\v8\Inc\Blob\Win64 +copy SnapshotBlob.h output\v8\Inc\Blob\Win64\ + +echo =====[ Copy V8 header ]===== +xcopy include output\v8\Inc\ /s/h/e/k/f/c \ No newline at end of file diff --git a/windows_64MD.cmd b/windows_64MD.cmd new file mode 100644 index 0000000..9e02692 --- /dev/null +++ b/windows_64MD.cmd @@ -0,0 +1,45 @@ +set VERSION=%1 + +cd %HOMEPATH% +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 + + +mkdir v8 +cd v8 + +echo =====[ Fetching V8 ]===== +call fetch v8 +cd v8 +call git checkout refs/tags/%VERSION% +cd test\test262\data +call git config --system core.longpaths true +call git restore * +cd ..\..\..\ +call gclient sync + +@REM echo =====[ Patching V8 ]===== +@REM node %GITHUB_WORKSPACE%\CRLF2LF.js %GITHUB_WORKSPACE%\patch\builtins-puerts.patch +@REM call git apply --cached --reject %GITHUB_WORKSPACE%\patch\builtins-puerts.patch +@REM call git checkout -- . + +echo =====[ Make dynamic_crt ]===== +node %~dp0\rep.js build\config\win\BUILD.gn + +echo =====[ Building V8 ]===== +call gn gen out.gn\x64.release -args="target_os=""win"" target_cpu=""x64"" v8_use_external_startup_data=true 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 -C out.gn\x64.release -t clean +call ninja -C out.gn\x64.release wee8 + +node %~dp0\genBlobHeader.js "window x64" out.gn\x64.release\snapshot_blob.bin + +md output\v8\Lib\Win64MD +copy /Y out.gn\x64.release\obj\wee8.lib output\v8\Lib\Win64MD\ +md output\v8\Inc\Blob\Win64MD +copy SnapshotBlob.h output\v8\Inc\Blob\Win64MD\ \ No newline at end of file diff --git a/windows_64MD_DLL.cmd b/windows_64MD_DLL.cmd new file mode 100644 index 0000000..1c6eff7 --- /dev/null +++ b/windows_64MD_DLL.cmd @@ -0,0 +1,46 @@ +set VERSION=%1 + +cd %HOMEPATH% +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 + + +mkdir v8 +cd v8 + +echo =====[ Fetching V8 ]===== +call fetch v8 +cd v8 +call git checkout refs/tags/%VERSION% +cd test\test262\data +call git config --system core.longpaths true +call git restore * +cd ..\..\..\ +call gclient sync + +@REM echo =====[ Patching V8 ]===== +@REM node %GITHUB_WORKSPACE%\CRLF2LF.js %GITHUB_WORKSPACE%\patch\builtins-puerts.patch +@REM call git apply --cached --reject %GITHUB_WORKSPACE%\patch\builtins-puerts.patch +@REM call git checkout -- . + +echo =====[ Make dynamic_crt ]===== +node %~dp0\rep.js build\config\win\BUILD.gn + +echo =====[ Building V8 ]===== +call gn gen out.gn\x64.release -args="target_os=""win"" target_cpu=""x64"" v8_use_external_startup_data=true v8_enable_i18n_support=false is_debug=false is_clang=false strip_debug_info=true symbol_level=0 v8_enable_pointer_compression=false is_component_build=true" + +call ninja -C out.gn\x64.release -t clean +call ninja -C out.gn\x64.release v8 + +md output\v8\Lib\Win64DLL +copy /Y out.gn\x64.release\v8.dll.lib output\v8\Lib\Win64DLL\ +copy /Y out.gn\x64.release\v8_libplatform.dll.lib output\v8\Lib\Win64DLL\ +copy /Y out.gn\x64.release\v8.dll output\v8\Lib\Win64DLL\ +copy /Y out.gn\x64.release\v8_libbase.dll output\v8\Lib\Win64DLL\ +copy /Y out.gn\x64.release\v8_libplatform.dll output\v8\Lib\Win64DLL\ +copy /Y out.gn\x64.release\zlib.dll output\v8\Lib\Win64DLL\ \ No newline at end of file