Skip to content

Commit 2ef90b6

Browse files
glib: Guard new windows/linux APIs
1 parent 75218a3 commit 2ef90b6

File tree

4 files changed

+87
-58
lines changed

4 files changed

+87
-58
lines changed

glib/sys/Gir.toml

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,35 +68,41 @@ ignore = [
6868
name = "GLib.*"
6969
status = "generate"
7070
[[object.function]]
71-
name = "unix_get_passwd_entry"
72-
cfg_condition = "unix"
71+
name = "win32_locale_filename_from_utf8"
72+
cfg_condition = "window"
7373
[[object.function]]
74-
name = "get_user_state_dir"
75-
version = "2.72"
74+
name = "win32_get_windows_version"
75+
cfg_condition = "window"
76+
[[object.function]]
77+
name = "win32_getlocale"
78+
cfg_condition = "window"
79+
[[object.function]]
80+
name = "win32_check_windows_version"
81+
cfg_condition = "window"
7682
[[object.function]]
77-
name = "check_windows_version"
78-
manual = true
79-
cfg_condition = "windows"
83+
name = "win32_error_message"
84+
cfg_condition = "window"
8085
[[object.function]]
81-
name = "get_command_line"
82-
manual = true
83-
cfg_condition = "windows"
86+
name = "win32_ftruncate"
87+
cfg_condition = "window"
8488
[[object.function]]
85-
name = "error_message"
86-
manual = true
87-
cfg_condition = "windows"
89+
name = "win32_get_command_line"
90+
cfg_condition = "window"
8891
[[object.function]]
89-
name = "getlocale"
90-
manual = true
91-
cfg_condition = "windows"
92+
name = "win32_get_package_installation_directory"
93+
cfg_condition = "window"
9294
[[object.function]]
93-
name = "get_package_installation_directory_of_module"
94-
manual = true
95-
cfg_condition = "windows"
95+
name = "win32_get_package_installation_directory_of_module"
96+
cfg_condition = "window"
9697
[[object.function]]
97-
name = "locale_filename_from_utf8"
98-
manual = true
99-
cfg_condition = "windows"
98+
name = "win32_get_package_installation_subdirectory"
99+
cfg_condition = "window"
100+
[[object.function]]
101+
name = "unix_get_passwd_entry"
102+
cfg_condition = "unix"
103+
[[object.function]]
104+
name = "get_user_state_dir"
105+
version = "2.72"
100106
[[object.function]]
101107
name = "assertion_message_cmpint"
102108
version = "2.78"
@@ -114,11 +120,26 @@ status = "manual"
114120
name = "GLib.PollFD"
115121
status = "manual"
116122

123+
[[object]]
124+
name = "GLib.UnixPipe"
125+
status = "generate"
126+
cfg_condition = "unix"
127+
128+
[[object]]
129+
name = "GLib.UnixPipeEnd"
130+
status = "generate"
131+
cfg_condition = "unix"
132+
117133
[[object]]
118134
name = "GLib.TestLogMsg"
119135
# layout is broken due to rust having no long double
120136
status = "ignore"
121137

138+
[[object]]
139+
name = "GLib.Win32OSType"
140+
status = "generate"
141+
cfg_condition = "window"
142+
122143
[[object]]
123144
name = "GLib.macro__has_attribute___noreturn__"
124145
# C-only macro

glib/sys/src/lib.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,14 @@ pub const G_UNICODE_LINE_SEPARATOR: GUnicodeType = 27;
636636
pub const G_UNICODE_PARAGRAPH_SEPARATOR: GUnicodeType = 28;
637637
pub const G_UNICODE_SPACE_SEPARATOR: GUnicodeType = 29;
638638

639+
#[cfg(unix)]
640+
#[cfg_attr(docsrs, doc(cfg(unix)))]
639641
pub type GUnixPipeEnd = c_int;
642+
#[cfg(unix)]
643+
#[cfg_attr(docsrs, doc(cfg(unix)))]
640644
pub const G_UNIX_PIPE_END_READ: GUnixPipeEnd = 0;
645+
#[cfg(unix)]
646+
#[cfg_attr(docsrs, doc(cfg(unix)))]
641647
pub const G_UNIX_PIPE_END_WRITE: GUnixPipeEnd = 1;
642648

643649
pub type GUriError = c_int;
@@ -704,9 +710,17 @@ pub const G_VARIANT_PARSE_ERROR_UNTERMINATED_STRING_CONSTANT: GVariantParseError
704710
pub const G_VARIANT_PARSE_ERROR_VALUE_EXPECTED: GVariantParseError = 17;
705711
pub const G_VARIANT_PARSE_ERROR_RECURSION: GVariantParseError = 18;
706712

713+
#[cfg(window)]
714+
#[cfg_attr(docsrs, doc(cfg(window)))]
707715
pub type GWin32OSType = c_int;
716+
#[cfg(window)]
717+
#[cfg_attr(docsrs, doc(cfg(window)))]
708718
pub const G_WIN32_OS_ANY: GWin32OSType = 0;
719+
#[cfg(window)]
720+
#[cfg_attr(docsrs, doc(cfg(window)))]
709721
pub const G_WIN32_OS_WORKSTATION: GWin32OSType = 1;
722+
#[cfg(window)]
723+
#[cfg_attr(docsrs, doc(cfg(window)))]
710724
pub const G_WIN32_OS_SERVER: GWin32OSType = 2;
711725

712726
// Constants
@@ -2527,12 +2541,16 @@ impl ::std::fmt::Debug for GTuples {
25272541
}
25282542
}
25292543

2544+
#[cfg(unix)]
2545+
#[cfg_attr(docsrs, doc(cfg(unix)))]
25302546
#[derive(Copy, Clone)]
25312547
#[repr(C)]
25322548
pub struct GUnixPipe {
25332549
pub fds: [c_int; 2],
25342550
}
25352551

