Skip to content

Commit 4219ad1

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

18 files changed

+421
-153
lines changed

.dockerignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
deps/v8
2+
deps/depot_tools

.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/test.yml

+30-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,33 @@ jobs:
4747
fossa analyze
4848
env:
4949
FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}
50-
50+
test-alpine:
51+
name: Tests on ${{ matrix.go-version }} ${{ matrix.base-os }}
52+
strategy:
53+
matrix:
54+
base-image: [golang]
55+
base-os: [alpine3.16]
56+
go-version: [1.17.13, 1.19.3]
57+
runs-on: ubuntu-latest
58+
steps:
59+
- name: Checkout
60+
uses: actions/checkout@v3
61+
- name: Set up QEMU
62+
uses: docker/setup-qemu-action@v2
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v2
65+
- name: Build container image
66+
run: docker buildx build --build-arg IMAGE_NAME=${IMAGE_NAME} --platform=linux/amd64 --output=type=docker -t v8go-alpine-test -f alpine-test.Dockerfile .
67+
env:
68+
IMAGE_NAME: ${{ format('{0}:{1}-{2}', matrix.image-name, matrix.go-version, matrix.base-os) }}
69+
- name: Go Test
70+
run: |
71+
docker run v8go-alpine-test > c.out
72+
- name: Upload coverage to Codecov
73+
uses: codecov/codecov-action@v1
74+
env:
75+
OS: ${{ matrix.base-os }}
76+
GO: ${{ matrix.go-version }}
77+
with:
78+
files: ./c.out
79+
env_vars: OS,GO

.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__

alpine-test.Dockerfile

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
ARG GOLANG_IMAGE=golang:1.19.3-alpine3.16
2+
FROM $GOLANG_IMAGE
3+
4+
RUN apk add --update \
5+
alpine-sdk \
6+
g++ \
7+
gcc \
8+
git \
9+
libc-dev \
10+
glib-dev \
11+
libstdc++
12+
13+
ENV CGO_CXXFLAGS="-Werror"
14+
WORKDIR v8go
15+
COPY . ./
16+
17+
CMD go test --tags muslgcc -v -coverprofile c.out ./... && go tool cover -html=c.out -o /dev/stdout

cgo.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
//go:build cgo
6+
// +build cgo
7+
58
package v8go
69

710
//go:generate clang-format -i --verbose -style=Chromium v8go.h v8go.cc
@@ -10,14 +13,14 @@ package v8go
1013
// #cgo LDFLAGS: -pthread -lv8
1114
// #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/deps/darwin_x86_64
1215
// #cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/deps/darwin_arm64
13-
// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/deps/linux_x86_64 -ldl
1416
// #cgo linux,arm64 LDFLAGS: -L${SRCDIR}/deps/linux_arm64 -ldl
1517
import "C"
1618

1719
// These imports forces `go mod vendor` to pull in all the folders that
1820
// contain V8 libraries and headers which otherwise would be ignored.
1921
// DO NOT REMOVE
2022
import (
23+
_ "rogchap.com/v8go/deps/alpine_x86_64"
2124
_ "rogchap.com/v8go/deps/darwin_arm64"
2225
_ "rogchap.com/v8go/deps/darwin_x86_64"
2326
_ "rogchap.com/v8go/deps/include"

cgo_opt_glibc.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2019 Roger Chapman and the v8go contributors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
//go:build !muslgcc || glibc
6+
// +build !muslgcc glibc
7+
8+
package v8go
9+
10+
// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/deps/linux_x86_64 -ldl
11+
import "C"

cgo_opt_musl.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2019 Roger Chapman and the v8go contributors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
//go:build muslgcc && !glibc
6+
// +build muslgcc,!glibc
7+
8+
package v8go
9+
10+
// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/deps/alpine_x86_64 -ldl
11+
import "C"

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

0 commit comments

Comments
 (0)