Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.50 regression: Default option c_std not applied when cross-compiling #5097

Closed
lgrahl opened this issue Mar 17, 2019 · 15 comments
Closed

0.50 regression: Default option c_std not applied when cross-compiling #5097

lgrahl opened this issue Mar 17, 2019 · 15 comments
Assignees
Milestone

Comments

@lgrahl
Copy link

lgrahl commented Mar 17, 2019

When providing default_options: ['c_std=c99'] to the project, it is not being applied on meson build --cross-file <cross-file> invocation on a simple test project using flexible array members:

ninja -v

[1/2] cc -Itest-executable@exe -I. -I../../work -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -g -pedantic -MD -MQ 'test-executable@exe/main.c.o' -MF 'test-executable@exe/main.c.o.d' -o 'test-executable@exe/main.c.o' -c ../../work/main.c
../../work/main.c:5:9: warning: ISO C90 does not support flexible array members [-Wpedantic]
int array[];
^
[2/2] cc -o test-executable 'test-executable@exe/main.c.o' -Wl,--no-undefined -Wl,--as-needed

However, after doing any kind of (even unrelated) configuration such as meson configure -Db_asneeded=true, the configuration is being fixed and applies as expected:

ninja -v

[1/2] cc -Itest-executable@exe -I. -I../../work -fdiagnostics-color=always -pipe -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -std=c99 -g -pedantic -MD -MQ 'test-executable@exe/main.c.o' -MF 'test-executable@exe/main.c.o.d' -o 'test-executable@exe/main.c.o' -c ../../work/main.c
[2/2] cc -o test-executable 'test-executable@exe/main.c.o' -Wl,--no-undefined -Wl,--as-needed

Note: I haven't tested whether this also applies to other default options.


main.c

#include <stdio.h>

struct a {
    int foo;
    int array[];
};

int main(int argc, char* argv[]) {
    printf("Hey!\n");
    return 0;
}

meson.build

project('test-project', 'c', version: '0.0.1', default_options: ['c_std=c99'])
add_project_arguments('-pedantic', language: 'c')
executable('test-executable', 'main.c')

cross-file

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

[properties]
root = '/usr/android-ndk/toolchains/llvm/prebuilt/linux-x86_64'
needs_exe_wrapper = true

[paths]
prefix = '/usr/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot'

[binaries]
c = '/usr/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang'
cpp = '/usr/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android28-clang++'
ar = '/usr/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-ar'
as = '/usr/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-as'
ld = '/usr/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/ld.lld'
strip = '/usr/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/x86_64-linux-android-strip'
pkgconfig = '/usr/bin/pkg-config'
@lgrahl
Copy link
Author

lgrahl commented Mar 17, 2019

What's also weird is that it's trying to use native cc to compile instead of using the cross-compiler. I've opened a new issue for that (#5102). However, the above described issue also happens when cross-compiling for ARM (using the appropriate cross-compiler).

@mgautierfr
Copy link
Contributor

I have the same issue. (with cpp_std).
This is a regression with 0.50.0. 0.49.2 correctly pass the option (-std=c++11 in my case) to the compiler.

It seems also that meson doesn't append LDFLAGS and CPPFLAGS from environment for c and cpp compiler. (Also a regression, 0.49.2 works)

mgautierfr added a commit to kiwix/kiwix-build that referenced this issue Mar 18, 2019
Force the use of mesoon 0.49.2
mgautierfr added a commit to kiwix/kiwix-build that referenced this issue Mar 18, 2019
Force the use of mesoon 0.49.2
@nirbheek nirbheek added this to the 0.50.1 milestone Mar 18, 2019
@nirbheek nirbheek changed the title Default option c_std not applied when cross-compiling 0.50 regression: Default option c_std not applied when cross-compiling Mar 18, 2019
@lgrahl
Copy link
Author

lgrahl commented Mar 18, 2019

I can also confirm that it works with 0.49.2.

mgautierfr added a commit to kiwix/kiwix-build that referenced this issue Mar 19, 2019
Force the use of meson 0.49.2
mgautierfr added a commit to kiwix/kiwix-build that referenced this issue Mar 19, 2019
Force the use of meson 0.49.2
@michaelolbrich
Copy link
Contributor

