|
1 | | -fn main() { |
2 | | - #[cfg(feature = "cpp")] |
3 | | - { |
4 | | - use std::path::Path; |
| 1 | +//! Build script for `FastPFOR-rs`. |
5 | 2 |
|
6 | | - assert!( |
7 | | - Path::new("cpp/CMakeLists.txt").exists(), |
8 | | - "FastPFOR submodule not initialized. Run `git submodule update --init`." |
9 | | - ); |
| 3 | +/// Builds the C++ `FastPFOR` library and bridge when the `cpp` feature is enabled. |
| 4 | +#[cfg(feature = "cpp")] |
| 5 | +fn build_fastpfor() { |
| 6 | + use std::path::Path; |
10 | 7 |
|
11 | | - // Compile FastPFOR using CMake |
12 | | - println!("cargo:rerun-if-changed=cpp"); |
13 | | - let lib_path = cmake::Config::new("cpp") |
14 | | - .define("WITH_TEST", "OFF") |
15 | | - .build() |
16 | | - .join("lib"); |
17 | | - let lib_path = lib_path.to_str().unwrap(); |
| 8 | + assert!( |
| 9 | + Path::new("cpp/CMakeLists.txt").exists(), |
| 10 | + "FastPFOR submodule not initialized. Run `git submodule update --init`." |
| 11 | + ); |
18 | 12 |
|
19 | | - // Compile the bridge |
20 | | - println!("cargo:rerun-if-changed=src/cpp/fastpfor_bridge.h"); |
21 | | - println!("cargo:rerun-if-changed=src/cpp/mod.rs"); |
22 | | - cxx_build::bridge("src/cpp/mod.rs") |
23 | | - .include("cpp/headers") |
24 | | - .include("src/cpp") |
25 | | - .std("c++14") |
26 | | - .compile("fastpfor_bridge"); |
| 13 | + // Compile FastPFOR using CMake |
| 14 | + println!("cargo:rerun-if-changed=cpp"); |
| 15 | + let lib_path = cmake::Config::new("cpp") |
| 16 | + .define("WITH_TEST", "OFF") |
| 17 | + .build() |
| 18 | + .join("lib"); |
| 19 | + let lib_path = lib_path.to_str().unwrap(); |
27 | 20 |
|
28 | | - // Link the FastPFOR library - must be done after the bridge is compiled |
29 | | - println!("cargo:rustc-link-search=native={lib_path}"); |
30 | | - println!("cargo:rustc-link-lib=static=FastPFOR"); |
31 | | - } |
| 21 | + // Compile the bridge |
| 22 | + println!("cargo:rerun-if-changed=src/cpp/fastpfor_bridge.h"); |
| 23 | + println!("cargo:rerun-if-changed=src/cpp/mod.rs"); |
| 24 | + cxx_build::bridge("src/cpp/mod.rs") |
| 25 | + .include("cpp/headers") |
| 26 | + .include("src/cpp") |
| 27 | + .std("c++14") |
| 28 | + .compile("fastpfor_bridge"); |
| 29 | + |
| 30 | + // Link the FastPFOR library - must be done after the bridge is compiled |
| 31 | + println!("cargo:rustc-link-search=native={lib_path}"); |
| 32 | + println!("cargo:rustc-link-lib=static=FastPFOR"); |
| 33 | +} |
| 34 | + |
| 35 | +/// Build script entry point. |
| 36 | +fn main() { |
| 37 | + #[cfg(feature = "cpp")] |
| 38 | + build_fastpfor(); |
32 | 39 | } |
0 commit comments