summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/rust.py
AgeCommit message (Collapse)Author
2025-04-02ninjabackend: generate command line for rust doctestsPaolo Bonzini
Adjust get_rust_compiler_args() to accept the crate-type externally, because rustdoc tests are an executable but are compiled with the parent target's --crate-type. Apart from that, the rustdoc arguments are very similar to the parent target, and are handled by the same functions that were split out of generate_rust_target. This concludes the backend implementation of doctests, only leaving the implementation of a doctest() function in the rust module. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02compilers: introduce get_exe() and get_exe_args()Paolo Bonzini
This will be used by rustdoc tests because the Test objects takes a single string for the command and everything else goes in the args. But apart from this, the need to split the executable from the arguments is common so create new methods to do it. While at it, fix brokenness in the handling of the zig compiler, which is checking against "zig" but failing to detect e.g. "/usr/bin/zig". Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-02ninjabackend: split out generation of rustc argumentsPaolo Bonzini
Allow reusing the code for doctests. In particular, the sources are shared between the two cases. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-03-09compilers/rust: implement has_argument checksDylan Baker
We're about to convert the `b_sanitize` option into a free-form array whose value gets verified via a compiler check. This conversion will also impact the Rust toolchain, which does not yet know to check for multiple arguments at once. Implement both `has_multi_arguments()` and `has_multi_link_arguments()` to prepare the code accordingly.
2025-02-27modules/rust: use 'nightly' as the bindgen version if the compiler is nightlyDylan Baker
This adds tracking for both nightly and beta to the rust compiler.
2025-02-13Make all Meson level options overridable per subproject.Jussi Pakkanen
2025-02-05options: Add an EnumeratedUserOption classDylan Baker
This will allow us to take choices out of the UserOption class, which doesn't actually use this attribute.
2025-02-05options: use dataclasses for UserOptionDylan Baker
This reduces code, makes this clearer, and will be a nice step toward the goal of getting everything typesafe. For `UserIntegerOption` this makes a fairly nice, but substantial change in that the old method used a tuple of `(min, value, max)` to pass to the initializer, while all other types just passed `value`. The new `UserIntegerOption` does the same, with keyword arguments for the min and max values.
2025-02-05compilers: remove Compiler.create_optionDylan Baker
This saves a *tiny* bit of typing, but at the cost of requiring either the current solution of throwing up our hands and saying "typing is too hard, better to have bugs!" or an extensive amount of `TypedDict`s, `overloads`, and a very new version of mypy. Let's get our type safety back, even if it means writing a little bit more code.
2025-02-03rust: use f-string to build rpath argumentsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-03ninjabackend: start adjusting for differences between rustc and rustdocPaolo Bonzini
Add functions to RustCompiler() to account for differences between rustc and "rustdoc --test": rustdoc always generates a binary, does not support -g, and does not need --emit. Reviewed-by: Dylan Baker <dylan@pnwbakers.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-02-03ninjabackend: unify building rpath argsPaolo Bonzini
Implement RustCompiler.build_rpath_args, so that more code can be shared between non-Rust and Rust targets. Then, RustCompiler can override it to convert the arguments to "-C link-arg=" and add the rustup sysroot. Reviewed-by: Dylan Baker <dylan@pnwbakers.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-01-08rust: add 2024 editionPaolo Bonzini
Rust edition 2024 is being released in February, add support for rust_std=2024. Resolves: #14074 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-01-08rust: change warning_level=0 to "--cap-lints allow"Paolo Bonzini
This is a better and more backwards-compatible way to disable all warnings, compared to "-A warnings". The Rust RFC (https://rust-lang.github.io/rfcs/1193-cap-lints.html) explains the rationale: > We would very much like to be able to modify lints, however. For example > rust-lang/rust#26473 updated the missing_docs lint to also look for missing > documentation on const items. This ended up breaking some crates in the > ecosystem due to their usage of #![deny(missing_docs)]. While at it, document that Rust deviates from the other languages in its interpretation of warning_level=0. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-12-19scripts: add "clippy" internal toolPaolo Bonzini
Similar to the "ninja scan-build" target for C, add a clippy internal tool that runs clippy-driver on all crates in the project. The approach used is more efficient than with "ninja scan-build", and does not require rerunning Meson in a separate build directory; it uses the introspection data to find the compiler arguments for the target and invokes clippy-driver with a slightly modified command line. This could actually be applied to scan-build as well, reusing the run_tool_on_targets() function. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-11-20rust: fix computation of library directoryPaolo Bonzini
Using a rustup-based toolchain fails the "rust/2 sharedlib" test for me: ./prog: error while loading shared libraries: libstd-211931512faabf29.so: cannot open shared object file: No such file or directory This happens because recent rustup places the standard library under SYSROOT/lib/rustlib/TARGET/lib. Retrieve the right directory using "--print target-libdir". This also provides a more accurate version for rustc installed in /usr. Before: $ echo $(/usr/bin/rustc --print sysroot)/lib /usr/lib After: $ /usr/bin/rustc --print target-libdir /usr/lib/rustlib/x86_64-unknown-linux-gnu/lib While at it, cache the value to avoid repeated process invocation. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2024-09-24compiler,rust: fix sanity check and internal deps for baremetal rust ↵Florent Valette
project/target Sanity check for bare metal rust wasn't working for a while and there is a pending PR (#12175). To workaround this problem, we used to let sanity check for build machine and manually defined rustc target. Commit 18f8aeda8b59a132f24fa1af800ff65cac2f61f4 breaks this workaround as, even without an exe_wrapper, native_static_libs are appends as internal deps. This behaviour makes sense for cross compiled rust in a rich environment but not any for no-std rust. As said in comments, one can't tell if the code is no-std or not because this is an annotation from sources. From our point of view, it is pretty clear that building a no-std rust target means that one has to define system='bare metal' and kernel='none' in his cross-file. According to that, sanity_check for rust compiler is modified to handle kernel == 'none' case by building a specific no-std rust snippet, with an extra args if rust_ld is ls.bfd (in order to prevent the linker to link with a potentially non existing startfile for the given target). 'native_static_libs' is also leave empty in that very case. This commit fix the spurious native static libs for no-std case and allow us to remove our dirty workaround which by-passed non working sanity check for bare metal rust. One who wants to use meson for baremetal Rust project only have to define the rust target in their cross file. e.g. rust = ['rustc', '--target', '<rustc valid target>']
2024-07-16Revert various cross compile changesChristoph Reiter
c1076241af11f10acac28d771688bb54c6b0b340 changed the logic in multiple places, in particular it looks like it was assumed that is_cross is always the same as need_exe_wrapper(), but that's not true. Also the commit only talks about mypy, so this was definitely not intended. This reverts all the cases where need_exe_wrapper() was introduced back to is_cross. The change in backends.py could be a correct simplification, but I don't know the code base enough, so reverting that too. See #13403 and #13410
2024-07-12Rename langopt methodJussi Pakkanen
The public facing name of language options is compiler option, so let's standardise on that.
2024-07-11Move OptionKey in the option source file.Jussi Pakkanen
2024-06-14Replace direct indexing with named methods.Jussi Pakkanen
2024-06-08Use helper method in Rust compiler class.Jussi Pakkanen
2024-05-23Refactor option classes to their own file.Jussi Pakkanen
2024-04-24rust: Fix warning_level=everything caseXavier Claessens
Fixes: #13100
2024-03-28Pass Environment down from BackendSam James
We'll need it in a moment for get_base_compile_args -> get_assert_args. Bug: https://github.com/mesonbuild/meson/issues/12962 Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Eli Schwartz <eschwartz93@gmail.com>
2024-03-15Improve error messages for invalid option valuesCharles Brunet
By adding the option name to UserOption object, it is now possible to display the name of the affected option when the given option value is not valid. Fixes #12635
2024-03-15rust: Get native-static-libs even when it cannot run host binariesXavier Claessens
When rustc cannot run host binaries it does an early return which skipped getting native-static-libs. Move that code earlier to always run it. While at it, failing to determine those libs is a fatal error. We would crash later when trying to access rustc.native_static_libs attribute otherwise.
2024-03-15compilers: No need to pass exe_wrapper everywhereXavier Claessens
Places where compiler needs it already have access to Environment object and can use it directly. This fixes mypy complaining that not all compilers have self.exe_wrapper in run() method that got moved to base class.
2024-01-17rust: fix linking static executablesAlyssa Ross
For the same reason as for static libraries, we have to use -l when generating static executables. Fixes: https://github.com/mesonbuild/meson/issues/12585
2023-12-23Remove `get_buildtype_args` functionCharles Brunet
This is a first step to make `buildtype` a true alias of `debug` and `optimization` options. See #10808. Relates to: - #11645 - #12096 - #5920 - #5814 - #8220 - #8493 - #9540 - #10487 - #12265 - #8308 - #8214 - #7194 - #11732
2023-12-13Use SPDX-License-Identifier consistentlyDylan Baker
This replaces all of the Apache blurbs at the start of each file with an `# SPDX-License-Identifier: Apache-2.0` string. It also fixes existing uses to be consistent in capitalization, and to be placed above any copyright notices. This removes nearly 3000 lines of boilerplate from the project (only python files), which no developer cares to look at. SPDX is in common use, particularly in the Linux kernel, and is the recommended format for Meson's own `project(license: )` field
2023-12-05compilers: drop dead codeEli Schwartz
no_warn_args is unused. Its only purpose was to implement automatic hiding of UB in transpiled code, and it was not used at all in languages other than C/C++ -- specifically when the C/C++ source files were created by transpiling from vala or cython.
2023-10-19rust: Always link dll and exe with the correct vscrtXavier Claessens
This fixes missing flags in the link_whole case and link failure for static libraries.
2023-09-19Rust: Use Popen_safe_logged in sanity checksXavier Claessens
2023-08-11treewide: automatic rewriting of all comment-style type annotationsEli Schwartz
Performed using https://github.com/ilevkivskyi/com2ann This has no actual effect on the codebase as type checkers (still) support both and negligible effect on runtime performance since __future__ annotations ameliorates that. Technically, the bytecode would be bigger for non function-local annotations, of which we have many either way. So if it doesn't really matter, why do a large-scale refactor? Simple: because people keep wanting to, but it's getting nickle-and-dimed. If we're going to do this we might as well do it consistently in one shot, using tooling that guarantees repeatability and correctness. Repeat with: ``` com2ann mesonbuild/ ```
2023-07-15rust: disable overflow-checks by defaultDylan Baker
These result in very large binaries when linked, and are not generally useful. A user can turn them back on by passing `-C overflow-checks=yes` manually via `-Drust_args` or the `RUSTFLAGS` environment variable fixes: #11785
2023-06-26linkers: delay implementations import until detect is runEli Schwartz
This saves on a 1500-line import at startup and may be skipped entirely if no compiled languages are used. In exchange, we move the implementation to a new file that is imported instead. Followup to commit ab20eb5bbc21ae855bcd211131132d2778602bcf.
2023-06-07rust: PIC is always enabledXavier Claessens
rustc enables PIC by default and Meson currently has no way to force disabling PIC, it can only force enable or use compiler's default.
2023-05-20rust: Add system libs used by rust std to staticlib external depsXavier Claessens
2023-05-20rust: Use Popen_safe() for sanity checksXavier Claessens
2023-05-16rust compiler: use better sanity check logging comparable to the clike oneEli Schwartz
Don't spew debug-level info. Log the actual command line run.
2023-04-21rust: add support for b_ndebugDylan Baker
Rust has a `debug_assert!()` macro, which is designed to be toggled on the command line. It is on by default in debug builds, and off by default in release builds, in cargo. This matches what meson's b_ndebug option does in `if-release` mode.
2023-04-14rust: Don't pass dependency compile arguments to the compilerSebastian Dröge
Rust doesn't have a concept of dependency compile arguments, i.e. something like headers. Dependencies are linked in and all required metadata is provided by the linker flags.
2023-04-11Change "can not" to "cannot" throughout projectHiPhish
The word "cannot" expresses inability to do something whereas "can not" expresses the ability to refrain from doing something.
2022-10-25compilers: Make sure to not use ccache in compiler checksXavier Claessens
ccache was used in all command lines but disabled using CCACHE_DISABLE in Compiler.compile() method. Wrapping invokations still has a cost, especially on Windows. With sccache things are even worse because CCACHE_DISABLE was not respected at all, making configure *extremely* slow on Windows when sccache is installed.
2022-10-25Compilers: Keep ccache and exelist separatedXavier Claessens
Only combine them in the Compiler base class, this will make easier to run compiler without ccache.
2022-10-09compilers: Add optimization=plain optionJan Tojnar
https://github.com/mesonbuild/meson/pull/9287 changed the `optimization=0` to pass `-O0` to the compiler. This change is reasonable by itself but unfortunately, it breaks `buildtype=plain`, which promises that “no extra build flags are used”. `buildtype=plain` is important for distros like NixOS, which manage compiler flags for optimization and hardening themselves. Let’s introduce a new optimization level that does nothing and set it as the default for `buildtype=plain`.
2022-09-19pylint: enable use-maxsplit-argDylan Baker
This finds a bunch of places where we can do more efficient string splitting.
2022-06-10treewide: various cleanups to move imports for mypy into typechecking blocksEli Schwartz
Along the way, add __future__ annotations where lacking.
2022-04-30linkers: Add support for mold linkerFini Jastrow
[why] Support for the relatively new mold linker is missing. If someone wants to use mold as linker `LDFLAGS="-B/path/to/mold"` has to be added instead of the usual `CC_LD=mold meson ...` or `CXX_LD=mold meson ...`. [how] Allow `mold' as linker for clang and newer GCC versions (that versions that have support). The error message can be a bit off, because it is generic for all GNU like compilers, but I guess that is ok. (i.e. 'mold' is not listed as possible linker, even if it would be possible for the given compiler.) [note] GCC Version 12.0.1 is not sufficient to say `mold` is supported. The expected release with support will be 12.1.0. On the other hand people that use the un-released 12.0.1 will probably have built it from trunk. Allowing 12.0.1 is helping bleeding edge developers to use mold in Meson already now. Fixes: #9072 Signed-off-by: Fini Jastrow <ulf.fini.jastrow@desy.de>