-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
74 lines (66 loc) · 2.63 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use cmake::Config;
fn main() {
let cfg = Config::new("third_party/protobuf")
.define("protobuf_BUILD_TESTS", "OFF")
.define("protobuf_WITH_ZLIB", "OFF")
.define("protobuf_BUILD_CONFORMANCE", "ON")
.define("CMAKE_CXX_STANDARD", "17")
.define("CMAKE_BUILD_TYPE", "Release")
.define("BUILD_SHARED_LIBS", "OFF")
.build();
let out_dir = std::env::var_os("OUT_DIR").expect("OUT_DIR");
let out_dir = out_dir.to_str().expect("msg");
let mut b = autocxx_build::Builder::new(
"src/ffi.rs",
&["include", &format!("{}/include", cfg.display())],
)
.build()
.unwrap();
b.cpp(true)
.std("c++17")
.file("include/runner.h")
.file("include/runner.cc")
.file("include/gen.h")
.file("include/gen.cc")
.include(format!("{}/include", cfg.display()))
.include("third_party/protobuf")
.static_flag(true)
.out_dir(&out_dir)
.compile("conformance");
// Rebuild
println!("cargo:rerun-if-changed=src/ffi.rs");
println!("cargo:rerun-if-changed=include/gen.h");
println!("cargo:rerun-if-changed=include/gen.cc");
println!("cargo:rerun-if-changed=include/runner.h");
println!("cargo:rerun-if-changed=include/runner.cc");
// Linking
for f in cfg.join("lib").read_dir().unwrap().into_iter() {
let f = f.unwrap().file_name().to_str().unwrap().to_string();
if f.starts_with("libabsl") && f.ends_with(".a") {
println!(
"cargo:rustc-link-lib=static={}",
f.strip_prefix("lib").unwrap().strip_suffix(".a").unwrap()
);
}
}
println!("cargo:rustc-link-search=native={}/build/lib", cfg.display());
println!("cargo:rustc-link-lib=static=conformance_common");
println!("cargo:rustc-link-search=native={}/lib", cfg.display());
println!("cargo:rustc-link-lib=static=protobuf");
println!("cargo:rustc-link-lib=static=jsoncpp");
println!("cargo:rustc-link-lib=static=utf8_range");
println!("cargo:rustc-link-lib=static=utf8_validity");
println!("cargo:rustc-link-search=native={}", &out_dir.to_string());
println!("cargo:rustc-link-lib=conformance");
println!("cargo:warning={}", &out_dir.to_string());
// Proto
protobuf_codegen::Codegen::new()
.protoc()
.include("third_party/protobuf/conformance")
.include("include")
.input("third_party/protobuf/conformance/conformance.proto")
.input("include/test_messages_proto3.proto")
.input("include/test_messages_proto2.proto")
.cargo_out_dir("conformance")
.run_from_script();
}