#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

#459 in Build Utils

Download history 622/week @ 2024-09-04 597/week @ 2024-09-11 410/week @ 2024-09-18 472/week @ 2024-09-25 371/week @ 2024-10-02 484/week @ 2024-10-09 631/week @ 2024-10-16 622/week @ 2024-10-23 814/week @ 2024-10-30 581/week @ 2024-11-06 521/week @ 2024-11-13 513/week @ 2024-11-20 642/week @ 2024-11-27 849/week @ 2024-12-04 864/week @ 2024-12-11 584/week @ 2024-12-18

3,046 downloads per month
Used in caddyfile-parser

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–325KB