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

Transition to pre-built binaries for common platforms #1

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
debug/
target/

Cargo.lock
go-vrl
example-govrl

v5/target
v10/target

8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions produce_artifacts.sh
Original file line number Diff line number Diff line change
@@ -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/"
2 changes: 1 addition & 1 deletion v10/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[profile.release]
debug=true
debug=0

[lib]
name = "vrl_bridge"
Expand Down
Binary file added v10/deps/vrl_bridge.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion v10/wasminterface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions v5/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Binary file added v5/deps/darwin_arm64/libvrl_bridge.a
Binary file not shown.
6 changes: 5 additions & 1 deletion v5/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ package govrl
//#include <stdlib.h>
//#include <string.h>
//#include <vrl.h>
//#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"

Expand Down
1 change: 0 additions & 1 deletion v5/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package govrl
//#include <stdlib.h>
//#include <string.h>
//#include <vrl.h>
//#cgo LDFLAGS: -L${SRCDIR}/target/release -Wl,-rpath,${SRCDIR}/target/release -lvrl_bridge -lm -ldl
import "C"
import "unsafe"

Expand Down
1 change: 0 additions & 1 deletion v5/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package govrl
//#include <stdlib.h>
//#include <string.h>
//#include <vrl.h>
//#cgo LDFLAGS: -L${SRCDIR}/target/release -Wl,-rpath,${SRCDIR}/target/release -lvrl_bridge -lm -ldl
import "C"
import (
"runtime"
Expand Down