#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 个版本

0.1.0-alpha.22020年4月12日
0.1.0-alpha.12020年4月10日

#497 in 构建工具

Download history • Rust 包仓库 709/week @ 2024-04-14 • Rust 包仓库 602/week @ 2024-04-21 • Rust 包仓库 466/week @ 2024-04-28 • Rust 包仓库 1028/week @ 2024-05-05 • Rust 包仓库 1427/week @ 2024-05-12 • Rust 包仓库 833/week @ 2024-05-19 • Rust 包仓库 602/week @ 2024-05-26 • Rust 包仓库 562/week @ 2024-06-02 • Rust 包仓库 542/week @ 2024-06-09 • Rust 包仓库 775/week @ 2024-06-16 • Rust 包仓库 715/week @ 2024-06-23 • Rust 包仓库 317/week @ 2024-06-30 • Rust 包仓库 348/week @ 2024-07-07 • Rust 包仓库 712/week @ 2024-07-14 • Rust 包仓库 752/week @ 2024-07-21 • Rust 包仓库 560/week @ 2024-07-28 • Rust 包仓库

2,384 monthly downloads
用于 caddyfile-parser

MIT 许可证

18KB
317

gobuild

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

使用 gobuild

首先,你需要在你的crate中添加一个构建脚本(build.rs),并通过以下方式将这个crate添加到你的Cargo.toml中

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

然后,更新 build.rs 为以下内容

// build.rs

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

这将在 OUT_DIR 中生成 libhello.hlibhello.a


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"

示例

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.

依赖

~185KB