-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
45 lines (41 loc) · 1.32 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
use std::env;
fn main() {
// need to find a good default value for the compiler
let compiler = env::var("CXX").unwrap_or("g++".to_string());
// messy but works
let ompflags = if compiler.contains("clang++") {
// clang++ flavor
"-fopenmp=libomp"
} else if compiler.contains("g++") {
// g++ flavor
"-fopenmp"
} else {
unimplemented!()
};
cxx_build::bridge("src/lib.rs")
.compiler(compiler)
.file("src/cpp/hello.cpp")
.flag_if_supported("-std=c++20")
.flag(ompflags) // clang
.compile("poc-cc");
// --- linking shenanigans ---
match env::consts::OS {
"macos" => {
println!("cargo:rustc-link-arg=-L/opt/homebrew/opt/libomp/lib");
//println!("cargo:rustc-link-arg=-ld_classic");
println!("cargo:rustc-link-arg=-lomp");
}
"linux" => {
println!("cargo:rustc-link-arg=-I/usr/include");
println!("cargo:rustc-link-arg=-L/usr/lib");
println!("cargo:rustc-link-arg=-lgomp");
}
_ => unimplemented!(),
}
// main
println!("cargo:rerun-if-changed=src/main.rs");
// cpp files
println!("cargo:rerun-if-changed=src/cpp/hello.cpp");
// header files
println!("cargo:rerun-if-changed=src/include/hello.hpp");
}