I'm seeing the same thing here. The fist broken commit is 19f81d3.

@nirbheek
Copy link
Member

CCing @Ericson2314

@Ericson2314
Copy link
Member

Hmm so this option affected native and cross compilation previously? That is fine, but inconsistent with the other options. I'll take a look.

@michaelolbrich
Copy link
Contributor

I'm not sure what you think should happen but systemd, mesa and libdrm set c_std in the default_options and with the current meson release the all fail to cross-compile with a compiler that uses an older standard by default.

@Ericson2314
Copy link
Member

@michaelolbrich for comparison what does c_args or c_link_args do in default_options, and what do all 3 do as -D cli args to meson?

(I'm in transit so can't check yet. Not just asking rhetorically :). )

@michaelolbrich
Copy link
Contributor

As soon as I use --cross-file, c_args c_link_args and c_std are all ignored. For default_options and as -D cli args.

@Ericson2314
Copy link
Member

@michaelolbrich Thanks! That is the new behavior?

@michaelolbrich
Copy link
Contributor

For c_std that's new. For c_args and c_link_args this was also the case in 0.49.0.

I'm not sure what c_args is supposed to be used for but the correct C standard depends on the code that is compiled. Cross-compiling or not should not have an effect for this.

And after doing some testing, I must say that it is very confusing that command line options don't have any effect.

buildroot-auto-update pushed a commit to buildroot/buildroot that referenced this issue Mar 20, 2019
This reverts commit 114e9dc.
Indeed, there is major issue with this version because c_std is not
passed anymore when cross-compiling:
mesonbuild/meson#5097

As a result, some meson packages (at least systemd, libmpdclient,
glib-networking) fail to build

Fixes:
 - http://autobuild.buildroot.org/results/9eae2181fb3fcfe12481e5496b7d87c0dcd109eb
 - http://autobuild.buildroot.org/results/e828c7925d9247e14d8a8694febfee8ce6c86e81
 - http://autobuild.buildroot.org/results/031aee7cf12ad882727eb2da5e953fd8813b52e2

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
Signed-off-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
@Ericson2314
Copy link
Member

Ericson2314 commented Mar 21, 2019

Yes it is confusing. So the regession was due to me trying to match the status quo in a pure refactor, but not realizing c_std worked differently. What I actually want is #4963. This would solve your issue completely in that default_options works reliably whether or not the user is cross or native compiling.

refeed pushed a commit to refeed/kiwix-build that referenced this issue Mar 24, 2019
Force the use of meson 0.49.2
@Ericson2314
Copy link
Member

Ericson2314 commented Mar 29, 2019

Could somebody assign this to me too?

@jpakkane
Copy link
Member

I debugged why this happens. In get_compiler_options_for_target an OverrideProxy is created and it overrides c_std to be none. It should not do that since c_std is not a per-machine setting. It should be the same for native and cross compilation (at least for now to preserve backwards compatibility).

Maybe once we get cross_c_args et al we could also have a cross_c_std, but I'm not sure even that is necessary.

@Ericson2314
Copy link
Member

@jpakkane So right now all compiler options are per-machine, since compilers target a single machine (as far as meson knows). The solution I think is when reading in the file to make a temporary hack to duplicate this one.

Maybe once we get cross_c_args et al we could also have a cross_c_std, but I'm not sure even that is necessary.

I have done GCC native, Clang cross builds where the clang might support a newer standard.

Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue Apr 15, 2019
nirbheek pushed a commit that referenced this issue Apr 16, 2019
@nirbheek nirbheek modified the milestones: 0.50.1, 0.51.0 Apr 16, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue Apr 25, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue Apr 29, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue Apr 29, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue Apr 29, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 2, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 2, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 3, 2019
jpakkane added a commit that referenced this issue May 9, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 10, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 10, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 10, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 11, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 11, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 11, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 11, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 12, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 13, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 16, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue May 20, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue Jun 2, 2019
Ericson2314 pushed a commit to Ericson2314/meson that referenced this issue Jun 3, 2019
tbeloqui pushed a commit to pexip/meson that referenced this issue Aug 22, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants