Debian Codegraph @

subprojects/meson-docs/docs/markdown/Release-notes-for-1.3.0.md

raw
1 ---
2 title: Release 1.3.0
3 short-description: Release notes for 1.3.0
4 ...
5
6 # New features
7
8 Meson 1.3.0 was released on 19 November 2023
9 ## Clarify implicitly-included headers in C-like compiler checks
10
11 Compiler check methods `compiler.compute_int()`, `compiler.alignment()`
12 and `compiler.sizeof()` now have their implicitly-included headers
13 corrected and documented.
14
15 `<stdio.h>` was included unintentionally when cross-compiling, which
16 is less than ideal because there is no guarantee that a standard library
17 is available for the target platform. Only `<stddef.h>` is included instead.
18
19 For projects that depend on the old behavior, the compiler check methods
20 have an optional argument `prefix`, which can be used to specify additional
21 `#include` directives.
22
23 ## Treat warnings as error in compiler checks
24
25 Compiler check methods `compiler.compiles()`, `compiler.links()` and `compiler.run()`
26 now have a new `werror: true` keyword argument to treat compiler warnings as error.
27 This can be used to check if code compiles without warnings.
28
29 ## Compilers now have a `has_define` method
30
31 This method returns true if the given preprocessor symbol is
32 defined, else false is returned. This is useful is cases where
33 an empty define has to be distinguished from a non-set one, which
34 is not possible using `get_define`.
35
36 Additionally it makes intent clearer for code that only needs
37 to check if a specific define is set at all and does not care
38 about its value.
39
40 ## [[configure_file]] now has a `macro_name` parameter.
41
42 This new parameter, `macro_name` allows C macro-style include guards to be added
43 to [[configure_file]]'s output when a template file is not given. This change
44 simplifies the creation of configure files that define macros with dynamic names
45 and want the C-style include guards.
46
47 ## `c_std` and `cpp_std` options now accepts a list of values
48
49 Projects that prefer GNU C, but can fallback to ISO C, can now set, for
50 example, `default_options: 'c_std=gnu11,c11'`, and it will use `gnu11` when
51 available, but fallback to `c11` otherwise. It is an error only if none of the
52 values are supported by the current compiler.
53
54 Likewise, a project that can take benefit of `c++17` but can still build with
55 `c++11` can set `default_options: 'cpp_std=c++17,c++11'`.
56
57 This allows us to deprecate `gnuXX` values from the MSVC compiler. That means
58 that `default_options: 'c_std=gnu11'` will now print a warning with MSVC
59 but fallback to `c11`. No warning is printed if at least one
60 of the values is valid, i.e. `default_options: 'c_std=gnu11,c11'`.
61
62 In the future that deprecation warning will become an hard error because
63 `c_std=gnu11` should mean GNU is required, for projects that cannot be
64 built with MSVC for example.
65
66 ## More meaningful description of many generative tasks
67
68 When a module uses a `CustomTarget` to process files, it now has the possibility
69 to customize the message displayed by ninja.
70
71 Many modules were updated to take advantage of this new feature.
72
73 ## Deprecate 'jar' as a build_target type
74
75 The point of `build_target()` is that what is produced can be conditionally
76 changed. However, `jar()` has a significant number of non-overlapping arguments
77 from other build_targets, including the kinds of sources it can include. Because
78 of this crafting a `build_target` that can be used as a Jar and as something
79 else is incredibly hard to do. As such, it has been deprecated, and using
80 `jar()` directly is recommended.
81
82 ## generator.process() gains 'env' keyword argument
83
84 Like the kwarg of the same name in `custom_target()`, `env` allows
85 you to set the environment in which the generator will process inputs.
86
87 ## Target names for executables now take into account suffixes.
88
89 In previous versions of meson, a `meson.build` file like this:
90
91 ```
92 executable('foo', 'main.c')
93 executable('foo', 'main.c', name_suffix: 'bar')
94 ```
95
96 would result in a configure error because meson internally used
97 the same id for both executables. This build file is now allowed
98 since meson takes into account the `bar` suffix when generating the
99 second executable. This allows for executables with the same basename
100 but different suffixes to be built in the same subdirectory.
101
102 ## Executable gains vs_module_defs keyword
103
104 This allows using a .def file to control which functions an [[executable]] will
105 expose to a [[shared_module]].
106
107 ## find_program() now supports the 'default_options' argument
108
109 In a similar fashion as dependency(), find_program() now also allows you to set default
110 options for the subproject that gets built in case of a fallback.
111
112 ## `fs.relative_to()`
113
114 The `fs` module now has a `relative_to` method. The method will return the
115 relative path from argument one to argument two, if one exists. Otherwise, the
116 absolute path to argument one is returned.
117
118 ```meson
119 assert(fs.relative_to('c:\\prefix\\lib', 'c:\\prefix\\bin') == '..\\lib')
120 assert(fs.relative_to('c:\\proj1\\foo', 'd:\\proj1\\bar') == 'c:\\proj1\\foo')
121 assert(fs.relative_to('prefix\\lib\\foo', 'prefix') == 'lib\\foo')
122
123 assert(fs.relative_to('/prefix/lib', '/prefix/bin') == '../lib')
124 assert(fs.relative_to('prefix/lib/foo', 'prefix') == 'lib/foo')
125 ```
126
127 In addition to strings, it can handle files, custom targets, custom target
128 indices, and build targets.
129
130 ## Added follow_symlinks arg to install_data, install_header, and install_subdir
131
132 The [[install_data]], [[install_headers]], [[install_subdir]] functions now
133 have an optional argument `follow_symlinks` that, if set to `true`, makes it so
134 symbolic links in the source are followed, rather than copied into the
135 destination tree, to match the old behavior. The default, which is currently
136 to follow links, is subject to change in the future.
137
138 ## Added 'fill' kwarg to int.to_string()
139
140 int.to_string() now accepts a `fill` argument. This allows you to pad the
141 string representation of the integer with leading zeroes:
142
143 ```meson
144 n = 4
145 message(n.to_string())
146 message(n.to_string(fill: 3))
147
148 n = -4
149 message(n.to_string(fill: 3))
150 ```
151
152 OUTPUT:
153 ```meson
154 4
155 004
156 -04
157 ```
158
159 ## Added 'json' output_format to configure_file()
160
161 When no input file is specified, [[configure_file]] can now
162 generate a `json` file from given [[@cfg_data]].
163 Field descriptions are not preserved in the json file.
164
165 ## `@GLOBAL_SOURCE_ROOT@` and `@DIRNAME@` in machine files
166
167 Some tokens are now replaced in the machine file before parsing it:
168 - `@GLOBAL_SOURCE_ROOT@`: the absolute path to the project's source tree
169 - `@DIRNAME@`: the absolute path to the machine file's parent directory.
170
171 It can be used, for example, to have paths relative to the source directory, or
172 relative to toolchain's installation directory.
173 ```ini
174 [binaries]
175 c = '@DIRNAME@/toolchain/gcc'
176 exe_wrapper = '@GLOBAL_SOURCE_ROOT@' / 'build-aux' / 'my-exe-wrapper.sh'
177 ```
178
179 ## clang-tidy-fix target
180
181 If `clang-tidy` is installed and the project's source root contains a
182 `.clang-tidy` (or `_clang-tidy`) file, Meson will automatically define
183 a `clang-tidy-fix` target that runs `run-clang-tidy` tool with `-fix`
184 option to apply the changes found by clang-tidy to the source code.
185
186 If you have defined your own `clang-tidy-fix` target, Meson will not
187 generate its own target.
188
189 ## Meson compile command now accepts suffixes for TARGET
190
191 The syntax for specifying a target for meson compile is now
192 `[PATH_TO_TARGET/]TARGET_NAME.TARGET_SUFFIX[:TARGET_TYPE]` where
193 `TARGET_SUFFIX` is the suffix argument given in the build target
194 within meson.build. It is optional and `TARGET_NAME` remains
195 sufficient if it uniquely resolves to one single target.
196
197 ## New environment variable `MESON_PACKAGE_CACHE_DIR`
198
199 If the `MESON_PACKAGE_CACHE_DIR` environment variable is set, it is used instead of the
200 project's `subprojects/packagecache`. This allows sharing the cache across multiple
201 projects. In addition it can contain an already extracted source tree as long as it
202 has the same directory name as the `directory` field in the wrap file. In that
203 case, the directory will be copied into `subprojects/` before applying patches.
204
205 ## Update options with `meson setup <builddir> -Dopt=value`
206
207 If the build directory already exists, options are updated with their new value
208 given on the command line (`-Dopt=value`). Unless `--reconfigure` is also specified,
209 this won't reconfigure immediately. This has the same behaviour as
210 `meson configure <builddir> -Dopt=value`.
211
212 Previous Meson versions were simply a no-op.
213
214 ## Clear persistent cache with `meson setup --clearcache`
215
216 Just like `meson configure --clearcache`, it is now possible to clear the cache
217 and reconfigure in a single command with `meson setup --clearcache --reconfigure <builddir>`.
218
219 ## pkg-config dependencies can now get a variable with multiple replacements
220
221 When using [[dep.get_variable]] and defining a `pkgconfig_define`, it is
222 sometimes useful to remap multiple dependency variables. For example, if the
223 upstream project changed the variable name that is interpolated and it is
224 desirable to support both versions.
225
226 It is now possible to pass multiple pairs of variable/value.
227
228 The same applies to the compatibility [[dep.get_pkgconfig_variable]] method.
229
230 ## Machine files: `pkgconfig` field deprecated and replaced by `pkg-config`
231
232 Meson used to allow both `pkgconfig` and `pkg-config` entries in machine files,
233 the former was used for `dependency()` lookup and the latter was used as return
234 value for `find_program('pkg-config')`.
235
236 This inconsistency is now fixed by deprecating `pkgconfig` in favor of
237 `pkg-config` which matches the name of the binary. For backward compatibility
238 it is still allowed to define both with the same value, in that case no
239 deprecation warning is printed.
240
241 ## Support targeting Python's limited C API
242
243 The Python module's `extension_module` function has gained the ability
244 to build extensions which target Python's limited C API via a new keyword
245 argument: `limited_api`.
246
247 ## All compiler `has_*` methods support the `required` keyword
248
249 Now instead of
250
251 ```meson
252 assert(cc.has_function('some_function'))
253 assert(cc.has_type('some_type'))
254 assert(cc.has_member('struct some_type', 'x'))
255 assert(cc.has_members('struct some_type', ['x', 'y']))
256 ```
257
258 we can use
259
260 ```meson
261 cc.has_function('some_function', required: true)
262 cc.has_type('some_type', required: true)
263 cc.has_member('struct some_type', 'x', required: true)
264 cc.has_members('struct some_type', ['x', 'y'], required: true)
265 ```
266
267 ## Deprecated `rust_crate_type` and replaced by `rust_abi`
268
269 The new `rust_abi` keyword argument is accepted by [[shared_library]],
270 [[static_library]], [[library]] and [[shared_module]] functions. It can be either
271 `'rust'` (the default) or `'c'` strings.
272
273 `rust_crate_type` is now deprecated because Meson already knows if it's a shared
274 or static library, user only need to specify the ABI (Rust or C).
275
276 `proc_macro` crates are now handled by the [`rust.proc_macro()`](Rust-module.md#proc_macro)
277 method.
278
279 ## Tests now abort on errors by default under sanitizers
280
281 Sanitizers like AddressSanitizer and UndefinedBehaviorSanitizer do not abort
282 by default on detected violations. Meson now exports `ASAN_OPTIONS` and `UBSAN_OPTIONS`
283 when unset in the environment to provide sensible abort-by-default behavior.
284
285 ## `<lang>_(shared|static)_args` for both_library, library, and build_target
286
287 We now allow passing arguments like `c_static_args` and `c_shared_args`. This
288 allows a [[both_libraries]] to have arguments specific to either the shared or
289 static library, as well as common arguments to both.
290
291 There is a drawback to this, since Meson now cannot re-use object files between
292 the static and shared targets. This could lead to much higher compilation time
293 when using a [[both_libraries]] if there are many sources.
294
295 ## `-j` shorthand for `--num-processes`
296
297 `-j` now means the same thing as `--num-processes`. It was inconsistently
298 supported only in some subcommands. Now you may use it everywhere
299
300 ## Unified message(), str.format() and f-string formatting
301
302 They now all support the same set of values: strings, integers, bools, options,
303 dictionaries and lists thereof.
304
305 - Feature options (i.e. enabled, disabled, auto) were not previously supported
306 by any of those functions.
307 - Lists and dictionaries were not previously supported by f-string.
308 - str.format() allowed any type and often resulted in printing the internal
309 representation which is now deprecated.
310
311 ## Subprojects excluded from scan-build reports
312
313 The `scan-build` target, created when using the `ninja` backend with `scan-build`
314 present, now excludes bugs found in subprojects from its final report.
315
316 ## vs_module_defs keyword now supports indexes of custom_target
317
318 This means you can do something like:
319 ```meson
320 defs = custom_target('generate_module_defs', ...)
321 shared_library('lib1', vs_module_defs : defs[0])
322 shared_library('lib2', vs_module_defs : defs[2])
323 ```
324
325 ## Automatic fallback to `cmake` and `cargo` subproject
326
327 CMake subprojects have been supported for a while using the `cmake.subproject()`
328 module method. However until now it was not possible to use a CMake subproject
329 as fallback in a `dependency()` call.
330
331 A wrap file can now specify the method used to build it by setting the `method`
332 key in the wrap file's first section. The method defaults to `meson`.
333
334 Supported methods:
335 - `meson` requires `meson.build` file.
336 - `cmake` requires `CMakeLists.txt` file. [See details](Wrap-dependency-system-manual.md#cmake-wraps).
337 - `cargo` requires `Cargo.toml` file. [See details](Wrap-dependency-system-manual.md#cargo-wraps).
338