From bb09463f043b5ca93fa3c4446e8246f1f77be38e Mon Sep 17 00:00:00 2001 From: eri Date: Wed, 18 Sep 2024 10:33:02 +0200 Subject: [PATCH] detect static library and regenerate gir --- Cargo.lock | 1 - gdk-pixbuf/src/auto/versions.txt | 2 +- gdk-pixbuf/sys/versions.txt | 2 +- gio/src/auto/versions.txt | 2 +- gio/sys/versions.txt | 2 +- gir | 2 +- glib/gobject-sys/Cargo.toml | 7 +++++-- glib/gobject-sys/build_manual.rs | 23 +++++++++++++++++++++++ glib/gobject-sys/src/manual.rs | 18 ++++++++++++------ glib/gobject-sys/versions.txt | 2 +- glib/src/auto/versions.txt | 2 +- glib/sys/Cargo.toml | 10 ---------- glib/sys/versions.txt | 2 +- graphene/src/auto/versions.txt | 2 +- graphene/sys/versions.txt | 2 +- pango/src/auto/versions.txt | 2 +- pango/sys/versions.txt | 2 +- pangocairo/src/auto/versions.txt | 2 +- pangocairo/sys/versions.txt | 2 +- 19 files changed, 54 insertions(+), 33 deletions(-) create mode 100644 glib/gobject-sys/build_manual.rs diff --git a/Cargo.lock b/Cargo.lock index d0ccb47a2a2a..fa2a2b891ba3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -527,7 +527,6 @@ version = "0.21.0" dependencies = [ "glib-sys", "libc", - "pkg-config", "shell-words", "system-deps", "tempfile", diff --git a/gdk-pixbuf/src/auto/versions.txt b/gdk-pixbuf/src/auto/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/gdk-pixbuf/src/auto/versions.txt +++ b/gdk-pixbuf/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/gdk-pixbuf/sys/versions.txt b/gdk-pixbuf/sys/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/gdk-pixbuf/sys/versions.txt +++ b/gdk-pixbuf/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/gio/src/auto/versions.txt b/gio/src/auto/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/gio/src/auto/versions.txt +++ b/gio/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/gio/sys/versions.txt b/gio/sys/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/gio/sys/versions.txt +++ b/gio/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/gir b/gir index f0a4546b0a06..37c4bce0892f 160000 --- a/gir +++ b/gir @@ -1 +1 @@ -Subproject commit f0a4546b0a065befe300e26c93029881978fde21 +Subproject commit 37c4bce0892f883b6b6dd4ff517639f92f4cb18f diff --git a/glib/gobject-sys/Cargo.toml b/glib/gobject-sys/Cargo.toml index 82e296d10c53..fb2c44740b5e 100644 --- a/glib/gobject-sys/Cargo.toml +++ b/glib/gobject-sys/Cargo.toml @@ -1,6 +1,5 @@ [build-dependencies] system-deps = "7" -pkg-config = "0.3" [dependencies] libc = "0.2" @@ -29,7 +28,7 @@ v2_82 = ["v2_80"] name = "gobject_sys" [package] -build = "build.rs" +build = "build_manual.rs" description = "FFI bindings to libgobject-2.0" keywords = ["gobject", "ffi", "gtk-rs", "gnome"] name = "gobject-sys" @@ -99,3 +98,7 @@ version = "2.81" rustc-args = ["--cfg", "docsrs"] rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] all-features = true + +[lints.rust.unexpected_cfgs] +level = "warn" +check-cfg = ['cfg(msvc_dll)'] diff --git a/glib/gobject-sys/build_manual.rs b/glib/gobject-sys/build_manual.rs new file mode 100644 index 000000000000..2b89af2a9f03 --- /dev/null +++ b/glib/gobject-sys/build_manual.rs @@ -0,0 +1,23 @@ +#[cfg(docsrs)] +fn main() {} // prevent linking libraries to avoid documentation failure + +#[cfg(not(docsrs))] +fn main() { + match system_deps::Config::new().probe() { + Ok(deps) => { + let msvc = std::env::var("CARGO_CFG_TARGET_ENV") + .expect("Cargo should set this variable") + == "msvc"; + let lib = deps + .get_by_name("gobject_2_0") + .expect("The dependency key for gobject in its Cargo.toml should not change"); + if msvc && !lib.statik { + println!("cargo:rustc-cfg=msvc_dll"); + } + } + Err(s) => { + println!("cargo:warning={s}"); + std::process::exit(1); + } + } +} diff --git a/glib/gobject-sys/src/manual.rs b/glib/gobject-sys/src/manual.rs index f78079f17e8e..b700b781da45 100644 --- a/glib/gobject-sys/src/manual.rs +++ b/glib/gobject-sys/src/manual.rs @@ -1,24 +1,30 @@ use glib_sys::GType; -#[cfg(not(target_os = "windows"))] +#[cfg(not(msvc_dll))] type GParamSpecType = *const GType; -#[cfg(target_os = "windows")] +#[cfg(msvc_dll)] type GParamSpecType = *const *const GType; +// When using MSVC, variables marked with dllexport only have the load time linking version +// (prefixed by `__imp_`) publicly exported in the library. This means that it is necessary to either +// call dllimport those symbols (in Rust, this only happens when using the `#[link]` attribute), or +// to manually link to the `__imp_` version when using dynamic libraries. Since we need more customization +// of the library name than the link attribute currently allows, we choose the second option. extern "C" { - #[cfg_attr(target_os = "windows", link_name = "__imp_g_param_spec_types")] + #[cfg_attr(msvc_dll, link_name = "__imp_g_param_spec_types")] static g_param_spec_types: GParamSpecType; } /// # Safety /// This should be safe as long as the offset added to g_param_spec_types is in bounds. pub unsafe fn g_param_spec_types_get_type(offset: usize) -> GType { - #[cfg(not(target_os = "windows"))] + #[cfg(not(msvc_dll))] let ptr = g_param_spec_types; - // One more step of indirection on windows because of the __imp_ prefix - #[cfg(target_os = "windows")] + // One more step of indirection on windows because `__imp_` signifies a pointer to the + // underlying symbol https://learn.microsoft.com/en-us/windows/win32/dlls/load-time-dynamic-linking. + #[cfg(msvc_dll)] let ptr = *g_param_spec_types; *ptr.add(offset) diff --git a/glib/gobject-sys/versions.txt b/glib/gobject-sys/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/glib/gobject-sys/versions.txt +++ b/glib/gobject-sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/glib/src/auto/versions.txt b/glib/src/auto/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/glib/src/auto/versions.txt +++ b/glib/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/glib/sys/Cargo.toml b/glib/sys/Cargo.toml index f61c9f2c4781..f89144c45917 100644 --- a/glib/sys/Cargo.toml +++ b/glib/sys/Cargo.toml @@ -99,16 +99,6 @@ version = "2.80" [package.metadata.system-deps.glib_2_0.v2_82] version = "2.81" -[package.metadata.system-deps.gobject_2_0] -name = "gobject-2.0" -version = "2.56" - -[package.metadata.system-deps.gobject_2_0.v2_58] -version = "2.58" - -[package.metadata.system-deps.gobject_2_0.v2_62] -version = "2.62" - [package.metadata.docs.rs] rustc-args = ["--cfg", "docsrs"] rustdoc-args = ["--cfg", "docsrs", "--generate-link-to-definition"] diff --git a/glib/sys/versions.txt b/glib/sys/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/glib/sys/versions.txt +++ b/glib/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/graphene/src/auto/versions.txt b/graphene/src/auto/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/graphene/src/auto/versions.txt +++ b/graphene/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/graphene/sys/versions.txt b/graphene/sys/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/graphene/sys/versions.txt +++ b/graphene/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/pango/src/auto/versions.txt b/pango/src/auto/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/pango/src/auto/versions.txt +++ b/pango/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/pango/sys/versions.txt b/pango/sys/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/pango/sys/versions.txt +++ b/pango/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/pangocairo/src/auto/versions.txt b/pangocairo/src/auto/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/pangocairo/src/auto/versions.txt +++ b/pangocairo/src/auto/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70) diff --git a/pangocairo/sys/versions.txt b/pangocairo/sys/versions.txt index fb79f7ae83d1..2e2629d644a6 100644 --- a/pangocairo/sys/versions.txt +++ b/pangocairo/sys/versions.txt @@ -1,2 +1,2 @@ -Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06) +Generated by gir (https://github.com/gtk-rs/gir @ 37c4bce0892f) from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)