summaryrefslogtreecommitdiff
path: root/mesonbuild/cargo
AgeCommit message (Collapse)Author
2025-12-22quick fixHEADmasterJohn Turner
2025-12-22modules: rust: add package.override_dependency methodPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22cargo: populate bin table from src/bin/Paolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22modules: rust: add package.library/package.proc_macro methodsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22cargo: use dependencies() method to get dependenciesPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22modules: rust: invoke subprojects automatically from dependencies()Paolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22cargo: use rust.workspace() to build the argumentsPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22cargo: use rust.to_system_dependencyPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22modules: rust: implement workspace.package()Paolo Bonzini
Note that, as shown in the testcase, package() works in the subproject as well. This means that in the future the Cargo code generator can be changed to reduce the amount of generated code and instead rely on the package object. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22cargo: use cargo_ws.subproject().dependency()Paolo Bonzini
This is up to 2x faster because it avoids checks for pkg-config and cmake. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22modules: rust: implement workspace.subproject() and package.dependency()Paolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22cargo: add configurable features to InterpreterPaolo Bonzini
Add features property to cargo.Interpreter to make default features configurable; customization of which features are enabled by default is triggered by rust.workspace(). Fixes: #14290 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22rust: add rust.workspace() skeleton implementationPaolo Bonzini
rust.workspace() is the entry point for global feature resolution. It loads a Cargo.toml file and ensures that all dependencies will be built with the correct set of features. Fixes: #13404 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-22cargo: show nice exception if Cargo.toml missingPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-15cargo: convert TOMLDecodeError or toml2json errors to a MesonExceptionPaolo Bonzini
Avoid getting a raw exception, instead use a (subclass of) MesonException that is printed in the usual "FILE:LINE:COLUMN: MESSAGE" format. Fixes: #15023 Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-15cargo: fix UnboundLocalError if Cargo.lock only has local packagesPaolo Bonzini
2025-12-15cargo: include the implicit feature for dependencies in the manifestPaolo Bonzini
Make the implicit `xyz = ["dep:xyz"]` declaration explicit in the Manifest. This also makes it possible to implement correctly the part of the spec where "If you specify the optional dependency with the dep: prefix anywhere in the [features] table, that disables the implicit feature." Unfortunately, this can only be done after target-specific configurations are resolved, which makes it hard to write a unit test for this. Rustix requires it, though; without this patch, something like [package] name = "rustix" edition = "2021" rust-version = "1.63" version = "0.38.34" [dependencies] alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" } libc = { version = "0.2.0", optional = true, package = "libc" } libc_errno = { version = "0.3.8", optional = true, package = "errno" } [features] alloc = [] default = ["std"] rustc-dep-of-std = ["dep:alloc"] std = ["alloc"] use-libc = ["libc_errno", "libc"] would incorrectly request the rustc-std-workspace-alloc crate via the chain default->std->alloc. The patch blocks it because it finds the "dep:alloc" dependency of feature rustc-dep-of-std. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-15cargo: add --check-cfg cfg(test) unconditionallyPaolo Bonzini
It should be added even if unexpected_cfgs is not part of Cargo.toml. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08interpreterbase: make ArithmeticNode and MesonOperator both use operator namesPaolo Bonzini
This avoids creating a dictionary every time an arithmetic operator is evaluated. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08make ctype the same as the printed ASTPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08cargo: autodetect patch directoryPaolo Bonzini
Many crates that have a build.rs will usually require an overlay with the translated meson/meson.build file. To avoid having to create a .wrap file, when parsing Cargo.lock autodetect a directory in subproject/packagefiles/ and add it as the patch_directory. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-12-08cargo: unify call to PackageDefinition.from_valuesPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-11-19fix parsing cgit pathsJohn Turner
Using os.path.basename on a string such as "/foo/bar/" returns an empty string, which breaks on e.g. Cgit git URLs. The fix uses pathlibs Path class "parent" method, which gets the last component of the path, so "bar" for "/foo/bar/".
2025-10-29cargo: add check-cfg for system_deps_have_* symbolsPaolo Bonzini
2025-10-29cargo: use subproject() if a workspace member is in subprojects/Paolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: propagate PackageState from the full resolution into workspacesPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: always create a dummy workspacePaolo Bonzini
Cargo allows path in dependencies even outside a workspace. To support this in Meson, always create a dummy WorkspaceState outside non-workspace manifests. Another bug that this fixes is that the default feature was not added for workspaces, only for projects. In addition, this removes some confusion and code duplication between interpret_package() and interpret_workspace(). Because they are respectively for top-level directories and subdirectories, interpret_package always has a project_root and interpret_workspace never does.
2025-10-29cargo: mark workspaces as downloadedPaolo Bonzini
... and propagate to their packages Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: extract _resolve_packagePaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: move rust_dependency_map generation to PackageConfigurationPaolo Bonzini
Add a dep_packages cache to PackageConfiguration to store resolved dependencies, so that there is no need to call _dep_package() again and all knowledge of how to build arguments is removed from _create_lib()
2025-10-29cargo: put all dependencies in the rust_dependency_mapPaolo Bonzini
While this has no effect, it makes it easier to move the generation of the rust_dependency_map out of the interpreter. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: move rustc argument generation to PackageState and PackageConfigurationPaolo Bonzini
Generating command line arguments needs the Environment, not the whole cargo interpreter state. Move it out of Interpreter. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: move environment generation to PackageStatePaolo Bonzini
Generating environment variables needs the Environment, not the whole cargo interpreter state. Move it out of Interpreter. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: move _prepare_package outside _fetch_packagePaolo Bonzini
Make the PackageConfiguration optional: this makes it easy to see if the package had already been found earlier. This also removes calls to _prepare_package and makes it idempotent. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: ensure all prepared package are in self.packagesPaolo Bonzini
The next step is to ensure that all packages are in self.packages prior to _prepare_package. For now, instead, ensure that nothing breaks if the packages are _absent_ from self.packages. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: pull feature and dependency data out of PackageStatePaolo Bonzini
Part of PackageState refers to the package itself, and part to the feature and dependency resolution process. Pull the latter outside, in preparation for having different features and dependencies for the build and the host machine. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: unify handling of DEP/FEATURE and DEP?/FEATUREPaolo Bonzini
self._add_dependency is idempotent so do it freely, and process DEP/FEATURE as a self._add_dependency followed by regular DEP?/FEATURE processing. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: only create dependencies if there is a [lib] tablePaolo Bonzini
In the long term, dependencies that do not have a [lib] table will not create an invocation of override_dependency; do not expect there to be a handwritten meson.build that does it. In particular, this is the case for extra-dep-1-rs in the "rust/22 cargo subproject" test case, so change that to use the extra_deps mechanism instead to invoke the subproject. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: remove cfg importPaolo Bonzini
Leave the cfg symbol free. Only one function is used. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: use Package.api directlyPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: allow putting "." in membersPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: ensure default members is validPaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-29cargo: avoid AttributeError if cargolock is NonePaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-28cargo: Add library API version into its nameXavier Claessens
It is required to have unique library names for rust_dependency_map to work. In the case we have foo crate in multiple versions, we have to make sure their .rlib file have a different name.
2025-10-28cargo: Dependency variable name must include its APIXavier Claessens
A crate can depend on 2 different API versions of the same crate: foo_1_dep and foo_2_dep. Make sure a Dependency always has a version. When it's defined by a git URL, or a path, the version could be omitted. Update once we fetched the dependency's package.
2025-10-28cargo: Fix version_arr paddingXavier Claessens
2025-10-27cargo: edition and lint args are per packageXavier Claessens
edition and lint args were not set the Cargo subproject is a workspace.
2025-10-23cargo: fix proc-macro=true without crate_typePaolo Bonzini
The default value is not passed further through the converter, therefore it must take proc-macro into account. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2025-10-23cargo: Use --env-set when we have nightly rustcXavier Claessens
2025-10-23cargo: generate lint arguments from tablePaolo Bonzini
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>