Skip to content

Commit

Permalink
Merge pull request #2 from wasmerio/use-official-v8
Browse files Browse the repository at this point in the history
Use upstream V8 with patches
  • Loading branch information
xdoardo authored Feb 12, 2025
2 parents 7fe1d9f + 261bdc3 commit 249383e
Show file tree
Hide file tree
Showing 6 changed files with 820 additions and 90 deletions.
131 changes: 102 additions & 29 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ name: Build

on: [push]

env:
V8_COMMIT: a173aac0492

jobs:
build:
name: Build
Expand All @@ -10,23 +13,37 @@ jobs:
matrix:
target:
- id: 'linux-amd64'
os: 'ubuntu-20.04'
os: "ubuntu-latest-4-cores"
native: true
#- id: 'linux-arm64'
# os: 'ubuntu-24.04-arm'
# native: true
- id: 'linux-musl'
os: 'ubuntu-20.04'
container: alpine:latest
os: 'ubuntu-latest-4-cores'
native: true
container: alpine:3.19
- id: 'darwin-amd64'
os: 'macos-13'
native: true
- id: 'darwin-aarch64'
os: 'macos-latest'
- id: 'windows-amd64'
os: 'windows-2022'
# When unpacking an archive on Windows, the symlinks can't be
# created unless the target path already exists. This causes
# problems when the linked file is ordered after the link
# inside the archive. Dereferencing the files when packing them
# adds an additional copy per link, but it reliably works and
# the additional size is not too large on Windows.
tar_extra_args: '--dereference'
os: 'macos-14'
native: true
- id: 'ios'
os: 'macos-14'
native: false # Not used in the `Build` job, but here for reference
- id: 'android'
os: 'ubuntu-latest-4-cores'
native: false # Not used in the `Build` job, but here for reference
#- id: 'windows-amd64'
# os: 'windows-2022'
# native: true
# # When unpacking an archive on Windows, the symlinks can't be
# # created unless the target path already exists. This causes
# # problems when the linked file is ordered after the link
# # inside the archive. Dereferencing the files when packing them
# # adds an additional copy per link, but it reliably works and
# # the additional size is not too large on Windows.
# tar_extra_args: '--dereference'
tag: ['11.7']
fail-fast: true

Expand All @@ -36,24 +53,46 @@ jobs:
- name: Check out the code
uses: actions/checkout@v3

- name: Install `ninja` on Ubuntu
- name: Install dependencies on Ubuntu
if: startsWith(matrix.target.id, 'linux-amd64')
shell: bash
run: |
sudo apt-get install ninja-build -y
sudo apt-get install ninja-build clang libglib2.0-dev -y
- name: Install dependencies on Ubuntu (android)
if: startsWith(matrix.target.id, 'android')
shell: bash
run: |
sudo apt install gcc make gcc-aarch64-linux-gnu binutils-aarch64-linux-gnu
sudo apt-get install ninja-build clang libglib2.0-dev -y
- name: Install tools on Alpine
- name: Install dependencies on Ubuntu (arm64)
if: startsWith(matrix.target.id, 'linux-arm64')
shell: bash
run: |
sudo apt-get install ninja-build clang libglib2.0-dev -y
- name: Install dependencies on Alpine
if: startsWith(matrix.target.id, 'linux-musl')
run: |
apk add ninja bash git cmake clang18-dev llvm18-dev xz
- name: Install `ninja` on macOS
apk add ninja bash git cmake clang-dev llvm-dev wget python3 alpine-sdk curl git tar xz py3-virtualenv py3-google-auth-httplib2 py3-httplib2 py3-distutils-extra py3-setuptools py3-pip gn
python3 -m pip config set global.break-system-packages true
python3 -m pip uninstall six --yes
python3 -m pip install --upgrade --user six
- name: Install dependencies on macOS
if: startsWith(matrix.target.id, 'darwin-')
shell: bash
run: |
brew install ninja
brew install ninja llvm@18
- name: Install `ninja` on Windows
- name: Set default Xcode on macOS (aarch64)
if: startsWith(matrix.target.id, 'darwin-aarch64')
shell: bash
run: |
sudo xcode-select -s /Applications/Xcode_16.2.app
- name: Install dependencies on Windows
if: startsWith(matrix.target.id, 'windows-')
shell: bash
run: |
Expand All @@ -63,42 +102,57 @@ jobs:
uses: ilammy/msvc-dev-cmd@v1
if: matrix.target.id == 'windows-amd64'

- name: Build
if: matrix.target.id != 'windows-amd64' && matrix.target.id != 'linux-musl'
- name: Build (native target)
if: matrix.target.id != 'windows-amd64' && matrix.target.id != 'linux-musl' && matrix.target.native == true
shell: bash
run: |
./build.sh
- name: Build (android)
if: matrix.target.id == 'android'
shell: bash
run: |
./build.sh "arm64" "android"
- name: Build (iOS)
if: matrix.target.os == 'macos-14' && matrix.target.id == 'ios'
shell: bash
run: |
./build.sh "arm64" "ios"
- name: Build musl
if: matrix.target.id == 'linux-musl'
shell: bash
run: |
CXX=clang++-18 ./build.sh
env:
VPYTHON_BYPASS: "manually managed python not supported by chrome operations"

