Skip to content

Commit f60e94a

Browse files
Mogztterggrossetie
Mogztter
authored andcommitted
resolves #170 build v8go for musl libc
1 parent 1f00b50 commit f60e94a

13 files changed

+348
-151
lines changed

.github/workflows/gnalpinebuild.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: GN Alpine Build
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
build-alpine:
8+
name: Build GN for Alpine x86_64
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
with:
14+
submodules: true
15+
fetch-depth: 1
16+
- name: Set up QEMU
17+
uses: docker/setup-qemu-action@v2
18+
- name: Set up Docker Buildx
19+
uses: docker/setup-buildx-action@v2
20+
- name: Build container images
21+
run: docker buildx build --platform=linux/amd64 --output=type=docker -t gn-builder-alpine -f deps/alpine-gn-builder.Dockerfile deps
22+
- name: Copy files
23+
run: |
24+
id=$(docker create gn-builder-alpine)
25+
docker cp $id:/usr/local/bin/gn deps/alpine_x86_64/gn
26+
docker rm -v $id
27+
- name: Create PR
28+
uses: peter-evans/create-pull-request@v3
29+
with:
30+
commit-message: Update GN static library for Alpine x86_64
31+
branch-suffix: random
32+
delete-branch: true
33+
title: GN static library for Alpine x86_64
34+
body: Auto-generated pull request to build GN for Alpine x86_64
35+
base: master

.github/workflows/v8build.yml

+60-27
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,65 @@ jobs:
1414
#
1515
# We need xcode 12.4 or newer to cross compile between arm64/amd64
1616
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode
17-
platform: [ubuntu-18.04, macos-11]
18-
arch: [x86_64, arm64]
17+
platform: [ ubuntu-18.04, macos-11 ]
18+
arch: [ x86_64, arm64 ]
1919
runs-on: ${{ matrix.platform }}
2020
steps:
21-
- name: Checkout
22-
uses: actions/checkout@v2
23-
with:
24-
submodules: true
25-
fetch-depth: 1
26-
- name: Update depot_tools fetch config
27-
run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
28-
shell: bash
29-
- name: Install g++-aarch64-linux-gnu
30-
if: matrix.platform == 'ubuntu-18.04' && matrix.arch == 'arm64'
31-
run: sudo apt update && sudo apt install g++-aarch64-linux-gnu -y
32-
- name: Build V8 linux
33-
if: matrix.platform == 'ubuntu-18.04'
34-
run: cd deps && ./build.py --no-clang --arch ${{ matrix.arch }}
35-
- name: Build V8 macOS
36-
if: matrix.platform == 'macos-11'
37-
run: cd deps && ./build.py --arch ${{ matrix.arch }}
38-
- name: Create PR
39-
uses: peter-evans/create-pull-request@v3
40-
with:
41-
commit-message: Update V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
42-
branch-suffix: random
43-
delete-branch: true
44-
title: V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
45-
body: Auto-generated pull request to build V8 for ${{ matrix.platform }} ${{ matrix.arch }}
21+
- name: Checkout
22+
uses: actions/checkout@v2
23+
with:
24+
submodules: true
25+
fetch-depth: 1
26+
- name: Update depot_tools fetch config
27+
run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
28+
shell: bash
29+
- name: Install g++-aarch64-linux-gnu
30+
if: matrix.platform == 'ubuntu-18.04' && matrix.arch == 'arm64'
31+
run: sudo apt update && sudo apt install g++-aarch64-linux-gnu -y
32+
- name: Build V8 linux
33+
if: matrix.platform == 'ubuntu-18.04'
34+
run: cd deps && ./build.py --no-clang --arch ${{ matrix.arch }}
35+
- name: Build V8 macOS
36+
if: matrix.platform == 'macos-11'
37+
run: cd deps && ./build.py --arch ${{ matrix.arch }}
38+
- name: Create PR
39+
uses: peter-evans/create-pull-request@v3
40+
with:
41+
commit-message: Update V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
42+
branch-suffix: random
43+
delete-branch: true
44+
title: V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
45+
body: Auto-generated pull request to build V8 for ${{ matrix.platform }} ${{ matrix.arch }}
46+
build-alpine:
47+
name: Build V8 for Alpine x86_64
48+
runs-on: ubuntu-20.04
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v3
52+
with:
53+
submodules: true
54+
fetch-depth: 1
55+
- name: Update depot_tools fetch config
56+
run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
57+
shell: bash
58+
- name: Get V8 deps linux
59+
run: cd deps && ./get_v8deps.py
60+
- name: Set up QEMU
61+
uses: docker/setup-qemu-action@v2
62+
- name: Set up Docker Buildx
63+
uses: docker/setup-buildx-action@v2
64+
- name: Build container images
65+
run: docker buildx build --platform=linux/amd64 --output=type=docker -t v8-builder-alpine -f deps/alpine-v8-builder.Dockerfile deps
66+
- name: Copy files
67+
run: |
68+
id=$(docker create v8-builder-alpine)
69+
docker cp $id:alpine_x86_64/. deps/alpine_x86_64/
70+
docker rm -v $id
71+
- name: Create PR
72+
uses: peter-evans/create-pull-request@v3
73+
with:
74+
commit-message: Update V8 static library for Alpine x86_64
75+
branch-suffix: random
76+
delete-branch: true
77+
title: V8 static library for Alpine x86_64
78+
body: Auto-generated pull request to build V8 for Alpine x86_64

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ deps/darwin-x86_64/libv8_debug.a
1010
c.out
1111

