Skip to contentSkip to conversation

meson: export native env only for native build

PATCH Superseded Martin Kelly 2 participants 5 messages Nov 13, 2017 – Nov 15, 2017 Arm/Amlogic Meson SoC support

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 meson: export native env only for native build

Although the meson crossfile should take care of setting the right cross environment for a target build, meson slurps any set CFLAGS, CXXFLAGS, LDFLAGS, and CPPFLAGS from the environment and injects them into the build (see mesonbuild/environment.py:get_args_from_envvars for details).

This means that we are seeing native CFLAGS, CXXFLAGS, LDFLAGS, and CPPFLAGS in the target build, which is wrong and causes build failures when target and native have libraries in common (the linker gets confused and bails).

That said, we *do* need to set certain vars for all builds so that meson can find the right build tools. Without this, meson will fail during its sanity checking step because it will determine the build tools to be unrunnable since they output target instead of native artifacts.

The solution to all of this is to set CC, CXX, LD, and AR globally to the native tools while setting the other native vars *only* for the native build. For target builds, these vars will get overridden by the cross file as we expect.

---
 meta-oe/classes/meson.bbclass | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)
meta-oe/classes/meson.bbclass +12 -10
index a09bc240d..3a2d5755e 100644
@@ -9,16 +9,14 @@ do_configure[cleandirs] = "${B}"
 # Where the meson.build build configuration is
 MESON_SOURCEPATH = "${S}"
 
-# These variables in the environment override the *native* tools, not the cross.
-export CPPFLAGS = "${BUILD_CPPFLAGS}"
-export CC = "${BUILD_CC}"
-export CFLAGS = "${BUILD_CFLAGS}"
-export CXX = "${BUILD_CXX}"
-export CXXFLAGS = "${BUILD_CXXFLAGS}"
-export LD = "${BUILD_LD}"
-export LDFLAGS = "${BUILD_LDFLAGS}"
-export AR = "${BUILD_AR}"
-export PKG_CONFIG = "pkg-config-native"
+# These variables apply to both the cross and native build. Note that we do
+# *not* set CFLAGS, CPPFLAGS, and LDFLAGS because meson will import them into
+# the cross-build if we do so; we want the entire cross-build to flow from the
+# crossfile.
+export CC="${BUILD_CC}"
+export CXX="${BUILD_CXX}"
+export LD="${BUILD_LD}"
+export AR="${BUILD_AR}"
 
 def noprefix(var, d):
     return d.getVar(var, True).replace(d.getVar('prefix', True) + '/', '', 1)
@@ -94,6 +92,10 @@ meson_do_configure() {
     fi
 }
 
