diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-10-24 10:24:45 +0200 |
|---|---|---|
| committer | Paolo Bonzini <pbonzini@redhat.com> | 2025-12-22 11:59:07 +0100 |
| commit | 7a1aa179087a274d6f6b13c2c666043ac9760ea5 (patch) | |
| tree | b9bf5eed53e6a3ff41dee74b6429ef2916dae37a /mesonbuild/modules | |
| parent | 9752def1c96eb32dc37c32398a0fe8802392fbc9 (diff) | |
| download | meson-7a1aa179087a274d6f6b13c2c666043ac9760ea5.tar.gz | |
modules: rust: implement workspace.package()
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>
Diffstat (limited to 'mesonbuild/modules')
| -rw-r--r-- | mesonbuild/modules/rust.py | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py index 29d1b1fbb..186774413 100644 --- a/mesonbuild/modules/rust.py +++ b/mesonbuild/modules/rust.py @@ -101,6 +101,7 @@ class RustWorkspace(ModuleObject): self.ws = ws self.methods.update({ 'packages': self.packages_method, + 'package': self.package_method, 'subproject': self.subproject_method, }) @@ -111,6 +112,12 @@ class RustWorkspace(ModuleObject): package_names = [pkg.manifest.package.name for pkg in self.ws.packages.values()] return sorted(package_names) + @typed_pos_args('workspace.package', optargs=[str]) + def package_method(self, state: 'ModuleState', args: T.List, kwargs: TYPE_kwargs) -> RustPackage: + """Returns a package object.""" + package_name = args[0] if args else None + return RustPackage(self, self.interpreter.cargo.load_package(self.ws, package_name)) + def _do_subproject(self, pkg: cargo.PackageState) -> None: kw: _kwargs.DoSubproject = { 'required': True, @@ -138,8 +145,8 @@ class RustWorkspace(ModuleObject): return RustSubproject(self, pkg) -class RustSubproject(ModuleObject): - """Represents a Rust package within a workspace.""" +class RustCrate(ModuleObject): + """Abstract base class for Rust crate representations.""" def __init__(self, rust_ws: RustWorkspace, package: cargo.PackageState) -> None: super().__init__() @@ -148,7 +155,6 @@ class RustSubproject(ModuleObject): self.methods.update({ 'all_features': self.all_features_method, 'api': self.api_method, - 'dependency': self.dependency_method, 'features': self.features_method, 'name': self.name_method, 'version': self.version_method, @@ -184,6 +190,23 @@ class RustSubproject(ModuleObject): """Returns chosen features for specific package.""" return sorted(list(self.package.cfg.features)) + +class RustPackage(RustCrate): + """Represents a Rust package within a workspace.""" + + def __init__(self, rust_ws: RustWorkspace, package: cargo.PackageState) -> None: + super().__init__(rust_ws, package) + + +class RustSubproject(RustCrate): + """Represents a Cargo subproject.""" + + def __init__(self, rust_ws: RustWorkspace, package: cargo.PackageState) -> None: + super().__init__(rust_ws, package) + self.methods.update({ + 'dependency': self.dependency_method, + }) + @noPosargs @typed_kwargs('package.dependency', KwargInfo('rust_abi', (str, NoneType), default=None, validator=in_set_validator({'rust', 'c', 'proc-macro'}))) |
