Skip to content

Commit

Permalink
add multiple platform support in go wrapper, and add tests for that
Browse files Browse the repository at this point in the history
  • Loading branch information
siq1 committed Aug 21, 2024
1 parent 5677fcf commit 9cffed9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ jobs:
with:
workspaces: "expander_compiler -> expander_compiler/target"
- run: cargo test --manifest-path=expander_compiler/Cargo.toml
Test-go-mac:
runs-on: macos-latest
steps:
- uses: styfle/[email protected]
- uses: actions/checkout@v4
- name: Setup Go 1.21.x
uses: actions/setup-go@v5
with:
go-version: '1.21.x'
- run: cd ecgo && go test ./test/
Test-go-linux:
runs-on: ubuntu-latest
steps:
Expand Down
20 changes: 17 additions & 3 deletions ecgo/compile/wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,24 @@ func getUrl(url string) ([]byte, error) {
return body, nil
}

func getLibName() string {
switch runtime.GOOS {
case "darwin":
if runtime.GOARCH == "arm64" {
return "libec_go_lib.dylib"
}
case "linux":
if runtime.GOARCH == "amd64" {
return "libec_go_lib.so"
}
}
panic(fmt.Sprintf("unsupported platform %s %s", runtime.GOOS, runtime.GOARCH))
}

func downloadLib(path string) {
log := logger.Logger()
log.Info().Msg("Downloading rust libs ...")
err := downloadFile("https://github.com/PolyhedraZK/ExpanderCompilerCollection/raw/rust-built-libs/libec_go_lib.so", path)
err := downloadFile("https://github.com/PolyhedraZK/ExpanderCompilerCollection/raw/rust-built-libs/"+getLibName(), path)
if err != nil {
os.Remove(path)
panic(err)
Expand Down Expand Up @@ -143,11 +157,11 @@ func initCompilePtr() {
return
}
curDir := currentFileDirectory()
soPath := filepath.Join(curDir, "libec_go_lib.so")
soPath := filepath.Join(curDir, getLibName())
updateLib(soPath)
handle := C.dlopen(C.CString(soPath), C.RTLD_LAZY)
if handle == nil {
panic("failed to load libec_go_lib.so")
panic("failed to load libec_go_lib")
}
compilePtr = C.dlsym(handle, C.CString("compile"))
if compilePtr == nil {
Expand Down

0 comments on commit 9cffed9

Please sign in to comment.