+meson_do_configure_prepend_class-native() {
+    export PKG_CONFIG="pkg-config-native"
+}
+
 do_compile[progress] = "outof:^\[(\d+)/(\d+)\]\s+"
 meson_do_compile() {
     ninja ${PARALLEL_MAKE}
Signature · 1 line
2.11.0
#1 lore raw
Quoted 15 lines · Martin Kelly

Although the meson crossfile should take care of setting the right cross environment for a target build, meson slurps any set CFLAGS, CXXFLAGS, LDFLAGS, and CPPFLAGS from the environment and injects them into the build (see mesonbuild/environment.py:get_args_from_envvars for details).

This means that we are seeing native CFLAGS, CXXFLAGS, LDFLAGS, and CPPFLAGS in the target build, which is wrong and causes build failures when target and native have libraries in common (the linker gets confused and bails).

That said, we *do* need to set certain vars for all builds so that meson can find the right build tools. Without this, meson will fail during its sanity checking step because it will determine the build tools to be unrunnable since they output target instead of native artifacts.

Quoted 4 lines

The solution to all of this is to set CC, CXX, LD, and AR globally to the native tools while setting the other native vars *only* for the native build. For target builds, these vars will get overridden by the cross file as we expect.

Hello Martin,

meson support will land in oe-core shortly (and will be removed from meta-oe), so can you please check if my patchset is doing the right thing?
http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=akanavin/meson

Alex

#2 lore raw
Quoted 21 lines · Alexander Kanavin
Quoted 15 lines · Martin Kelly

Although the meson crossfile should take care of setting the right cross environment for a target build, meson slurps any set CFLAGS, CXXFLAGS, LDFLAGS, and CPPFLAGS from the environment and injects them into the build (see mesonbuild/environment.py:get_args_from_envvars for details).

This means that we are seeing native CFLAGS, CXXFLAGS, LDFLAGS, and CPPFLAGS in the target build, which is wrong and causes build failures when target and native have libraries in common (the linker gets confused and bails).

That said, we *do* need to set certain vars for all builds so that meson can find the right build tools. Without this, meson will fail during its sanity checking step because it will determine the build tools to be unrunnable since they output target instead of native artifacts.

Quoted 4 lines

The solution to all of this is to set CC, CXX, LD, and AR globally to the native tools while setting the other native vars *only* for the native build. For target builds, these vars will get overridden by the cross file as we expect.

Quoted 7 lines

Hello Martin,

meson support will land in oe-core shortly (and will be removed from meta-oe), so can you please check if my patchset is doing the right thing?
http://git.yoctoproject.org/cgit/cgit.cgi/poky-contrib/log/?h=akanavin/meson

Alex

Hi, excellent, I'm glad this is going to oe-core. I tried the meson.bbclass from your branch and it fails one of my builds because the CC variable is not found since it's unset.

It looks like the meson.bbclass in poky-contrib was forked at some point and some of the patches since have not been merged back in. I think some of them have needed fixes (e.g. the patch for PKG_CONFIG=pkg-config-native).

I believe the right configuration is:

For native builds:
- Keep the defaults (which use native tools), but export PKG_CONFIG=pkg-config-native instead of pkg-config.

For target builds:
- Set CC, CXX, LD, and AR, but *not* CFLAGS, CXXFLAGS, LDFLAGS etc. We need CC, CXX etc. so meson finds the native tools for its build sanity tests, but we don't want to set the flags, as meson will slurp them in and apply them to the cross build. Note that even though we set CC, etc. meson will correctly override them in the cross file for the actual target build.

By the way, I simplified my patch a little bit and made it slightly more correct, so I sent a patch v2 for this. I CC'ed you on that patch.

#3 lore raw
Quoted 7 lines · Martin Kelly

For native builds:
- Keep the defaults (which use native tools), but export PKG_CONFIG=pkg-config-native instead of pkg-config.

For target builds:
- Set CC, CXX, LD, and AR, but *not* CFLAGS, CXXFLAGS, LDFLAGS etc. We
need CC, CXX etc. so meson finds the native tools for its build sanity tests, but we don't want to set the flags, as meson will slurp them in and apply them to the cross build. Note that even though we set CC, etc. meson will correctly override them in the cross file for the actual target build.

Thanks for looking - can you make a patch for these things against my branch in poky-contrib, and send it to oe-core list? I will send the patchset any day now, and there will be a corresponding patch to remove meson recipe and class from meta-oe. So now is the good point to have it all fixed so that the transition is smooth.

Alex

#4 lore raw
Quoted 6 lines · Alexander Kanavin
Quoted 4 lines · Martin Kelly

For native builds:
- Keep the defaults (which use native tools), but export PKG_CONFIG=pkg-config-native instead of pkg-config.

Quoted 8 lines
Quoted 3 lines

For target builds:
- Set CC, CXX, LD, and AR, but *not* CFLAGS, CXXFLAGS, LDFLAGS etc. We
need CC, CXX etc. so meson finds the native tools for its build sanity tests, but we don't want to set the flags, as meson will slurp them in and apply them to the cross build. Note that even though we set CC, etc. meson will correctly override them in the cross file for the actual target build.

Thanks for looking - can you make a patch for these things against my branch in poky-contrib, and send it to oe-core list? I will send the patchset any day now, and there will be a corresponding patch to remove meson recipe and class from meta-oe. So now is the good point to have it all fixed so that the transition is smooth.

Alex

Yes, I'll do that.