Skip to content

feat: add Cargo.toml and build.rs for Bazel workspaces #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,665 changes: 2,665 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[workspace]
members = [
"detector",
"tracker",
"examples",
]
resolver = "2"

[workspace.package]
edition = "2021"
description = "Pose Track with RTMO and ByteTrack"
homepage = "https://github.com/wep21/tensorrt-rtmo-rust"
license = "MIT OR Apache-2.0"
authors = [
"Daisuke Nishimatsu <daisuke.nishimatsu1021@gmail.com>",
]
readme = "README.md"
repository = "https://github.com/wep21/tensorrt-rtmo-rus"
rust-version = "1.81"
version = "0.1.0"
58 changes: 13 additions & 45 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -26,51 +26,20 @@ use_repo(rust, "rust_toolchains")

register_toolchains("@rust_toolchains//:all")

crate = use_extension("@rules_rust//crate_universe:extensions.bzl", "crate")
crate.spec(
package = "image",
version = "0.25.0",
crate = use_extension(
"@rules_rust//crate_universe:extensions.bzl",
"crate",
)
crate.spec(
features = ["ndarray"],
package = "video-rs",
version = "0.10.3",
)
crate.spec(
package = "minifb",
version = "0.28.0",
)
crate.spec(
package = "thiserror",
version = "2.0.12",
)
crate.spec(
package = "nalgebra",
version = "0.33.2",
)
crate.spec(
package = "num",
version = "0.4.3",
)
crate.spec(
package = "nearly_eq",
version = "0.2.4",
)
crate.spec(
package = "quickcheck",
version = "1.0.3",
)
crate.spec(
package = "rand",
version = "0.8.5",
)
crate.spec(
package = "ab_glyph",
version = "0.2.29",
)
crate.spec(
package = "imageproc",
version = "0.25.0",

crate.from_cargo(
name = "crates",
cargo_lockfile = "//:Cargo.lock",
manifests = [
"//:Cargo.toml",
"//detector:Cargo.toml",
"//examples:Cargo.toml",
"//tracker:Cargo.toml",
],
)
crate.annotation(
build_script_env = dict(
Expand All @@ -84,7 +53,6 @@ crate.annotation(
crate = "rav1e",
repositories = ["crates"],
)
crate.from_specs()
use_repo(crate, "crates")

bazel_dep(
Expand Down
15 changes: 15 additions & 0 deletions detector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "rtmo"
version = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }

[lib]
name = "rtmo"
path = "src/lib.rs"

[dependencies]
cxx = "1.0.149"

[build-dependencies]
cxx-build = "1.0.149"
76 changes: 76 additions & 0 deletions detector/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use std::path::PathBuf;

fn main() {
println!("cargo:rerun-if-changed=src/rtmo.rs");
println!("cargo:rerun-if-changed=src/engine.cpp");
println!("cargo:rerun-if-changed=src/engine.hpp");
println!("cargo:rerun-if-changed=src/rtmo.cpp");
println!("cargo:rerun-if-changed=src/rtmo.hpp");

let manifest_dir = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
let workspace_root = manifest_dir.parent().unwrap_or(&manifest_dir); // Assuming detector is one level down from workspace root

// --- CUDA ---
// These are common paths. Adjust if your CUDA installation is different.
let cuda_include_path = PathBuf::from("/usr/local/cuda/include");
let cuda_lib_path = PathBuf::from("/usr/local/cuda/lib64");
println!("cargo:rustc-link-search=native={}", cuda_lib_path.display());
println!("cargo:rustc-link-lib=dylib=cudart"); // Link against CUDA runtime

// --- TensorRT ---
// Path relative to workspace root.
let tensorrt_base_path = workspace_root.join("/usr");
let tensorrt_include_path = tensorrt_base_path.join("include/x86_64-linux-gnu");
let tensorrt_lib_path = tensorrt_base_path.join("lib/x86_64-linux-gnu");

println!("cargo:rustc-link-search=native={}", tensorrt_lib_path.display());
println!("cargo:rustc-link-lib=dylib=nvinfer");
println!("cargo:rustc-link-lib=dylib=nvinfer_plugin");

// --- CVCUDA ---
// Path relative to workspace root.
let cvcuda_base_path = workspace_root.join("/usr");
let cvcuda_include_path = cvcuda_base_path.join("include");
let cvcuda_lib_path = cvcuda_base_path.join("lib");

println!("cargo:rustc-link-search=native={}", cvcuda_lib_path.display());
println!("cargo:rustc-link-lib=dylib=cvcuda");
println!("cargo:rustc-link-lib=dylib=nvcv_types");


// --- Build C++ files using cxx_build ---
let mut build = cxx_build::bridge("src/rtmo.rs"); // Path to the Rust file with CXX bridge
build
.file("src/engine.cpp")
.file("src/rtmo.cpp")
.include(&manifest_dir.join("src")) // for engine.hpp, rtmo.hpp
.include(&cuda_include_path)
.include(&tensorrt_include_path)
.include(&cvcuda_include_path)
.flag_if_supported("-std=c++17") // Assuming C++17, adjust if necessary
.flag_if_supported("-pthread"); // For TensorRT plugins

// Add any other necessary compiler flags or definitions
// e.g., .define("SOME_MACRO", "value")

// Linker arguments for specific libraries if needed (beyond simple -l flags)
// For TensorRT plugin, Bazel had: linkopts = ["-lpthread", "-Wl,--no-as-needed -ldl -lrt -Wl,--as-needed"]
// The -lpthread is covered by cargo:rustc-link-lib=pthread if cc crate doesn't add it.
// The cc crate usually handles pthread implicitly if specified with .flag("-pthread") for compiler and linker.
// Let's ensure pthread is linked.
println!("cargo:rustc-link-lib=dylib=pthread");
// For dlsym, rt_timer related symbols which might be needed by TensorRT
println!("cargo:rustc-link-lib=dylib=dl");
println!("cargo:rustc-link-lib=dylib=rt");


build.compile("rtmo_cpp_bridge");

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.");
println!("cargo:warning=CUDA include path: {}", cuda_include_path.display());
println!("cargo:warning=CUDA lib path: {}", cuda_lib_path.display());
println!("cargo:warning=TensorRT include path: {}", tensorrt_include_path.display());
println!("cargo:warning=TensorRT lib path: {}", tensorrt_lib_path.display());
println!("cargo:warning=CVCUDA include path: {}", cvcuda_include_path.display());
println!("cargo:warning=CVCUDA lib path: {}", cvcuda_lib_path.display());
}
4 changes: 4 additions & 0 deletions detector/src/rtmo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#include "rtmo.hpp"

#if __has_include("rtmo/src/rtmo.rs.h")
#include "rtmo/src/rtmo.rs.h"
#else
#include "rtmo.rs.h"
#endif

namespace rtmo {
Rtmo::~Rtmo() {
Expand Down
24 changes: 24 additions & 0 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "examples"
version = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }

[[bin]]
name = "image_demo"
path = "src/image_demo.rs"

[[bin]]
name = "video_demo"
path = "src/video_demo.rs"

[dependencies]
rtmo = { path = "../detector" }
tracker = { path = "../tracker" } # Needed by video_demo

cxx = "1.0.149"
image = "0.25.0"
ab_glyph = "0.2.29"
imageproc = "0.25.0"
minifb = "0.28.0"
video-rs = { version = "0.10.3", features = ["ndarray"] }
20 changes: 20 additions & 0 deletions tracker/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "tracker"
version = { workspace = true }
edition = { workspace = true }
authors = { workspace = true }

[lib]
name = "tracker"
path = "src/lib.rs"

[dependencies]
rtmo = { path = "../detector" }
nalgebra = "0.33.2"
num = "0.4.3"
thiserror = "2.0.12"

[dev-dependencies]
nearly_eq = "0.2.4"
quickcheck = "1.0.3"
rand = "0.8.5"