commit:     1c91e3825ce090212ba0bbafbd23deed1ffc7e37
Author:     Johannes Penßel <johannesp <AT> posteo <DOT> net>
AuthorDate: Mon Dec 29 12:54:23 2025 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Dec 29 17:29:55 2025 +0000
URL:        https://gitweb.gentoo.org/proj/pycargoebuild.git/commit/?id=1c91e382

cargo: default to 0.0.0 if version field is missing

Starting with Rust 1.75, the [version] field in cargo manifests is no
longer mandatory, defaulting to 0.0.0 if unset. (1)

[1] https://doc.rust-lang.org/cargo/reference/manifest.html#the-version-field

Closes: https://github.com/gentoo/pycargoebuild/issues/42
Signed-off-by: Johannes Penßel <johannesp <AT> posteo.net>
Part-of: https://github.com/gentoo/pycargoebuild/pull/45
Closes: https://github.com/gentoo/pycargoebuild/pull/45
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 pycargoebuild/cargo.py |  4 +++-
 test/test_cargo.py     | 11 +++++++++++
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/pycargoebuild/cargo.py b/pycargoebuild/cargo.py
index d9429a7..fc83769 100644
--- a/pycargoebuild/cargo.py
+++ b/pycargoebuild/cargo.py
@@ -300,9 +300,11 @@ def get_package_metadata(f: typing.BinaryIO,
     if pkg_license is not None:
         pkg_license = cargo_to_spdx(pkg_license)
 
+    # missing version field is legal in rust >= 1.75 and defaults to 0.0.0:
+    # https://doc.rust-lang.org/cargo/reference/manifest.html#the-version-field
     pkg_version = _get_meta_key("version")
     if pkg_version is None:
-        raise ValueError(f"No version found in {f.name}")
+        pkg_version = "0.0.0"
 
     features = cargo_toml.get("features", {})
     default_features = features.pop("default", [])

diff --git a/test/test_cargo.py b/test/test_cargo.py
index c8cb0d2..772ee45 100644
--- a/test/test_cargo.py
+++ b/test/test_cargo.py
@@ -237,6 +237,17 @@ def test_get_package_metadata_features():
                             license_file="COPYING"))
 
 
+def test_get_package_metadata_default_version():
+    input_toml = """
+        [package]
+        name = "test"
+    """
+
+    assert (get_package_metadata(io.BytesIO(input_toml.encode("utf-8"))) ==
+            PackageMetadata(name="test",
+                            version="0.0.0"))
+
+
 TOP_CARGO_TOML = b"""\
 [package]
 name = "toplevel"

Reply via email to