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 v8go for musl libc (e.g. for alpine linux) #170

Open
krhubert opened this issue Sep 8, 2021 · 6 comments · May be fixed by #350
Open

Build v8go for musl libc (e.g. for alpine linux) #170

krhubert opened this issue Sep 8, 2021 · 6 comments · May be fixed by #350

Comments

@krhubert
Copy link

krhubert commented Sep 8, 2021

Hi!

Is it possible to include alpine os to build pipeline?

@dylanahsmith
Copy link
Collaborator

Do you mean Alpine Linux? There is already a linux build of v8go. Are you having any issues with using the pre-built v8 library for linux that is bundled with v8go?

@krhubert krhubert changed the title Build v8go for alpine Build v8go for alpine linux Sep 9, 2021
@krhubert
Copy link
Author

krhubert commented Sep 9, 2021

Do you mean Alpine Linux?
Yes, I've updated PR title.

There is already a linux build of v8go. Are you having any issues with using the pre-built v8 library for linux that is bundled with v8go?

Yes, I do. It seems that I have to rebuild v8 for Alpine linux (probably because its different std c lib). Below you can see a go code (simple app copied from your README page) and dockerfile. I've also attached the build log.

What I found is an old thread how to build v8 on alpine. It would be great to have a precompiled version for alpine linux like there are for Linux, macOS and Windows.

 > [6/6] RUN go build:
#8 7.953 # rogchap.com/v8go
#8 7.953 /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/rogchap.com/v8go@v0.6.0/deps/linux_x86_64/libv8.a(preparser.o): in function `std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > __gnu_cxx::__to_xstring<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, char>(int (*)(char*, unsigned long, char const*, __va_list_tag*), unsigned long, char const*, ...) [clone .constprop.347]':
....
#8 7.953 source-location.cc:(.text._ZN9__gnu_cxx12__to_xstringINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEcEET_PFiPT0_mPKS8_P13__va_list_tagEmSB_z.constprop.26+0xb8): undefined reference to `__vsnprintf_chk'
#8 7.953 /usr/lib/gcc/x86_64-alpine-linux-musl/10.3.1/../../../../x86_64-alpine-linux-musl/bin/ld: /go/pkg/mod/rogchap.com/v8go@v0.6.0/deps/linux_x86_64/libv8.a(crc_folding.o): in function `Cr_z_crc_fold_copy':
#8 7.953 crc_folding.c:(.text.Cr_z_crc_fold_copy+0x78): undefined reference to `__memcpy_chk'
#8 7.953 collect2: error: ld returned 1 exit status
------
executor failed running [/bin/sh -c go build]: exit code: 2
FROM golang:1.17-alpine

WORKDIR /app

COPY go.mod go.sum main.go /app
RUN go mod download

RUN apk add build-base
RUN go build
package main

import (
    _ "embed"
    "fmt"

    "rogchap.com/v8go"
)

func main() {
    ctx, _ := v8go.NewContext()                             // creates a new V8 context with a new Isolate aka VM
    ctx.RunScript("const add = (a, b) => a + b", "math.js") // executes a script on the global context
    ctx.RunScript("const result = add(3, 4)", "main.js")    // any functions previously added to the context can be called
    val, _ := ctx.RunScript("result", "value.js")           // return a value in JavaScript back to Go
    fmt.Printf("addition result: %s", val)
}

@dylanahsmith
Copy link
Collaborator

I see, it isn't actually creating a fully static executable because of dependencies on the system's libc. If v8 were statically compiled against musl, then perhaps we could completely get rid of the external libc dependency and make the pre-compiled code portable to any linux distribution.

@dylanahsmith
Copy link
Collaborator

Note that the Go build constraints don't have builtin build constraint support for distinguishing between linux distributions or libc implementations. So even if we wanted a separate pre-compiled v8 build for alpine linux, it doesn't seem like it could just be automatically be used. However, it does seem like custom build tags could be specified using the go build -tags command line argument, which could be used to customize the build, which could be an alternative if we aren't able to get a universal static build of v8 for linux.

@dylanahsmith dylanahsmith changed the title Build v8go for alpine linux Build v8go for musl libc (e.g. for alpine linux) Aug 8, 2022
@Vaelatern
Copy link

This also breaks 32bit arm and 32bit x86, and musl libc.

Is there no better way to build this on demand?

ggrossetie pushed a commit to yuzutech/v8go that referenced this issue Nov 28, 2022
ggrossetie pushed a commit to yuzutech/v8go that referenced this issue Nov 28, 2022
@ggrossetie ggrossetie linked a pull request Nov 28, 2022 that will close this issue
ggrossetie pushed a commit to yuzutech/v8go that referenced this issue Nov 28, 2022
ggrossetie pushed a commit to yuzutech/v8go that referenced this issue Nov 29, 2022
@wuzyk
Copy link

wuzyk commented Jun 14, 2023

@dylanahsmith @krhubert
Hi, guys! Is there any update on the issue? Or Is there any concerns to merge the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants