Skip to content

Add go bindings via C static library #23

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ngotchac
Copy link

@ngotchac ngotchac commented Apr 6, 2025

Might fix #5 ?

This adds the necessary bits on the Rust part to expose a very simple C library, which only exposes the evmole_contract_info method with a EvmoleContractInfoOptions struct for options. It reads the bytecode as a hex-encoded string, and outputs the result JSON-encoded.

On the go part, it links via CGO the built static libraries files, and wraps the C methods in a usable API, unmarshaling the JSON result into proper Go structs.

A test has been added which simply checks that it works correctly:

cd go
go test -count=1 -v ./test

I added the prebuilt static libraries, built via cargo-zigbuild so I could compile them for MacOS and Windows as well (I only have a Linux machine). I added the commands to a Makefile. I could only test for Linux on amd64.

Regarding the building of the static libraries, I'm not sure what the best approach is. They need to be comited to the Git repo (AFAIK), since Go is cloning it when adding new packages; there's no post-install step that could fetch them from releases from example. I don't know how it could be done in the CI, unless it commits some artifacts in the build process? Another solution might be to release the libraries in this repo, and have another one for the go version that commits those files?

ngotchac added 2 commits April 7, 2025 00:37
A new feature `c_api` can be used to add a C interface, that can later
be used from a static library build in other languages (eg. Go).
This Go version uses the static libraries, built via `cargo-zigbuild`
for an easy cross-platform setup.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implementation on pure go
1 participant