Skip to contentSkip to conversation

toolchain-scripts: Add Meson settings for Yocto build SDK

PATCH Superseded Tom Hochstein 2 participants 6 messages Apr 6, 2025 – Apr 7, 2025 Arm/Amlogic Meson SoC support

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/5 toolchain-scripts: Add Meson settings for Yocto build SDK

The Meson settings for the standalone SDK also need to be available for the Yocto build SDK, a.k.a. meta-ide-support.

---
 meta/classes-recipe/toolchain-scripts.bbclass | 2 ++
 1 file changed, 2 insertions(+)
meta/classes-recipe/toolchain-scripts.bbclass +2 -0
index b59a295abc..9e4320f876 100644
@@ -99,6 +99,8 @@ toolchain_create_tree_env_script () {
 	echo 'export OECORE_BASELIB="${baselib}"' >> $script
 	echo 'export OECORE_TARGET_ARCH="${TARGET_ARCH}"' >>$script
 	echo 'export OECORE_TARGET_OS="${TARGET_OS}"' >>$script
+	echo 'export OECORE_TARGET_BITS="${@siteinfo_with_prefix(d, 'bit-')}"' >>$script
+	echo 'export OECORE_TARGET_ENDIAN="${@siteinfo_with_prefix(d, 'endian-')}"' >>$script
 
 	toolchain_shared_env_script
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v4 2/5 toolchain-scripts: Export meson settings for SDK builds

Create a new set of exports for the Meson host_machine cross settings. This allows the target cross file to be created correctly from meson.cross.template and aligns with meson.bbclass.

Note, one might think that HOST_OS and HOST_ARCH would be appropriate as inputs here, aligning nicely with the Meson naming. That turns out to be incorrect since the script is generated in a native/nativesdk build with HOST_OS and HOST_ARCH set for the "build machine", not the "host machine", using the Meson terminology. See
https://mesonbuild.com/Cross-compilation.html.

Fixes [YOCTO #15485]
---
 meta/classes-recipe/toolchain-scripts.bbclass | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
meta/classes-recipe/toolchain-scripts.bbclass +9 -1
index 9e4320f876..3053cd0f1f 100644
@@ -4,7 +4,7 @@
 # SPDX-License-Identifier: MIT
 #
 
-inherit toolchain-scripts-base siteinfo kernel-arch
+inherit toolchain-scripts-base siteinfo kernel-arch meson-routines
 
 # We want to be able to change the value of MULTIMACH_TARGET_SYS, because it
 # doesn't always match our expectations... but we default to the stock value
@@ -72,6 +72,10 @@ toolchain_create_sdk_env_script () {
 	echo 'export OECORE_TARGET_OS="${TARGET_OS}"' >>$script
 	echo 'export OECORE_TARGET_BITS="${@siteinfo_with_prefix(d, 'bit-')}"' >>$script
 	echo 'export OECORE_TARGET_ENDIAN="${@siteinfo_with_prefix(d, 'endian-')}"' >>$script
+	echo 'export OECORE_MESON_HOST_SYSTEM="${@meson_operating_system('TARGET_OS', d)}"' >>$script
+	echo 'export OECORE_MESON_HOST_CPU_FAMILY="${@meson_cpu_family('TARGET_ARCH', d)}"' >>$script
+	echo 'export OECORE_MESON_HOST_CPU="${TARGET_ARCH}"' >>$script
+	echo 'export OECORE_MESON_HOST_ENDIAN="${@meson_endian('TARGET', d)}"' >>$script
 
 	echo 'unset command_not_found_handle' >> $script
 
@@ -101,6 +105,10 @@ toolchain_create_tree_env_script () {
 	echo 'export OECORE_TARGET_OS="${TARGET_OS}"' >>$script
 	echo 'export OECORE_TARGET_BITS="${@siteinfo_with_prefix(d, 'bit-')}"' >>$script
 	echo 'export OECORE_TARGET_ENDIAN="${@siteinfo_with_prefix(d, 'endian-')}"' >>$script
+	echo 'export OECORE_MESON_HOST_SYSTEM="${@meson_operating_system('TARGET_OS', d)}"' >>$script
+	echo 'export OECORE_MESON_HOST_CPU_FAMILY="${@meson_cpu_family('TARGET_ARCH', d)}"' >>$script
+	echo 'export OECORE_MESON_HOST_CPU="${TARGET_ARCH}"' >>$script
+	echo 'export OECORE_MESON_HOST_ENDIAN="${@meson_endian('TARGET', d)}"' >>$script
 
 	toolchain_shared_env_script
 
Signature · 1 line
2.34.1
#2 lore raw

PATCH v4 3/5 meson: Fix host_machine setting for native cross-file

In reply to Tom Hochstein

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.

Fixes [YOCTO #15485]
---
 meta/recipes-devtools/meson/meson_1.7.0.bb | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
meta/recipes-devtools/meson/meson_1.7.0.bb +4 -12
index 44872a5f7b..3e89669807 100644
@@ -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_MESON_HOST_SYSTEM
+cpu_family = @OECORE_MESON_HOST_CPU_FAMILY
+cpu = @OECORE_MESON_HOST_CPU
+endian = @OECORE_MESON_HOST_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
Signature · 1 line
2.34.1
#3 lore raw

PATCH v4 4/5 oeqa/sdk/meson: improve test to validate host/build target assignments

In reply to Tom Hochstein

From: Ross Burton <[email protected]>

Use 'meson introspect' to dump JSON describing the build configuration and validate that the build and host architectures are correctly set in the meson.cross file.

Also instead of calling ninja directly, call the relevant meson commands.

Fixes [YOCTO #15485]
---
 meta/lib/oeqa/sdk/cases/meson.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
meta/lib/oeqa/sdk/cases/meson.py +12 -5
index 1edf78720a..f70177a033 100644
@@ -39,10 +39,17 @@ class MesonTest(OESDKTestCase):
             self.assertTrue(os.path.isdir(dirs["source"]))
             os.makedirs(dirs["build"])
 
-            log = self._run("meson --warnlevel 1 -Degl=no -Dglx=no -Dx11=false {build} {source}".format(**dirs))
-            # Check that Meson thinks we're doing a cross build and not a native
-            self.assertIn("Build type: cross build", log)
-            self._run("ninja -C {build} -v".format(**dirs))
-            self._run("DESTDIR={install} ninja -C {build} -v install".format(**dirs))
+            log = self._run("meson setup --warnlevel 1 -Degl=no -Dglx=no -Dx11=false {build} {source}".format(**dirs))
+
+            # Check that the host (gcc) and build (cross-gcc) compilers are different
+            data = json.loads(self._run("meson introspect --compilers {build}".format(**dirs)))
+            self.assertNotEqual(data["build"]["c"]["exelist"], data["host"]["c"]["exelist"])
+            # Check that the system architectures were set correctly
+            data = json.loads(self._run("meson introspect --machines {build}".format(**dirs)))
+            self.assertEqual(data["build"]["cpu"], self.td["SDK_ARCH"])
+            self.assertEqual(data["host"]["cpu"], self.td["HOST_ARCH"])
+
+            self._run("meson compile -C {build} -v".format(**dirs))
+            self._run("meson install -C {build} --destdir {install}".format(**dirs))
 
             self.check_elf(os.path.join(dirs["install"], "usr", "local", "lib", "libepoxy.so"))
Signature · 1 line
2.34.1
#4 lore raw

Re: [OE-core] [PATCH v4 4/5] oeqa/sdk/meson: improve test to validate host/build target assignments

Quoted 6 lines · Tom Hochstein via lists.openembedded.org

From: Ross Burton <[email protected]>

Use 'meson introspect' to dump JSON describing the build configuration and validate that the build and host architectures are correctly set in the meson.cross file.

Quoted 6 lines

Also instead of calling ninja directly, call the relevant meson commands.

Fixes [YOCTO #15485]

---

Hi,

Thanks for your patch.

Quoted 10 lines
 meta/lib/oeqa/sdk/cases/meson.py | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
meta/lib/oeqa/sdk/cases/meson.py +0 -0
index 1edf78720a..f70177a033 100644
@@ -39,10 +39,17 @@ class MesonTest(OESDKTestCase):
             self.assertTrue(os.path.isdir(dirs["source"]))
             os.makedirs(dirs["build"])

meta/lib/oeqa/sdk/cases/meson.py class MesonTest(OESDKTestCase): · line 45

Quoted 10 lines
meta/lib/oeqa/sdk/cases/meson.py +4 -5
 
-            log = self._run("meson --warnlevel 1 -Degl=no -Dglx=no -Dx11=false {build} {source}".format(**dirs))
-            # Check that Meson thinks we're doing a cross build and not a native
-            self.assertIn("Build type: cross build", log)
-            self._run("ninja -C {build} -v".format(**dirs))
-            self._run("DESTDIR={install} ninja -C {build} -v install".format(**dirs))
+            log = self._run("meson setup --warnlevel 1 -Degl=no -Dglx=no -Dx11=false {build} {source}".format(**dirs))
+
+            # Check that the host (gcc) and build (cross-gcc) compilers are different
+            data = json.loads(self._run("meson introspect --compilers {build}".format(**dirs)))

I have the following error on the autobuilder:

Traceback (most recent call last):
File "/srv/pokybuild/yocto-worker/beaglebone/build/meta/lib/oeqa/sdk/cases/meson.py", line 45, in test_epoxy

    data = json.loads(self._run("meson introspect --compilers {build}".format(**dirs)))

NameError: name 'json' is not defined

https://autobuilder.yoctoproject.org/valkyrie/#/builders/2/builds/1348

Can you have a look at this please?

Signature · 3 lines
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#5 lore raw

PATCH v4 5/5 meson: Allow user to override setup command options

In reply to Tom Hochstein

The user cannot override the setup command options --cross-file and --native-file because the meson-wrapper places these options on the command line after the user options. This problem was noticed when trying to build with an SDK using a custom cross-file.

---
 meta/recipes-devtools/meson/meson/meson-wrapper | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
meta/recipes-devtools/meson/meson/meson-wrapper +11 -4
index 7455985297..3aa1a93520 100755
@@ -14,8 +14,14 @@ fi
 unset CC CXX CPP LD AR NM STRIP
 
 case "$1" in
-setup|configure|dist|install|introspect|init|test|wrap|subprojects|rewrite|compile|devenv|env2mfile|help) MESON_CMD="$1" ;;
-*) echo meson-wrapper: Implicit setup command assumed; MESON_CMD=setup ;;
+setup|configure|dist|install|introspect|init|test|wrap|subprojects|rewrite|compile|devenv|env2mfile|help)
+    MESON_CMD="$1"
+    shift
+    ;;
+*)
+    MESON_CMD=setup
+    echo meson-wrapper: Implicit setup command assumed
+    ;;
 esac
 
 if [ "$MESON_CMD" = "setup" ]; then
@@ -27,5 +33,6 @@ if [ "$MESON_CMD" = "setup" ]; then
 fi
 
 exec "$OECORE_NATIVE_SYSROOT/usr/bin/meson.real" \
-    "$@" \
-    $MESON_SETUP_OPTS
+    $MESON_CMD \
+    $MESON_SETUP_OPTS \
+    "$@"
Signature · 1 line
2.34.1