#build-dependencies #compile #script #build-time #cargo #compiler #go

build gobuild

A build-time dependency for Cargo build scripts to invoke the go compiler to compile go code into a static archive/dynamic library to be linked into Rust code

2 releases

0.1.0-alpha.2 Apr 12, 2020
0.1.0-alpha.1 Apr 10, 2020

#711 in Build Utils

Download history 586/week @ 2024-11-16 541/week @ 2024-11-23 737/week @ 2024-11-30 879/week @ 2024-12-07 871/week @ 2024-12-14 151/week @ 2024-12-21 273/week @ 2024-12-28 666/week @ 2025-01-04 1189/week @ 2025-01-11 988/week @ 2025-01-18 1244/week @ 2025-01-25 851/week @ 2025-02-01 916/week @ 2025-02-08 642/week @ 2025-02-15 894/week @ 2025-02-22 544/week @ 2025-03-01

3,131 downloads per month

MIT license

18KB
317 lines

gobuild

A library to compile go code into a Rust library/application. This library takes inspiration from the cc crate.

Using gobuild

First, you'll want to both add a build script for your crate (build.rs) and also add this crate to your Cargo.toml via:

[build-dependencies]
gobuild = "0.1.0-alpha.1"

Next, update the build.rs to something like:

// build.rs

fn main() {
    gobuild::Build::new()
        .file("hello.go")
        .compile("hello");
}

This will produce a libhello.h and libhello.a in OUT_DIR.


lib.rs:

A library for build scripts to compile go Code. It's like the cc crate for go.

Add this library as a build-dependency in Cargo.toml:

[build-dependencies]
gobuild = "0.1.0-alpha.1"

Examples

Use the Build struct to compile hello.go:

fn main() {
    gobuild::Build::new()
        .file("hello.go")
        .compile("foo");
}

This will generate a libhello.h and libhello.a in OUT_DIR.

Consider combining this with bindgen to generate a Rust wrapper for the header.

Dependencies

~230–330KB