From c7293608bda409f2cf7ed2da3867a7b8d54fc9f1 Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Sun, 22 Dec 2024 16:45:22 +0800 Subject: [PATCH] fix: build error on `docs.rs` --- src/core_ffi/rust_ffi/build.rs | 38 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/core_ffi/rust_ffi/build.rs b/src/core_ffi/rust_ffi/build.rs index bd39b8b..e4e5af7 100644 --- a/src/core_ffi/rust_ffi/build.rs +++ b/src/core_ffi/rust_ffi/build.rs @@ -7,25 +7,29 @@ use cxx_build::CFG; +// TODO: assert version info + fn main() { - cmake::Config::new("klotski") - .define("CARGO_BUILD:BOOL", "ON") - .define("KLSK_ENABLE_TESTING:BOOL", "OFF") - .define("KLSK_ENABLE_BENCHMARK:BOOL", "OFF") - .define("KLSK_C_FFI:BOOL", "OFF") - .define("KLSK_PYTHON_FFI:BOOL", "OFF") - .build(); - println!("cargo:rustc-link-lib=static=klotski_core"); + if std::env::var("DOCS_RS").is_err() { + cmake::Config::new("klotski") + .define("CARGO_BUILD:BOOL", "ON") + .define("KLSK_ENABLE_TESTING:BOOL", "OFF") + .define("KLSK_ENABLE_BENCHMARK:BOOL", "OFF") + .define("KLSK_C_FFI:BOOL", "OFF") + .define("KLSK_PYTHON_FFI:BOOL", "OFF") + .build(); + println!("cargo:rustc-link-lib=static=klotski_core"); - CFG.include_prefix = "rust_ffi"; - cxx_build::bridge("src/bridge.rs") - .file("adapter/short_code.cc") - .file("adapter/common_code.cc") - .include("klotski/src/core") - .flag("-std=c++23") - .flag("-fno-rtti") - .flag("-fno-exceptions") - .compile("klotski"); + CFG.include_prefix = "rust_ffi"; + cxx_build::bridge("src/bridge.rs") + .file("adapter/short_code.cc") + .file("adapter/common_code.cc") + .include("klotski/src/core") + .flag("-std=c++23") + .flag("-fno-rtti") + .flag("-fno-exceptions") + .compile("klotski"); + } println!("cargo:rerun-if-changed=src/bridge.rs"); println!("cargo:rerun-if-changed=adapter/short_code.cc");