GtkSourceview with meson

Hi,

I am trying to create a simple text editor in Javascript. I am however unable to load gtksourceview. I guess it is a meson setup problem, as the code


imports.gi.versions.Gtk = "3.0";
imports.gi.versions.GtkSource = "3.0";
const { Gtk } = imports.gi;
const { GtkSource } = imports.gi;

Gtk.init(null);

const entry = new GtkSource.View({
    buffer: new GtkSource.Buffer(),
    vexpand: true
});

const win = new Gtk.Window({ defaultHeight: 600, defaultWidth: 800 });
win.connect('destroy', () => { Gtk.main_quit(); });
win.add(entry);
win.show_all();

Gtk.main();

runs properly. In Builder however the line const GtkSource = imports.gi.GtkSource results in the error message:

JS ERROR: Error: Requiring GtkSource, version none: Typelib file for namespace 'GtkSource' (any version) not found

Trying to add dependency('gtksourceview-3.0') to my meson.build (I haven’t changed the default setup apart from this ) results in the error

ERROR: Dependency "gtksourceview-3.0" not found, tried pkgconfig and cmake

I have very little idea what I am doing, can someone point me to the right direction?

Thanks in advance!

Do you have gtksourceview-3.0 installed? if the answer is No, then you should install it.

Are you using Builder gjs template? If so, then you need to add gtksourceview-3.0 to your project Flatpak manifest, to have it installed for you.

Here an example from a Python editor I maintain: https://github.com/flathub/org.sugarlabs.Pippy/blob/master/org.sugarlabs.Pippy.json#L232

Meson has nothing to do with this.

The dependency() object is for the underlying C library; you’re missing the typelib file, which is used by GJS to call the underlying C API.

The typelib files are generated when building a GObject-based library, and are usually shipped with the shared library itself, but it depends on your Linux distribution how they are packaged. You may need to install an additional package—on Debian/Ubuntu it’s gir1.2-gtksource-3.0, for instance.

Are you using Builder gjs template? If so, then you need to add gtksourceview-3.0 to your project Flatpak manifest, to have it installed for you.

Thanks a lot, this is exactly what I needed. For other ppl who happen to have the same problem, don’t modify the meson.build(), but add

        {
            "name": "gtksourceview",
            "config-opts": ["--enable-gtk-doc=no"],
            "sources": [
                {
                    "type": "archive",
                    "url": "https://download.gnome.org/sources/gtksourceview/3.24/gtksourceview-3.24.11.tar.xz",
                    "sha256": "691b074a37b2a307f7f48edc5b8c7afa7301709be56378ccf9cc9735909077fd"
                }
            ]
        },

to the modules section in the json file. Note that this should come before the entry describing your app (see flatpak tutorial).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.