diff --git a/.gitignore b/.gitignore index b35df26..7274b1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ -debug/ -target/ Cargo.lock +go-vrl example-govrl + +v5/target +v10/target + diff --git a/README.md b/README.md index aa35802..4d90841 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,9 @@ search](https://github.com/vectordotdev/vector/issues?q=is%3Aopen+is%3Aissue+lab ### Building and importing -Not quite ready yet. It's difficult to distribute a go module that depends on an external build system, we have some ideas though. - -To use this repo as-is, its required to manually compile the rust dependency. -For V5: `cd v5; cargo build --release; cd example/; go run .` -For V10: `cd v10; cargo build --target wasm32-wasi --release; cd example/; go run .` +There are pre-built libraries (both static libs for v5 and wasm for v10) +available in-tree. +They can be updated using `./produce_artifacts.sh` ### Examples diff --git a/produce_artifacts.sh b/produce_artifacts.sh new file mode 100755 index 0000000..a2ab89d --- /dev/null +++ b/produce_artifacts.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env bash + +arch=$(uname -m) +if [[ "$arch" == "aarch64" ]]; then + arch="arm64" +fi +plat=$(echo $(uname -s) | awk '{print tolower($0)}') + +$(cd v5; cargo build --release) +$(cd v10; cargo build --release --target wasm32-wasi) + +cp "v5/target/release/libvrl_bridge.a" "v5/deps/${plat}_${arch}/" +cp "v10/target/wasm32-wasi/release/vrl_bridge.wasm" "v10/deps/" diff --git a/v10/Cargo.toml b/v10/Cargo.toml index d97ea9d..8222dcc 100644 --- a/v10/Cargo.toml +++ b/v10/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" edition = "2021" [profile.release] -debug=true +debug=0 [lib] name = "vrl_bridge" diff --git a/v10/deps/vrl_bridge.wasm b/v10/deps/vrl_bridge.wasm new file mode 100755 index 0000000..c466b92 Binary files /dev/null and b/v10/deps/vrl_bridge.wasm differ diff --git a/v10/wasminterface.go b/v10/wasminterface.go index c17cdd8..4412047 100644 --- a/v10/wasminterface.go +++ b/v10/wasminterface.go @@ -12,7 +12,7 @@ import ( "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1" ) -//go:embed target/wasm32-wasi/release/vrl_bridge.wasm +//go:embed deps/vrl_bridge.wasm var wasmBytes []byte type WasmInterface struct { diff --git a/v5/Cargo.toml b/v5/Cargo.toml index d939e6f..e0a6dec 100644 --- a/v5/Cargo.toml +++ b/v5/Cargo.toml @@ -4,11 +4,14 @@ version = "0.1.0" edition = "2021" [profile.release] -debug=true +# It would be nice to have debug info, at least `debug=1` (line-level granularity) +# But unfortunately it balloons the binary size too much +# With level 0, darwin_arm64 == 57.1 +# With level 1, darwin_arm64 == 149Mi +debug = 0 [lib] name = "vrl_bridge" -# crate-type = ["rlib", "cdylib"] crate-type = ["staticlib"] [dependencies] diff --git a/v5/deps/darwin_arm64/libvrl_bridge.a b/v5/deps/darwin_arm64/libvrl_bridge.a new file mode 100644 index 0000000..b2bf74b Binary files /dev/null and b/v5/deps/darwin_arm64/libvrl_bridge.a differ diff --git a/v5/program.go b/v5/program.go index 99d5d86..16afc9a 100644 --- a/v5/program.go +++ b/v5/program.go @@ -4,7 +4,11 @@ package govrl //#include //#include //#include -//#cgo LDFLAGS: -L${SRCDIR}/target/release -Wl,-rpath,${SRCDIR}/target/release -lvrl_bridge -lm -ldl +//#cgo LDFLAGS: -lvrl_bridge -lm +//#cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/deps/darwin_x86_64/release -Wl,-rpath,${SRCDIR}/deps/darwin_x86_64/release -framework CoreFoundation +//#cgo darwin,arm64 LDFLAGS: -L${SRCDIR}/deps/darwin_arm64/release -Wl,-rpath,${SRCDIR}/deps/darwin_arm64/release -framework CoreFoundation +//#cgo linux,amd64 LDFLAGS: -L${SRCDIR}/deps/linux_x86_64/release -Wl,-rpath,${SRCDIR}/deps/linux_x86_64/release -ldl +//#cgo linux,arm64 LDFLAGS: -L${SRCDIR}/deps/linux_arm64/release -Wl,-rpath,${SRCDIR}/deps/linux_arm64/release -ldl import "C" import "unsafe" diff --git a/v5/runtime.go b/v5/runtime.go index 91ca227..e049de2 100644 --- a/v5/runtime.go +++ b/v5/runtime.go @@ -4,7 +4,6 @@ package govrl //#include //#include //#include -//#cgo LDFLAGS: -L${SRCDIR}/target/release -Wl,-rpath,${SRCDIR}/target/release -lvrl_bridge -lm -ldl import "C" import "unsafe" diff --git a/v5/types.go b/v5/types.go index c88e336..0eccced 100644 --- a/v5/types.go +++ b/v5/types.go @@ -4,7 +4,6 @@ package govrl //#include //#include //#include -//#cgo LDFLAGS: -L${SRCDIR}/target/release -Wl,-rpath,${SRCDIR}/target/release -lvrl_bridge -lm -ldl import "C" import ( "runtime"