mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-14 03:58:18 +00:00
dcd76fd3e1
The glue is done using the [cxx crate](https://cxx.rs/) on the Rust side. As a proof-of-concept, only a small console command (`rust_version`) printing the currently used Rust version was added. You can generate and open the Rust documentation using `DDNET_TEST_NO_LINK=1 cargo doc --open`. You can run the Rust tests using `cmake --build <build dir> --target run_rust_tests`, they're automatically included in the `run_tests` target as well. Rust tests don't work on Windows in debug mode on Windows because Rust cannot currently link with the debug version of the C stdlib on Windows: https://github.com/rust-lang/rust/issues/39016. --- The stuff in `src/rust-bridge` is generated using ``` cxxbridge src/engine/shared/rust_version.rs --output src/rust-bridge/engine/shared/rust_version.cpp --output src/rust-bridge/engine/shared/rust_version.h cxxbridge src/engine/console.rs --output src/rust-bridge/cpp/console.cpp --output src/rust-bridge/cpp/console.h ```
19 lines
557 B
Rust
19 lines
557 B
Rust
use std::env;
|
|
use std::fs;
|
|
use std::path::PathBuf;
|
|
use std::process::Command;
|
|
|
|
fn main() {
|
|
let mut out = PathBuf::from(env::var_os("OUT_DIR").expect("OUT_DIR"));
|
|
out.push("rustc-version");
|
|
let rustc = env::var_os("RUSTC").expect("RUSTC");
|
|
let rustc_output = Command::new(rustc)
|
|
.arg("--version")
|
|
.output()
|
|
.expect("rustc --version");
|
|
if !rustc_output.status.success() {
|
|
panic!("rustc --version: exit status {}", rustc_output.status);
|
|
}
|
|
fs::write(&out, rustc_output.stdout).expect("file write");
|
|
}
|