libfolks typelib bindings not working in Gjs (JavaScript Bindings for GNOME)
Currently Folks.0.x.typelib
does not work in conjunction with gjs
(importing any class results in dereferencing void). I assume that this a bug in all folks typelib
files and does not only affect gjs
but all languages using the typelib
bindings of libfolks.
Minimal example
Create a file typelib_test.js
const Folks = imports.gi.Folks;
const aggregator = Folks.IndividualAggregator.dup();
log(`agg is quiescent ${aggregator.is_quiescent}`);
and run it with gjs typelib_test.js
. This will use the current Folks-0.x.typelib
of your OS and give the error
JS ERROR: Error: Unsupported type void, deriving from fundamental void
@typelib_test.js:2:20
Possible fix
As far as I can see this is due to a missing --shared-library
flag in the meson script.
The flag is also missing in the meson valapointed out here: https://github.com/mesonbuild/meson/issues/2296#issuecomment-328882589
This means in folks/meson.build
:
custom_target(libfolks_gir_name + '.typelib',
command: [ g_ir_compiler,
'--output', '@OUTPUT@',
meson.current_build_dir() / (libfolks_gir_name + '.gir')
],
output: libfolks_gir_name + '.typelib',
depends: libfolks_lib,
install: true,
install_dir: folks_typelibdir,
)
should probably be:
custom_target(libfolks_gir_name + '.typelib',
command: [ g_ir_compiler,
'--output', '@OUTPUT@',
'--shared-library', 'lib' + libfolks_lib.name(),
meson.current_build_dir() / (libfolks_gir_name + '.gir')
],
output: libfolks_gir_name + '.typelib',
depends: libfolks_lib,
install: true,
install_dir: folks_typelibdir,
)
Test of the fix
Build with fixed Code above, put
const GIRepository = imports.gi.GIRepository;
GIRepository.Repository.prepend_search_path('.');
const Folks = imports.gi.Folks;
const aggregator = Folks.IndividualAggregator.dup();
log(`agg is quiescent ${aggregator.is_quiescent}`);
into the typelib_test.js
, put it inside build/folks
and run gjs typelib_test.js
from there. One can also temporarily move the Folks-0.x.typelib
of your OS, replace it with the new one and run the first test script.
Meson gnome module
An alternative is using gnome.generate_gir
from the gnome
meson module. This would also fix the FIXME:
with reference to https://github.com/mesonbuild/meson/issues/4481 in folks/meson.build
as the module takes care of the generating the output path.
Backends
The missing --shared-library
flag probably also applies to backends/dummy/lib/meson.build
, backends/eds/lib/meson.build
, backends/telepathy/lib/meson.build
as well. I have not tested those libraries tho.
Thanks in advance if anyone takes the time to have a look at this! :)