Skip to content

Commit

Permalink
detect static library and regenerate gir
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Sep 18, 2024
1 parent 18becdb commit df58d90
Show file tree
Hide file tree
Showing 19 changed files with 54 additions and 33 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gdk-pixbuf/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion gdk-pixbuf/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion gio/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion gio/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion gir
7 changes: 5 additions & 2 deletions glib/gobject-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
[build-dependencies]
system-deps = "7"
pkg-config = "0.3"

[dependencies]
libc = "0.2"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)"]
23 changes: 23 additions & 0 deletions glib/gobject-sys/build_manual.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
18 changes: 12 additions & 6 deletions glib/gobject-sys/src/manual.rs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion glib/gobject-sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion glib/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
10 changes: 0 additions & 10 deletions glib/sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion glib/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion graphene/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion graphene/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion pango/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion pango/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion pangocairo/src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion pangocairo/sys/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ f0a4546b0a06)
Generated by gir (https://github.com/gtk-rs/gir @ ea1ee40bf933)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)

0 comments on commit df58d90

Please sign in to comment.