Skip to content

Commit

Permalink
generate link attribute only for msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii committed Sep 12, 2024
1 parent e352a21 commit 5691ef9
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 21 deletions.
1 change: 1 addition & 0 deletions 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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
2 changes: 1 addition & 1 deletion gir
Submodule gir updated 1 files
+49 −3 src/codegen/sys/build.rs
1 change: 1 addition & 0 deletions glib/gobject-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[build-dependencies]
system-deps = "7"
pkg-config = "0.3"

[dependencies]
libc = "0.2"
Expand Down
4 changes: 4 additions & 0 deletions glib/gobject-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// from gir-files (https://github.com/gtk-rs/gir-files)
// DO NOT EDIT

mod build_manual;

#[cfg(not(docsrs))]
use std::process;

Expand All @@ -14,4 +16,6 @@ fn main() {
println!("cargo:warning={s}");
process::exit(1);
}

build_manual::main();
}
31 changes: 31 additions & 0 deletions glib/gobject-sys/build_manual.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use std::{env, fs::File, io::Write, path::Path};

pub fn main() {

Check warning on line 3 in glib/gobject-sys/build_manual.rs

View workflow job for this annotation

GitHub Actions / build

function `main` is never used
let deps = system_deps::Config::new()
.probe()
.expect("if this module is called, this is valid");

let out_dir = env::var("OUT_DIR").unwrap();
let out_path = Path::new(&out_dir).join("param_spec.rs");

// Generating a link attribute is necessary in windows
// (see https://rust-lang.github.io/rfcs/1717-dllimport.html#drawbacks)
// even if we are already linking with system_deps.
// We allow configuration of the library name from upstream dependents
// using the alias variable in the pkgconfig file.
let lib_name = deps
.iter()
.into_iter()
.filter_map(|(_, l)| pkg_config::get_variable(&l.name, "alias").ok())
.find(|s| !s.is_empty())
.unwrap_or("gobject-2.0".into());
let link = if cfg!(target_os = "windows") {
format!("#[link(name = \"{}\")]", lib_name)
} else {
"".into()
};

let code = format!("{link} extern \"C\" {{ pub static g_param_spec_types: *const GType; }}");
let mut f = File::create(&out_path).unwrap();
f.write_all(code.as_bytes()).unwrap();
}
11 changes: 4 additions & 7 deletions glib/gobject-sys/src/manual.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
// Take a look at the license at the top of the repository in the LICENSE file.

use glib_sys::GType;

extern "C" {
#[cfg_attr(target_os = "windows", link_name = "__imp_g_param_spec_types")]
pub static g_param_spec_types: *const GType;
}
// `g_param_spec_types` extern binding generated by build.rs
include!(concat!(env!("OUT_DIR"), "/param_spec.rs"));

Check failure on line 4 in glib/gobject-sys/src/manual.rs

View workflow job for this annotation

GitHub Actions / build

couldn't read /__w/gtk-rs-core/gtk-rs-core/target/debug/build/gobject-sys-0443df896c9d79c7/out/param_spec.rs: No such file or directory (os error 2)

// SAFETY: This should be safe as long as the offset added to g_param_spec_types is in bounds.
/// # 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 {
*g_param_spec_types.add(offset)
}
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
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 @ 37c4bce0892f)
Generated by gir (https://github.com/gtk-rs/gir @ d2ee14efdb8b)
from gir-files (https://github.com/gtk-rs/gir-files @ 4d1189172a70)

0 comments on commit 5691ef9

Please sign in to comment.