This repository contains:
examplerustlib
: A Rust library that doesn't do muchcrustexe
: A C program that links the Rust librarygorustmodule
: A Go library that wrapsexamplerustlib
in a Go API.gorustexe
:
This should build using make
on Linux and Mac OS X, although I may have screwed stuff up.
Rust x86_64-unknown-linux-gnu = Go linux amd64 Rust aarch64-apple-darwin = Go darwin arm64
- Rust: Use
#[no_mangle] pub unsafe extern "C"
on functions you want to export. - Rust: Add
[lib] crate-type = ["lib", "staticlib"]
toCargo.toml
. - Copy the resulting shared library to a directory with Go code.
- Go: Add
// #cgo LDFLAGS: ${SRCDIR}/libexamplerustlib_linux_amd64.a
to a .go file with the appropriate build tags. - Rust: Run
rustup target add (targets)
to configure for cross-compilation: https://rust-lang.github.io/rustup/cross-compilation.html - Rust: Run
cargo build --target=(target)
to cross-compile