conan icon indicating copy to clipboard operation
conan copied to clipboard

[bug] MesonToolchain incurrectly sets c and cpp values when no compiler is specified

Open jhol opened this issue 1 year ago • 3 comments

Describe the bug

Since 84a34554785e15d633b129de29ae98600ac5fe3e, when cross compiling, when no compiler has been specified in the host profile, MesonToolchain incorrectly sets the following values in the conan_meson_cross.ini file:

[binaries]
c = ''
cpp = ''

If the values are unset in the Conan profile, they should not be set as empty strings in conan_meson_cross.ini. Rather they should be omitted entirely as they were before 86d1ed6e0332d5f1dbf0a5a6dd351a2cd0f5e950.

How to reproduce it

No response

jhol avatar Aug 28 '24 23:08 jhol

Hi @jhol

Thanks for your feedback

when cross compiling, when no compiler has been specified in the host profile

I am not sure if I understand this. If you are cross-compiling, then there is a compiler, and the compiler must be specified in the host profile settings. What I am missing?

memsharded avatar Aug 28 '24 23:08 memsharded

Hi @jhol

Thanks for your feedback

when cross compiling, when no compiler has been specified in the host profile

I am not sure if I understand this. If you are cross-compiling, then there is a compiler, and the compiler must be specified in the host profile settings. What I am missing?

Hi @memsharded . Thanks for your review. I am tracking down this issue with Meson bare-metal building. At your suggestion, I wrote a test case to highlight the issue I was trying to resolve in my previous PR.

In so doing, I discovered 3 things:

  1. I wrote a test case copying heavily from test cases in test/functional/toolchains/meson/test_cross_compilation.py. This test case worked properly when applied to Conan 2.3.1 with no compilers set. However, since 84a34554785e15d633b129de29ae98600ac5fe3e, the c and cpp fields are always set in the conan_meson_cross.ini file even if the string is empty. I understand your point that this is a bad profile configuration. What compilers would you suggest test case should set? Is there a test case I can copy from? Regardless, I still think the behaviour since 84a34554785e15d633b129de29ae98600ac5fe3e is less desirable.

  2. My original problem with MesonToolchain not properly handling os=None was caused by my Conan recipe excluding os from the settings list. Arguably MesonToolchain should fail gracefully when os=None, but an easy solution is to add os back into the Conan recipe settings.

  3. There is one issue still to resolve which is that a mapping for os=baremetal should be added to _meson_system_map.

All these issues I have now addressed in !16904

jhol avatar Aug 29 '24 00:08 jhol

The issue is that we don't have a cross-compiler in CI in Linux (or other platform). It might be possible and makes sense to try to fake it, and use the native "gcc" even if we specify a cross-compilation with os=baremetal. The recommended approach for this configuration is:

  • It is impossible that Conan knows the cross-compiler in a Linux machine that will have the native gcc installed (the majority)
  • It is then needed some explicit configuration of the cross-compiler
  • This can be provided in 2 different ways:
    • Using the tools.build:compiler_executables, which can work for all build systems, even those that do not listen to CC/CXX env-vars, this can be defined in the [conf] section of the profile
    • Using the CC and CXX environment variables (like defining them in the [buildenv] section of the profile

With this info, the MesonToolchain will not have a blank compiler

memsharded avatar Aug 29 '24 01:08 memsharded

With this info, the MesonToolchain will not have a blank compiler

This is good enough to solve my immediate problem. However, I do think the errors/warnings could be improved.

jhol avatar Aug 29 '24 16:08 jhol