Skip to content

Commit 7498f86

Browse files
authored
feat: add Cargo.toml and build.rs for Bazel workspaces (#3)
1 parent 164bff1 commit 7498f86

File tree

8 files changed

+2837
-45
lines changed

8 files changed

+2837
-45
lines changed

Cargo.lock

Lines changed: 2665 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[workspace]
2+
members = [
3+
"detector",
4+
"tracker",
5+
"examples",
6+
]
7+
resolver = "2"
8+
9+
[workspace.package]
10+
edition = "2021"
11+
description = "Pose Track with RTMO and ByteTrack"
12+
homepage = "https://github.com/wep21/tensorrt-rtmo-rust"
13+
license = "MIT OR Apache-2.0"
14+
authors = [
15+
"Daisuke Nishimatsu <daisuke.nishimatsu1021@gmail.com>",
16+
]
17+
readme = "README.md"
18+
repository = "https://github.com/wep21/tensorrt-rtmo-rus"
19+
rust-version = "1.81"
20+
version = "0.1.0"

MODULE.bazel

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -26,51 +26,20 @@ use_repo(rust, "rust_toolchains")
2626

2727
register_toolchains("@rust_toolchains//:all")
2828

29-
crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
30-
crate.spec(
31-
package = "image",
32-
version = "0.25.0",
29+
crate = use_extension(
30+
"@rules_rust//crate_universe:extensions.bzl",
31+
"crate",
3332
)
34-
crate.spec(
35-
features = ["ndarray"],
36-
package = "video-rs",
37-
version = "0.10.3",
38-
)
39-
crate.spec(
40-
package = "minifb",
41-
version = "0.28.0",
42-
)
43-
crate.spec(
44-
package = "thiserror",
45-
version = "2.0.12",
46-
)
47-
crate.spec(
48-
package = "nalgebra",
49-
version = "0.33.2",
50-
)
51-
crate.spec(
52-
package = "num",
53-
version = "0.4.3",
54-
)
55-
crate.spec(
56-
package = "nearly_eq",
57-
version = "0.2.4",
58-
)
59-
crate.spec(
60-
package = "quickcheck",
61-
version = "1.0.3",
62-
)
63-
crate.spec(
64-
package = "rand",
65-
version = "0.8.5",
66-
)
67-
crate.spec(
68-
package = "ab_glyph",
69-
version = "0.2.29",
70-
)
71-
crate.spec(
72-
package = "imageproc",
73-
version = "0.25.0",
33+
34+
crate.from_cargo(
35+
name = "crates",
36+
cargo_lockfile = "//:Cargo.lock",
37+
manifests = [
38+
"//:Cargo.toml",
39+
"//detector:Cargo.toml",
40+
"//examples:Cargo.toml",
41+
"//tracker:Cargo.toml",
42+
],
7443
)
7544
crate.annotation(
7645
build_script_env = dict(
@@ -84,7 +53,6 @@ crate.annotation(
8453
crate = "rav1e",
8554
repositories = ["crates"],
8655
)
87-
crate.from_specs()
8856
use_repo(crate, "crates")
8957

9058
bazel_dep(

detector/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "rtmo"
3+
version = { workspace = true }
4+
edition = { workspace = true }
5+
authors = { workspace = true }
6+
7+
[lib]
8+
name = "rtmo"
9+
path = "src/lib.rs"
10+
11+
[dependencies]
12+
cxx = "1.0.149"
13+
14+
[build-dependencies]
15+
cxx-build = "1.0.149"

detector/build.rs

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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("/usr");
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("/usr");
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+
}

detector/src/rtmo.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
#include "rtmo.hpp"
22

3+
#if __has_include("rtmo/src/rtmo.rs.h")
4+
#include "rtmo/src/rtmo.rs.h"
5+
#else
36
#include "rtmo.rs.h"
7+
#endif
48

59
namespace rtmo {
610
Rtmo::~Rtmo() {

examples/Cargo.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[package]
2+
name = "examples"
3+
version = { workspace = true }
4+
edition = { workspace = true }
5+
authors = { workspace = true }
6+
7+
[[bin]]
8+
name = "image_demo"
9+
path = "src/image_demo.rs"
10+
11+
[[bin]]
12+
name = "video_demo"
13+
path = "src/video_demo.rs"
14+
15+
[dependencies]
16+
rtmo = { path = "../detector" }
17+
tracker = { path = "../tracker" } # Needed by video_demo
18+
19+
cxx = "1.0.149"
20+
image = "0.25.0"
21+
ab_glyph = "0.2.29"
22+
imageproc = "0.25.0"
23+
minifb = "0.28.0"
24+
video-rs = { version = "0.10.3", features = ["ndarray"] }

tracker/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "tracker"
3+
version = { workspace = true }
4+
edition = { workspace = true }
5+
authors = { workspace = true }
6+
7+
[lib]
8+
name = "tracker"
9+
path = "src/lib.rs"
10+
11+
[dependencies]
12+
rtmo = { path = "../detector" }
13+
nalgebra = "0.33.2"
14+
num = "0.4.3"
15+
thiserror = "2.0.12"
16+
17+
[dev-dependencies]
18+
nearly_eq = "0.2.4"
19+
quickcheck = "1.0.3"
20+
rand = "0.8.5"

0 commit comments

Comments
 (0)