refact: add cargo cxx feature

This commit is contained in:
Henri Bourcereau 2026-03-25 20:16:46 +01:00
parent 35d0b5cfb9
commit 3474d20d9b
7 changed files with 30 additions and 5 deletions

View file

@ -15,11 +15,13 @@ crate-type = ["cdylib", "rlib", "staticlib"]
[features]
# Enable Python bindings (required for maturin / AI training). Not available on wasm32.
python = ["pyo3"]
# Enable C++ bridge for OpenSpiel integration. Not available on wasm32.
cpp = ["dep:cxx"]
[dependencies]
anyhow = "1.0"
base64 = "0.21.7"
cxx = "1.0"
cxx = { version = "1.0", optional = true }
# provides macros for creating log messages to be used by a logger (for example env_logger)
log = "0.4.20"
merge = "0.1.0"

View file

@ -1,7 +1,9 @@
fn main() {
cxx_build::bridge("src/cxxengine.rs")
.std("c++17")
.compile("trictrac-cxx");
if std::env::var("CARGO_FEATURE_CPP").is_ok() {
cxx_build::bridge("src/cxxengine.rs")
.std("c++17")
.compile("trictrac-cxx");
println!("cargo:rerun-if-changed=src/cxxengine.rs");
println!("cargo:rerun-if-changed=src/cxxengine.rs");
}
}

View file

@ -24,4 +24,5 @@ pub mod training_common;
mod pyengine;
// C++ interface via cxx.rs (for OpenSpiel C++ integration)
#[cfg(feature = "cpp")]
pub mod cxxengine;