From 972794807ff654fbd10c1792350b2f171a6eee39 Mon Sep 17 00:00:00 2001 From: Levi Zim Date: Thu, 6 Feb 2025 22:50:39 +0800 Subject: [PATCH 1/3] Add dylib crate type --- Cargo.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 7a02a4f..a1a06ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,6 +12,9 @@ readme = "README.md" keywords = ["vsprintf", "sprintf", "printf", "va_list", "va_arg"] +[lib] +crate-type = ["rlib", "dylib"] + [dependencies] libc = "0.2" From 673c0704ddb197136eef23087092ae4338d6fcad Mon Sep 17 00:00:00 2001 From: Levi Zim Date: Thu, 6 Feb 2025 23:17:37 +0800 Subject: [PATCH 2/3] Explicitly set link lib and kind for vsnprintf_wrapper --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 97d99de..2fe15d5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,8 @@ pub unsafe fn vsprintf_raw(format: *const c_char, Ok(buffer) } -extern { +#[link(name = "vsprintf", kind = "static")] +extern "C" { fn vsnprintf_wrapper(buffer: *mut u8, size: size_t, format: *const c_char, From fad16d00ad5ff2b7b22dad910f102551984f37d8 Mon Sep 17 00:00:00 2001 From: Levi Zim Date: Thu, 6 Feb 2025 23:30:58 +0800 Subject: [PATCH 3/3] Rename c lib to avoid name collision The built dylib is libvsprintf.so, which could cause confusion with the static c lib. https://github.com/rust-lang/cargo/issues/6313 --- build.rs | 2 +- src/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/build.rs b/build.rs index c32e4e9..c720d16 100644 --- a/build.rs +++ b/build.rs @@ -3,6 +3,6 @@ fn main() { cc::Build::new() .file("src/lib.c") - .compile("libvsprintf.a"); + .compile("libvsprintf-c.a"); } diff --git a/src/lib.rs b/src/lib.rs index 2fe15d5..9177c0b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -67,7 +67,7 @@ pub unsafe fn vsprintf_raw(format: *const c_char, Ok(buffer) } -#[link(name = "vsprintf", kind = "static")] +#[link(name = "vsprintf-c", kind = "static")] extern "C" { fn vsnprintf_wrapper(buffer: *mut u8, size: size_t,