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

Add static build when tag "static_build" is used #40

Closed
wants to merge 10 commits into from
18 changes: 18 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@ build go-build-args='-v':
;;
*)
dylib_extension="so"
staticlib_extension="a"
esac
if ! test -f libwasmer_runtime_c_api.${dylib_extension}; then
cargo build --release
ln -s ../target/release/deps/libwasmer_runtime_c_api-*.${dylib_extension} libwasmer_runtime_c_api.${dylib_extension}
fi
go build {{go-build-args}} .

if test ! -z "${staticlib_extension:-}"; then
if ! test -f libwasmer_runtime_c_api.${staticlib_extension}; then
cargo build --release
ln -s ../target/release/deps/libwasmer_runtime_c_api-*.${staticlib_extension} libwasmer_runtime_c_api.${staticlib_extension}
fi
go build {{go-build-args}} -tags "static_build" .
fi

# Build the `go-wasmer` bin.
build-bin go-build-args='-v':
cd go-wasmer && go build {{go-build-args}} -o ../target/go/go-wasmer .
Expand All @@ -45,6 +54,15 @@ test:
# Run the long examples.
go test -test.v $(find . -type f \( -name "example_*_test.go" \! -name "_example_import_test.go" \) )

if test -f libwasmer_runtime_c_api.a; then
# Run the tests.
GODEBUG=cgocheck=2 go test -tags "static_build" -test.v $(find test -type f \( -name "*_test.go" \! -name "example_*.go" \! -name "benchmark*.go" \) ) test/imports.go
# Run the short examples.
go test -tags "static_build" -test.v example_test.go
# Run the long examples.
go test -tags "static_build" -test.v $(find . -type f \( -name "example_*_test.go" \! -name "_example_import_test.go" \) )
fi

# Run benchmarks. Subjects can be `wasmer`, `wagon` or `life`. Filter is a regex to select the benchmarks.
bench subject='wasmer' filter='.*':
cd benchmarks/{{subject}} && go test -bench '{{filter}}' benchmarks_test.go
Expand Down
1 change: 0 additions & 1 deletion wasmer/bridge.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package wasmer

// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lwasmer_runtime_c_api
// #include "./wasmer.h"
//
import "C"
Expand Down
Binary file added wasmer/libwasmer_runtime_c_api.a
Binary file not shown.
6 changes: 6 additions & 0 deletions wasmer/wasmer_link_dynamic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// +build !static_build
yaslama marked this conversation as resolved.
Show resolved Hide resolved

package wasmer

// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lwasmer_runtime_c_api
import "C"
6 changes: 6 additions & 0 deletions wasmer/wasmer_link_static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// +build static_build
yaslama marked this conversation as resolved.
Show resolved Hide resolved

package wasmer

// #cgo LDFLAGS: -lm -ldl -lrt -L${SRCDIR} -l:libwasmer_runtime_c_api.a
import "C"