2 个版本
0.1.0-alpha.2 | 2020年4月12日 |
---|---|
0.1.0-alpha.1 | 2020年4月10日 |
#497 in 构建工具
2,384 monthly downloads
用于 caddyfile-parser
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.h
和 libhello.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