GNOME Bugzilla – Bug 794898
Meson: Cannot cross build glib
Last modified: 2018-04-17 12:09:51 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.
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.
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.
Oh, just discovered that some variables are documented in docs/reference/glib/cross.xml. We should port that doc too I guess.
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.
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.
(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().
Patch looks good to me at first glance.
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.
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.
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.
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.
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.
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.
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.
(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
Let's close this bug because it now builds, I'll open another bug to revisit cross properties and update the doc.