Skip to content

Commit

Permalink
resolves rogchap#170 build v8go for musl libc
Browse files Browse the repository at this point in the history
  • Loading branch information
Mogztter authored and ggrossetie committed Nov 29, 2022
1 parent 1f00b50 commit 4219ad1
Show file tree
Hide file tree
Showing 18 changed files with 421 additions and 153 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
@@ -0,0 +1,2 @@
deps/v8
deps/depot_tools
35 changes: 35 additions & 0 deletions .github/workflows/gnalpinebuild.yml
@@ -0,0 +1,35 @@
name: GN Alpine Build

on:
workflow_dispatch:

jobs:
build-alpine:
name: Build GN for Alpine x86_64
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 1
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build container images
run: docker buildx build --platform=linux/amd64 --output=type=docker -t gn-builder-alpine -f deps/alpine-gn-builder.Dockerfile deps
- name: Copy files
run: |
id=$(docker create gn-builder-alpine)
docker cp $id:/usr/local/bin/gn deps/alpine_x86_64/gn
docker rm -v $id
- name: Create PR
uses: peter-evans/create-pull-request@v3
with:
commit-message: Update GN static library for Alpine x86_64
branch-suffix: random
delete-branch: true
title: GN static library for Alpine x86_64
body: Auto-generated pull request to build GN for Alpine x86_64
base: master
31 changes: 30 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -47,4 +47,33 @@ jobs:
fossa analyze
env:
FOSSA_API_KEY: ${{ secrets.FOSSA_API_KEY }}

