SwiftGtk: Building on Apple Silicon (arm64) and Linux 64-bit ARM (aarch64) fails

When trying to build on Apple M1, there are some problems.

Running run-gir2swift.sh does not find the gir files at all.

Output is

Everything is already up-to-date
Girs located at
Generating Swift Wrapper for Atk ... Cannot open '/GLib-2.0.gir': No such file or directory
Cannot open '/GObject-2.0.gir': No such file or directory
Cannot open '/Atk-1.0.gir': No such file or directory
[...]

Note the empty string printed as gir location.

If I manually set the gir path by changing https://github.com/rhx/gir2swift/blob/cdd15b3e0c81470ff1f48e8ec00fbb8e4797f227/gir2swift-generation-driver.sh#L161 from GIR_PATH=$(gir_path_arg-gir-names "$ALL_GIR_NAMES") to GIR_PATH=/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/ the output changes to

Everything is already up-to-date
Girs located at /opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0
Building gir2swift
Generating Swift Wrapper for Atk ... Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Atk-1.0.gir': No such file or directory
/swift-gtk/.build/checkouts/SwiftAtk/gir2swift-manifest.sh: line 21: Sources/Atk/*-*.swift: No such file or directory
mv: rename Sources/Atk/*-*.swift.out to Sources/Atk/*-*.swift: No such file or directory

Generating Swift Wrapper for Cairo ... 
Generating Swift Wrapper for GIO ... 
Generating Swift Wrapper for GLib ... /swift-gtk/.build/checkouts/SwiftGLib/gir2swift-manifest.sh: line 21: ${src}: ambiguous redirect
usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory
/swift-gtk/.build/checkouts/SwiftGLib/gir2swift-manifest.sh: line 25: ${src}: ambiguous redirect
usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory

Generating Swift Wrapper for GModule ... 
Generating Swift Wrapper for GLibObject ... /swift-gtk/.build/checkouts/SwiftGObject/gir2swift-manifest.sh: line 21: ${src}: ambiguous redirect
usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory

Generating Swift Wrapper for Gdk ... Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/GdkPixbuf-2.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Pango-1.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/PangoCairo-1.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Gdk-3.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/GdkPixbuf-2.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Pango-1.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/PangoCairo-1.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Gdk-3.0.gir': No such file or directory

Generating Swift Wrapper for GdkPixbuf ... Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/GdkPixbuf-2.0.gir': No such file or directory

Generating Swift Wrapper for Pango ... Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Pango-1.0.gir': No such file or directory
/swift-gtk/.build/checkouts/SwiftPango/gir2swift-manifest.sh: line 21: Sources/Pango/*-*.swift: No such file or directory
mv: rename Sources/Pango/*-*.swift.out to Sources/Pango/*-*.swift: No such file or directory

Generating Swift Wrapper for PangoCairo ... Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Pango-1.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/PangoCairo-1.0.gir': No such file or directory

Generating Swift Wrapper for Gtk ... Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Atk-1.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Gdk-3.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/GdkPixbuf-2.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Pango-1.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/PangoCairo-1.0.gir': No such file or directory
Cannot open '/opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/Gtk-3.0.gir': No such file or directory
/swift-gtk/gir2swift-manifest.sh: line 30: ${src}: ambiguous redirect
usage: mv [-f | -i | -n] [-v] source target
       mv [-f | -i | -n] [-v] source ... directory
Postprocessing Wrapper for *-*.swift Postprocessing Wrapper for Gtk-3.0.swift

meaning that GLib-2.0.gir and GObject-2.0.gir can now be found, but Atk-1.0.gir and others not.

This is correct, as the directory /opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0/, where my gir files seem to be located, only contains:

DBus-1.0.gir
DBusGLib-1.0.gir
GIRepository-2.0.gir
GL-1.0.gir
GLib-2.0.gir
GModule-2.0.gir
GObject-2.0.gir
Gio-2.0.gir
Vulkan-1.0.gir
cairo-1.0.gir
fontconfig-2.0.gir
freetype2-2.0.gir
gir-1.2.rnc
libxml2-2.0.gir
win32-1.0.gir
xfixes-4.0.gir
xft-2.0.gir
xlib-2.0.gir
xrandr-1.3.gir

There seem to be some different gir related problems:

  1. gir directory is not detected correctly (should be /opt/homebrew/Cellar/gobject-introspection/1.66.1_1/share/gir-1.0)
  2. Some .gir files are not available, although the corresponding brew packages are installed. For example Atk-1.0.gir is missing.

My impression is, that problem 1 is related to the build scripts and problem 2 more a problem of homebrew not generating all gir files on arm64.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 15 (15 by maintainers)

Most upvoted comments

Offtopic: There might be another problem on arch arm64. When I attempted to compile SwiftGtk on Raspberry OS 64 beta which is Arm64, compilation failed when compiling GLib due to unavailability of type CLongDouble. The underlying code is not generated properly by gir2swift and is patched in postprocessing. The .gir element in question is marked as introspectable=0. At the first glance, currently gir2swift does not filter out un-introspectable elements which imo should be the case. However implementation of such feature would require major refactoring of gir2swift which I intend to do - my personal goal is late 2021. I have not opened the issue yet, because I would like to do so when I have the time to set up proper Raspberry Pi CI.

I can confirm this. On Apple m1, I managed to start an ubuntu VM using vmcli. The resulting Linux kernel identifies itself as

$ uname -a
Linux ubuntu 5.4.0-62-generic #70-Ubuntu SMP Tue Jan 12 12:50:33 UTC 2021 aarch64 aarch64 aarch64 GNU/Linux

Here, ./run-gir2swift.sh runs without error but build.sh fails with:

$ ./build.sh 
'CGLib' gio-unix-2.0.pc: warning: non whitelisted flag(s): -pthread
'CGtk' gtk+-3.0.pc: warning: non whitelisted flag(s): -pthread, -pthread, -pthread, -pthread, -pthread, -pthread, -pthread, -pthread
'CGdkPixbuf' gdk-pixbuf-2.0.pc: warning: non whitelisted flag(s): -pthread, -pthread
'CGdk' gdk-3.0.pc: warning: non whitelisted flag(s): -pthread, -pthread, -pthread
/home/username/SwiftGtk/.build/checkouts/SwiftGLib/Sources/GLib/GLib-2.0-TestConfig-Variant.swift:923:47: error: cannot find type 'CLongDouble' in scope
    @inlinable var nums: UnsafeMutablePointer<CLongDouble>! {
                                              ^~~~~~~~~~~
/home/username/SwiftGtk/.build/checkouts/SwiftGLib/Sources/GLib/GLib-2.0-TestConfig-Variant.swift:923:47: error: cannot find type 'CLongDouble' in scope
    @inlinable var nums: UnsafeMutablePointer<CLongDouble>! {
                                              ^~~~~~~~~~~
[31/33] Compiling GLib GLib-2.0-unions.swift