-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild.rs
38 lines (31 loc) · 1.17 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
use std::{env, path::PathBuf};
fn main() {
let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
if target_os.as_str() == "macos" {
compile_macos()
}
}
fn compile_macos() {
println!("cargo:rerun-if-changed=native/darwin/enumdisk.h");
println!("cargo:rerun-if-changed=native/darwin/enumdisk.m");
println!("cargo:rustc-link-search=native/darwin");
println!("cargo:rustc-link-lib=caliguladarwin");
let frameworks = ["Cocoa", "IOKit", "Foundation", "DiskArbitration"];
for f in frameworks {
println!("cargo:rustc-link-lib=framework={f}");
}
cc::Build::new()
.file("native/darwin/REDiskList.m")
.file("native/darwin/enumdisk.m")
.include("native/darwin")
.compile("libcaliguladarwin.a");
let bindings = bindgen::Builder::default()
.header("native/darwin/enumdisk.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("darwin_bindings.rs"))
.expect("Couldn't write bindings!");
}