2552+
#[cfg(unix)]
2553+
#[cfg_attr(docsrs, doc(cfg(unix)))]
25362554
impl ::std::fmt::Debug for GUnixPipe {
25372555
fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
25382556
f.debug_struct(&format!("GUnixPipe @ {self:p}"))
@@ -7572,27 +7590,47 @@ extern "C" {
75727590
func: *const c_char,
75737591
warnexpr: *const c_char,
75747592
);
7593+
#[cfg(window)]
7594+
#[cfg_attr(docsrs, doc(cfg(window)))]
75757595
pub fn g_win32_check_windows_version(
75767596
major: c_int,
75777597
minor: c_int,
75787598
spver: c_int,
75797599
os_type: GWin32OSType,
75807600
) -> gboolean;
7601+
#[cfg(window)]
7602+
#[cfg_attr(docsrs, doc(cfg(window)))]
75817603
pub fn g_win32_error_message(error: c_int) -> *mut c_char;
7604+
#[cfg(window)]
7605+
#[cfg_attr(docsrs, doc(cfg(window)))]
75827606
pub fn g_win32_ftruncate(f: c_int, size: c_uint) -> c_int;
7607+
#[cfg(window)]
7608+
#[cfg_attr(docsrs, doc(cfg(window)))]
75837609
pub fn g_win32_get_command_line() -> *mut *mut c_char;
7610+
#[cfg(window)]
7611+
#[cfg_attr(docsrs, doc(cfg(window)))]
75847612
pub fn g_win32_get_package_installation_directory(
75857613
package: *const c_char,
75867614
dll_name: *const c_char,
75877615
) -> *mut c_char;
7616+
#[cfg(window)]
7617+
#[cfg_attr(docsrs, doc(cfg(window)))]
75887618
pub fn g_win32_get_package_installation_directory_of_module(hmodule: gpointer) -> *mut c_char;
7619+
#[cfg(window)]
7620+
#[cfg_attr(docsrs, doc(cfg(window)))]
75897621
pub fn g_win32_get_package_installation_subdirectory(
75907622
package: *const c_char,
75917623
dll_name: *const c_char,
75927624
subdir: *const c_char,
75937625
) -> *mut c_char;
7626+
#[cfg(window)]
7627+
#[cfg_attr(docsrs, doc(cfg(window)))]
75947628
pub fn g_win32_get_windows_version() -> c_uint;
7629+
#[cfg(window)]
7630+
#[cfg_attr(docsrs, doc(cfg(window)))]
75957631
pub fn g_win32_getlocale() -> *mut c_char;
7632+
#[cfg(window)]
7633+
#[cfg_attr(docsrs, doc(cfg(window)))]
75967634
pub fn g_win32_locale_filename_from_utf8(utf8filename: *const c_char) -> *mut c_char;
75977635

75987636
}

glib/sys/src/manual.rs

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -43,42 +43,6 @@ pub struct GPollFD {
4343
pub revents: c_ushort,
4444
}
4545

46-
#[cfg(target_family = "windows")]
47-
pub use self::win32::*;
48-
49-
#[cfg(target_family = "windows")]
50-
mod win32 {
51-
use libc::{c_char, c_int};
52-
53-
use crate::gboolean;
54-
55-
pub type GWin32OSType = c_int;
56-
pub const G_WIN32_OS_ANY: GWin32OSType = 0;
57-
pub const G_WIN32_OS_WORKSTATION: GWin32OSType = 1;
58-
pub const G_WIN32_OS_SERVER: GWin32OSType = 2;
59-
60-
extern "C" {
61-
pub fn g_win32_check_windows_version(
62-
major: c_int,
63-
minor: c_int,
64-
spver: c_int,
65-
os_type: GWin32OSType,
66-
) -> gboolean;
67-
68-
pub fn g_win32_get_command_line() -> *mut *mut c_char;
69-
70-
pub fn g_win32_error_message(error: c_int) -> *mut c_char;
71-
72-
pub fn g_win32_getlocale() -> *mut c_char;
73-
74-
pub fn g_win32_get_package_installation_directory_of_module(
75-
hmodule: std::os::windows::raw::HANDLE,
76-
) -> *mut c_char;
77-
78-
pub fn g_win32_locale_filename_from_utf8(utf8filename: *const c_char) -> *mut c_char;
79-
}
80-
}
81-
8246
// These are all non-NUL terminated strings in C
8347
pub const G_VARIANT_TYPE_BOOLEAN: &str = "b";
8448
pub const G_VARIANT_TYPE_BYTE: &str = "y";

glib/sys/tests/abi.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,13 +950,17 @@ const RUST_LAYOUTS: &[(&str, Layout)] = &[
950950
alignment: align_of::<GUnicodeType>(),
951951
},
952952
),
953+
#[cfg(unix)]
954+
#[cfg_attr(docsrs, doc(cfg(unix)))]
953955
(
954956
"GUnixPipe",
955957
Layout {
956958
size: size_of::<GUnixPipe>(),
957959
alignment: align_of::<GUnixPipe>(),
958960
},
959961
),
962+
#[cfg(unix)]
963+
#[cfg_attr(docsrs, doc(cfg(unix)))]
960964
(
961965
"GUnixPipeEnd",
962966
Layout {
@@ -1041,6 +1045,8 @@ const RUST_LAYOUTS: &[(&str, Layout)] = &[
10411045
alignment: align_of::<GVariantParseError>(),
10421046
},
10431047
),
1048+
#[cfg(window)]
1049+
#[cfg_attr(docsrs, doc(cfg(window)))]
10441050
(
10451051
"GWin32OSType",
10461052
Layout {

0 commit comments

Comments
 (0)