8000 GitHub - evanj/cgorustexample: Example of using Rust from Go with Cgo
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

evanj/cgorustexample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Using Rust from Go with Cgo: Example

This repository contains:

  • examplerustlib: A Rust library that doesn't do much
  • crustexe: A C program that links the Rust library
  • gorustmodule: A Go library that wraps examplerustlib in a Go API.
  • gorustexe:

This should build using make on Linux and Mac OS X, although I may have screwed stuff up.

Supported Rust Targets

Rust x86_64-unknown-linux-gnu = Go linux amd64 Rust aarch64-apple-darwin = Go darwin arm64

A Brief Tutorial

  • Rust: Use #[no_mangle] pub unsafe extern "C" on functions you want to export.
  • Rust: Add [lib] crate-type = ["lib", "staticlib"] to Cargo.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

About

Example of using Rust from Go with Cgo

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published
0