|
| 1 | +use std::path::PathBuf; |
| 2 | + |
| 3 | +fn main() { |
| 4 | + println!("cargo:rerun-if-changed=src/rtmo.rs"); |
| 5 | + println!("cargo:rerun-if-changed=src/engine.cpp"); |
| 6 | + println!("cargo:rerun-if-changed=src/engine.hpp"); |
| 7 | + println!("cargo:rerun-if-changed=src/rtmo.cpp"); |
| 8 | + println!("cargo:rerun-if-changed=src/rtmo.hpp"); |
| 9 | + |
| 10 | + let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()); |
| 11 | + let workspace_root = manifest_dir.parent().unwrap_or(&manifest_dir); // Assuming detector is one level down from workspace root |
| 12 | + |
| 13 | + // --- CUDA --- |
| 14 | + // These are common paths. Adjust if your CUDA installation is different. |
| 15 | + let cuda_include_path = PathBuf::from("/usr/local/cuda/include"); |
| 16 | + let cuda_lib_path = PathBuf::from("/usr/local/cuda/lib64"); |
| 17 | + println!("cargo:rustc-link-search=native={}", cuda_lib_path.display()); |
| 18 | + println!("cargo:rustc-link-lib=dylib=cudart"); // Link against CUDA runtime |
| 19 | + |
| 20 | + // --- TensorRT --- |
| 21 | + // Path relative to workspace root. |
| 22 | + let tensorrt_base_path = workspace_root.join("repositories/tensorrt"); |
| 23 | + let tensorrt_include_path = tensorrt_base_path.join("include/x86_64-linux-gnu"); |
| 24 | + let tensorrt_lib_path = tensorrt_base_path.join("lib/x86_64-linux-gnu"); |
| 25 | + |
| 26 | + println!("cargo:rustc-link-search=native={}", tensorrt_lib_path.display()); |
| 27 | + println!("cargo:rustc-link-lib=dylib=nvinfer"); |
| 28 | + println!("cargo:rustc-link-lib=dylib=nvinfer_plugin"); |
| 29 | + |
| 30 | + // --- CVCUDA --- |
| 31 | + // Path relative to workspace root. |
| 32 | + let cvcuda_base_path = workspace_root.join("repositories/cvcuda"); |
| 33 | + let cvcuda_include_path = cvcuda_base_path.join("include"); |
| 34 | + let cvcuda_lib_path = cvcuda_base_path.join("lib"); |
| 35 | + |
| 36 | + println!("cargo:rustc-link-search=native={}", cvcuda_lib_path.display()); |
| 37 | + println!("cargo:rustc-link-lib=dylib=cvcuda"); |
| 38 | + println!("cargo:rustc-link-lib=dylib=nvcv_types"); |
| 39 | + |
| 40 | + |
| 41 | + // --- Build C++ files using cxx_build --- |
| 42 | + let mut build = cxx_build::bridge("src/rtmo.rs"); // Path to the Rust file with CXX bridge |
| 43 | + build |
| 44 | + .file("src/engine.cpp") |
| 45 | + .file("src/rtmo.cpp") |
| 46 | + .include(&manifest_dir.join("src")) // for engine.hpp, rtmo.hpp |
| 47 | + .include(&cuda_include_path) |
| 48 | + .include(&tensorrt_include_path) |
| 49 | + .include(&cvcuda_include_path) |
| 50 | + .flag_if_supported("-std=c++17") // Assuming C++17, adjust if necessary |
| 51 | + .flag_if_supported("-pthread"); // For TensorRT plugins |
| 52 | + |
| 53 | + // Add any other necessary compiler flags or definitions |
| 54 | + // e.g., .define("SOME_MACRO", "value") |
| 55 | + |
| 56 | + // Linker arguments for specific libraries if needed (beyond simple -l flags) |
| 57 | + // For TensorRT plugin, Bazel had: linkopts = ["-lpthread", "-Wl,--no-as-needed -ldl -lrt -Wl,--as-needed"] |
| 58 | + // The -lpthread is covered by cargo:rustc-link-lib=pthread if cc crate doesn't add it. |
| 59 | + // The cc crate usually handles pthread implicitly if specified with .flag("-pthread") for compiler and linker. |
| 60 | + // Let's ensure pthread is linked. |
| 61 | + println!("cargo:rustc-link-lib=dylib=pthread"); |
| 62 | + // For dlsym, rt_timer related symbols which might be needed by TensorRT |
| 63 | + println!("cargo:rustc-link-lib=dylib=dl"); |
| 64 | + println!("cargo:rustc-link-lib=dylib=rt"); |
| 65 | + |
| 66 | + |
| 67 | + build.compile("rtmo_cpp_bridge"); |
| 68 | + |
| 69 | + println!("cargo:warning=This build.rs attempts to compile C++ dependencies. Ensure CUDA, TensorRT, and CVCUDA are correctly installed and paths are configured if issues arise."); |
| 70 | + println!("cargo:warning=CUDA include path: {}", cuda_include_path.display()); |
| 71 | + println!("cargo:warning=CUDA lib path: {}", cuda_lib_path.display()); |
| 72 | + println!("cargo:warning=TensorRT include path: {}", tensorrt_include_path.display()); |
| 73 | + println!("cargo:warning=TensorRT lib path: {}", tensorrt_lib_path.display()); |
| 74 | + println!("cargo:warning=CVCUDA include path: {}", cvcuda_include_path.display()); |
| 75 | + println!("cargo:warning=CVCUDA lib path: {}", cvcuda_lib_path.display()); |
| 76 | +} |
0 commit comments