Skip to content

Commit

Permalink
Bump nixpkgs to 24.05, GTK to 4.14.4 (#145)
Browse files Browse the repository at this point in the history
* Bump nixpkgs to 24.05

* Detect length parameters

* Add vscode debug config

* Set module to go 1.22.0

* Regenerate pkg
  • Loading branch information
jgillich authored Jul 12, 2024
1 parent 0add5fd commit ab1a56e
Show file tree
Hide file tree
Showing 31 changed files with 51,307 additions and 30,509 deletions.
19 changes: 19 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Generate",
"type": "go",
"request": "launch",
"cwd": "${workspaceFolder}",
"program": "${workspaceFolder}/gir/cmd/gir-generate",
"args": [
"-o",
"./pkg"
]
}
]
}
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-gotk4.url = "github:NixOS/nixpkgs/fbfb79400a08bf754e32b4d4fc3f7d8f8055cf94"; # 2021-06-06
nixpkgs-gotk4.url = "github:NixOS/nixpkgs?ref=nixos-24.05";
flake-utils.url = "github:numtide/flake-utils";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";

Expand Down
72 changes: 14 additions & 58 deletions gir/cmd/gir-generate/gendata/gendata.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var PkgExceptions = []string{
// the given Packages list. It is manually updated.
var PkgGenerated = []string{
"atk",
// "atspi",
"gdk",
"gdkpixbuf",
"gdkpixdata",
Expand All @@ -68,6 +69,7 @@ var PkgGenerated = []string{
// GenerateExceptions contains the keys of the underneath ImportOverrides map.
var GenerateExceptions = []string{
"cairo-1",
"Atspi-2", // Missing AtspiDevice
}

// ImportOverrides is the list of imports to defer to another library, usually
Expand All @@ -79,10 +81,12 @@ var ImportOverrides = map[string]string{}
// Packages lists pkg-config packages and optionally the namespaces to be
// generated. If the list of namespaces is nil, then everything is generated.
var Packages = []genmain.Package{
{Name: "gobject-introspection-1.0", Namespaces: []string{
{Name: "glib-2.0", Namespaces: []string{
"GLib-2",
"GObject-2",
"Gio-2",
}},
{Name: "gobject-introspection-1.0", Namespaces: []string{
"cairo-1",
}},
{Name: "gdk-pixbuf-2.0"},
Expand Down Expand Up @@ -119,6 +123,7 @@ var Preprocessors = []Preprocessor{
RenameEnumMembers("Pango-1.AttrType", "ATTR_(.*)", "ATTR_TYPE_$1"),
RenameEnumMembers("Gsk-4.RenderNodeType", ".*", "${0}_TYPE"),
RenameEnumMembers("Gdk-3.EventType", ".*", "${0}_TYPE"),
RenameEnumMembers("Gtk-4.GraphicsOffloadEnabled", ".*", "${0}_TYPE"),
// See #28.
RemoveCIncludes("Gio-2.0.gir", "gio/gdesktopappinfo.h"),
// These probably shouldn't be built on Windows.
Expand Down Expand Up @@ -206,63 +211,6 @@ var Preprocessors = []Preprocessor{
}
}
}),

modifyBufferInsert("Gtk-4.TextBuffer.insert"),
modifyBufferInsert("Gtk-4.TextBuffer.insert_markup"),
modifyBufferInsert("Gtk-4.TextBuffer.insert_at_cursor"),
modifyBufferInsert("Gtk-4.TextBuffer.insert_interactive"),
modifyBufferInsert("Gtk-4.TextBuffer.insert_interactive_at_cursor"),
modifyBufferInsert("Gtk-4.TextBuffer.set_text"),

modifyBufferInsert("Gtk-3.TextBuffer.insert"),
modifyBufferInsert("Gtk-3.TextBuffer.insert_markup"),
modifyBufferInsert("Gtk-3.TextBuffer.insert_at_cursor"),
modifyBufferInsert("Gtk-3.TextBuffer.insert_interactive"),
modifyBufferInsert("Gtk-3.TextBuffer.insert_interactive_at_cursor"),
modifyBufferInsert("Gtk-3.TextBuffer.set_text"),
}

func modifyBufferInsert(name string) Preprocessor {
names := []string{"text", "markup"}

return ModifyCallable(name, func(c *gir.CallableAttrs) {
var p *gir.ParameterAttrs

for _, name := range names {
if p = FindParameter(c, name); p != nil {
break
}
}

if p == nil {
return
}

lenIx := findTextLenParam(c.Parameters.Parameters)
if lenIx == -1 {
return
}

p.Type = nil
p.Array = &gir.Array{
CType: "const char*",
Type: &gir.Type{Name: "gchar"},
Length: &lenIx,
ZeroTerminated: new(bool), // false
}
})
}

func findTextLenParam(params []gir.Parameter) int {
const doc = "length of"

for i, param := range params {
if param.Doc != nil && strings.Contains(param.Doc.String, doc) {
return i
}
}

return -1
}

var ConversionProcessors = []ConversionProcessor{
Expand All @@ -276,6 +224,7 @@ var ConversionProcessors = []ConversionProcessor{
// namespace, and the values are list of names.
var Filters = []FilterMatcher{
AbsoluteFilter("C.cairo_image_surface_create"),
AbsoluteFilter("C.gsk_path_builder_add_cairo_path"),

// This seems to be macro-guarded between x86 and arm64.
AbsoluteFilter("GLib.VA_COPY_AS_ARRAY"),
Expand Down Expand Up @@ -309,6 +258,9 @@ var Filters = []FilterMatcher{
AbsoluteFilter("GdkPixbuf.PixbufFormat.domain"),
AbsoluteFilter("GdkPixbuf.PixbufFormat.flags"),
AbsoluteFilter("GdkPixbuf.PixbufFormat.disabled"),
// Incomplete GArray implementation
AbsoluteFilter("Atk.Document.get_text_selections"),
AbsoluteFilter("Atk.Document.set_text_selections"),
// Dangerous.
AbsoluteFilter("GLib.IOChannel.read"),
AbsoluteFilter("GLib.Bytes.new_take"),
Expand Down Expand Up @@ -386,6 +338,10 @@ var Filters = []FilterMatcher{
AbsoluteFilter("C.gtk_print_capabilities_get_type"),
AbsoluteFilter("C.GdkPixbufAnimationClass"),
AbsoluteFilter("C.GdkPixbufAnimationIterClass"),
AbsoluteFilter("C.GThreadedResolverClass"),
AbsoluteFilter("C.g_threaded_resolver_get_type"),
AbsoluteFilter("C.GtkFileChooserWidgetAccessibleClass"),
AbsoluteFilter("C.gtk_file_chooser_widget_accessible_get_type"),

// Missing.
AbsoluteFilter("Gtk-3.HeaderBarAccessibleClass"),
Expand Down
2 changes: 2 additions & 0 deletions gir/girgen/generators/callable/callable.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func (g *Generator) renderDynamicLinkedBlock() bool {
// Copy the parameters list so we can freely mutate it.
parameters := types.ResolveParameters(g.gen, g.Parameters.Parameters)

types.DetectLengthParameters(parameters)

// Preprocess the values to normalize an edge case; see comment below.
for i, value := range parameters {
if value.AnyType.Array == nil || value.AnyType.Array.Length == nil {
Expand Down
2 changes: 2 additions & 0 deletions gir/girgen/generators/callback/callback.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ func (g *Generator) renderBlock() bool {
if g.Parameters != nil && len(g.Parameters.Parameters) > 0 {
callbackValues = make([]typeconv.ConversionValue, 0, len(g.Parameters.Parameters)+2)

types.DetectLengthParameters(g.Parameters.Parameters)

for i, param := range g.Parameters.Parameters {
// Skip generating the closure parameter.
if param.Skip || (g.Closure != nil && i == *g.Closure) {
Expand Down
25 changes: 25 additions & 0 deletions gir/girgen/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -586,3 +586,28 @@ func GuessParameterOutput(param *gir.Parameter) string {
param.Direction = "in"
return "in"
}

// Convert char* to array with an associated length parameter
// Based on detect_length https://github.com/gtk-rs/gir/blob/master/src/analysis/function_parameters.rs
func DetectLengthParameters(params []gir.Parameter) {
for i, param := range params {
if i == 0 ||
GuessParameterOutput(&param) != "in" ||
param.Name != "length" && !strings.HasSuffix(param.Name, "len") {
continue
}

data := &params[i-1]
if data.Type == nil || data.Type.CType != "const gchar*" && data.Type.CType != "const char*" {
continue
}

data.Array = &gir.Array{
CType: data.Type.CType,
Type: &gir.Type{Name: "gchar"},
Length: &i,
ZeroTerminated: new(bool), // false
}
data.Type = nil
}
}
12 changes: 6 additions & 6 deletions gir/pkgconfig/pkgconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,17 @@ func TestGIRDirs(t *testing.T) {
{
[]string{"gtk4"},
map[string]string{
"gtk4": "/nix/store/niw855nnjgqbq2s0iqxrk9xs5mr10rz8-gtk4-4.2.1-dev/share/gir-1.0",
"gtk4": "/nix/store/j2vgh4x3wmxrycvwkbnp74vh32yip9i5-gtk4-4.14.4-dev/share/gir-1.0",
},
},
{
[]string{"gtk4", "pango", "cairo", "glib-2.0", "gdk-3.0"},
map[string]string{
"gtk4": "/nix/store/niw855nnjgqbq2s0iqxrk9xs5mr10rz8-gtk4-4.2.1-dev/share/gir-1.0",
"pango": "/nix/store/c52730cidby7p2qwwq8cf91anqrni6lg-pango-1.48.4-dev/share/gir-1.0",
"cairo": "/nix/store/gp87jysb40b919z8s7ixcilwdsiyl0rp-cairo-1.16.0-dev/share/gir-1.0",
"glib-2.0": "/nix/store/d9zs9xg86lhqjqni0v8h2ibdrjb57fn4-glib-2.68.2-dev/share/gir-1.0",
"gdk-3.0": "/nix/store/vsk1qc1na4izgz461vxkvn655yvarfr7-gtk+3-3.24.27-dev/share/gir-1.0",
"gtk4": "/nix/store/j2vgh4x3wmxrycvwkbnp74vh32yip9i5-gtk4-4.14.4-dev/share/gir-1.0",
"pango": "/nix/store/fmqv9zpvf9fkb8n384ramhhbp8k20rnw-pango-1.52.2-dev/share/gir-1.0",
"cairo": "/nix/store/0i4xfw9ylgmg8f7z6rwwmfbin3ckyli5-cairo-1.18.0-dev/share/gir-1.0",
"glib-2.0": "/nix/store/kd2a4kyia0lai7n7hn657mpcr2gykw00-glib-2.80.2-dev/share/gir-1.0",
"gdk-3.0": "/nix/store/kd2a4kyia0lai7n7hn657mpcr2gykw00-glib-2.80.2-dev/share/gir-1.0",
},
},
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/diamondburned/gotk4

go 1.21.0
go 1.22.0

require (
github.com/alecthomas/assert/v2 v2.8.1
Expand Down
Loading

0 comments on commit ab1a56e

Please sign in to comment.