diff options
| author | Paolo Bonzini <pbonzini@redhat.com> | 2025-06-04 10:13:59 +0200 |
|---|---|---|
| committer | Dylan Baker <dylan@pnwbakers.com> | 2025-08-01 07:55:49 -0700 |
| commit | 4e058cc3ae1dec4041866a55ad6afd1a90c07005 (patch) | |
| tree | 0f88fbec0345ae20e412de4f4c3c6cea49330cee | |
| parent | fe25a14bd9d5a69379d8b598d1f57330bd1c50cd (diff) | |
| download | meson-4e058cc3ae1dec4041866a55ad6afd1a90c07005.tar.gz | |
cargo: fix path and crate-type for executable targets
Path cannot be empty and according to Cargo documentation these are
always of bin type.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
| -rw-r--r-- | mesonbuild/cargo/manifest.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/mesonbuild/cargo/manifest.py b/mesonbuild/cargo/manifest.py index d58939126..08ac79a9e 100644 --- a/mesonbuild/cargo/manifest.py +++ b/mesonbuild/cargo/manifest.py @@ -220,7 +220,7 @@ class BuildTarget(T.Generic[_R]): name: str path: str - crate_type: T.List[CRATE_TYPE] = dataclasses.field(default_factory=lambda: ['lib']) + crate_type: T.List[CRATE_TYPE] # https://doc.rust-lang.org/cargo/reference/cargo-targets.html#the-test-field # True for lib, bin, test @@ -274,6 +274,13 @@ class Binary(BuildTarget['raw.BuildTarget']): """Representation of a Cargo Bin Entry.""" doc: bool = True + crate_type: T.List[CRATE_TYPE] = dataclasses.field(default_factory=lambda: ['bin']) + + @classmethod + def from_raw(cls, raw: raw.BuildTarget) -> Self: + if 'path' not in raw: + raw['path'] = os.path.join('bin', raw['name'] + '.rs') + return super().from_raw(raw) @dataclasses.dataclass @@ -282,6 +289,13 @@ class Test(BuildTarget['raw.BuildTarget']): """Representation of a Cargo Test Entry.""" bench: bool = True + crate_type: T.List[CRATE_TYPE] = dataclasses.field(default_factory=lambda: ['bin']) + + @classmethod + def from_raw(cls, raw: raw.BuildTarget) -> Self: + if 'path' not in raw: + raw['path'] = os.path.join('tests', raw['name'] + '.rs') + return super().from_raw(raw) @dataclasses.dataclass class Benchmark(BuildTarget['raw.BuildTarget']): @@ -289,6 +303,13 @@ class Benchmark(BuildTarget['raw.BuildTarget']): """Representation of a Cargo Benchmark Entry.""" test: bool = True + crate_type: T.List[CRATE_TYPE] = dataclasses.field(default_factory=lambda: ['bin']) + + @classmethod + def from_raw(cls, raw: raw.BuildTarget) -> Self: + if 'path' not in raw: + raw['path'] = os.path.join('benches', raw['name'] + '.rs') + return super().from_raw(raw) @dataclasses.dataclass @@ -296,6 +317,14 @@ class Example(BuildTarget['raw.BuildTarget']): """Representation of a Cargo Example Entry.""" + crate_type: T.List[CRATE_TYPE] = dataclasses.field(default_factory=lambda: ['bin']) + + @classmethod + def from_raw(cls, raw: raw.BuildTarget) -> Self: + if 'path' not in raw: + raw['path'] = os.path.join('examples', raw['name'] + '.rs') + return super().from_raw(raw) + @dataclasses.dataclass class Manifest: |
