mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.6k stars 1.63k forks source link

Regression: CFLAGS leak to cross compiler #7664

Open Xiretza opened 4 years ago

Xiretza commented 4 years ago

Describe the bug This seems to be a regression of #1772.

To Reproduce

main.c

#include <stdio.h>

int main(int argc, char **argv) {
  printf("Hello there.\n");
  return 0;
}

meson.build

project('tutorial', 'c')
executable('demo', 'main.c')

ubuntu-armhf.txt (directly from meson sources)

[binaries]
# we could set exe_wrapper = qemu-arm-static but to test the case
# when cross compiled binaries can't be run we don't do that
c = '/usr/bin/arm-linux-gnueabihf-gcc'
cpp = '/usr/bin/arm-linux-gnueabihf-g++'
rust = ['rustc', '--target', 'arm-unknown-linux-gnueabihf', '-C', 'linker=/usr/bin/arm-linux-gnueabihf-gcc-7']
ar = '/usr/arm-linux-gnueabihf/bin/ar'
strip = '/usr/arm-linux-gnueabihf/bin/strip'
pkgconfig = '/usr/bin/arm-linux-gnueabihf-pkg-config'
ld = '/usr/bin/arm-linux/gnueabihf-ld'

[properties]
root = '/usr/arm-linux-gnueabihf'
# Used in unit test '140 get define'
c_args = ['-DMESON_TEST_ISSUE_1665=1']
cpp_args = '-DMESON_TEST_ISSUE_1665=1'

has_function_printf = true
has_function_hfkerhisadf = false

skip_sanity_check = true

[host_machine]
system = 'linux'
cpu_family = 'arm'
cpu = 'armv7' # Not sure if correct.
endian = 'little'
$ env CFLAGS=-march=x86-64 meson setup builddir --cross ubuntu-armhf.txt
The Meson build system
Version: 0.55.1
Source dir: /home/xiretza/temp/meson_cross_pollution
Build dir: /home/xiretza/temp/meson_cross_pollution/builddir
Build type: cross build
Project name: tutorial
Project version: undefined
Cross compiler sanity tests disabled via the cross file.
C compiler for the build machine: cc (gcc 10.2.0 "cc (GCC) 10.2.0")
C linker for the build machine: cc ld.bfd 2.35
Using 'CFLAGS' from environment with value: '-march=x86-64'
C compiler for the host machine: /usr/bin/arm-linux-gnueabihf-gcc (gcc 10.1.0 "arm-linux-gnueabihf-gcc (GCC) 10.1.0")
C linker for the host machine: /usr/bin/arm-linux-gnueabihf-gcc ld.bfd 2.34.0.20200521
Build machine cpu family: x86_64
Build machine cpu: x86_64
Host machine cpu family: arm
Host machine cpu: armv7
Target machine cpu family: arm
Target machine cpu: armv7
Build targets in project: 1

Found ninja-1.10.1 at /usr/bin/ninja
$ cd builddir/
$ ninja
[2/2] Linking target demo
FAILED: demo 
/usr/bin/arm-linux-gnueabihf-gcc  -o demo demo.p/main.c.o -Wl,--as-needed -Wl,--no-undefined -march=x86-64
arm-linux-gnueabihf-gcc: error: unrecognized -march target: x86-64
arm-linux-gnueabihf-gcc: note: valid arguments are: armv4 armv4t armv5t armv5te armv5tej armv6 armv6j armv6k armv6z armv6kz armv6zk armv6t2 armv6-m armv6s-m armv7 armv7-a armv7ve armv7-r armv7-m armv7e-m armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a armv8.6-a armv8-m.base armv8-m.main armv8-r armv8.1-m.main iwmmxt iwmmxt2
arm-linux-gnueabihf-gcc: error: missing argument to '-march='
ninja: build stopped: subcommand failed.

Expected behavior

Ninja successfully produces an armhf binary demo, without trying to pass the CFLAGS present while running meson to the cross compiler.

system parameters

nirbheek commented 4 years ago

I don't think this is a regression. We do this explicitly since 0.54: https://mesonbuild.com/Release-notes-for-0-54-0.html#environment-variables-with-cross-builds