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 794898 - Meson: Cannot cross build glib
Meson: Cannot cross build glib
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: build
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks: 790954
 
 
Reported: 2018-04-02 14:00 UTC by Xavier Claessens
Modified: 2018-04-17 12:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Meson: Get results from cross file properties if cannot run code (6.13 KB, patch)
2018-04-03 03:28 UTC, Xavier Claessens
none Details | Review
Meson: Get results from cross file properties if cannot run code (6.81 KB, patch)
2018-04-03 15:07 UTC, Xavier Claessens
none Details | Review
Meson: Use cc.compute_int() instead of running our own code (3.69 KB, patch)
2018-04-06 17:55 UTC, Xavier Claessens
none Details | Review
Meson: Get results from cross file properties if cannot run code (4.10 KB, patch)
2018-04-06 17:55 UTC, Xavier Claessens
none Details | Review
Meson: Use cc.compute_int() instead of running our own code (3.57 KB, patch)
2018-04-06 18:02 UTC, Xavier Claessens
committed Details | Review
Meson: Get results from cross file properties if cannot run code (4.10 KB, patch)
2018-04-06 18:02 UTC, Xavier Claessens
committed Details | Review

Description Xavier Claessens 2018-04-02 14:00:33 UTC
Cross building glib for anything other than windows with Meson will fail with this error:

meson.build:680:2: ERROR:  Can not run test applications in this cross environment.

That's because it's trying to run code on the target to check vsnprintf C99 support. The corresponding code in acinclude.m4 fail safe in cross environment and just assume we don't have vsnprintf C99.
Comment 1 Xavier Claessens 2018-04-03 03:28:34 UTC
Created attachment 370470 [details] [review]
Meson: Get results from cross file properties if cannot run code

When cross compiling and not exe wrapper has been defined cc.run() raise
an exception. Avoid this by taking the value from [properties] in the
cross file and provide sensible default if the variable is not defined.
Comment 2 Xavier Claessens 2018-04-03 03:30:51 UTC
I didn't understood in the autoconf code where g_af_unix default value comes from if it cannot run code. For all other cc.run() I copied the default value.
Comment 3 Xavier Claessens 2018-04-03 13:31:45 UTC
Oh, just discovered that some variables are documented in docs/reference/glib/cross.xml. We should port that doc too I guess.
Comment 4 Xavier Claessens 2018-04-03 14:35:05 UTC
Checking the configure generated by autoconf, it has totally impossible to read ac_fn_c_compute_int() function that seems to do clever stuff to find out value of stuff where GLIB_CHECK_VALUE is used without running code when cross compiling.
Comment 5 Xavier Claessens 2018-04-03 15:07:37 UTC
Created attachment 370488 [details] [review]
Meson: Get results from cross file properties if cannot run code

When cross compiling and not exe wrapper has been defined cc.run() raise
an exception. Avoid this by taking the value from [properties] in the
cross file and provide sensible default if the variable is not defined.
Comment 6 Xavier Claessens 2018-04-03 15:08:18 UTC
(In reply to Xavier Claessens from comment #4)
> Checking the configure generated by autoconf, it has totally impossible to
> read ac_fn_c_compute_int() function that seems to do clever stuff to find
> out value of stuff where GLIB_CHECK_VALUE is used without running code when
> cross compiling.

Actually meson already has that same trick, cc.compute_int().
Comment 7 Tim-Philipp Müller 2018-04-06 15:16:03 UTC
Patch looks good to me at first glance.
Comment 8 Tim-Philipp Müller 2018-04-06 16:13:02 UTC
I think it would be good to split this into two patches:

 - use cc.compute_int() instead of homegrown cc.run() stuff

 - the other bits (can_cc_run + cross_properties)

I think this is ok to push and see what happens. Only risk I can see is that compute_int() by default has a limit of 1024, so we just have to hope that the defines don't exceed that on some OS or preventatively set a higher upper threshold.
Comment 9 Xavier Claessens 2018-04-06 16:25:19 UTC
Indeed meson checks in the [-1024,1024] range. I checked again the autoconf code and it is a bit smarter, it starts with hival=1 lowval=-1 and then double them until lowval <= val <= hival. And only after that it does a binary search in [lowval, hival] range. Would be nice to add that logic in meson too, but I don't think we are going to hit that issue here.
Comment 10 Tim-Philipp Müller 2018-04-06 16:34:02 UTC
Ack. If anyone hits that issue it will be obvious (meson error) and the fix will be obvious and trivial as well, so we probably don't have to worry too much about it.
Comment 11 Xavier Claessens 2018-04-06 17:55:10 UTC
Created attachment 370606 [details] [review]
Meson: Use cc.compute_int() instead of running our own code

When cross compiling we cannot run code, and meson has code to compute
int values without executing code.

This also fix inet values being all wrong because glib_inet_includes was
not used and compilation was always failing.
Comment 12 Xavier Claessens 2018-04-06 17:55:17 UTC
Created attachment 370607 [details] [review]
Meson: Get results from cross file properties if cannot run code

When cross compiling and not exe wrapper has been defined cc.run() raise
an exception. Avoid this by taking the value from [properties] in the
cross file and provide sensible default if the variable is not defined.
Comment 13 Xavier Claessens 2018-04-06 18:02:45 UTC
Created attachment 370610 [details] [review]
Meson: Use cc.compute_int() instead of running our own code

When cross compiling we cannot run code, and meson has code to compute
int values without executing code.
Comment 14 Xavier Claessens 2018-04-06 18:02:52 UTC
Created attachment 370611 [details] [review]
Meson: Get results from cross file properties if cannot run code

When cross compiling and not exe wrapper has been defined cc.run() raise
an exception. Avoid this by taking the value from [properties] in the
cross file and provide sensible default if the variable is not defined.
Comment 15 Xavier Claessens 2018-04-06 20:17:02 UTC
(In reply to Tim-Philipp Müller from comment #10)
> Ack. If anyone hits that issue it will be obvious (meson error) and the fix
> will be obvious and trivial as well, so we probably don't have to worry too
> much about it.

I though it would be fun, so I just did it:
https://github.com/mesonbuild/meson/pull/3365
Comment 16 Xavier Claessens 2018-04-09 13:26:34 UTC
Let's close this bug because it now builds, I'll open another bug to revisit cross properties and update the doc.