Skip to content

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.
@cdump
Copy link
Owner

cdump commented Apr 25, 2025

I took a look at two of your approaches and I have to say, I like #10 much more. It seems to have more pros than cons compared to the current cgo variant.

I tried updating your #10 to the new API with contract_info, and it looks like it's working. I'll probably add this to the backlog and include it here.

Thanks for showing two different approaches - it really helps to understand the pros and cons of each one.

@ngotchac
Copy link
Author

I actually found that using the C-bindings was much simpler than I expected. My only gripe is that the static libs are quite big, and I'm not sure whether this could be improved. I tried adding no_std capibilities to evmole, but the size didn't reduce by much... I'll let you choose though, let me know if/how I can help :)

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

2 participants