1212
/v8go.test
13+
__pycache__

cgo.go

+2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ package v8go
1212
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/deps/darwin_arm64
1313
// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/deps/linux_x86_64 -ldl
1414
// #cgo linux,arm64 LDFLAGS: -L${SRCDIR}/deps/linux_arm64 -ldl
15+
// #cgo linux,amd64,musl-gcc LDFLAGS: -L${SRCDIR}/deps/alpine_x86_64 -ldl
1516
import "C"
1617

1718
// These imports forces `go mod vendor` to pull in all the folders that
1819
// contain V8 libraries and headers which otherwise would be ignored.
1920
// DO NOT REMOVE
2021
import (
22+
_ "rogchap.com/v8go/deps/alpine_x86_64"
2123
_ "rogchap.com/v8go/deps/darwin_arm64"
2224
_ "rogchap.com/v8go/deps/darwin_x86_64"
2325
_ "rogchap.com/v8go/deps/include"

deps/alpine-gn-builder.Dockerfile

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Build GN for alpine (this is a build dependency)
3+
#
4+
FROM alpine:3.16.3 as gn-builder
5+
6+
# This is the GN commit that we want to build.
7+
# Most commits will probably build just fine but this happened to be the latest commit when I did this.
8+
ARG GN_COMMIT=1c4151ff5c1d6fbf7fa800b8d4bb34d3abc03a41
9+
10+
RUN \
11+
apk add --update --virtual .gn-build-dependencies \
12+
alpine-sdk \
13+
binutils-gold \
14+
clang \
15+
curl \
16+
git \
17+
llvm12 \
18+
ninja \
19+
python3 \
20+
tar \
21+
xz \
22+
# Quick fixes: we need the LLVM tooling in $PATH, and we also have to use gold instead of ld.
23+
&& PATH=$PATH:/usr/lib/llvm12/bin \
24+
&& cp -f /usr/bin/ld.gold /usr/bin/ld \
25+
# Clone and build gn
26+
&& git clone https://gn.googlesource.com/gn /tmp/gn \
27+
&& git -C /tmp/gn checkout ${GN_COMMIT} \
28+
&& cd /tmp/gn \
29+
&& python3 build/gen.py \
30+
&& ninja -C out \
31+
&& cp -f /tmp/gn/out/gn /usr/local/bin/gn

deps/alpine-v8-builder.Dockerfile

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#
2+
# Building V8 for alpine
3+
#
4+
FROM alpine:3.16.3 as v8
5+
6+
COPY depot_tools ./depot_tools
7+
COPY include ./include
8+
COPY v8 ./v8
9+
COPY .gclient compile_v8.py ./
10+
COPY alpine_x86_64 ./alpine_x86_64
11+
12+
RUN \
13+
apk add --update --virtual .v8-build-dependencies \
14+
bash \
15+
curl \
16+
g++ \
17+
gcc \
18+
glib-dev \
19+
icu-dev \
20+
libstdc++ \
21+
linux-headers \
22+
make \
23+
ninja \
24+
python3 \
25+
tar \
26+
xz \
27+
&& cp alpine_x86_64/gn depot_tools/gn \
28+
&& ln -s /usr/bin/python3 /usr/bin/python \
29+
# Compile V8
30+
&& ./compile_v8.py --no-clang --arch x86_64

deps/alpine_x86_64/gn

7.69 MB
Binary file not shown.

deps/alpine_x86_64/libv8.a

72 MB
Binary file not shown.

deps/alpine_x86_64/vendor.go

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Package alpine_x86_64 is required to provide support for vendoring modules
2+
// DO NOT REMOVE
3+
package alpine_x86_64

deps/build.py

+3-123
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import subprocess
55
import shutil
66
import argparse
7+
from get_v8deps import v8deps
8+
from compile_v8 import v8compile
79

810
valid_archs = ['arm64', 'x86_64']
911
# "x86_64" is called "amd64" on Windows
@@ -22,131 +24,9 @@
2224
parser.set_defaults(debug=False, clang=True)
2325
args = parser.parse_args()
2426

25-
deps_path = os.path.dirname(os.path.realpath(__file__))
26-
v8_path = os.path.join(deps_path, "v8")
27-
tools_path = os.path.join(deps_path, "depot_tools")
28-
is_windows = platform.system().lower() == "windows"
29-
30-
gclient_sln = [
31-
{ "name" : "v8",
32-
"url" : "https://chromium.googlesource.com/v8/v8.git",
33-
"deps_file" : "DEPS",
34-
"managed" : False,
35-
"custom_deps" : {
36-
# These deps are unnecessary for building.
37-
"v8/testing/gmock" : None,
38-
"v8/test/wasm-js" : None,
39-
"v8/third_party/android_tools" : None,
40-
"v8/third_party/catapult" : None,
41-
"v8/third_party/colorama/src" : None,
42-
"v8/tools/gyp" : None,
43-
"v8/tools/luci-go" : None,
44-
},
45-
"custom_vars": {
46-
"build_for_node" : True,
47-
},
48-
},
49-
]
50-
51-
gn_args = """
52-
is_debug=%s
53-
is_clang=%s
54-
target_cpu="%s"
55-
v8_target_cpu="%s"
56-
clang_use_chrome_plugins=false
57-
use_custom_libcxx=false
58-
use_sysroot=false
59-
symbol_level=%s
60-
strip_debug_info=%s
61-
is_component_build=false
62-
v8_monolithic=true
63-
v8_use_external_startup_data=false
64-
treat_warnings_as_errors=false
65-
v8_embedder_string="-v8go"
66-
v8_enable_gdbjit=false
67-
v8_enable_i18n_support=true
68-
icu_use_data_file=false
69-
v8_enable_test_features=false
70-
v8_untrusted_code_mitigations=false
71-
exclude_unwind_tables=true
72-
"""
73-
74-
def v8deps():
75-
spec = "solutions = %s" % gclient_sln
76-
env = os.environ.copy()
77-
env["PATH"] = tools_path + os.pathsep + env["PATH"]
78-
subprocess.check_call(cmd(["gclient", "sync", "--spec", spec]),
79-
cwd=deps_path,
80-
env=env)
81-
82-
def cmd(args):
83-
return ["cmd", "/c"] + args if is_windows else args
84-
85-
def os_arch():
86-
u = platform.uname()
87-
return u[0].lower() + "_" + args.arch
88-
89-
def v8_arch():
90-
if args.arch == "x86_64":
91-
return "x64"
92-
return args.arch
93-
94-
def apply_mingw_patches():
95-
v8_build_path = os.path.join(v8_path, "build")
96-
apply_patch("0000-add-mingw-main-code-changes", v8_path)
97-
apply_patch("0001-add-mingw-toolchain", v8_build_path)
98-
update_last_change()
99-
zlib_path = os.path.join(v8_path, "third_party", "zlib")
100-
zlib_src_gn = os.path.join(deps_path, os_arch(), "zlib.gn")
101-
zlib_dst_gn = os.path.join(zlib_path, "BUILD.gn")
102-
shutil.copy(zlib_src_gn, zlib_dst_gn)
103-
104-
def apply_patch(patch_name, working_dir):
105-
patch_path = os.path.join(deps_path, os_arch(), patch_name + ".patch")
106-
subprocess.check_call(["git", "apply", "-v", patch_path], cwd=working_dir)
107-
108-
def update_last_change():
109-
out_path = os.path.join(v8_path, "build", "util", "LASTCHANGE")
110-
subprocess.check_call(["python", "build/util/lastchange.py", "-o", out_path], cwd=v8_path)
111-
11227
def main():
11328
v8deps()
114-
if is_windows:
115-
apply_mingw_patches()
116-
117-
gn_path = os.path.join(tools_path, "gn")
118-
assert(os.path.exists(gn_path))
119-
ninja_path = os.path.join(tools_path, "ninja" + (".exe" if is_windows else ""))
120-
assert(os.path.exists(ninja_path))
121-
122-
build_path = os.path.join(deps_path, ".build", os_arch())
123-
env = os.environ.copy()
124-
125-
is_debug = 'true' if args.debug else 'false'
126-
is_clang = 'true' if args.clang else 'false'
127-
# symbol_level = 1 includes line number information
128-
# symbol_level = 2 can be used for additional debug information, but it can increase the
129-
# compiled library by an order of magnitude and further slow down compilation
130-
symbol_level = 1 if args.debug else 0
131-
strip_debug_info = 'false' if args.debug else 'true'
132-
133-
arch = v8_arch()
134-
gnargs = gn_args % (is_debug, is_clang, arch, arch, symbol_level, strip_debug_info)
135-
gen_args = gnargs.replace('\n', ' ')
136-
137-
subprocess.check_call(cmd([gn_path, "gen", build_path, "--args=" + gen_args]),
138-
cwd=v8_path,
139-
env=env)
140-
subprocess.check_call([ninja_path, "-v", "-C", build_path, "v8_monolith"],
141-
cwd=v8_path,
142-
env=env)
143-
144-
lib_fn = os.path.join(build_path, "obj/libv8_monolith.a")
145-
dest_path = os.path.join(deps_path, os_arch())
146-
if not os.path.exists(dest_path):
147-
os.makedirs(dest_path)
148-
dest_fn = os.path.join(dest_path, 'libv8.a')
149-
shutil.copy(lib_fn, dest_fn)
29+
v8compile(args.debug, args.clang, args.arch)
15030

15131

15232
if __name__ == "__main__":

0 commit comments

Comments
 (0)