-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
54 lines (48 loc) · 1.99 KB
/
build.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
use std::path::PathBuf;
use std::{env, fs, process::Command};
fn main() {
println!("cargo:rerun-if-changed=src/go");
env::set_current_dir("src/go").unwrap();
let out_dir = env::var("OUT_DIR").unwrap();
let out_path = PathBuf::from(&out_dir);
// The docs.rs builder blocks network access, which would require vendoring everything. I don't
// want to go through that hassle right now, so just generate a dummy file to allow the docs to
// build.
if env::var("DOCS_RS").is_ok() {
fs::write(out_path.join("bindings.rs"), "").unwrap();
return;
}
let status = Command::new("go")
.args(["build", "-buildmode=c-archive", "-o"])
.arg(&format!("{out_dir}/libhusk.a"))
.arg("main.go")
.status()
.expect("`go build` failed. Is `go` installed and on the latest version?");
if !status.success() {
panic!("`go build` failed. Is `go` on the latest version?");
}
env::set_current_dir("../../").unwrap();
println!("cargo:rustc-link-search=native={out_dir}");
println!("cargo:rustc-link-lib=static=husk");
let bindings = bindgen::Builder::default()
.header(format!("{out_dir}/libhusk.h"))
.allowlist_function("HuskDeleteGoItem")
.allowlist_function("HuskGetCStringFromArray")
.allowlist_function("HuskShellExpand")
.allowlist_function("HuskShellFields")
.allowlist_function("HuskSyntaxIsKeyword")
.allowlist_function("HuskSyntaxNewParser")
.allowlist_function("HuskSyntaxNewPos")
.allowlist_function("HuskSyntaxPosAfter")
.allowlist_function("HuskSyntaxPosCol")
.allowlist_function("HuskSyntaxPosIsValid")
.allowlist_function("HuskSyntaxPosLine")
.allowlist_function("HuskSyntaxPosOffset")
.allowlist_function("HuskSyntaxQuote")
.allowlist_function("HuskSyntaxValidName")
.generate()
.unwrap();
bindings
.write_to_file(out_path.join("bindings.rs"))
.unwrap();
}