-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbuild.rs
More file actions
51 lines (41 loc) · 1.94 KB
/
build.rs
File metadata and controls
51 lines (41 loc) · 1.94 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
use std::env;
fn main() -> miette::Result<()> {
println!("cargo:rerun-if-env-changed=BUILD_INCLUDE_DIRS");
let include_dirs = env::var("BUILD_INCLUDE_DIRS")
.unwrap_or_else(|_| report_missing_build_vars_and_exit("BUILD_INCLUDE_DIRS"));
let mut include_dirs: Vec<_> = include_dirs.split(";").collect();
println!("cargo:rerun-if-env-changed=BUILD_CFLAGS");
let flags = env::var("BUILD_CFLAGS")
.unwrap_or_else(|_| report_missing_build_vars_and_exit("BUILD_CFLAGS"));
dbg!(&flags);
let flags = flags.split_ascii_whitespace();
let this_path = env::var("CARGO_MANIFEST_DIR").unwrap();
include_dirs.insert(0, this_path.as_str());
let mut b = autocxx_build::Builder::new("src/abi.rs", &include_dirs)
.extra_clang_args(&flags.clone().collect::<Vec<_>>())
.build()?;
for flag in flags {
b.flag(flag);
}
b.flag_if_supported("-std=c++14").compile("rustapp-ffi");
println!("cargo:rerun-if-changed=src/abi.rs");
println!("cargo:rerun-if-changed=src/abi.hpp");
Ok(())
}
fn report_missing_build_vars_and_exit(name: &str) -> ! {
eprint!(
r#"error: environment variable ${name} is not provided
This package needs to know the C++ compiler flags of your program to
automatically generate low-level Rust bindings.
You have to configure your SOLID-Rust project to pass C++ compiler flags to
Rust's build system. Open your '.ptrsproj' file by a text editor and add the
following code next to the 'ProjectGuid' element (make sure to replace
'< PROJECT >' with the name of a C++ project in your SOLID-IDE solution):
<CargoEnvironmentVariables>
BUILD_INCLUDE_DIRS=$expand:{{"projectName":"< PROJECT >", "type": "property", "query": "IncludePath"}}
BUILD_CFLAGS=$expand:{{"projectName":"< PROJECT >", "type": "property", "query": "GCCSW"}}
</CargoEnvironmentVariables>
"#
);
std::process::exit(1);
}