Add go bindings via C static library #23
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 aEvmoleContractInfoOptions
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:
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?