Skip to content

Commit

Permalink
generate gir without link attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
eerii authored and bilelmoussaoui committed Sep 26, 2024
1 parent 925f262 commit e651fc0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 37 deletions.
1 change: 0 additions & 1 deletion gio/sys/src/manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ mod windows_streams {
gboolean, GInputStream, GInputStreamClass, GOutputStream, GOutputStreamClass, GType,
};

#[link(name = "gio-2.0")]
extern "C" {
//=========================================================================
// GWin32InputStream
Expand Down
98 changes: 63 additions & 35 deletions glib/src/param_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,20 +296,16 @@ pub unsafe trait ParamSpecType:
{
}

#[link(name = "gobject-2.0")]
extern "C" {
pub static g_param_spec_types: *const ffi::GType;
}

macro_rules! define_param_spec {
($rust_type:ident, $ffi_type:path, $rust_type_offset:expr) => {
// Can't use get_type here as this is not a boxed type but another fundamental type
($rust_type:ident, $ffi_type:path, $type_name:literal) => {
impl StaticType for $rust_type {
#[inline]
fn static_type() -> Type {
unsafe {
from_glib(*g_param_spec_types.add($rust_type_offset))
}
// Instead of using the direct reference to the `g_param_spec_types` table, we
// use `g_type_from_name` to query for each of the param spec types. This is
// because rust currently has issues properly linking variables from external
// libraries without using a `#[link]` attribute.
unsafe { from_glib(gobject_ffi::g_type_from_name(concat!($type_name, "\0").as_ptr() as *const _)) }
}
}

Expand Down Expand Up @@ -557,8 +553,8 @@ macro_rules! define_param_spec_min_max {
}

macro_rules! define_param_spec_numeric {
($rust_type:ident, $ffi_type:path, $value_type:ty, $rust_type_offset:expr, $ffi_fun:ident) => {
define_param_spec!($rust_type, $ffi_type, $rust_type_offset);
($rust_type:ident, $ffi_type:path, $value_type:ty, $type_name:literal, $ffi_fun:ident) => {
define_param_spec!($rust_type, $ffi_type, $type_name);
define_param_spec_default!($rust_type, $ffi_type, $value_type, |x| x);
define_param_spec_min_max!($rust_type, $ffi_type, $value_type);

Expand Down Expand Up @@ -788,7 +784,7 @@ define_param_spec_numeric!(
ParamSpecChar,
gobject_ffi::GParamSpecChar,
i8,
0,
"GParamChar",
g_param_spec_char
);

Expand All @@ -808,7 +804,7 @@ define_param_spec_numeric!(
ParamSpecUChar,
gobject_ffi::GParamSpecUChar,
u8,
1,
"GParamUChar",
g_param_spec_uchar
);

Expand All @@ -829,7 +825,11 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecBoolean, gobject_ffi::GParamSpecBoolean, 2);
define_param_spec!(
ParamSpecBoolean,
gobject_ffi::GParamSpecBoolean,
"GParamBoolean"
);

define_param_spec_default!(
ParamSpecBoolean,
Expand Down Expand Up @@ -880,7 +880,7 @@ define_param_spec_numeric!(
ParamSpecInt,
gobject_ffi::GParamSpecInt,
i32,
3,
"GParamInt",
g_param_spec_int
);

Expand All @@ -900,7 +900,7 @@ define_param_spec_numeric!(
ParamSpecUInt,
gobject_ffi::GParamSpecUInt,
u32,
4,
"GParamUInt",
g_param_spec_uint
);

Expand All @@ -925,7 +925,7 @@ define_param_spec_numeric!(
ParamSpecLong,
gobject_ffi::GParamSpecLong,
libc::c_long,
5,
"GParamLong",
g_param_spec_long
);

Expand All @@ -950,7 +950,7 @@ define_param_spec_numeric!(
ParamSpecULong,
gobject_ffi::GParamSpecULong,
libc::c_ulong,
6,
"GParamULong",
g_param_spec_ulong
);

Expand All @@ -975,7 +975,7 @@ define_param_spec_numeric!(
ParamSpecInt64,
gobject_ffi::GParamSpecInt64,
i64,
7,
"GParamInt64",
g_param_spec_int64
);

Expand All @@ -1000,7 +1000,7 @@ define_param_spec_numeric!(
ParamSpecUInt64,
gobject_ffi::GParamSpecUInt64,
u64,
8,
"GParamUInt64",
g_param_spec_uint64
);

Expand All @@ -1021,7 +1021,11 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecUnichar, gobject_ffi::GParamSpecUnichar, 9);
define_param_spec!(
ParamSpecUnichar,
gobject_ffi::GParamSpecUnichar,
"GParamUnichar"
);
define_param_spec_default!(ParamSpecUnichar, gobject_ffi::GParamSpecUnichar, Result<char, CharTryFromError>, TryFrom::try_from);

impl ParamSpecUnichar {
Expand Down Expand Up @@ -1063,7 +1067,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecEnum, gobject_ffi::GParamSpecEnum, 10);
define_param_spec!(ParamSpecEnum, gobject_ffi::GParamSpecEnum, "GParamEnum");

impl ParamSpecEnum {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1207,7 +1211,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecFlags, gobject_ffi::GParamSpecFlags, 11);
define_param_spec!(ParamSpecFlags, gobject_ffi::GParamSpecFlags, "GParamFlags");

impl ParamSpecFlags {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1350,7 +1354,7 @@ define_param_spec_numeric!(
ParamSpecFloat,
gobject_ffi::GParamSpecFloat,
f32,
12,
"GParamFloat",
g_param_spec_float
);

Expand All @@ -1375,7 +1379,7 @@ define_param_spec_numeric!(
ParamSpecDouble,
gobject_ffi::GParamSpecDouble,
f64,
13,
"GParamDouble",
g_param_spec_double
);

Expand All @@ -1396,7 +1400,11 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecString, gobject_ffi::GParamSpecString, 14);
define_param_spec!(
ParamSpecString,
gobject_ffi::GParamSpecString,
"GParamString"
);

define_param_spec_default!(
ParamSpecString,
Expand Down Expand Up @@ -1505,7 +1513,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecParam, gobject_ffi::GParamSpecParam, 15);
define_param_spec!(ParamSpecParam, gobject_ffi::GParamSpecParam, "GParamParam");

impl ParamSpecParam {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1547,7 +1555,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecBoxed, gobject_ffi::GParamSpecBoxed, 16);
define_param_spec!(ParamSpecBoxed, gobject_ffi::GParamSpecBoxed, "GParamBoxed");

impl ParamSpecBoxed {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1635,7 +1643,11 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecPointer, gobject_ffi::GParamSpecPointer, 17);
define_param_spec!(
ParamSpecPointer,
gobject_ffi::GParamSpecPointer,
"GParamPointer"
);

impl ParamSpecPointer {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1671,7 +1683,11 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecValueArray, gobject_ffi::GParamSpecValueArray, 18);
define_param_spec!(
ParamSpecValueArray,
gobject_ffi::GParamSpecValueArray,
"GParamValueArray"
);

impl ParamSpecValueArray {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1791,7 +1807,11 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecObject, gobject_ffi::GParamSpecObject, 19);
define_param_spec!(
ParamSpecObject,
gobject_ffi::GParamSpecObject,
"GParamObject"
);

impl ParamSpecObject {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -1879,7 +1899,11 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecOverride, gobject_ffi::GParamSpecOverride, 20);
define_param_spec!(
ParamSpecOverride,
gobject_ffi::GParamSpecOverride,
"GParamOverride"
);

impl ParamSpecOverride {
unsafe fn new_unchecked(name: &str, overridden: impl AsRef<ParamSpec>) -> ParamSpec {
Expand Down Expand Up @@ -1987,7 +2011,7 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecGType, gobject_ffi::GParamSpecGType, 21);
define_param_spec!(ParamSpecGType, gobject_ffi::GParamSpecGType, "GParamGType");

impl ParamSpecGType {
unsafe fn new_unchecked<'a>(
Expand Down Expand Up @@ -2027,7 +2051,11 @@ wrapper! {
unref => |ptr| gobject_ffi::g_param_spec_unref(ptr as *mut gobject_ffi::GParamSpec),
}
}
define_param_spec!(ParamSpecVariant, gobject_ffi::GParamSpecVariant, 22);
define_param_spec!(
ParamSpecVariant,
gobject_ffi::GParamSpecVariant,
"GParamVariant"
);

define_param_spec_default!(
ParamSpecVariant,
Expand Down
1 change: 0 additions & 1 deletion glib/sys/src/manual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ mod win32 {
pub const G_WIN32_OS_WORKSTATION: GWin32OSType = 1;
pub const G_WIN32_OS_SERVER: GWin32OSType = 2;

#[link(name = "glib-2.0")]
extern "C" {
pub fn g_win32_check_windows_version(
major: c_int,
Expand Down

0 comments on commit e651fc0

Please sign in to comment.