All of lore.kernel.org
 help / color / mirror / Atom feed
* [meta-oe][PATCH] meson: export native env only for native build
@ 2017-11-13 19:27 Martin Kelly
  2017-11-14 12:36 ` Alexander Kanavin
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Kelly @ 2017-11-13 19:27 UTC (permalink / raw)
  To: openembedded-devel

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.

Signed-off-by: Martin Kelly <mkelly@xevo.com>
---
 meta-oe/classes/meson.bbclass | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/meta-oe/classes/meson.bbclass b/meta-oe/classes/meson.bbclass
index a09bc240d..3a2d5755e 100644
--- a/meta-oe/classes/meson.bbclass
+++ b/meta-oe/classes/meson.bbclass
@@ -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}
-- 
2.11.0



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [meta-oe][PATCH] meson: export native env only for native build
  2017-11-13 19:27 [meta-oe][PATCH] meson: export native env only for native build Martin Kelly
@ 2017-11-14 12:36 ` Alexander Kanavin
  2017-11-14 18:23   ` Martin Kelly
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Kanavin @ 2017-11-14 12:36 UTC (permalink / raw)
  To: Martin Kelly, openembedded-devel

On 11/13/2017 09:27 PM, Martin Kelly wrote:
> 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.

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [meta-oe][PATCH] meson: export native env only for native build
  2017-11-14 12:36 ` Alexander Kanavin
@ 2017-11-14 18:23   ` Martin Kelly
  2017-11-15 10:05     ` Alexander Kanavin
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Kelly @ 2017-11-14 18:23 UTC (permalink / raw)
  To: Alexander Kanavin, openembedded-devel

On 11/14/2017 04:36 AM, Alexander Kanavin wrote:
> On 11/13/2017 09:27 PM, Martin Kelly wrote:
>> 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.
> 
> 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.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [meta-oe][PATCH] meson: export native env only for native build
  2017-11-14 18:23   ` Martin Kelly
@ 2017-11-15 10:05     ` Alexander Kanavin
  2017-11-15 17:23       ` Martin Kelly
  0 siblings, 1 reply; 5+ messages in thread
From: Alexander Kanavin @ 2017-11-15 10:05 UTC (permalink / raw)
  To: Martin Kelly, openembedded-devel

On 11/14/2017 08:23 PM, Martin Kelly wrote:

> 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


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [meta-oe][PATCH] meson: export native env only for native build
  2017-11-15 10:05     ` Alexander Kanavin
@ 2017-11-15 17:23       ` Martin Kelly
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Kelly @ 2017-11-15 17:23 UTC (permalink / raw)
  To: Alexander Kanavin, openembedded-devel

On 11/15/2017 02:05 AM, Alexander Kanavin wrote:
> On 11/14/2017 08:23 PM, Martin Kelly wrote:
> 
>> 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

Yes, I'll do that.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-11-15 17:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-11-13 19:27 [meta-oe][PATCH] meson: export native env only for native build Martin Kelly
2017-11-14 12:36 ` Alexander Kanavin
2017-11-14 18:23   ` Martin Kelly
2017-11-15 10:05     ` Alexander Kanavin
2017-11-15 17:23       ` Martin Kelly

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.