Skip to content

Commit

Permalink
glib: Auto generate various win32 functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bilelmoussaoui committed Jan 18, 2024
1 parent 8f03582 commit dd971da
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 61 deletions.
36 changes: 36 additions & 0 deletions glib/Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,37 @@ manual = [
[[object]]
name = "GLib.*"
status = "generate"
[[object.function]]
name = "win32_locale_filename_from_utf8"
cfg_condition = "window"
[[object.function]]
name = "win32_get_windows_version"
cfg_condition = "window"
[[object.function]]
name = "win32_getlocale"
cfg_condition = "window"
[[object.function]]
name = "win32_check_windows_version"
cfg_condition = "window"
[[object.function]]
name = "win32_error_message"
cfg_condition = "window"
[[object.function]]
name = "win32_ftruncate"
cfg_condition = "window"
[[object.function]]
name = "win32_get_command_line"
cfg_condition = "window"
[[object.function]]
name = "win32_get_package_installation_directory"
cfg_condition = "window"
[[object.function]]
name = "win32_get_package_installation_directory_of_module"
cfg_condition = "window"
manual = true
[[object.function]]
name = "win32_get_package_installation_subdirectory"
cfg_condition = "window"
[[object.function]]
pattern = "(assertion_message_cmpint|assert_warning|assertion_message|assertion_message_cmpnum|assertion_message_cmpstr|warn_message|return_if_fail_warning)"
ignore = true # Not useful assertions functions
Expand Down Expand Up @@ -886,3 +917,8 @@ status = "generate"
name = "GLib.Uri"
status = "generate"
concurrency = "send+sync"

[[object]]
name = "GLib.Win32OSType"
status = "generate"
cfg_condition = "windows"
46 changes: 46 additions & 0 deletions glib/src/auto/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2352,3 +2352,49 @@ impl FromGlib<ffi::GVariantClass> for VariantClass {
}
}
}

#[cfg(windows)]
#[cfg_attr(docsrs, doc(cfg(windows)))]
#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone, Copy)]
#[non_exhaustive]
#[doc(alias = "GWin32OSType")]
pub enum Win32OSType {
#[doc(alias = "G_WIN32_OS_ANY")]
Any,
#[doc(alias = "G_WIN32_OS_WORKSTATION")]
Workstation,
#[doc(alias = "G_WIN32_OS_SERVER")]
Server,
#[doc(hidden)]
__Unknown(i32),
}

#[cfg(windows)]
#[doc(hidden)]
impl IntoGlib for Win32OSType {
type GlibType = ffi::GWin32OSType;

Check failure on line 2375 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find type `GWin32OSType` in crate `ffi`

Check failure on line 2375 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find type `GWin32OSType` in crate `ffi`

#[inline]
fn into_glib(self) -> ffi::GWin32OSType {

Check failure on line 2378 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find type `GWin32OSType` in crate `ffi`

Check failure on line 2378 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find type `GWin32OSType` in crate `ffi`
match self {
Self::Any => ffi::G_WIN32_OS_ANY,

Check failure on line 2380 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find value `G_WIN32_OS_ANY` in crate `ffi`

Check failure on line 2380 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find value `G_WIN32_OS_ANY` in crate `ffi`
Self::Workstation => ffi::G_WIN32_OS_WORKSTATION,

Check failure on line 2381 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find value `G_WIN32_OS_WORKSTATION` in crate `ffi`

Check failure on line 2381 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find value `G_WIN32_OS_WORKSTATION` in crate `ffi`
Self::Server => ffi::G_WIN32_OS_SERVER,

Check failure on line 2382 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find value `G_WIN32_OS_SERVER` in crate `ffi`

Check failure on line 2382 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find value `G_WIN32_OS_SERVER` in crate `ffi`
Self::__Unknown(value) => value,
}
}
}

