-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.rs
More file actions
64 lines (54 loc) · 1.77 KB
/
build.rs
File metadata and controls
64 lines (54 loc) · 1.77 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
53
54
55
56
57
58
59
60
61
62
63
64
use std::path::{Path, PathBuf};
// from ocaml_build
pub struct Dune {
root: PathBuf,
library: PathBuf,
}
impl Dune {
pub fn new(library: impl AsRef<Path>) -> Dune {
Dune {
root: PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()),
library: library.as_ref().to_path_buf(),
}
}
pub fn with_root(mut self, root: impl AsRef<Path>) -> Dune {
self.root = root.as_ref().to_path_buf();
self
}
fn run(&self) {
// TODO: this builds every dune package in this repo everytime
// (including the ppx lib), we should make it only build the bindings
let c = std::process::Command::new("dune")
.current_dir(&self.root)
.arg("build")
// --root enforces dune to not search for a better dune project root
// if we don't do this dune freaks out when building via opam
.arg("--root")
.arg(".")
// for speed!
.arg("--profile")
.arg("release")
.status()
.unwrap();
assert!(c.success());
}
pub fn build(self) {
self.run();
let path = self.root.join("_build").join("default").join(&self.library);
let mut build = cc::Build::new();
for file in std::fs::read_dir(&path).unwrap() {
let file = file.unwrap();
let path = file.path();
if path.extension().map(|x| x.to_str().unwrap()) == Some("o") {
build.object(&path);
}
}
build.compile("ocaml");
}
}
pub fn main() {
// ensure rebuild if dependent ocaml libraries change
println!("cargo:rerun-if-changed=bindings");
println!("cargo:rerun-if-changed=lib");
Dune::new("bindings").build()
}