test-alpine:
name: Tests on ${{ matrix.go-version }} ${{ matrix.base-os }}
strategy:
matrix:
base-image: [golang]
base-os: [alpine3.16]
go-version: [1.17.13, 1.19.3]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build container image
run: docker buildx build --build-arg IMAGE_NAME=${IMAGE_NAME} --platform=linux/amd64 --output=type=docker -t v8go-alpine-test -f alpine-test.Dockerfile .
env:
IMAGE_NAME: ${{ format('{0}:{1}-{2}', matrix.image-name, matrix.go-version, matrix.base-os) }}
- name: Go Test
run: |
docker run v8go-alpine-test > c.out
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
env:
OS: ${{ matrix.base-os }}
GO: ${{ matrix.go-version }}
with:
files: ./c.out
env_vars: OS,GO
87 changes: 60 additions & 27 deletions .github/workflows/v8build.yml
Expand Up @@ -14,32 +14,65 @@ jobs:
#
# We need xcode 12.4 or newer to cross compile between arm64/amd64
# https://github.com/actions/virtual-environments/blob/main/images/macos/macos-11-Readme.md#xcode
platform: [ubuntu-18.04, macos-11]
arch: [x86_64, arm64]
platform: [ ubuntu-18.04, macos-11 ]
arch: [ x86_64, arm64 ]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 1
- name: Update depot_tools fetch config
run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
shell: bash
- name: Install g++-aarch64-linux-gnu
if: matrix.platform == 'ubuntu-18.04' && matrix.arch == 'arm64'
run: sudo apt update && sudo apt install g++-aarch64-linux-gnu -y
- name: Build V8 linux
if: matrix.platform == 'ubuntu-18.04'
run: cd deps && ./build.py --no-clang --arch ${{ matrix.arch }}
- name: Build V8 macOS
if: matrix.platform == 'macos-11'
run: cd deps && ./build.py --arch ${{ matrix.arch }}
- name: Create PR
uses: peter-evans/create-pull-request@v3
with:
commit-message: Update V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
branch-suffix: random
delete-branch: true
title: V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
body: Auto-generated pull request to build V8 for ${{ matrix.platform }} ${{ matrix.arch }}
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
fetch-depth: 1
- name: Update depot_tools fetch config
run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
shell: bash
- name: Install g++-aarch64-linux-gnu
if: matrix.platform == 'ubuntu-18.04' && matrix.arch == 'arm64'
run: sudo apt update && sudo apt install g++-aarch64-linux-gnu -y
- name: Build V8 linux
if: matrix.platform == 'ubuntu-18.04'
run: cd deps && ./build.py --no-clang --arch ${{ matrix.arch }}
- name: Build V8 macOS
if: matrix.platform == 'macos-11'
run: cd deps && ./build.py --arch ${{ matrix.arch }}
- name: Create PR
uses: peter-evans/create-pull-request@v3
with:
commit-message: Update V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
branch-suffix: random
delete-branch: true
title: V8 static library for ${{ matrix.platform }} ${{ matrix.arch }}
body: Auto-generated pull request to build V8 for ${{ matrix.platform }} ${{ matrix.arch }}
build-alpine:
name: Build V8 for Alpine x86_64
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
submodules: true
fetch-depth: 1
- name: Update depot_tools fetch config
run: cd deps/depot_tools && git config --unset-all remote.origin.fetch; git config --add remote.origin.fetch +refs/heads/*:refs/remotes/origin/*
shell: bash
- name: Get V8 deps linux
run: cd deps && ./get_v8deps.py
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build container images
run: docker buildx build --platform=linux/amd64 --output=type=docker -t v8-builder-alpine -f deps/alpine-v8-builder.Dockerfile deps
- name: Copy files
run: |
id=$(docker create v8-builder-alpine)
docker cp $id:alpine_x86_64/. deps/alpine_x86_64/
docker rm -v $id
- name: Create PR
uses: peter-evans/create-pull-request@v3
with:
commit-message: Update V8 static library for Alpine x86_64
branch-suffix: random
delete-branch: true
title: V8 static library for Alpine x86_64
body: Auto-generated pull request to build V8 for Alpine x86_64
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -10,3 +10,4 @@ deps/darwin-x86_64/libv8_debug.a
c.out

/v8go.test
__pycache__
17 changes: 17 additions & 0 deletions alpine-test.Dockerfile
@@ -0,0 +1,17 @@
ARG GOLANG_IMAGE=golang:1.19.3-alpine3.16
FROM $GOLANG_IMAGE

RUN apk add --update \
alpine-sdk \
g++ \
gcc \
git \
libc-dev \
glib-dev \
libstdc++

ENV CGO_CXXFLAGS="-Werror"
WORKDIR v8go
COPY . ./

CMD go test --tags muslgcc -v -coverprofile c.out ./... && go tool cover -html=c.out -o /dev/stdout
5 changes: 4 additions & 1 deletion cgo.go
Expand Up @@ -2,6 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//go:build cgo
// +build cgo

package v8go

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

// These imports forces `go mod vendor` to pull in all the folders that
// contain V8 libraries and headers which otherwise would be ignored.
// DO NOT REMOVE
import (
_ "rogchap.com/v8go/deps/alpine_x86_64"
_ "rogchap.com/v8go/deps/darwin_arm64"
_ "rogchap.com/v8go/deps/darwin_x86_64"
_ "rogchap.com/v8go/deps/include"
Expand Down
11 changes: 11 additions & 0 deletions cgo_opt_glibc.go
@@ -0,0 +1,11 @@
// Copyright 2019 Roger Chapman and the v8go contributors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//go:build !muslgcc || glibc
// +build !muslgcc glibc

package v8go

// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/deps/linux_x86_64 -ldl
import "C"
11 changes: 11 additions & 0 deletions cgo_opt_musl.go
@@ -0,0 +1,11 @@
// Copyright 2019 Roger Chapman and the v8go contributors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//go:build muslgcc && !glibc
// +build muslgcc,!glibc

package v8go

// #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/deps/alpine_x86_64 -ldl
import "C"
31 changes: 31 additions & 0 deletions deps/alpine-gn-builder.Dockerfile
@@ -0,0 +1,31 @@
#
# Build GN for alpine (this is a build dependency)
#
FROM alpine:3.16.3 as gn-builder

# This is the GN commit that we want to build.
# Most commits will probably build just fine but this happened to be the latest commit when I did this.
ARG GN_COMMIT=1c4151ff5c1d6fbf7fa800b8d4bb34d3abc03a41

RUN \
apk add --update --virtual .gn-build-dependencies \
alpine-sdk \
binutils-gold \
clang \
curl \
git \
llvm12 \
ninja \
python3 \
tar \
xz \
# Quick fixes: we need the LLVM tooling in $PATH, and we also have to use gold instead of ld.
&& PATH=$PATH:/usr/lib/llvm12/bin \
&& cp -f /usr/bin/ld.gold /usr/bin/ld \
# Clone and build gn
&& git clone https://gn.googlesource.com/gn /tmp/gn \
&& git -C /tmp/gn checkout ${GN_COMMIT} \
&& cd /tmp/gn \
&& python3 build/gen.py \
&& ninja -C out \
&& cp -f /tmp/gn/out/gn /usr/local/bin/gn
30 changes: 30 additions & 0 deletions deps/alpine-v8-builder.Dockerfile
@@ -0,0 +1,30 @@
#
# Building V8 for alpine
#
FROM alpine:3.16.3 as v8

COPY depot_tools ./depot_tools
COPY include ./include
COPY v8 ./v8
COPY .gclient compile_v8.py ./
COPY alpine_x86_64 ./alpine_x86_64

RUN \
apk add --update --virtual .v8-build-dependencies \
bash \
curl \
g++ \
gcc \
glib-dev \
icu-dev \
libstdc++ \
linux-headers \
make \
ninja \
python3 \
tar \
xz \
&& cp alpine_x86_64/gn depot_tools/gn \
&& ln -s /usr/bin/python3 /usr/bin/python \
# Compile V8
&& ./compile_v8.py --no-clang --arch x86_64
Binary file added deps/alpine_x86_64/gn
Binary file not shown.
Binary file added deps/alpine_x86_64/libv8.a
Binary file not shown.
3 changes: 3 additions & 0 deletions deps/alpine_x86_64/vendor.go
@@ -0,0 +1,3 @@
// Package alpine_x86_64 is required to provide support for vendoring modules
// DO NOT REMOVE
package alpine_x86_64

0 comments on commit 4219ad1

Please sign in to comment.