From 8479fb8ad3950915b38c68b7275aab896d66fe01 Mon Sep 17 00:00:00 2001 From: Ivan FB Date: Mon, 11 May 2026 21:25:05 +0200 Subject: [PATCH] =?UTF-8?q?fix=20build.rs=20is=20broken=20on=20Windows=20(?= =?UTF-8?q?rust.nim:112=E2=80=93115).=20lib=5Fext=20is=20only=20set=20unde?= =?UTF-8?q?r=20cfg(target=5Fos=20=3D=20"macos"|"linux").=20On=20Windows=20?= =?UTF-8?q?the=20symbol=20is=20undefined=20=E2=86=92=20compile=20error.=20?= =?UTF-8?q?The=20=20=20CMakeLists=20handles=20Windows;=20the=20Rust=20gene?= =?UTF-8?q?rator=20should=20either=20match=20or=20fail=20loudly.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- examples/nim_timer/rust_bindings/build.rs | 14 ++++++++++---- ffi/codegen/rust.nim | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/examples/nim_timer/rust_bindings/build.rs b/examples/nim_timer/rust_bindings/build.rs index b5b12a8..a6f0fd8 100644 --- a/examples/nim_timer/rust_bindings/build.rs +++ b/examples/nim_timer/rust_bindings/build.rs @@ -21,12 +21,18 @@ fn main() { } } + // Match the per-OS shared-library naming used by the CMakeLists: + // macOS: lib.dylib + // Linux: lib.so + // Windows: .dll (Cargo links the auto-generated .lib import lib) #[cfg(target_os = "macos")] - let lib_ext = "dylib"; + let out_lib = repo_root.join("libnimtimer.dylib"); #[cfg(target_os = "linux")] - let lib_ext = "so"; - - let out_lib = repo_root.join(format!("libnimtimer.{lib_ext}")); + let out_lib = repo_root.join("libnimtimer.so"); + #[cfg(target_os = "windows")] + let out_lib = repo_root.join("nimtimer.dll"); + #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))] + compile_error!("nim-ffi build.rs: unsupported target OS (expected macos, linux, or windows)"); let mut cmd = Command::new("nim"); cmd.arg("c") diff --git a/ffi/codegen/rust.nim b/ffi/codegen/rust.nim index 5236dfc..0d59327 100644 --- a/ffi/codegen/rust.nim +++ b/ffi/codegen/rust.nim @@ -109,12 +109,18 @@ fn main() { } } + // Match the per-OS shared-library naming used by the CMakeLists: + // macOS: lib.dylib + // Linux: lib.so + // Windows: .dll (Cargo links the auto-generated .lib import lib) #[cfg(target_os = "macos")] - let lib_ext = "dylib"; + let out_lib = repo_root.join("lib$2.dylib"); #[cfg(target_os = "linux")] - let lib_ext = "so"; - - let out_lib = repo_root.join(format!("lib$2.{lib_ext}")); + let out_lib = repo_root.join("lib$2.so"); + #[cfg(target_os = "windows")] + let out_lib = repo_root.join("$2.dll"); + #[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))] + compile_error!("nim-ffi build.rs: unsupported target OS (expected macos, linux, or windows)"); let mut cmd = Command::new("nim"); cmd.arg("c")