diff --git a/.gitignore b/.gitignore index 4af7c46..fd979b8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +*.tar.zst bindings test/abi zig-cache diff --git a/README.md b/README.md index 04cb21b..09297d0 100644 --- a/README.md +++ b/README.md @@ -31,12 +31,14 @@ use [Flatpak](https://flatpak.org/): 1. Install `flatpak`. 2. Install the base SDK dependencies: - - `flatpak install org.freedesktop.Sdk//22.08` - - `flatpak install org.gnome.Sdk//44` + - `flatpak install org.freedesktop.Sdk//23.08` + - `flatpak install org.gnome.Sdk//45` 3. Install the Zig master extension for the Freedesktop SDK. This is not (yet) available on Flathub, so it must be built and installed manually. 1. Install `flatpak-builder`. - 2. Clone https://github.com/ianprime0509/org.freedesktop.Sdk.Extension.ziglang-master + 2. Clone + https://github.com/ianprime0509/org.freedesktop.Sdk.Extension.ziglang-master + and use the branch corresponding to the Freedesktop SDK installed above. 3. Inside the clone, run `flatpak-builder --user --install build-dir org.freedesktop.Sdk.Extension.ziglang-master.yml`. The steps above only need to be done once per GNOME SDK version. To enter a @@ -57,14 +59,16 @@ get the full set of required GIR files is to set up a Flatpak development environment as described in the previous section. Otherwise, a custom set of bindings can be built by running the `zig-gobject` binary directly. -To generate all available bindings using the files under `lib/gir-files`, run -`zig build codegen`. This will generate bindings to the `bindings` directory, -which can be used as a dependency (using the Zig package manager) in other -projects. +The command `zig build codegen -Dgir-profile=profile` can be used to generate +bindings for a predefined set of GIR files expected to be present at the path +specified by `-Dgir-files-path`, or `/usr/share/gir-1.0` if not specified. The +currently supported profiles are `gnome44` and `gnome45`, with the default being +`gnome45`. This will generate bindings to the `bindings` directory, which can be +used as a dependency (using the Zig package manager) in other projects. -The underlying `zig-gobject` binary can be built using `zig build` and run -directly if more control is required over the source of the bindings (for -example, to run on a different set of GIR files as input). +If more control is needed over the source GIR files, `zig build` can be used to +build the `zig-gobject` binding generator executable, and it can be run directly +with any set of GIR input files and options. ## Further reading diff --git a/build.zig b/build.zig index a3221ab..d68483d 100644 --- a/build.zig +++ b/build.zig @@ -69,104 +69,216 @@ pub fn build(b: *std.Build) !void { } fn addCodegenStep(b: *std.Build, codegen_exe: *std.Build.Step.Compile) !*std.Build.Step { - const gir = [_][]const u8{ - "Adw-1.gir", - "AppStreamGlib-1.0.gir", - "Atk-1.0.gir", - "Atspi-2.0.gir", - "cairo-1.0.gir", - "DBus-1.0.gir", - "DBusGLib-1.0.gir", - "fontconfig-2.0.gir", - "freetype2-2.0.gir", - "GCab-1.0.gir", - "Gck-1.gir", - "Gck-2.gir", - "Gcr-3.gir", - "Gcr-4.gir", - "GcrUi-3.gir", - "GDesktopEnums-3.0.gir", - "Gdk-3.0.gir", - "Gdk-4.0.gir", - "GdkPixbuf-2.0.gir", - "GdkPixdata-2.0.gir", - "GdkWayland-4.0.gir", - "GdkX11-3.0.gir", - "GdkX11-4.0.gir", - "Gee-0.8.gir", - "Geoclue-2.0.gir", - "Gio-2.0.gir", - "GIRepository-2.0.gir", - "GL-1.0.gir", - "GLib-2.0.gir", - "GModule-2.0.gir", - "GObject-2.0.gir", - "Graphene-1.0.gir", - "Gsk-4.0.gir", - "Gst-1.0.gir", - "GstAllocators-1.0.gir", - "GstApp-1.0.gir", - "GstAudio-1.0.gir", - "GstBadAudio-1.0.gir", - "GstBase-1.0.gir", - "GstCheck-1.0.gir", - "GstCodecs-1.0.gir", - "GstController-1.0.gir", - "GstGL-1.0.gir", - "GstGLEGL-1.0.gir", - "GstGLWayland-1.0.gir", - "GstGLX11-1.0.gir", - "GstInsertBin-1.0.gir", - "GstMpegts-1.0.gir", - "GstNet-1.0.gir", - "GstPbutils-1.0.gir", - "GstPlay-1.0.gir", - "GstPlayer-1.0.gir", - "GstRtp-1.0.gir", - "GstRtsp-1.0.gir", - "GstSdp-1.0.gir", - "GstTag-1.0.gir", - "GstTranscoder-1.0.gir", - "GstVideo-1.0.gir", - "GstVulkan-1.0.gir", - "GstVulkanWayland-1.0.gir", - "GstVulkanXCB-1.0.gir", - "GstWebRTC-1.0.gir", - "Gtk-3.0.gir", - "Gtk-4.0.gir", - "GtkSource-4.gir", - "GtkSource-5.gir", - "GUdev-1.0.gir", - "Handy-1.gir", - "HarfBuzz-0.0.gir", - "IBus-1.0.gir", - "JavaScriptCore-4.1.gir", - "JavaScriptCore-6.0.gir", - "Json-1.0.gir", - "libxml2-2.0.gir", - "Manette-0.2.gir", - "Nice-0.1.gir", - "Notify-0.7.gir", - "Pango-1.0.gir", - "PangoCairo-1.0.gir", - "PangoFc-1.0.gir", - "PangoFT2-1.0.gir", - "PangoOT-1.0.gir", - "Polkit-1.0.gir", - "Rsvg-2.0.gir", - "Secret-1.gir", - "Soup-3.0.gir", - "Tracker-3.0.gir", - "Vulkan-1.0.gir", - "WebKit2-4.1.gir", - "WebKit2WebExtension-4.1.gir", - "WebKit-6.0.gir", - "WebKitWebProcessExtension-6.0.gir", - "win32-1.0.gir", - "xfixes-4.0.gir", - "xft-2.0.gir", - "xlib-2.0.gir", - "xrandr-1.3.gir", + const GirProfile = enum { gnome44, gnome45 }; + const gir_profile = b.option(GirProfile, "gir-profile", "Predefined GIR profile for codegen") orelse .gnome45; + const gir: []const []const u8 = switch (gir_profile) { + .gnome44 => &.{ + "Adw-1.gir", + "AppStreamGlib-1.0.gir", + "Atk-1.0.gir", + "Atspi-2.0.gir", + "cairo-1.0.gir", + "DBus-1.0.gir", + "DBusGLib-1.0.gir", + "fontconfig-2.0.gir", + "freetype2-2.0.gir", + "GCab-1.0.gir", + "Gck-1.gir", + "Gck-2.gir", + "Gcr-3.gir", + "Gcr-4.gir", + "GcrUi-3.gir", + "GDesktopEnums-3.0.gir", + "Gdk-3.0.gir", + "Gdk-4.0.gir", + "GdkPixbuf-2.0.gir", + "GdkPixdata-2.0.gir", + "GdkWayland-4.0.gir", + "GdkX11-3.0.gir", + "GdkX11-4.0.gir", + "Gee-0.8.gir", + "Geoclue-2.0.gir", + "Gio-2.0.gir", + "GIRepository-2.0.gir", + "GL-1.0.gir", + "GLib-2.0.gir", + "GModule-2.0.gir", + "GObject-2.0.gir", + "Graphene-1.0.gir", + "Gsk-4.0.gir", + "Gst-1.0.gir", + "GstAllocators-1.0.gir", + "GstApp-1.0.gir", + "GstAudio-1.0.gir", + "GstBadAudio-1.0.gir", + "GstBase-1.0.gir", + "GstCheck-1.0.gir", + "GstCodecs-1.0.gir", + "GstController-1.0.gir", + "GstGL-1.0.gir", + "GstGLEGL-1.0.gir", + "GstGLWayland-1.0.gir", + "GstGLX11-1.0.gir", + "GstInsertBin-1.0.gir", + "GstMpegts-1.0.gir", + "GstNet-1.0.gir", + "GstPbutils-1.0.gir", + "GstPlay-1.0.gir", + "GstPlayer-1.0.gir", + "GstRtp-1.0.gir", + "GstRtsp-1.0.gir", + "GstSdp-1.0.gir", + "GstTag-1.0.gir", + "GstTranscoder-1.0.gir", + "GstVideo-1.0.gir", + "GstVulkan-1.0.gir", + "GstVulkanWayland-1.0.gir", + "GstVulkanXCB-1.0.gir", + "GstWebRTC-1.0.gir", + "Gtk-3.0.gir", + "Gtk-4.0.gir", + "GtkSource-4.gir", + "GtkSource-5.gir", + "GUdev-1.0.gir", + "Handy-1.gir", + "HarfBuzz-0.0.gir", + "IBus-1.0.gir", + "JavaScriptCore-4.1.gir", + "JavaScriptCore-6.0.gir", + "Json-1.0.gir", + "libxml2-2.0.gir", + "Manette-0.2.gir", + "Nice-0.1.gir", + "Notify-0.7.gir", + "Pango-1.0.gir", + "PangoCairo-1.0.gir", + "PangoFc-1.0.gir", + "PangoFT2-1.0.gir", + "PangoOT-1.0.gir", + "Polkit-1.0.gir", + "Rsvg-2.0.gir", + "Secret-1.gir", + "Soup-3.0.gir", + "Tracker-3.0.gir", + "Vulkan-1.0.gir", + "WebKit2-4.1.gir", + "WebKit2WebExtension-4.1.gir", + "WebKit-6.0.gir", + "WebKitWebProcessExtension-6.0.gir", + "win32-1.0.gir", + "xfixes-4.0.gir", + "xft-2.0.gir", + "xlib-2.0.gir", + "xrandr-1.3.gir", + }, + .gnome45 => &.{ + "Adw-1.gir", + "AppStream-1.0.gir", + "AppStreamCompose-1.0.gir", + "AppStreamGlib-1.0.gir", + "Atk-1.0.gir", + "Atspi-2.0.gir", + "Avahi-0.6.gir", + "AvahiCore-0.6.gir", + "cairo-1.0.gir", + "CudaGst-1.0.gir", + "DBus-1.0.gir", + "DBusGLib-1.0.gir", + "Dex-1.gir", + "fontconfig-2.0.gir", + "freetype2-2.0.gir", + "GCab-1.0.gir", + "Gck-1.gir", + "Gck-2.gir", + "Gcr-3.gir", + "Gcr-4.gir", + "GcrUi-3.gir", + "GDesktopEnums-3.0.gir", + "Gdk-3.0.gir", + "Gdk-4.0.gir", + "GdkPixbuf-2.0.gir", + "GdkPixdata-2.0.gir", + "GdkWayland-4.0.gir", + "GdkX11-3.0.gir", + "GdkX11-4.0.gir", + "Gee-0.8.gir", + "Geoclue-2.0.gir", + "Gio-2.0.gir", + "GIRepository-2.0.gir", + "GL-1.0.gir", + "GLib-2.0.gir", + "GModule-2.0.gir", + "GObject-2.0.gir", + "Graphene-1.0.gir", + "Gsk-4.0.gir", + "Gst-1.0.gir", + "GstAllocators-1.0.gir", + "GstApp-1.0.gir", + "GstAudio-1.0.gir", + "GstBadAudio-1.0.gir", + "GstBase-1.0.gir", + "GstCheck-1.0.gir", + "GstCodecs-1.0.gir", + "GstController-1.0.gir", + "GstCuda-1.0.gir", + "GstGL-1.0.gir", + "GstGLEGL-1.0.gir", + "GstGLWayland-1.0.gir", + "GstGLX11-1.0.gir", + "GstInsertBin-1.0.gir", + "GstMpegts-1.0.gir", + "GstNet-1.0.gir", + "GstPbutils-1.0.gir", + "GstPlay-1.0.gir", + "GstPlayer-1.0.gir", + "GstRtp-1.0.gir", + "GstRtsp-1.0.gir", + "GstSdp-1.0.gir", + "GstTag-1.0.gir", + "GstTranscoder-1.0.gir", + "GstVa-1.0.gir", + "GstVideo-1.0.gir", + "GstVulkan-1.0.gir", + "GstVulkanWayland-1.0.gir", + "GstVulkanXCB-1.0.gir", + "GstWebRTC-1.0.gir", + "Gtk-3.0.gir", + "Gtk-4.0.gir", + "GtkSource-5.gir", + "GUdev-1.0.gir", + "Handy-1.gir", + "HarfBuzz-0.0.gir", + "IBus-1.0.gir", + "JavaScriptCore-4.1.gir", + "JavaScriptCore-6.0.gir", + "Json-1.0.gir", + "Libproxy-1.0.gir", + "libxml2-2.0.gir", + "Manette-0.2.gir", + "Nice-0.1.gir", + "Notify-0.7.gir", + "Pango-1.0.gir", + "PangoCairo-1.0.gir", + "PangoFc-1.0.gir", + "PangoFT2-1.0.gir", + "PangoOT-1.0.gir", + "Polkit-1.0.gir", + "Rsvg-2.0.gir", + "Secret-1.gir", + "Soup-3.0.gir", + "Tracker-3.0.gir", + "Vulkan-1.0.gir", + "WebKit2-4.1.gir", + "WebKit2WebExtension-4.1.gir", + "WebKit-6.0.gir", + "WebKitWebProcessExtension-6.0.gir", + "win32-1.0.gir", + "xfixes-4.0.gir", + "xft-2.0.gir", + "xlib-2.0.gir", + "Xmlb-2.0.gir", + "xrandr-1.3.gir", + }, }; const binding_overrides = [_][]const u8{ @@ -197,6 +309,7 @@ fn addCodegenStep(b: *std.Build, codegen_exe: *std.Build.Step.Compile) !*std.Bui var file_deps = std.ArrayList([]const u8).init(b.allocator); for (gir) |file| { codegen_cmd.addArg(file[0 .. file.len - ".gir".len]); + try file_deps.append(b.pathJoin(&.{ gir_files_path, file })); } for (binding_overrides) |file| { try file_deps.append(try b.build_root.join(b.allocator, &.{ "binding-overrides", file }));