feat: call rust ffi from go

This commit is contained in:
2025-01-12 12:45:44 +08:00
parent a092935265
commit 32a429d555
10 changed files with 576 additions and 6 deletions

29
call-from-go.go Normal file
View File

@@ -0,0 +1,29 @@
package main
import (
"fmt"
"github.com/ebitengine/purego"
)
func main() {
libPath := "target/debug/librust_ffi_from_go.dylib"
arcjetlib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
if err != nil {
// Handle error
panic("load dylib error")
}
defer purego.Dlclose(arcjetlib)
// Register the function
var launch func(string) string
purego.RegisterLibFunc(&launch, arcjetlib, "arcjet_launch")
result := launch("hatter")
fmt.Println("result: ", result)
}