Skip to content

Commit

Permalink
feat(runtime) Use pre-compiled dynamic libraries.
Browse files Browse the repository at this point in the history
This patch depends on wasmerio/wasmer#474,
which fixes the dylib ID for macOS to use `@rpath`.

This patch renames the `just go` recipe to `just build`.

The `just build` recipe compiles the Rust dynamic library only when
required, i.e. when the `libwasmer_runtime_c_api.*` file is absent
from the source tree.

This patch also updates `bridge.go` to specify the `rpath` to the
linker with `-Wl,-rpath`. On macOS, the solution would be to set
`rpath` to `@executable_path` but since
https://nvd.nist.gov/vuln/detail/CVE-2018-6574, some flags are
disabled (see https://github.com/golang/go/wiki/InvalidFlag for more
information). Hopefully for us, cgo has this special `${SRCDIR}`
variable (see
https://golang.org/cmd/cgo/#hdr-Using_cgo_with_the_go_command), which
is a possible alternative.
  • Loading branch information
Hywan committed May 29, 2019
1 parent a2d7c65 commit a599b8c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 18 deletions.
9 changes: 1 addition & 8 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,12 @@ jobs:
export PATH="$HOME/.cargo/bin:$PATH"
test -f $HOME/.cargo/bin/just || cargo install just
# Compile the Rust part of the library.
- run:
name: Compile the Rust part of the Go library
command: |
export PATH="$HOME/.cargo/bin:$PATH"
just rust
# Compile and install the Go library.
- run:
name: Compile and install the Go library
command: |
export PATH="$HOME/.cargo/bin:$PATH"
just go
just build
# Run the library test suites.
- run:
Expand Down
20 changes: 11 additions & 9 deletions justfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# Compile the Rust part for this specific system.
rust:
cargo build --release

# Compile the Go part.
go go-build-args='':
# Compile the library.
build go-build-args='-v':
#!/usr/bin/env bash
set -euo pipefail
cd wasmer
Expand All @@ -17,9 +13,15 @@ go go-build-args='':
*)
dylib_extension="so"
esac
test -f libwasmer_runtime_c_api.${dylib_extension} || \
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}
go build -ldflags="-r $(pwd)" -v {{go-build-args}} .
fi
go build {{go-build-args}} .
# Compile the Rust part for this specific system.
rust:
cargo build --release
# Generate cgo debug objects.
debug-cgo:
Expand All @@ -30,7 +32,7 @@ debug-cgo:
# Run all the tests.
test:
#!/usr/bin/env bash
export LD_LIBRARY_PATH=$(pwd)/wasmer
#export DYLD_PRINT_LIBRARIES=y
cd wasmer/test/
# Run the tests.
go test -test.v $(find . -type f \( -name "*_test.go" \! -name "example_*.go" \! -name "benchmark*.go" \) ) imports.go
Expand Down
2 changes: 1 addition & 1 deletion wasmer/bridge.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package wasmer

// #cgo LDFLAGS: -L./ -lwasmer_runtime_c_api
// #cgo LDFLAGS: -Wl,-rpath,${SRCDIR} -L${SRCDIR} -lwasmer_runtime_c_api
// #include "./wasmer.h"
//
import "C"
Expand Down
Binary file modified wasmer/libwasmer_runtime_c_api.dylib
Binary file not shown.

0 comments on commit a599b8c

Please sign in to comment.