After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 773603 - Add support for building with the meson build system
Add support for building with the meson build system
Status: RESOLVED FIXED
Product: json-glib
Classification: Core
Component: general
git master
Other All
: Normal normal
: ---
Assigned To: json-glib-maint
json-glib-maint
Depends on:
Blocks:
 
 
Reported: 2016-10-27 20:09 UTC by Thibault Saunier
Modified: 2017-03-13 12:32 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Stop providing our own marshaller and use the generic one (5.97 KB, patch)
2016-10-27 20:09 UTC, Thibault Saunier
committed Details | Review
meson: Add support for building with the meson build system (7.62 KB, patch)
2016-10-27 20:09 UTC, Thibault Saunier
none Details | Review
meson: Add support for building with the meson build system (8.13 KB, patch)
2016-10-27 21:47 UTC, Thibault Saunier
none Details | Review
meson: Add support for building with the meson build system (9.07 KB, patch)
2016-10-28 11:03 UTC, Thibault Saunier
none Details | Review
Update patch (7.89 KB, patch)
2016-10-31 12:52 UTC, Thibault Saunier
needs-work Details | Review
meson: Add support for building with the meson build system (8.23 KB, patch)
2017-02-08 13:23 UTC, Thibault Saunier
committed Details | Review

Description Thibault Saunier 2016-10-27 20:09:17 UTC
The meson[0] build system is gaining momentum in particular in the GNOME
community and we might very much want to port json-glib to using it,
first as a second build system and hopfully as a replacement of the autotools.

I am attaching here patches that port json-glib to meson.
It is not fully complete yet as the following parts are known to be missing:

 * gir generation
 * documentation generation

It already builds:
  * libjson_glib
  * generates the .pc file
  * build the tests and they pass.
  * json-glib-validate
  * json-glib-format


