Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: make build infrastructure more stable #2

Merged
merged 4 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-experiment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ jobs:
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}
- name: Build v8
run: cmake -P v8.cmake
run: python3 tools/build_v8.py
- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
17 changes: 9 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# In the newer v8 versions, lld may be required:
#set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fuse-ld=lld")
#set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fuse-ld=lld")

add_definitions(-DV8_ENABLE_SANDBOX=1 -DV8_COMPRESS_POINTERS=1)

add_executable(pand
Expand All @@ -30,11 +34,11 @@ add_executable(pand
core/tcp_server.h
core/tcp_server.cc
core/main.cc
core/fs.h
core/fs.cc
core/fs.h
core/fs.cc
)

target_include_directories(pand SYSTEM
target_include_directories(pand
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/deps/v8/include
PRIVATE
Expand All @@ -47,11 +51,7 @@ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/ada ada_build)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/simdutf simdutf_build)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/deps/fmt)

target_link_directories(pand
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/deps/v8/out.gn/x64.release/obj
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/deps/swcc/target/release)
target_link_directories(pand PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/deps/v8/out.gn/x64.release/obj)

target_link_libraries(pand fmt::fmt)

Expand All @@ -71,6 +71,7 @@ else ()
ada
simdutf
v8_libplatform
v8_libbase
v8_monolith
pthread
rt
Expand Down
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ You need to download v8 as dependency and it will take reasonable amount of time


```sh
# Download v8 and build
cmake -P v8.cmake

python3 tools/build_v8.py
# Build our actual project
mkdir build
cd build
Expand Down
4 changes: 2 additions & 2 deletions core/js_internals.h

Large diffs are not rendered by default.

83 changes: 83 additions & 0 deletions tools/build_v8.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import os
import sys
import subprocess
from typing import Optional

file_path = os.path.abspath(__file__)
PROJECT_ROOT = os.path.dirname(os.path.dirname(file_path))
DEPS_ROOT = os.path.join(PROJECT_ROOT, "deps")

env = os.environ.copy()

def cmd(command: str, cwd: Optional[str] = None):
subprocess.run(command, env=env, cwd=cwd, shell=True)

# prepare gclient config:
gconfig_location = os.path.join(DEPS_ROOT, ".gclient")
gconfig_content = """solutions = [
{
"name": "v8",
"url": "https://github.com/pandland/v8.git",
"deps_file": "DEPS",
"managed": False,
"custom_deps": {},
"safesync_url": "",
},
]
"""

print(f"# Writing config to file: '{gconfig_location}'")
print(gconfig_content)

with open(gconfig_location, "+wt") as file:
file.write(gconfig_content)

# download depot_tools and prepare $PATH
print("# Downloading depot_tools")
DEPOT_TOOLS_REPO="https://chromium.googlesource.com/chromium/tools/depot_tools.git"
DEPOT_TOOLS_BRANCH="bc85464a"
DEPOT_TOOLS_PATH = os.path.join(DEPS_ROOT, "depot_tools")

cmd(f"git clone {DEPOT_TOOLS_REPO}", DEPS_ROOT)
cmd(f"git checkout {DEPOT_TOOLS_BRANCH}", DEPOT_TOOLS_PATH)

PATH = env["PATH"]
env["PATH"] = f"{PATH}:{DEPOT_TOOLS_PATH}"

print("# Running: 'gclient sync'")
cmd("gclient sync", DEPS_ROOT)

print("# Preparing v8 for build")

V8_DIR = os.path.join(DEPS_ROOT, "v8")
V8_TARGET="x64.release" # TODO: make it configurable
V8_BUILD_DIR=f"{V8_DIR}/out.gn/{V8_TARGET}"
V8_VERSION="12.9.203"

cmd(f"git checkout {V8_VERSION}", V8_DIR)
cmd(f"gclient sync", V8_DIR)

gn_location = os.path.join(V8_BUILD_DIR, "args.gn")
gn_content = """dcheck_always_on = false
is_component_build = false
is_debug = false
target_cpu = \"x64\"
use_custom_libcxx = false
v8_monolithic = true
v8_use_external_startup_data = false
v8_enable_i18n_support = false
treat_warnings_as_errors = false
"""

def use_py(args: str):
if sys.platform == "win32":
return "python " + args
return args

cmd(use_py(f"tools/dev/v8gen.py -vv {V8_TARGET}"), V8_DIR)

with open(gn_location, "+wt") as file:
file.write(gn_content)

print("# Compiling v8...")
cmd(f"ninja -C {V8_BUILD_DIR} v8_monolith", V8_DIR)
2 changes: 1 addition & 1 deletion codegen.py → tools/codegen.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

def generate_cpp_header(folder_path, output_file):
def generate_cpp_header(folder_path: str, output_file: str):
header_guard = "JS_MODULES_H"
with open(output_file, 'w') as f:
f.write("/* AUTO GENERATED FILE - DO NOT EDIT IT MANUALLY */\n")
Expand Down
105 changes: 0 additions & 105 deletions v8.cmake

This file was deleted.

Loading