diff --git a/.gitignore b/.gitignore index 1f6f247..2213a1b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,7 @@ v8 -.cipd \ No newline at end of file +.cipd +build_results +.gclient +.gclient_entries +.gclient_previous_sync_commits +.gcs_entries \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..3537ce9 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# V8 Build Tools + +This repository contains all the necessary tools and scripts to build Google's V8 for embedding. + +## Prerequisites + +1. **Clone this repository:** + + ```sh + git clone https://github.com/citizenfx/v8-build.git + cd v8-build + ``` + +2. **Python 3.8+ must be installed on your system.** + +3. **Drive Mapping:** + + Ensure you do not have a drive mapped to the letter 'Y'. If you do, change the mapping drive target to another letter in the `prepare-depot.ps1` and `build.ps1` files. + +## Building V8 + +1. **Prepare the depot:** + + Run the following script to prepare the depot: + + ```sh + .\build\prepare-depot.ps1 + ``` + +2. **Build V8:** + + Run the build script: + + ```sh + .\build\build.ps1 + ``` + +3. **Wait approximately 20 minutes** for the build process to complete. + +## Build Results + +The build results will be located in the `builds_results` folder. diff --git a/UPDATE.md b/UPDATE.md new file mode 100644 index 0000000..878a52e --- /dev/null +++ b/UPDATE.md @@ -0,0 +1,7 @@ +# In case if update needed +## Things you need to know +* There was bug in ICU script that generating ASM file with icudata for embedding. If it still generates ASM file with `icudata` variable that prefixed with `_` - bug still exists and clang compilation will fail. We are doing trick to remove underscore in build script +* By default v8_monolith use static crt, so are forcing it to use dynamic CRT. Maybe with some time Google will fix it, so then you need to check flags with `gn args` and look for flag that forcing dynamic crt to be used. + +## How to update to newer V8 +Simply put new commit hash/tag/branch from [V8 repository](https://github.com/v8/v8) into `target.txt`. It will be added to `git checkout` command \ No newline at end of file diff --git a/build/args.gn b/build/args_release.gn similarity index 100% rename from build/args.gn rename to build/args_release.gn diff --git a/build/build.ps1 b/build/build.ps1 index a675876..da7f98f 100644 --- a/build/build.ps1 +++ b/build/build.ps1 @@ -13,18 +13,47 @@ Write-Host "Mount directory: $MOUNT_DIR" Invoke-Expression "subst ${MOUNT_TARGET_DRIVE}: /D" -ErrorAction SilentlyContinue Invoke-Expression "subst ${MOUNT_TARGET_DRIVE}: $MOUNT_DIR" -ErrorAction SilentlyContinue -# Reading target commit hash -$COMMIT = Get-Content "${MOUNT_TARGET_DRIVE}:\build\target_commit.txt " -Raw +# Reading target commit/tag/branch hash +$REPOSITORY_TARGET_CHECKOUT = Get-Content "${MOUNT_TARGET_DRIVE}:\build\target.txt " -Raw # Fetch v8 source & fetch v8 New-Item -ItemType Directory -Force -Path "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.release" -Copy-Item -Path "${MOUNT_TARGET_DRIVE}:\build\args_debug.gn" -Destination "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.release\" +New-Item -ItemType Directory -Force -Path "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.debug" +Copy-Item -Path "${MOUNT_TARGET_DRIVE}:\build\args_debug.gn" -Destination "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.debug\args.gn" +Copy-Item -Path "${MOUNT_TARGET_DRIVE}:\build\args_release.gn" -Destination "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.release\args.gn" Set-Location "${MOUNT_TARGET_DRIVE}:\v8" -git checkout $COMMIT +git checkout $REPOSITORY_TARGET_CHECKOUT gclient sync + +#################################### +# # +# Tricks and hacks zone # +# # +#################################### + +# Trick to force v8 to use dynamic CRT +(Get-Content "${MOUNT_TARGET_DRIVE}:\v8\build\config\BUILDCONFIG.gn").Replace('//build/config/win:default_crt', '//build/config/win:dynamic_crt') | Set-Content "${MOUNT_TARGET_DRIVE}:\v8\build\config\BUILDCONFIG.gn" + +# Fixing bug with compiling inlined icudata in ASM with Clang +# This cheap trick breaks macos version compilation, but we don't care about that +(Get-Content "${MOUNT_TARGET_DRIVE}:\v8\third_party\icu\scripts\make_data_assembly.py").Replace('_icudt%s_dat', 'icudt%s_dat') | Set-Content "${MOUNT_TARGET_DRIVE}:\v8\third_party\icu\scripts\make_data_assembly.py" + +#################################### +# # +# Tricks and hacks zone end # +# # +#################################### + +gn gen out.gn/x64.debug +ninja -C out.gn/x64.debug -j16 v8_monolith + gn gen out.gn/x64.release -ninja -C out.gn/x64.release -j16 v8 +ninja -C out.gn/x64.release -j16 v8_monolith + +New-Item -ItemType Directory -Force -Path "${MOUNT_TARGET_DRIVE}:\build_results" +Copy-Item -Path "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.debug\obj\v8_monolith.lib" -Destination "${MOUNT_TARGET_DRIVE}:\build_results\v8_monolithd.lib" +Copy-Item -Path "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.release\obj\v8_monolith.lib" -Destination "${MOUNT_TARGET_DRIVE}:\build_results\v8_monolith.lib" # Attempt to clean up and remove X: mapping at the end; ignore errors Invoke-Expression "subst ${MOUNT_TARGET_DRIVE}: /D" -ErrorAction SilentlyContinue diff --git a/build/build.ps1.bak b/build/build.ps1.bak new file mode 100644 index 0000000..c3c3c81 --- /dev/null +++ b/build/build.ps1.bak @@ -0,0 +1,35 @@ +# Define environment variables +$env:DEPOT_TOOLS_WIN_TOOLCHAIN = "0" + +# Get the current directory of the script +$CURRENT_DIR = Split-Path -Parent $MyInvocation.MyCommand.Path +Write-Host "Current directory: $CURRENT_DIR" + +# Define the directory to be mounted +$MOUNT_DIR = Split-Path -Path $CURRENT_DIR -Parent +$MOUNT_TARGET_DRIVE = "Y" +Write-Host "Mount directory: $MOUNT_DIR" + +Invoke-Expression "subst ${MOUNT_TARGET_DRIVE}: /D" -ErrorAction SilentlyContinue +Invoke-Expression "subst ${MOUNT_TARGET_DRIVE}: $MOUNT_DIR" -ErrorAction SilentlyContinue + +# Reading target commit hash +$COMMIT = Get-Content "${MOUNT_TARGET_DRIVE}:\build\target_commit.txt " -Raw + +# Fetch v8 source +& fetch v8 +New-Item -ItemType Directory -Force -Path "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.release" +New-Item -ItemType Directory -Force -Path "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.debug" +Copy-Item -Path "${MOUNT_TARGET_DRIVE}:\build\args_debug.gn" -Destination "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.debug\args.gn" +Copy-Item -Path "${MOUNT_TARGET_DRIVE}:\build\args_release.gn" -Destination "${MOUNT_TARGET_DRIVE}:\v8\out.gn\x64.release\args.gn" +Set-Location "${MOUNT_TARGET_DRIVE}:\v8" +git checkout $COMMIT +gclient sync +gn gen out.gn/x64.debug +ninja -C out.gn/x64.debug -j16 v8_monolith + +gn gen out.gn/x64.release +ninja -C out.gn/x64.release -j16 v8_monolith + +# Attempt to clean up and remove X: mapping at the end; ignore errors +Invoke-Expression "subst ${MOUNT_TARGET_DRIVE}: /D" -ErrorAction SilentlyContinue diff --git a/build/target_commit.txt b/build/target.txt similarity index 100% rename from build/target_commit.txt rename to build/target.txt diff --git a/depot_tools b/depot_tools index e138529..9a8c80c 160000 --- a/depot_tools +++ b/depot_tools @@ -1 +1 @@ -Subproject commit e1385296c4ab4c7ee0a809676635b52d1df23b87 +Subproject commit 9a8c80ca55f2bd2023c801dfd97651617e618867