From 37c4bce0892f883b6b6dd4ff517639f92f4cb18f Mon Sep 17 00:00:00 2001 From: Thibault Saunier Date: Tue, 14 Mar 2023 15:39:04 -0300 Subject: [PATCH 1/2] Revert "Specify link attribute for Windows to be happy" This reverts commit a8dc21319bf6edaba19b2046ffd60c80fd91a2d7. Linking flags should be provided by the system-deps crate. Specifying linking with the attribute creates issue when statically linking system dependencies. --- src/codegen/sys/lib_.rs | 13 ------------- src/nameutil.rs | 29 ----------------------------- 2 files changed, 42 deletions(-) diff --git a/src/codegen/sys/lib_.rs b/src/codegen/sys/lib_.rs index c3f7b181f..abc97414d 100644 --- a/src/codegen/sys/lib_.rs +++ b/src/codegen/sys/lib_.rs @@ -25,18 +25,6 @@ pub fn generate(env: &Env) { save_to_file(&path, env.config.make_backup, |w| generate_lib(w, env)); } -fn write_link_attr(w: &mut dyn Write, shared_libs: &[String]) -> Result<()> { - for it in shared_libs { - writeln!( - w, - "#[link(name = \"{}\")]", - shared_lib_name_to_link_name(it) - )?; - } - - Ok(()) -} - fn generate_lib(w: &mut dyn Write, env: &Env) -> Result<()> { general::start_comments(w, &env.config)?; statics::begin(w)?; @@ -89,7 +77,6 @@ fn generate_lib(w: &mut dyn Write, env: &Env) -> Result<()> { } if !env.namespaces.main().shared_libs.is_empty() { - write_link_attr(w, &env.namespaces.main().shared_libs)?; writeln!(w, "extern \"C\" {{")?; functions::generate_enums_funcs(w, env, &enums)?; functions::generate_bitfields_funcs(w, env, &bitfields)?; diff --git a/src/nameutil.rs b/src/nameutil.rs index 9a5f6076d..09b2c85ef 100644 --- a/src/nameutil.rs +++ b/src/nameutil.rs @@ -129,25 +129,6 @@ pub fn lib_name_to_toml(name: &str) -> String { name.to_string().replace(['-', '.'], "_") } -pub fn shared_lib_name_to_link_name(name: &str) -> &str { - let mut s = name; - - if s.starts_with("lib") { - s = &s[3..]; - } - - if let Some(offset) = s.rfind(".so") { - s = &s[..offset]; - } else if let Some(offset) = s.rfind(".dll") { - s = &s[..offset]; - if let Some(offset) = s.rfind('-') { - s = &s[..offset]; - } - } - - s -} - pub fn use_glib_type(env: &crate::env::Env, import: &str) -> String { format!( "{}::{}", @@ -253,14 +234,4 @@ mod tests { fn lib_name_to_toml_works() { assert_eq!(lib_name_to_toml("gstreamer-1.0"), "gstreamer_1_0"); } - - #[test] - fn shared_lib_name_to_link_name_works() { - assert_eq!(shared_lib_name_to_link_name("libgtk-4-1.dll"), "gtk-4"); - assert_eq!(shared_lib_name_to_link_name("libatk-1.0.so.0"), "atk-1.0"); - assert_eq!( - shared_lib_name_to_link_name("libgdk_pixbuf-2.0.so.0"), - "gdk_pixbuf-2.0" - ); - } } From ea1ee40bf933e9330250cc4d35edd5c7cbbe5b36 Mon Sep 17 00:00:00 2001 From: eri Date: Wed, 18 Sep 2024 10:48:38 +0200 Subject: [PATCH 2/2] dont override build script in cargo.toml --- src/codegen/sys/cargo_toml.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/codegen/sys/cargo_toml.rs b/src/codegen/sys/cargo_toml.rs index fab07dd35..ccfccb1be 100644 --- a/src/codegen/sys/cargo_toml.rs +++ b/src/codegen/sys/cargo_toml.rs @@ -99,7 +99,9 @@ fn fill_empty(root: &mut Table, env: &Env, crate_name: &str) { fn fill_in(root: &mut Table, env: &Env) { { let package = upsert_table(root, "package"); - set_string(package, "build", "build.rs"); + package + .entry("build") + .or_insert_with(|| Value::String("build.rs".into())); // set_string(package, "version", "0.2.0"); }