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

adding a build tag specific cgo bridge #190

Closed
wants to merge 1 commit into from

Conversation

traetox
Copy link

@traetox traetox commented Feb 7, 2021

Purpose of this PR

I am attempting to do some static linking and also to use an alternative LIBC implementation (musl) this requires that I have greater control over the LDFLAGS and CFLAGS. The current flags hard code the location of the library and include files, requiring some file copypasta.

What this PR does

Adds an optional customlib build tag that when specified during builds requires that the user provide all the CFLAG and LDFLAG variables.

What this allows

I can build the upstream wasmerio/wasmer package with custom targets, etc.. and then build my golang application with total control over which wasmer library file is included.

Example Usage

Assuming that i have cloned the wasmer repo to /wasmer and built an appropriate wasmer C-API I can then perform the following to get a sweet sweet statically compiled executable using the MUSL libc:

export CGO_CFLAGS="-I/wasmer/lib/c-api/"
export CGO_LDFLAGS="-Wl,-rpath,/wasmer/target/x86_64-unknown-linux-musl/release/ -L/wasmer/target/x86_64-unknown-linux-musl/release/ -pthread -lwasmer_c_api -lm -ldl -static"
CC=/usr/bin/musl-gcc go build -tags customlib

The additional build tag will not affect existing users at all.

…trol build behavior using environment variables
@Hywan Hywan self-assigned this Feb 9, 2021
@Hywan Hywan added the 🎉 enhancement New feature or request label Feb 9, 2021
Copy link
Contributor

@Hywan Hywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea very much, thanks!

I wonder whether customlib is a common name in the Go landscape?

@Hywan
Copy link
Contributor

Hywan commented Feb 9, 2021

bors try

bors bot added a commit that referenced this pull request Feb 9, 2021
@Hywan Hywan mentioned this pull request Feb 9, 2021
@Hywan Hywan closed this in #193 Feb 9, 2021
Hywan added a commit that referenced this pull request Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎉 enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants