-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bundle passthrough component in Go directly
Signed-off-by: Roman Volosatovs <[email protected]>
- Loading branch information
1 parent
d5d6293
commit 3c36dc9
Showing
8 changed files
with
20 additions
and
97 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
//go:generate cargo build -p west-sys --release | ||
//go:generate cargo build -p west-passthrough --target wasm32-unknown-unknown --release | ||
//go:generate wasm-tools component new target/wasm32-unknown-unknown/release/west_passthrough.wasm -o lib/passthrough.wasm | ||
//go:generate go run github.com/ydnar/wasm-tools-go/cmd/[email protected] generate -w imports -o bindings ./wit | ||
|
||
package west | ||
|
@@ -13,6 +15,7 @@ package west | |
import "C" | ||
|
||
import ( | ||
_ "embed" | ||
"errors" | ||
"fmt" | ||
"log" | ||
|
@@ -23,6 +26,9 @@ import ( | |
"unsafe" | ||
) | ||
|
||
//go:embed lib/passthrough.wasm | ||
var Passthrough []byte | ||
|
||
var ( | ||
errorHandlerMu sync.RWMutex | ||
errorHandler atomic.Value | ||
|
@@ -148,19 +154,20 @@ func NewInstance(conf *Config) (*Instance, error) { | |
var pinner runtime.Pinner | ||
defer pinner.Unpin() | ||
|
||
c := C.default_config() | ||
wasm := Passthrough | ||
if conf != nil { | ||
if len(conf.Wasm) > 0 { | ||
ptr := unsafe.SliceData(conf.Wasm) | ||
pinner.Pin(ptr) | ||
|
||
c.wasm = C.List_u8{ | ||
ptr: (*C.uchar)(ptr), | ||
len: C.ulong(len(conf.Wasm)), | ||
} | ||
wasm = conf.Wasm | ||
} | ||
} | ||
ptr := C.instance_new(c) | ||
wasmPtr := unsafe.SliceData(wasm) | ||
pinner.Pin(wasmPtr) | ||
ptr := C.instance_new(C.Config{ | ||
wasm: C.List_u8{ | ||
ptr: (*C.uchar)(wasmPtr), | ||
len: C.ulong(len(wasm)), | ||
}, | ||
}) | ||
if ptr == nil { | ||
n := C.error_len() | ||
buf := make([]C.char, n) | ||
|