- name: Build (Windows)
if: matrix.target.id == 'windows-amd64'
run: |
./build.ps1
env:
DEPOT_TOOLS_WIN_TOOLCHAIN: 0

- name: Zip
if: matrix.target.id != 'windows-amd64'
shell: bash
run: |
mkdir -p dist
tar --directory v8-cmake/build --create --xz --verbose ${{ matrix.target.tar_extra_args }} --file dist/wee8.tar.xz libv8_base_without_compiler.a libv8_compiler.a libv8_initializers.a libv8_libbase.a libv8_libplatform.a libv8_libsampler.a libv8_snapshot.a libv8_torque_generated.a libwee8.a
tar --directory v8/out/release --create --xz --verbose ${{ matrix.target.tar_extra_args }} --file dist/wee8.tar.xz obj/libwee8.a
ls -lh dist/wee8.tar.xz
- name: Zip (Windows)
if: matrix.target.id == 'windows-amd64'
shell: bash
run: |
mkdir -p dist
tar --directory v8-cmake/build --create --xz --verbose ${{ matrix.target.tar_extra_args }} --file dist/wee8.tar.xz v8_base_without_compiler.lib v8_compiler.lib v8_initializers.lib v8_libbase.lib v8_libplatform.lib v8_libsampler.lib v8_snapshot.lib v8_torque_generated.lib wee8.lib
tar --directory v8/out/release --create --xz --verbose ${{ matrix.target.tar_extra_args }} --file dist/wee8.tar.xz obj/wee8.lib
ls -lh dist/wee8.tar.xz
- name: Upload Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.target.id }}-${{ matrix.tag }}
path: dist
Expand All @@ -114,10 +168,9 @@ jobs:
matrix:
tag: ['11.7']


steps:
- name: Download the Artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
path: artifacts

Expand Down Expand Up @@ -177,6 +230,26 @@ jobs:
asset_path: artifacts/darwin-aarch64-${{matrix.tag}}/wee8.tar.xz
asset_name: wee8-darwin-aarch64.tar.xz
asset_content_type: application/gzip

- name: Upload Release Asset iOS
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/ios-${{matrix.tag}}/wee8.tar.xz
asset_name: wee8-ios.tar.xz
asset_content_type: application/gzip

- name: Upload Release Asset Android
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/android-${{matrix.tag}}/wee8.tar.xz
asset_name: wee8-android.tar.xz
asset_content_type: application/gzip

- name: Upload Release Asset Windows
uses: actions/upload-release-asset@v1
Expand Down
48 changes: 23 additions & 25 deletions build.ps1
Original file line number Diff line number Diff line change
@@ -1,36 +1,34 @@
$V8_REPO_URL = $args[1]
$DEPOT_TOOLS_REPO="https://chromium.googlesource.com/chromium/tools/depot_tools.git"

if ([string]::IsNullOrEmpty($V8_REPO_URL)) {
$V8_REPO_URL = "https://github.com/laper32/v8-cmake.git"
# Clone depot-tools
if (-not (Test-Path -Path "depot_tools" -PathType Container)) {
git clone --single-branch --depth=1 "$DEPOT_TOOLS_REPO" "C:\tmp\depot_tools"
}

# Clone the LLVM project.
if (-not (Test-Path -Path "v8-cmake" -PathType Container)) {
git clone -b "msvc" --single-branch --depth=1 "$V8_REPO_URL" v8-cmake
}

Set-Location v8-cmake
git fetch origin
echo "C:\tmp\depot_tools" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
$env:Path = "C:\tmp\depot_tools;" + $env:Path

# Create a directory to build the project.
New-Item -Path "build" -Force -ItemType "directory"
Set-Location build
# Set up google's client and fetch v8
if (-not (Test-Path -Path "v8" -PathType Container)) {
gclient
fetch v8
}

# Create a directory to receive the complete installation.
New-Item -Path "install" -Force -ItemType "directory"
Set-Location v8

# Adjust compilation based on the OS.
$CMAKE_ARGUMENTS = ""
git checkout $V8_COMMIT

# Adjust cross compilation
$CROSS_COMPILE = ""
# Apply patches

# Run `cmake` to configure the project, using MSVC.
$CMAKE_CXX_COMPILER="cl.exe"
$CMAKE_C_COMPILER="cl.exe"
$CMAKE_LINKER_TYPE="MSVC"
$files = Get-ChildItem "../patches" -Filter *.patch
foreach ($f in $files){
git apply $f
}

cmake -G "Ninja" -DCMAKE_BUILD_TYPE=MinSizeRel ..
gn gen out/release --args="is_debug=false v8_symbol_level=2 is_component_build=false is_official_build=false use_custom_libcxx=false use_custom_libcxx_for_host=true use_sysroot=false use_glib=false is_clang=false v8_expose_symbols=true v8_optimized_debug=false v8_enable_sandbox=false v8_enable_i18n_support=false v8_enable_gdbjit=false v8_use_external_startup_data=false
treat_warnings_as_errors=false target_cpu=\"$ARCH\" v8_target_cpu=\"$ARCH\" target_os=\"$OS\""

# Showtime!
cmake --build . --config MinSizeRel --target wee8
ninja -C out/release wee8

ls -laR out/release/obj
Loading

0 comments on commit 249383e

Please sign in to comment.