#[cfg(windows)]
#[doc(hidden)]
impl FromGlib<ffi::GWin32OSType> for Win32OSType {

Check failure on line 2390 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find type `GWin32OSType` in crate `ffi`

Check failure on line 2390 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find type `GWin32OSType` in crate `ffi`
#[inline]
unsafe fn from_glib(value: ffi::GWin32OSType) -> Self {

Check failure on line 2392 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find type `GWin32OSType` in crate `ffi`

Check failure on line 2392 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find type `GWin32OSType` in crate `ffi`
match value {
ffi::G_WIN32_OS_ANY => Self::Any,

Check failure on line 2394 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find unit struct, unit variant or constant `G_WIN32_OS_ANY` in crate `ffi`

Check failure on line 2394 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find unit struct, unit variant or constant `G_WIN32_OS_ANY` in crate `ffi`
ffi::G_WIN32_OS_WORKSTATION => Self::Workstation,

Check failure on line 2395 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find unit struct, unit variant or constant `G_WIN32_OS_WORKSTATION` in crate `ffi`

Check failure on line 2395 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find unit struct, unit variant or constant `G_WIN32_OS_WORKSTATION` in crate `ffi`
ffi::G_WIN32_OS_SERVER => Self::Server,

Check failure on line 2396 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

cannot find unit struct, unit variant or constant `G_WIN32_OS_SERVER` in crate `ffi`

Check failure on line 2396 in glib/src/auto/enums.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

cannot find unit struct, unit variant or constant `G_WIN32_OS_SERVER` in crate `ffi`
value => Self::__Unknown(value),
}
}
}
46 changes: 37 additions & 9 deletions glib/src/auto/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
#[cfg(feature = "v2_66")]
#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
use crate::FileSetContentsFlags;
#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]
use crate::Win32OSType;
use crate::{
translate::*, Bytes, ChecksumType, Error, FileTest, FormatSizeFlags, Pid, Source, SpawnFlags,
UserDirectory,
Expand Down Expand Up @@ -969,26 +972,48 @@ pub fn uuid_string_random() -> crate::GString {
unsafe { from_glib_full(ffi::g_uuid_string_random()) }
}

//#[doc(alias = "g_win32_check_windows_version")]
//pub fn win32_check_windows_version(major: i32, minor: i32, spver: i32, os_type: /*Ignored*/Win32OSType) -> bool {
// unsafe { TODO: call ffi:g_win32_check_windows_version() }
//}
#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]
#[doc(alias = "g_win32_check_windows_version")]
pub fn win32_check_windows_version(
major: i32,
minor: i32,
spver: i32,
os_type: Win32OSType,
) -> bool {
unsafe {
from_glib(ffi::g_win32_check_windows_version(
major,
minor,
spver,
os_type.into_glib(),
))
}
}

#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]
#[doc(alias = "g_win32_error_message")]
pub fn win32_error_message(error: i32) -> crate::GString {
unsafe { from_glib_full(ffi::g_win32_error_message(error)) }
}

#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]

Check warning on line 1002 in glib/src/auto/functions.rs

View workflow job for this annotation

GitHub Actions / build

unresolved link to `crate::ThreadPool::new`
#[doc(alias = "g_win32_ftruncate")]
pub fn win32_ftruncate(f: i32, size: u32) -> i32 {
unsafe { ffi::g_win32_ftruncate(f, size) }
}

#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]
#[doc(alias = "g_win32_get_command_line")]
pub fn win32_get_command_line() -> Vec<crate::GString> {
unsafe { FromGlibPtrContainer::from_glib_none(ffi::g_win32_get_command_line()) }
}

#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]
#[doc(alias = "g_win32_get_package_installation_directory")]
pub fn win32_get_package_installation_directory(package: &str, dll_name: &str) -> crate::GString {
unsafe {
Expand All @@ -999,11 +1024,8 @@ pub fn win32_get_package_installation_directory(package: &str, dll_name: &str) -
}
}

//#[doc(alias = "g_win32_get_package_installation_directory_of_module")]
//pub fn win32_get_package_installation_directory_of_module(hmodule: /*Unimplemented*/Option<Basic: Pointer>) -> crate::GString {
// unsafe { TODO: call ffi:g_win32_get_package_installation_directory_of_module() }
//}

#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]
#[doc(alias = "g_win32_get_package_installation_subdirectory")]
pub fn win32_get_package_installation_subdirectory(
package: &str,
Expand All @@ -1019,16 +1041,22 @@ pub fn win32_get_package_installation_subdirectory(
}
}

#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]
#[doc(alias = "g_win32_get_windows_version")]
pub fn win32_get_windows_version() -> u32 {
unsafe { ffi::g_win32_get_windows_version() }
}

#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]
#[doc(alias = "g_win32_getlocale")]
pub fn win32_getlocale() -> crate::GString {
unsafe { from_glib_full(ffi::g_win32_getlocale()) }
}

#[cfg(window)]
#[cfg_attr(docsrs, doc(cfg(window)))]
#[doc(alias = "g_win32_locale_filename_from_utf8")]
pub fn win32_locale_filename_from_utf8(utf8filename: &str) -> crate::GString {
unsafe {
Expand Down
3 changes: 3 additions & 0 deletions glib/src/auto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ pub use self::enums::UnicodeType;
#[cfg_attr(docsrs, doc(cfg(feature = "v2_66")))]
pub use self::enums::UriError;
pub use self::enums::VariantClass;
#[cfg(windows)]
#[cfg_attr(docsrs, doc(cfg(windows)))]
pub use self::enums::Win32OSType;

mod flags;
#[cfg(feature = "v2_66")]
Expand Down
52 changes: 0 additions & 52 deletions glib/src/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,6 @@ use std::path::PathBuf;

use crate::{translate::*, GString, StrV};

Check warning on line 5 in glib/src/win32.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (cairo, true, --features png,pdf,svg,ps,use_glib,v1_16,freetype,script,wi...

unused imports: `GString`, `StrV`

Check warning on line 5 in glib/src/win32.rs

View workflow job for this annotation

GitHub Actions / build gtk-rs on Windows (graphene, false)

unused imports: `GString`, `StrV`

#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
pub enum OSType {
#[doc(alias = "G_WIN32_OS_ANY")]
Any,
#[doc(alias = "G_WIN32_OS_WORKSTATION")]
Workstation,
#[doc(alias = "G_WIN32_OS_SERVER")]
Server,
}

#[doc(hidden)]
impl IntoGlib for OSType {
type GlibType = ffi::GWin32OSType;

#[inline]
fn into_glib(self) -> Self::GlibType {
match self {
Self::Any => ffi::G_WIN32_OS_ANY,
Self::Workstation => ffi::G_WIN32_OS_WORKSTATION,
Self::Server => ffi::G_WIN32_OS_SERVER,
}
}
}

#[doc(alias = "g_win32_check_windows_version")]
pub fn check_windows_version(major: i32, minor: i32, spver: i32, os_type: OSType) -> bool {
unsafe {
from_glib(ffi::g_win32_check_windows_version(
major,
minor,
spver,
os_type.into_glib(),
))
}
}

#[doc(alias = "g_win32_get_command_line")]
#[doc(alias = "get_command_line")]
pub fn command_line() -> StrV {
unsafe { FromGlibPtrContainer::from_glib_full(ffi::g_win32_get_command_line()) }
}

#[doc(alias = "g_win32_error_message")]
pub fn error_message(error: i32) -> GString {
unsafe { from_glib_full(ffi::g_win32_error_message(error)) }
}

#[doc(alias = "g_win32_getlocale")]
pub fn getlocale() -> GString {
unsafe { from_glib_full(ffi::g_win32_getlocale()) }
}

#[doc(alias = "g_win32_get_package_installation_directory_of_module")]
#[doc(alias = "get_package_installation_directory_of_module")]
pub fn package_installation_directory_of_module(
Expand Down

0 comments on commit dd971da

Please sign in to comment.