Debian Codegraph @

doc/book/src/differences.md

raw
1 # Differences Between Muon and Meson
2
3 This document describes functional differences between muon and Meson. None of
4 these is a set-in-stone design decision, just a reflection of the current state
5 of affairs. This document is also not exhaustive, but is a best-effort list.
6
7 Some other small differences may be found by searching the tests/project for "#
8 different than meson" comments.
9
10 ## nested subproject promotion
11
12 Meson performs nested subproject promotion. This means that nested subprojects
13 become top-level subprojects, and all subprojects share the same namespace.
14
15 For example, given the following project structure:
16
17 ```
18 .
19 ├── meson.build
20 └── subprojects
21 ├── a
22 │ ├── meson.build
23 │ └── subprojects
24 │ └── b
25 │ └── meson.build
26 └── b
27 └── meson.build
28 ```
29
30 The order of `subproject` calls determines which subprojects will be used:
31
32 ```meson
33 project('main')
34
35 # This causes all subprojects under subprojects/a/subprojects/ to be "promoted"
36 subproject('a')
37
38 # This will now use subprojects/a/subprojects/b, instead of subprojects/b
39 subproject('b')
40 ```
41
42 muon does not perform subproject promotion.
43
44 ## malformed escape sequences
45
46 Meson silently accepts malformed escape sequences and outputs them literally,
47 removing the leading escape character. For example:
48
49 ```meson
50 '\c' # becomes 'c'
51 '\Uabcdefghi' # becomes 'Uabcdefghi'
52 '\xqr' # becomes 'xqr'
53 ```
54
55 In muon, malformed escape sequences are parse errors.
56
57 ## format strings
58
59 Format strings in various parts of Meson use `@` as the delimiter. The behavior
60 is inconsistent, `configure_file()` recognizes `\` as an escape character, but
61 format strings in `string.format()` and `custom_target` command arguments do
62 not. Muon will accept `\` as an escape character in `string.format()` and
63 `custom_target`, but this is incompatible with meson. `\` use in
64 `custom_target` command arguments is already incompatible though (see next
65 point).
66
67 `configure_file()` will also warn you about invalid substitutions, and will
68 remove them in the output, `string.format()` will error on invalid
69 substitutions, and `custom_target` command arguments will be silently treated as
70 literals if they are invalid substitutions (e.g. `@BAZ@`).
71
72 Because some projects rely on the above custom target command argument
73 behaviour, muon merely adds a warning for invalid substitutions. In all other
74 cases muon will raise error.
75
76 ## `custom_target` replaces backslashes with slashes in the command arguments
77
78 In Meson, all backslashes in `custom_target` command line arguments are blindly
79 replaced to forward slashes. This behavior is not present in muon.
80
81 Reference: <https://github.com/mesonbuild/meson/issues/1564>
82
83 ## `build_target()` functions with empty sources
84
85 Meson allows you to create build targets (`executable()`, `shared_library()`,
86 `static_library()`, etc.) without specifying any sources. In muon this is an
87 error.
88
89 ## global compiler cache
90
91 Meson maintains a global compiler cache, which means that all languages added by
92 subprojects are available to the main project and vice-versa. This can hide
93 bugs that will surface if the subproject is built by itself, or subproject calls
94 are rearranged. muon also maintains a global cache, but requires subprojects to
95 still call add_languages to access this cache.
96
97 ## backslash escaping in compiler defines
98
99 Meson replaces `\` with `\\` in compiler defines. muon does not. This is
100 legacy behavior that prevents you from using things like C escapes (e.g. `\n`)
101 in compiler defines, at the benefit of making it easier to use windows paths.
102 See meson commit aca93df184a32ed7faf3636c0fbe90d05cb67857 for more information:
103
104 > Jon Turney:
105 > Now that all command-line escaping for ninja is dealt with in the ninja
106 > backend, escape_extra_args() shouldn't need to do anything.
107 >
108 > But tests of existing behaviour rely on all backslashes in defines being
109 > C escaped: This means that Windows-style paths including backslashes can
110 > be safely used, but makes it impossible to have a define containing a C
111 > escape.
112
113 ## default option values
114
115 A number of builtin options have different default values:
116
117 - `default_library` is `'static'`
118
119 ## native: true
120
121 In muon `native: true` always means "for the build machine", while in meson
122 sometimes it doesn't.
123
124 Meson distinguishes between cross and native builds. A native build is one
125 where the build machine and the host machine are the same, while a cross build
126 is one where they differ. Since this is a build system, "machine" in this
127 context is mostly synonymous with "toolchain for a machine".
128
129 A nice cross compilation feature that meson supports is the ability to toggle
130 which toolchain a particular target uses at configure time. This is
131 accomplished by using the `native` keyword available for many functions. Passing
132 `native: false` causes the target/dependency to be created/looked up for the
133 host machine. Likewise, `native: true` causes the target/dependency to be
134 created/looked up for the build machine. In most cases omitting the native
135 keyword is the same as passing `native: false`, although some functions treat
136 the omission of `native` specially, such as `add_languages` adding languages for
137 both the host and build machine if the keyword is omitted.
138
139 The above paragraph is true for muon too, but it is actually subtly wrong for
140 meson. You might be wondering, why meson uses `native: true/false` and not
141 something more readable such as `for_machine: 'build'/'host'`. The reason is
142 that during a *native build*, meson effectively [ignores the native keyword].
143 While this makes sense on some level since the machines you are selecting
144 between are the same, it confuses the usage of the `native` keyword even more
145 than just the odd mapping from boolean to machine, and makes it easier to create
146 a build file that is broken for cross compilation.
147
148 For example (taken from [meson's own tests]), the following code is perfectly
149 valid during a native build:
150
151 ```meson
152 meson.override_dependency('expat', declare_dependency())
153 dependency('expat')
154 dependency('expat', native : true)
155 dependency('expat', native : false)
156 ```
157
158 But will break with a dependency not found error during a cross build.
159
160 [ignores the native keyword]: https://github.com/mesonbuild/meson/pull/8582#issue-841311146
161 [meson's own tests]: https://github.com/mesonbuild/meson/blob/6b99eeb2c99d4af4be2562b25507541bfd842692/test%20cases/common/240%20dependency%20native%20host%20%3D%3D%20build/meson.build#L15