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

1
Cargo.lock generated
View file

@ -1386,6 +1386,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"backbone-lib", "backbone-lib",
"futures", "futures",
"getrandom 0.3.4",
"gloo-storage", "gloo-storage",
"leptos", "leptos",
"serde", "serde",

View file

@ -14,3 +14,6 @@ gloo-storage = "0.3"
[target.'cfg(target_arch = "wasm32")'.dependencies] [target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen-futures = "0.4" wasm-bindgen-futures = "0.4"
# getrandom 0.3 requires an explicit WASM backend; "wasm_js" uses window.crypto.getRandomValues.
# Must be a direct dependency (not just transitive) for the feature to take effect.
getrandom = { version = "0.3", features = ["wasm_js"] }

View file

@ -5,6 +5,9 @@ let
in in
{ {
packages = [ packages = [
# for Leptos
pkgs.trunk
# pkgs.wasm-bindgen-cli_0_2_114
# pour burn-rs # pour burn-rs
pkgs.SDL2_gfx pkgs.SDL2_gfx

View file

@ -8,6 +8,19 @@ shell:
devenv shell devenv shell
runcli: runcli:
RUST_LOG=info cargo run --bin=client_cli RUST_LOG=info cargo run --bin=client_cli
[working-directory: 'client_web/']
dev-leptos:
trunk serve
[working-directory: 'client_web']
build-leptos:
trunk build --release
cp dist/index.html /home/henri/travaux/programmes/forks/multiplayer/deploy/trictrac.html
cp dist/*.wasm /home/henri/travaux/programmes/forks/multiplayer/deploy/
cp dist/*.js /home/henri/travaux/programmes/forks/multiplayer/deploy/
cp dist/*.css /home/henri/travaux/programmes/forks/multiplayer/deploy/
runclibots: runclibots:
cargo run --bin=client_cli -- --bot random,dqnburn:./bot/models/burnrl_dqn_40.mpk cargo run --bin=client_cli -- --bot random,dqnburn:./bot/models/burnrl_dqn_40.mpk
#cargo run --bin=client_cli -- --bot dqn:./bot/models/dqn_model_final.json,dummy #cargo run --bin=client_cli -- --bot dqn:./bot/models/dqn_model_final.json,dummy

View file

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

View file

@ -1,7 +1,9 @@
fn main() { fn main() {
cxx_build::bridge("src/cxxengine.rs") if std::env::var("CARGO_FEATURE_CPP").is_ok() {
.std("c++17") cxx_build::bridge("src/cxxengine.rs")
.compile("trictrac-cxx"); .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; mod pyengine;
// C++ interface via cxx.rs (for OpenSpiel C++ integration) // C++ interface via cxx.rs (for OpenSpiel C++ integration)
#[cfg(feature = "cpp")]
pub mod cxxengine; pub mod cxxengine;