8000 Disable flag_enum import for GIR enumerations (GLib 2.88) by vivekgalatage · Pull Request #10 · rhx/SwiftGLib · GitHub
[go: up one dir, main page]

Skip to content

Disable flag_enum import for GIR enumerations (GLib 2.88) - #10

Merged
rhx merged 1 commit into
rhx:mainfrom
vivekgalatage:main
Oct 7, 2026
Merged

rhx merged 1 commit into
rhx:mainfrom
vivekgalatage:main

Conversation

@vivekgalatage
Copy link
Copy Markdown
Contributor

Fix GIO build with GLib 2.88 (G_GNUC_FLAG_ENUM)

Problem

GLib 2.88 added G_GNUC_FLAG_ENUM (__attribute__((flag_enum))) to many enums in its headers. When a C enum has that attribute, Swift imports it as an OptionSet instead of a plain C enum:

  • the enum's constants become static members of the type instead of global constants
  • the zero-valued member is marked unavailable ("use [] to construct an empty option set")

That's fine for types the GIR describes as <bitfield>. However, a few types are <enumeration> in the GIR but flag enums in the C headers. gir2swift generates code for these that uses the global C constants, and that code no longer compiles:

error: 'G_IO_MODULE_SCOPE_NONE' is unavailable: use [] to construct an empty option set
error: cannot find 'G_TLS_CERTIFICATE_REQUEST_NONE' in scope
error: cannot find 'G_TLS_DATABASE_LOOKUP_NONE' in scope
error: cannot find 'G_TLS_DATABASE_LOOKUP_KEYPAIR' in scope

Fix

Add Sources/CGLib/CGLib.apinotes with FlagEnum: false for the affected types. Clang applies API notes when it loads the module, so these enums import the way they did before GLib 2.88. The headers stay unchanged, and there are no Swift source changes.

Affected types:

  • GIOModuleScopeFlags
  • GTlsCertificateRequestFlags
  • GTlsDatabaseLookupFlags

With older GLib releases these types have no flag_enum attribute, so the notes do nothing there and builds against older GLib are unaffected.

Testing

  • GLib 2.88.0, Swift 6.4.0, Linux x86_64: GIO module builds (previously failed with the errors above)
  • <older GLib version / macOS, if tested>

@rhx
rhx merged commit 895fb27 into rhx:main Oct 7, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

0