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
23 changes: 19 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@ build-runtime:
case "{{os()}}" in
"macos")
shared_library_path=$( ls -t target/release/deps/libwasmer_runtime_c_api*.dylib | head -n 1 )
shared_library=libwasmer_runtime_c_api.dylib
static_library_path=$( ls -t target/release/deps/libwasmer_runtime_c_api*.a | head -n 1 )
shared_library=libwasmer.dylib
static_library=libwasmer.a
;;
"windows")
shared_library_path=$( ls -t target/release/deps/wasmer_runtime_c_api*.dll | head -n 1 )
shared_library=wasmer_runtime_c_api.dll
static_library_path=$( ls -t target/release/deps/wasmer_runtime_c_api*.lib | head -n 1 )
shared_library=wasmer.dll
static_library=wasmer.lib
;;
*)
shared_library_path=$( ls -t target/release/deps/libwasmer_runtime_c_api*.so | head -n 1 )
shared_library=libwasmer_runtime_c_api.so
static_library_path=$( ls -t target/release/deps/libwasmer_runtime_c_api*.a | head -n 1 )
shared_library=libwasmer.so
static_library=libwasmer.a
esac

# Link `wasmer/*wasmer_runtime_c_api.*`.
rm -f wasmer/${shared_library}
ln -s "../${shared_library_path}" wasmer/${shared_library}
rm -f wasmer/static/${static_library}
ln -s "../../${static_library_path}" wasmer/static/${static_library}

# Build the `wasmer` library.
build go-build-args='-v':
cd wasmer && go build {{go-build-args}} .
cd wasmer && go build {{go-build-args}} . && go build {{go-build-args}} -tags "static_build" .

# Build the `go-wasmer` bin.
build-bin go-build-args='-v':
Expand Down Expand Up @@ -55,6 +63,13 @@ test:
# Run the long examples.
go test -test.v $(find . -type f \( -name "example_*_test.go" \! -name "_example_import_test.go" \) )

# Run the tests using static lib.
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" \) )

# 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
// #include "./wasmer.h"
//
import "C"
Expand Down
Binary file added wasmer/static/libwasmer.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
import "C"
7 changes: 7 additions & 0 deletions wasmer/wasmer_link_static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// +build static_build
yaslama marked this conversation as resolved.
Show resolved Hide resolved

package wasmer

// #cgo !darwin LDFLAGS: -L${SRCDIR}/static -lwasmer -lm -ldl -lrt
// #cgo darwin LDFLAGS: -L${SRCDIR}/static -lwasmer -lm -ldl
import "C"