diff mbox series

[2/2] meson: Fix host_machine setting for native cross-file

Message ID 20250327225959.3611495-2-tom.hochstein@oss.nxp.com
State New
Headers show
Series [1/2] meson: Allow user to override setup command options | expand

Commit Message

Tom Hochstein March 27, 2025, 10:59 p.m. UTC
For native and nativesdk, the meson cross-file settings for
`host_machine` are incorrectly set for the build machine, not the
"machine on which the compiled binary will run". See
https://mesonbuild.com/Cross-compilation.html.

Signed-off-by: Tom Hochstein <tom.hochstein@oss.nxp.com>
---
 meta/recipes-devtools/meson/meson_1.7.0.bb | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)

Comments

Alexander Kanavin March 28, 2025, 10:08 a.m. UTC | #1
On Fri, 28 Mar 2025 at 00:00, Tom Hochstein via lists.openembedded.org
<tom.hochstein=oss.nxp.com@lists.openembedded.org> wrote:

> For native and nativesdk, the meson cross-file settings for
> `host_machine` are incorrectly set for the build machine, not the
> "machine on which the compiled binary will run". See
> https://mesonbuild.com/Cross-compilation.html.
...
>  [host_machine]
> -system = '$host_system'
> -cpu_family = '$host_cpu_family'
> -cpu = '$host_cpu'
> -endian = '$host_endian'
> +system = @OECORE_TARGET_OS
> +cpu_family = @OECORE_TARGET_ARCH
> +cpu = @OECORE_TARGET_ARCH
> +endian = @OECORE_TARGET_ENDIAN
>  EOF
>  }
>
>  do_install:append:class-nativesdk() {
> -    host_system=${SDK_OS}
> -    host_cpu_family=${@meson_cpu_family("SDK_ARCH", d)}
> -    host_cpu=${SDK_ARCH}
> -    host_endian=${@meson_endian("SDK", d)}
>      install_templates
>
>      install -d ${D}${SDKPATHNATIVE}/post-relocate-setup.d
> @@ -143,10 +139,6 @@ do_install:append:class-nativesdk() {
>  FILES:${PN}:append:class-nativesdk = "${datadir}/meson ${SDKPATHNATIVE}"
>
>  do_install:append:class-native() {
> -    host_system=${HOST_OS}
> -    host_cpu_family=${@meson_cpu_family("HOST_ARCH", d)}
> -    host_cpu=${HOST_ARCH}
> -    host_endian=${@meson_endian("HOST", d)}
>      install_templates

I'm struggling to see how the existing code ends up with incorrect
values in both native and nativesdk cases. Can you provide specific
example values and a way to see them?

Alex
Tom Hochstein March 28, 2025, 3:36 p.m. UTC | #2
On 3/28/2025 5:08 AM, Alexander Kanavin wrote:
> On Fri, 28 Mar 2025 at 00:00, Tom Hochstein via 
> lists.openembedded.org 
> <tom.hochstein=oss.nxp.com@lists.openembedded.org> wrote:
> 
>> For native and nativesdk, the meson cross-file settings for 
>> `host_machine` are incorrectly set for the build machine, not the 
>> "machine on which the compiled binary will run". See 
>> https://mesonbuild.com/Cross-compilation.html.
> ...
>> [host_machine] -system = '$host_system' -cpu_family = 
>> '$host_cpu_family' -cpu = '$host_cpu' -endian = '$host_endian' 
>> +system = @OECORE_TARGET_OS +cpu_family = @OECORE_TARGET_ARCH +cpu 
>> = @OECORE_TARGET_ARCH +endian = @OECORE_TARGET_ENDIAN EOF }
>> 
>> do_install:append:class-nativesdk() { -    host_system=${SDK_OS} - 
>> host_cpu_family=${@meson_cpu_family("SDK_ARCH", d)} - 
>> host_cpu=${SDK_ARCH} -    host_endian=${@meson_endian("SDK", d)} 
>> install_templates
>> 
>> install -d ${D}${SDKPATHNATIVE}/post-relocate-setup.d @@ -143,10 
>> +139,6 @@ do_install:append:class-nativesdk() { 
>> FILES:${PN}:append:class-nativesdk = "${datadir}/meson 
>> ${SDKPATHNATIVE}"
>> 
>> do_install:append:class-native() { -    host_system=${HOST_OS} - 
>> host_cpu_family=${@meson_cpu_family("HOST_ARCH", d)} - 
>> host_cpu=${HOST_ARCH} -    host_endian=${@meson_endian("HOST", d)}
>>  install_templates
> 
> I'm struggling to see how the existing code ends up with incorrect 
> values in both native and nativesdk cases. Can you provide specific 
> example values and a way to see them?
> 
> Alex

Yes, it does seem surprising. I'm guessing that the use case for using
these files is not common.

One way to see the problem is to check an installed SDK. For example,
for an i.MX SDK, check the file:

sysroots/x86_64-pokysdk-linux/usr/share/meson/aarch64-poky-linux-meson.cross

You'll see:

[host_machine]
system = 'linux'
cpu_family = 'x86_64'
cpu = 'x86_64'
endian = 'little'

These values are hard-coded in the template here:

sysroots/x86_64-pokysdk-linux/usr/share/meson/meson.cross.template

For the native case, you can build meson-native and check the file:

${D}/.../build/tmp/work/x86_64-linux/meson-native/1.7.0/recipe-sysroot-native/usr/share/meson/meson.cross.template

You'll see the same content.

Tom
diff mbox series

Patch

diff --git a/meta/recipes-devtools/meson/meson_1.7.0.bb b/meta/recipes-devtools/meson/meson_1.7.0.bb
index 44872a5f7b..e1c6759d5e 100644
--- a/meta/recipes-devtools/meson/meson_1.7.0.bb
+++ b/meta/recipes-devtools/meson/meson_1.7.0.bb
@@ -118,18 +118,14 @@  needs_exe_wrapper = true
 sys_root = @OECORE_TARGET_SYSROOT
 
 [host_machine]
-system = '$host_system'
-cpu_family = '$host_cpu_family'
-cpu = '$host_cpu'
-endian = '$host_endian'
+system = @OECORE_TARGET_OS
+cpu_family = @OECORE_TARGET_ARCH
+cpu = @OECORE_TARGET_ARCH
+endian = @OECORE_TARGET_ENDIAN
 EOF
 }
 
 do_install:append:class-nativesdk() {
-    host_system=${SDK_OS}
-    host_cpu_family=${@meson_cpu_family("SDK_ARCH", d)}
-    host_cpu=${SDK_ARCH}
-    host_endian=${@meson_endian("SDK", d)}
     install_templates
 
     install -d ${D}${SDKPATHNATIVE}/post-relocate-setup.d
@@ -143,10 +139,6 @@  do_install:append:class-nativesdk() {
 FILES:${PN}:append:class-nativesdk = "${datadir}/meson ${SDKPATHNATIVE}"
 
 do_install:append:class-native() {
-    host_system=${HOST_OS}
-    host_cpu_family=${@meson_cpu_family("HOST_ARCH", d)}
-    host_cpu=${HOST_ARCH}
-    host_endian=${@meson_endian("HOST", d)}
     install_templates
 
     install -d ${D}${datadir}/post-relocate-setup.d