#build-dependencies #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

#571 in Build Utils

Download history 636/week @ 2025-04-08 661/week @ 2025-04-15 578/week @ 2025-04-22 527/week @ 2025-04-29 628/week @ 2025-05-06 591/week @ 2025-05-13 585/week @ 2025-05-20 399/week @ 2025-05-27 509/week @ 2025-06-03 453/week @ 2025-06-10 724/week @ 2025-06-17 578/week @ 2025-06-24 264/week @ 2025-07-01 367/week @ 2025-07-08 337/week @ 2025-07-15 254/week @ 2025-07-22

1,291 downloads per month

MIT license

18KB
317 lines

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.


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.

Dependencies

~205–300KB