mesonbuild / meson

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

--default-library specified in crossfile and command line works inconsistently once reconfigured #11294

Open sfan5 opened 1 year ago

sfan5 commented 1 year ago

Describe the bug Situation: Your cross file specifies libraries to build as static, but you configure a certain project to build as shared. You configure, build, get a shared library and all is fine. Then you edit your cross file in any way. The next time you build meson will automatically reconfigure, the shared setting gets "lost" and you suddenly get a static library.

To Reproduce meson.build:

project('hello', 'c')
library('hello', 'hello.c')

hello.c:

int hello;

crossfile.txt

[built-in options]
default_library = 'static'
  1. meson build --cross-file crossfile.txt --default-library shared
  2. meson compile -C build -> [2/2] Linking target libhello.so
  3. touch crossfile.txt
  4. meson compile -C build -> a reconfigure runs and you get [2/2] Linking static target libhello.a

Expected behavior Step 4 still links a shared library.

system parameters

tristan957 commented 1 year ago

I wonder what the intended behavior is supposed to be. Are you of any docs that talk about this precedence?

StratusFearMe21 commented 1 year ago

@tristan957 This is what the docs say the precedence should be

You can set some Meson built-in options on a per-subproject basis, such as default_library and werror. The order of precedence is:

  1. Command line
  2. Machine file
  3. Build system definitions
sfan5 commented 1 year ago

Issue persists in meson 1.1.0.

tristan957 commented 1 year ago

@xclaesse you said you might know this issue right?

xclaesse commented 1 year ago

The problem is on reconfigure we reload machine files and override options with what it contains. Meson should remember the source of every option (command line, machine file, env, etc) and only override if it got changed in a higher priority source. That means when reloading machine file we should override the option if the value we got was from env but not if it was from command line. That's also the reason why we don't update options when changing project(..., default_options: ...) because we don,t know if current value comes from command line or not.

This is something I got told that muon does correctly.