[0] mesonbuild.com
Comment 1 Thibault Saunier 2016-10-27 20:09:21 UTC
Created attachment 338635 [details] [review]
Stop providing our own marshaller and use the generic one
Comment 2 Thibault Saunier 2016-10-27 20:09:26 UTC
Created attachment 338636 [details] [review]
meson: Add support for building with the meson build system
Comment 3 Thibault Saunier 2016-10-27 21:47:54 UTC
Created attachment 338642 [details] [review]
meson: Add support for building with the meson build system
Comment 4 Thibault Saunier 2016-10-27 21:48:33 UTC
(In reply to Thibault Saunier from comment #3)
> Created attachment 338642 [details] [review] [review]
> meson: Add support for building with the meson build system

Just added support for building as a subproject.
Comment 5 Emmanuele Bassi (:ebassi) 2016-10-28 09:24:00 UTC
Generating GIR is entirely possible and trivial to add.

The documentation part is, on the other hand, currently broken with Meson because of this issue: https://github.com/mesonbuild/meson/issues/550
Comment 6 Thibault Saunier 2016-10-28 11:03:14 UTC
Created attachment 338680 [details] [review]
meson: Add support for building with the meson build system
Comment 7 Thibault Saunier 2016-10-28 11:03:46 UTC
(In reply to Emmanuele Bassi (:ebassi) from comment #5)
> Generating GIR is entirely possible and trivial to add.

Added support in that last patch version.
Comment 8 Emmanuele Bassi (:ebassi) 2016-10-30 16:17:52 UTC
Review of attachment 338680 [details] [review]:

Thanks; it's improved, but still needs some work.

::: config.h.meson
@@ +23,3 @@
+#mesondefine PACKAGE_TARNAME
+#mesondefine PACKAGE_URL
+#mesondefine PACKAGE_VERSION

All the `PACKAGE` defines are unused, as far as I know, and are there only because autoconf puts them there.

::: json-glib/meson.build
@@ +1,3 @@
+install_header_dir ='json-glib-1.0/json-glib'
+
+source_h = ['json-builder.h', 'json-generator.h',

Please, one line per header.

@@ +12,3 @@
+
+json_glib_enums = gnome.mkenums('json-enum-types',
+  sources : headers_paths,

This seems like a bug in gnome.mkenums(); I'd expect all sources to come from current_source_dir().

@@ +13,3 @@
+json_glib_enums = gnome.mkenums('json-enum-types',
+  sources : headers_paths,
+  h_template : 'json-enum-types.h.in',

I prefer the colon to be flush with the positional argument, e.g.: `h_template: foo`.

@@ +16,3 @@
+  c_template : 'json-enum-types.c.in',
+  install_header : true,
+  install_dir : get_option('includedir') + '/' + install_header_dir)

This sounds like something that should have its own variable.

@@ +20,3 @@
+
+source_c = [
+  'json-array.c', 'json-builder.c', 'json-debug.c',

One file per line.

::: json-glib/tests/meson.build
@@ +18,3 @@
+python3 = find_program('python3')
+
+cp = run_command(python3, '-c',

Ugh, this is pretty terrible.

::: meson.build
@@ +15,3 @@
+  json_version_nano = version_arr[3]
+else
+  json_version_nano = 0

We never use a nano version.

@@ +23,3 @@
+# maintaining compatibility with the previous libtool versioning
+# current = minor * 100 + micro
+libversion = '@0@.@1@.0'.format(soversion, json_version_minor.to_int() * 100 + json_version_micro.to_int())

This is not how we do libtool versioning.

We use the same scheme as GTK+:

```
version_arr = meson.project_version().split('.')
json_version_major = version_arr[0].to_int()
json_version_minor = version_arr[1].to_int()
json_version_micro = version_arr[2].to_int()

if json_version_micro.is_odd()
  json_interface_age = 0
else
  json_interface_age = json_version_micro
endif

# maintaining compatibility with the previous libtool versioning
# current = minor * 100 + micro - interface
# revision = interface
soversion = 0
current = json_version_minor * 100 + json_version_micro - json_interface_age
revision = json_interface_age
libversion = '@0@.@1@.@2@'.format(soversion, current, revision)
```

@@ +35,3 @@
+
+check_headers = [
+  ['dlfcn.h','HAVE_DLFCN_H'],

Unused.

@@ +37,3 @@
+  ['dlfcn.h','HAVE_DLFCN_H'],
+  ['unistd.h', 'HAVE_UNISTD_H'],
+  ['sys/types.h', 'HAVE_SYS_TYPES_H'],

Unused.

@@ +38,3 @@
+  ['unistd.h', 'HAVE_UNISTD_H'],
+  ['sys/types.h', 'HAVE_SYS_TYPES_H'],
+  ['sys/stat.h', 'HAVE_SYS_STAT_H'],

Unused.

@@ +40,3 @@
+  ['sys/stat.h', 'HAVE_SYS_STAT_H'],
+  ['string.h', 'HAVE_STRING_H'],
+  ['strings.h', 'HAVE_STRINGS_H'],

Unused.

@@ +41,3 @@
+  ['string.h', 'HAVE_STRING_H'],
+  ['strings.h', 'HAVE_STRINGS_H'],
+  ['stdint.h', 'HAVE_STDINT_H'],

Unused.

@@ +42,3 @@
+  ['strings.h', 'HAVE_STRINGS_H'],
+  ['stdint.h', 'HAVE_STDINT_H'],
+  ['memory.h', 'HAVE_MEMORY_H'],

Unused.

@@ +43,3 @@
+  ['stdint.h', 'HAVE_STDINT_H'],
+  ['memory.h', 'HAVE_MEMORY_H'],
+  ['inttypes.h', 'HAVE_INTTYPES_H'],

Unused.

@@ +44,3 @@
+  ['memory.h', 'HAVE_MEMORY_H'],
+  ['inttypes.h', 'HAVE_INTTYPES_H'],
+  ['dlfcn.h','HAVE_DLFCN_H'],

Duplicate, and unused.

@@ +54,3 @@
+
+check_functions = [
+  ['HAVE_DCGETTEXT', 'dcgettext', '#include<libintl.h>'],

Unused.

@@ +67,3 @@
+cdata.set_quoted('PACKAGE_STRING', 'json-glib ' + json_version)
+cdata.set_quoted('PACKAGE_URL', 'http://live.gnome.org/JsonGlib')
+cdata.set_quoted('PACKAGE_VERSION', json_version)

All the `PACKAGE_*` defines can go away. We're only interested in `GETTEXT_PACKAGE`.

@@ +69,3 @@
+cdata.set_quoted('PACKAGE_VERSION', json_version)
+# FIXME Check how to do it with mingw
+cdata.set('_JSON_EXTERN', '__attribute__((visibility("default"))) extern')

The FIXME can be fixed with:

if get_option('default_library') != 'static'
  if host_system == 'windows'
    conf.set('DLL_EXPORT', true)
    if cc.get_id() == 'msvc'
      conf.set('_JSON_EXTERN', '__declspec(dllexport) extern')
    else
      conf.set('_JSON_EXTERN', '__attribute__((visibility("default"))) __declspec(dllexport) extern')
      extra_args += ['-fvisibility=hidden']
    endif
  else
    conf.set('_JSON_EXTERN', '__attribute__((visibility("default")))')
    extra_args += ['-fvisibility=hidden']
  endif
endif
Comment 9 Tim-Philipp Müller 2016-10-30 16:35:00 UTC
> ::: config.h.meson
> @@ +23,3 @@
> +#mesondefine PACKAGE_TARNAME
> +#mesondefine PACKAGE_URL
> +#mesondefine PACKAGE_VERSION
> 
> All the `PACKAGE` defines are unused, as far as I know, and are there only
> because autoconf puts them there.

For what it's worth the config.h.meson template is no longer needed, recent versions just do the right thing if you leave out the input file (and git master has support for a description: kwarg for cdata.set() etc. if you want descriptions in the config.h).
Comment 10 Thibault Saunier 2016-10-31 12:52:34 UTC
Created attachment 338827 [details] [review]
Update patch

Thanks for the review!

(In reply to Emmanuele Bassi (:ebassi) from comment #8)
> Review of attachment 338680 [details] [review] [review]:
> 
> Thanks; it's improved, but still needs some work.
> 
> ::: config.h.meson
> @@ +23,3 @@
> +#mesondefine PACKAGE_TARNAME
> +#mesondefine PACKAGE_URL
> +#mesondefine PACKAGE_VERSION
> 
> All the `PACKAGE` defines are unused, as far as I know, and are there only
> because autoconf puts them there.

Removed.

> ::: json-glib/meson.build
> @@ +1,3 @@
> +install_header_dir ='json-glib-1.0/json-glib'
> +
> +source_h = ['json-builder.h', 'json-generator.h',
> 
> Please, one line per header.

DONE

> @@ +12,3 @@
> +
> +json_glib_enums = gnome.mkenums('json-enum-types',
> +  sources : headers_paths,
> 
> This seems like a bug in gnome.mkenums(); I'd expect all sources to come
> from current_source_dir().

Yes, this is a bug when using subprojects, I will fix it in meson
(https://github.com/mesonbuild/meson/issues/973)
but meanwhile I would prefer to have this workaround.

Added well due FIXME.

> 
> @@ +13,3 @@
> +json_glib_enums = gnome.mkenums('json-enum-types',
> +  sources : headers_paths,
> +  h_template : 'json-enum-types.h.in',
> 
> I prefer the colon to be flush with the positional argument, e.g.:
> `h_template: foo`.

OK, fixed everywhere.

> @@ +16,3 @@
> +  c_template : 'json-enum-types.c.in',
> +  install_header : true,
> +  install_dir : get_option('includedir') + '/' + install_header_dir)
> 
> This sounds like something that should have its own variable.
DONE

> @@ +20,3 @@
> +
> +source_c = [
> +  'json-array.c', 'json-builder.c', 'json-debug.c',
> 
> One file per line.
DONE

> ::: json-glib/tests/meson.build
> @@ +18,3 @@
> +python3 = find_program('python3')
> +
> +cp = run_command(python3, '-c',
> 
> Ugh, this is pretty terrible.

Well, it is the simple solution to get the tests working without
modifying the current way it works.

> ::: meson.build
> @@ +15,3 @@
> +  json_version_nano = version_arr[3]
> +else
> +  json_version_nano = 0
> 
> We never use a nano version.
REMOVED

> @@ +23,3 @@
> +# maintaining compatibility with the previous libtool versioning
> +# current = minor * 100 + micro
> +libversion = '@0@.@1@.0'.format(soversion, json_version_minor.to_int() *
> 100 + json_version_micro.to_int())
> 
> This is not how we do libtool versioning.
> 
> We use the same scheme as GTK+:
> 
> ```
> version_arr = meson.project_version().split('.')
> json_version_major = version_arr[0].to_int()
> json_version_minor = version_arr[1].to_int()
> json_version_micro = version_arr[2].to_int()
> 
> if json_version_micro.is_odd()
>   json_interface_age = 0
> else
>   json_interface_age = json_version_micro
> endif
> 
> # maintaining compatibility with the previous libtool versioning
> # current = minor * 100 + micro - interface
> # revision = interface
> soversion = 0
> current = json_version_minor * 100 + json_version_micro - json_interface_age
> revision = json_interface_age
> libversion = '@0@.@1@.@2@'.format(soversion, current, revision)
> ```

DONE, almost reused your snipnet as is.

> @@ +35,3 @@
> +
> +check_headers = [
> +  ['dlfcn.h','HAVE_DLFCN_H'],
> 
> Unused.
DONE

> 
> @@ +37,3 @@
> +  ['dlfcn.h','HAVE_DLFCN_H'],
> +  ['unistd.h', 'HAVE_UNISTD_H'],
> +  ['sys/types.h', 'HAVE_SYS_TYPES_H'],
> 
> Unused.

+  ['unistd.h', 'HAVE_UNISTD_H'],

This one is used, rest is DONE.

> 
> @@ +38,3 @@
> +  ['unistd.h', 'HAVE_UNISTD_H'],
> +  ['sys/types.h', 'HAVE_SYS_TYPES_H'],
> +  ['sys/stat.h', 'HAVE_SYS_STAT_H'],
> 
> Unused.
DONE

> 
> @@ +40,3 @@
> +  ['sys/stat.h', 'HAVE_SYS_STAT_H'],
> +  ['string.h', 'HAVE_STRING_H'],
> +  ['strings.h', 'HAVE_STRINGS_H'],
> 
> Unused.
DONE

> 
> @@ +41,3 @@
> +  ['string.h', 'HAVE_STRING_H'],
> +  ['strings.h', 'HAVE_STRINGS_H'],
> +  ['stdint.h', 'HAVE_STDINT_H'],
> 
> Unused.
DONE

> 
> @@ +42,3 @@
> +  ['strings.h', 'HAVE_STRINGS_H'],
> +  ['stdint.h', 'HAVE_STDINT_H'],
> +  ['memory.h', 'HAVE_MEMORY_H'],
> 
> Unused.
DONE

> 
> @@ +43,3 @@
> +  ['stdint.h', 'HAVE_STDINT_H'],
> +  ['memory.h', 'HAVE_MEMORY_H'],
> +  ['inttypes.h', 'HAVE_INTTYPES_H'],
> 
> Unused.
DONE

> 
> @@ +44,3 @@
> +  ['memory.h', 'HAVE_MEMORY_H'],
> +  ['inttypes.h', 'HAVE_INTTYPES_H'],
> +  ['dlfcn.h','HAVE_DLFCN_H'],
> 
> Duplicate, and unused.
DONE

> 
> @@ +54,3 @@
> +
> +check_functions = [
> +  ['HAVE_DCGETTEXT', 'dcgettext', '#include<libintl.h>'],
> 
> Unused.
DONE

> 
> @@ +67,3 @@
> +cdata.set_quoted('PACKAGE_STRING', 'json-glib ' + json_version)
> +cdata.set_quoted('PACKAGE_URL', 'http://live.gnome.org/JsonGlib')
> +cdata.set_quoted('PACKAGE_VERSION', json_version)
> 
> All the `PACKAGE_*` defines can go away. We're only interested in
> `GETTEXT_PACKAGE`.
> 
> @@ +69,3 @@
> +cdata.set_quoted('PACKAGE_VERSION', json_version)
> +# FIXME Check how to do it with mingw
> +cdata.set('_JSON_EXTERN', '__attribute__((visibility("default"))) extern')
> 
> The FIXME can be fixed with:
> 
> if get_option('default_library') != 'static'
>   if host_system == 'windows'
>     conf.set('DLL_EXPORT', true)
>     if cc.get_id() == 'msvc'
>       conf.set('_JSON_EXTERN', '__declspec(dllexport) extern')
>     else
>       conf.set('_JSON_EXTERN', '__attribute__((visibility("default")))
> __declspec(dllexport) extern')
>       extra_args += ['-fvisibility=hidden']
>     endif
>   else
>     conf.set('_JSON_EXTERN', '__attribute__((visibility("default")))')
>     extra_args += ['-fvisibility=hidden']
>   endif
> endif

DONE, reusing your snipnet almost as is.


(In reply to Tim-Philipp Müller from comment #9)
> > ::: config.h.meson
> > @@ +23,3 @@
> > +#mesondefine PACKAGE_TARNAME
> > +#mesondefine PACKAGE_URL
> > +#mesondefine PACKAGE_VERSION
> > 
> > All the `PACKAGE` defines are unused, as far as I know, and are there only
> > because autoconf puts them there.
> 
> For what it's worth the config.h.meson template is no longer needed, recent
> versions just do the right thing if you leave out the input file (and git
> master has support for a description: kwarg for cdata.set() etc. if you want
> descriptions in the config.h).

I removed the config.h.meson file, as it is useless now indeed.
Comment 11 Thibault Saunier 2016-11-14 19:58:03 UTC
Anything missing here?
Comment 12 Tim-Philipp Müller 2016-12-16 14:52:01 UTC
Comment on attachment 338635 [details] [review]
Stop providing our own marshaller and use the generic one

Note that for most of these there are also g_cclosure_marshal_* in GLib already and we could just use those here directly in case performance is a concern, then the generic marshaller would only be used for the VOID__BOXED_XYZ ones.
Comment 13 Tim-Philipp Müller 2016-12-16 14:53:45 UTC
Actually nevermind the last comment, g_signal_new*() will figure out the right built-in marshaller for us already when we pass NULL, sorry for the noise.
Comment 14 Thibault Saunier 2017-01-13 19:07:44 UTC
Another gentle ping :)
Comment 15 Emmanuele Bassi (:ebassi) 2017-02-07 23:07:47 UTC
Review of attachment 338635 [details] [review]:

I don't particularly like using the generic marshaller because the libffi → GValue → libffi transformation is slower, but hopefully *nobody* is using signals in performance critical paths.
Comment 16 Emmanuele Bassi (:ebassi) 2017-02-07 23:15:01 UTC
Review of attachment 338827 [details] [review]:

Getting there.

::: json-glib/json-enum-types.c.in
@@ +2,3 @@
+#ifndef JSON_COMPILATION
+#define JSON_COMPILATION
+#endif

No, this is not right.

This will define JSON_COMPILATION when including json-enum-types.h from any dependent project, which is *definitely* not what we want.

::: json-glib/meson.build
@@ +1,2 @@
+install_header_subdir = 'json-glib-1.0/json-glib'
+install_header_dir = get_option('includedir') + '/' + install_header_subdir

This should be:

  includedir = join_paths(get_option('prefix'), get_option('includedir'))

@@ +15,3 @@
+]
+
+# FIXME remove this workaround https://github.com/mesonbuild/meson/issues/973

I guess this FIXME can be fixed, now.

@@ +60,3 @@
+install_headers(source_h, subdir: install_header_subdir)
+
+localedir = get_option('localedir')

This should really be:

  localedir = join_paths(get_option('prefix'), get_option('localedir'))

@@ +111,3 @@
+    dependencies: json_glib_dep)
+
+json_glib_validate = executable('json-glib-format',

I know it's not necessary, but you're re-using the same variable name.

::: meson.build
@@ +1,3 @@
+project('json-glib', 'c',
+  version: '1.2.3',
+  meson_version: '>= 0.35.0',

I'd bump it up to 0.37.1, since it's the version in Fedora, Debian, and the next Ubuntu release.

@@ +16,3 @@
+soversion = 0
+
+if json_version_micro.to_int() % 2 != 0

meson ≥ 0.36 has is_odd() for this case.
Comment 17 Thibault Saunier 2017-02-08 13:23:22 UTC
Review of attachment 338827 [details] [review]:

::: json-glib/json-enum-types.c.in
@@ +2,3 @@
+#ifndef JSON_COMPILATION
+#define JSON_COMPILATION
+#endif

This is the .c file so it is obviously being built... It fixes corner cases when building a subproject of in a subproject

::: json-glib/meson.build
@@ +1,2 @@
+install_header_subdir = 'json-glib-1.0/json-glib'
+install_header_dir = get_option('includedir') + '/' + install_header_subdir

No need to specify prefix no, using join_paths now though.

@@ +60,3 @@
+install_headers(source_h, subdir: install_header_subdir)
+
+localedir = get_option('localedir')

Done.

@@ +111,3 @@
+    dependencies: json_glib_dep)
+
+json_glib_validate = executable('json-glib-format',

Fixed.

::: meson.build
@@ +1,3 @@
+project('json-glib', 'c',
+  version: '1.2.3',
+  meson_version: '>= 0.35.0',

Done

@@ +16,3 @@
+soversion = 0
+
+if json_version_micro.to_int() % 2 != 0

Done.
Comment 18 Thibault Saunier 2017-02-08 13:23:36 UTC
Created attachment 345210 [details] [review]
meson: Add support for building with the meson build system
Comment 19 Emmanuele Bassi (:ebassi) 2017-03-10 11:13:05 UTC
Review of attachment 345210 [details] [review]:

Looks generally good for an initial merge; still a couple of issues.

::: json-glib/json-gvariant.c
@@ +762,3 @@
   GList *children = NULL;
   gboolean roll_back = FALSE;
+  const gchar *orig_signature = NULL;

This is an extraneous chunk, and should be in a separate commit.

::: meson.build
@@ +61,3 @@
+    endif
+  else
+    cdata.set('_JSON_EXTERN', '__attribute__((visibility("default")))')

This is missing an `extern` after the `__attribute__`.

@@ +66,3 @@
+endif
+
+configure_file(output: 'config.h', configuration: cdata)

I'd rather have this in the `json-glib` sub-directory.
Comment 20 Emmanuele Bassi (:ebassi) 2017-03-13 11:35:42 UTC
Comment on attachment 338635 [details] [review]
Stop providing our own marshaller and use the generic one

Attachment 338635 [details] pushed as d77a1c8 - Stop providing our own marshaller and use the generic one
Comment 21 Emmanuele Bassi (:ebassi) 2017-03-13 12:32:23 UTC
Attachment 345210 [details] pushed as 234ae81 - meson: Add support for building with the meson build system

I've also pushed a series of follow up commits that make the Meson build equivalent to the autotools one:

  - API reference
  - man pages
  - localization

Thanks again for starting this!