Repository navigation
Expand file tree
/
Copy pathbuild.rs
More file actions
52 lines (44 loc) · 1.44 KB
/
Copy pathbuild.rs
File metadata and controls
52 lines (44 loc) · 1.44 KB
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
#[cfg(not(feature = "_docsrs"))]
use std::fs;
#[cfg(not(feature = "_docsrs"))]
use std::path::Path;
#[cfg(not(feature = "_docsrs"))]
use std::time::SystemTime;
#[cfg(not(feature = "_docsrs"))]
macro_rules! watch_files {
($($p:literal),* $(,)?) => {
$(println!("cargo:rerun-if-changed={}", $p);)*
};
}
#[cfg(not(feature = "_docsrs"))]
fn modified(path: &Path) -> Option<SystemTime> {
fs::metadata(path).ok()?.modified().ok()
}
#[cfg(not(feature = "_docsrs"))]
fn should_regen(src: &Path, dst: &Path) -> Option<bool> {
Some(modified(src)? > modified(dst)?)
}
// Allow docs.rs to build without golang or r2g dependency
#[cfg(not(feature = "_docsrs"))]
fn build() {
// Ensure build script reruns when Rust API definitions change.
watch_files!("src", "go/go.sum", "go/go.mod", "go/impl.go",);
let mut builder = rust2go::Builder::new()
.with_go_src("go")
// Use dynamic linking, as we don't expect to run envtest outside of local tests use case
.with_link(rust2go::LinkType::Dynamic);
let src = Path::new("./src/lib.rs");
let dst = Path::new("./go/gen.go");
if let Some(true) | None = should_regen(src, dst) {
builder = builder.with_regen_arg(rust2go::RegenArgs {
src: src.display().to_string(),
dst: dst.display().to_string(),
..Default::default()
});
}
builder.build();
}
fn main() {
#[cfg(not(feature = "_docsrs"))]
build();
}