summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/rust.py
AgeCommit message (Collapse)Author
2025-12-22rust: add to_system_dependencyPaolo Bonzini
Move the logic for system dependencies outside Cargo.interpreter and into the rust module, so that it can be reused by the workspace object. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-01rust: Rust-ABI dynamic libraries do not support LTOPaolo Bonzini
Attempting to use LTO on e.g. a procedural macro crate fails with error: lto cannot be used for proc-macro crate type without -Zdylib-lto Do not return -Clto for such crate types. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-01compilers: pass target to get_lto_*_argsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-23compilers: forward gen_vs_module_defs_args to linkerPaolo Bonzini
This adds support for DEF files to rust and removes some hasattr duck typing. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-19compilers/rust: make use the fact we have an Environment to cleanupDylan Baker
This adds a second stage initialization, which allows us to use options for setting attributes on the compiler. This is called during the detect phase, so the Compiler is never used in a partially initialized state.
2025-11-19compilers: Remove Environment parameter from RustCompiler.get_nightlyDylan Baker
2025-11-19compilers: Remove Environment parameter from RustCompiler.lib_file_to_l_argsDylan Baker
2025-11-19compilers: Remove Environment parameter from RustCompiler.get_rustdocDylan Baker
2025-11-19compilers: Remove Environment parameter from RustCompiler.get_rust_toolDylan Baker
2025-11-19compilers: Remove Environment parameter from Compiler.get_option_std_argsDylan Baker
2025-11-19compilers: Remove Environment parameter from Compiler.sanitizer_argsDylan Baker
2025-11-19compilers: Remove Environment parameter from Compiler.has_multi_argumentsDylan Baker
2025-11-19compilers: Remove Environment parameter from Compiler.build_rpath_argsDylan Baker
2025-11-19compilers: Remove Environment parameter from Compiler.get_assert_argsDylan Baker
2025-11-19compilers: Remove Environment parameter from Compiler.sanity_checkDylan Baker
2025-11-19compilers: Remove Environment parameter from Compiler.run_sanity_checkDylan Baker
2025-11-19compilers: Remove Environment parameter from Compiler.compiles()Dylan Baker
2025-11-19compilers: Remove Environment parameter from get_compileropt_valueDylan Baker
2025-11-19compilers: Stop passing `is_cross`Dylan Baker
This is calculated by `Environment().is_cross_build(for_machine)`. Since we have that in the Compiler class, just calculate it in the Compiler initializer
2025-11-19compilers: Pass Environment instead of MachineInfoDylan Baker
We end up needing it everywhere, so just store it. This patch is huge already, so it's just the conversion to passing Environment, more cleanups to come.
2025-11-19rust: add functions for coverage argumentsPaolo Bonzini
Adding support for linker option broke -Db_coverage because the `--coverage` option is added to the command line without the `-Clink-arg=` part. Fix it by overriding get_coverage_link_args; since we have to add the get_coverage_* functions to RustCompiler, teach it to generate `-Cinstrument-coverage` as well. Note that `-Clink-arg==--coverage` is actually useful only for mixed C/Rust programs. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-12rust: allow linking with sanitizer-enabled C librariesPaolo Bonzini
Fixes: #15222 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-12rust: call compilers.get_base_link_argsPaolo Bonzini
The rustc invocation performs both compilation and linking, so it should include link-phase arguments for LTO or sanitizers. RustCompiler has been taught how to include these arguments, so now add them. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-12rust: always pass -C default-linker-librariesPaolo Bonzini
This is often needed for mixed Rust/C programs, and in particular always needed with sanitizers. Add it always. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-12rust: use proper linker arguments to get the MSVC runtime libraryPaolo Bonzini
Follow the suggestion in https://github.com/rust-lang/rust/issues/39016#issuecomment-2391095973 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-12rust: add full set of linker argument functions to RustCompilerPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-12compilers: generalize -fembed-bitcodePaolo Bonzini
Produce -Cembed-bitcode for Rust, and also disable bitcode generation when LTO is not enabled.
2025-11-12rust: add get_lto_compile_argsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-23cargo: Use --env-set when we have nightly rustcXavier Claessens
2025-10-23rust: Add rust_nightly feature optionXavier Claessens
This is used for project to require a nightly Rust compiler, and also for Meson to enable nightly feature if available.
2025-10-23cargo: generate lint arguments from tablePaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-15rust: mark verbatim unsupported also for wasmKohei Tokunaga
This fixes the following error occured in the test 3 of the Emscripten build. > wasm-ld: error: unable to find library -llibvalue.a Signed-off-by: Kohei Tokunaga <ktokunaga.mail@gmail.com>
2025-10-14compilers: make link/lld-link check homogeneousPaolo Bonzini
Use the same check for all of clang, nasm and rustc. This also avoids the following warning: Sanity check compiler command line: clang++ sanitycheckobjcpp.mm -o sanitycheckobjcpp.exe -D_MT -D_DLL -D_DEBUG -D_FILE_OFFSET_BITS=64 -Wl,-fms-runtime-lib=dll_dbg Sanity check compile stdout: LINK : warning LNK4044: unrecognized option /fms-runtime-lib=dll_dbg; ignored iWhat happens is that -fms-runtime-lib sets up an automatic dependency from the .o files to the final link product, and therefore must be passed as a compiler argument. But the constructor for ClangCompiler was incorrectly allowing b_vscrt for MINGW, so I messed up the logic. With this change, MINGW won't get the b_vscrt option. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-11fix rustc -l argument on WindowsPaolo Bonzini
On Windows, rustc searches both FOO.lib and libFOO.a when passed -lfoo. This means that the check for nonstandard names in the Unix sense is too struct, and indeed it breaks passing for example -lkernel32 (which adds kernel32.lib to the link). Fix this by special casing Windows. Extract the logic to the Rust compiler class for clarity. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-08rust: query linker in addition to compiler for verbatim supportPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-06Revert "compilers: refactor sanity checking code"Dylan Baker
This reverts commit 806289a5d27958a084bc6cba41b7cf9ccee4ecf4.
2025-10-06compilers: refactor sanity checking codeDylan Baker
The goal is to reduce code duplication, and allow each language to implement as little as possible to get good checking. The main motivation is that half of the checks are fragile, as they add the work directory to the paths of the generated files they want to use. This works when run inside mesonmain because we always have an absolute build directory, but when put into run_project_tests.py it doesn't work because that gives a relative build directory.
2025-08-10compiler,rust: No native-static-libs for wasm after 1.84Ruben Gonzalez
Rust 1.84 uses the latest emsdk 3.1.68 [1], and it fixed an issue with Emscripten dynamic linking and libc [2]. After that no native-static-libs in the output if running: ``` rustc --target=wasm32-unknown-emscripten --crate-type staticlib --print native-static-libs - < /dev/null ``` [1] https://github.com/rust-lang/rust/pull/131533 [2] https://github.com/rust-lang/libc/pull/4002
2025-08-01call determine_rpath_dirs only when linker requires itCharles Brunet
2025-07-21rust: pass rpath arguments to rustdoc --testPaolo Bonzini
rustdoc does not support --print, and therefore the rpath argument corresponding to the rust installation is not passed to doctests. Forward anything that requires --print to the RustCompiler, thus fixing doctests with a shared library dependency. Fixes: #14813 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-18rust: add rust_dynamic_std optionPaolo Bonzini
As an initial implementation, simply adding "-C prefer-dynamic" works for binary crates (as well as dylib and proc-macro that already used it). In the future this could be extended to other crate types. For more information see the comment in the changed file, as well as https://github.com/mesonbuild/meson/issues/8828 and https://github.com/mesonbuild/meson/issues/14215. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-07-18compilers: add Rustup libdir even if there is no other rpath argumentPaolo Bonzini
RustCompiler.build_rpath_args works by appending the directory to the arguments computed by self.linker.build_rpath_args. This does not work if there is no argument to begin with, which happens for example in program crates. Use the new extra_paths argument to force inclusion of the libdir into the rpath of the binary, even in that case. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-05-31cargo: Add support for target specific dependenciesXavier Claessens
2025-05-11compilers/rust: fix syntax of has_argument checksDaniel Foster
2025-04-30compilers: introduce common helper for sanity checksPaolo Bonzini
Avoid reinventing the wheel and instead use a single helper, taking care of logging and cross compilation. Fixes: #14373 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-16compilers/rust: remove CRT selection from native_static_libs argsKacper Michajłow
This will be handled by target binary link. And if it's not compatible with what Rust uses, it wouldn't work anyway.
2025-04-08coredata: move MutableKeyedOptionDict to optionsDylan Baker
2025-04-04compilers: move -std options to get_option_std_args, special-casing CUDAPaolo Bonzini
Move building the -std option to the new get_option_std_args method, special casing CUDA to never include the option from the host compiler. This fixes again #8523, which was broken by the option refactoring (unsurprisingly, since the fix was ripped out unceremoniously without a replacement). Fixes: #14365 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-04-03compilers/rust: fix sanity_check for Windows targetsKacper Michajłow
Windows toolchains append `.exe` to executables. When cross-compiling on Linux, attempting to run `./rusttest` will not execute the generated `rusttest.exe`. Fix this by always appending `.exe`, which is a valid filename on all supported platforms. This is what the `CLikeCompiler` class does too. While reviewing `rust.py`, there are opportunities for improvements and better unification with the rest of the Meson code. However, this commit focuses on fixing cross-compilation with minimal changes. Fixes: #14374
2025-04-02compilers: rust: fix derivation of RustdocTestCompilerPaolo Bonzini
Pass down the full_version, otherwise assigning "self.is_beta" fails. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>