Bug 2329304 - spec-files created with rust2rpm contain sub-packages for dependencies
Summary: spec-files created with rust2rpm contain sub-packages for dependencies
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: rust2rpm
Version: rawhide
Hardware: Unspecified
OS: Linux
unspecified
medium
Target Milestone: ---
Assignee: Rust SIG
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-11-28 09:25 UTC by Uri Lublin
Modified: 2024-11-28 09:46 UTC (History)
2 users (show)

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2024-11-28 09:46:08 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

Description Uri Lublin 2024-11-28 09:25:05 UTC
Usually rust2rpm creates spec files with subpackages rust-<cratename>+<feature>-devel.
But now it also creates subpackages rust-<cratename>+<dependency>-devel for dependencies that appear in the [features] table.


rust2rpm-26.2.0-1.fc42.noarch


Reproducible: Always

Steps to Reproduce:
1. rust2rpm jsonwebkey 0.3.5
2. grep '^.package' rust-jsonwebkey.spec

Actual Results:  
%package        devel
%package     -n %{name}+default-devel
%package     -n %{name}+generate-devel
%package     -n %{name}+jsonwebtoken-devel
%package     -n %{name}+jwt-convert-devel
%package     -n %{name}+num-bigint-devel
%package     -n %{name}+p256-devel
%package     -n %{name}+pkcs-convert-devel
%package     -n %{name}+rand-devel
%package     -n %{name}+yasna-devel


Expected Results:  
%package        devel
%package     -n %{name}+default-devel
%package     -n %{name}+generate-devel
%package     -n %{name}+jwt-convert-devel
%package     -n %{name}+pkcs-convert-devel


Not create subpackages for dependencies, only for features.

Comment 1 Uri Lublin 2024-11-28 09:30:22 UTC
A workaround exists:
Prefix each dependency in [features] table with "dep:".

For example:
$ rust2rpm jsonwebkey 0.3.5 -p # run with -p and change Cargo.toml ==> creates jsonwebkey-fix-metadata.diff
$ cat jsonwebkey-fix-metadata.diff
--- jsonwebkey-0.3.5/Cargo.toml	1970-01-01T00:00:01+00:00
+++ jsonwebkey-0.3.5/Cargo.toml	2024-11-28T09:27:02.133502+00:00
@@ -73,14 +73,14 @@
 
 [features]
 generate = [
-    "p256",
-    "rand",
+    "dep:p256",
+    "dep:rand",
 ]
 jwt-convert = [
     "pkcs-convert",
-    "jsonwebtoken",
+    "dep:jsonwebtoken",
 ]
 pkcs-convert = [
-    "num-bigint",
-    "yasna",
+    "dep:num-bigint",
+    "dep:yasna",
 ]

$ grep '^.package' rust-jsonwebkey.spec
%package        devel
%package     -n %{name}+default-devel
%package     -n %{name}+generate-devel
%package     -n %{name}+jwt-convert-devel
%package     -n %{name}+pkcs-convert-devel

Comment 2 Fabio Valentini 2024-11-28 09:46:08 UTC
> Usually rust2rpm creates spec files with subpackages rust-<cratename>+<feature>-devel.
> But now it also creates subpackages rust-<cratename>+<dependency>-devel for dependencies that appear in the [features] table.

Yes- this is intentional, and matches behaviour of cargo itself.

You can verify this by running `cargo metadata` against the project's "Cargo.toml" file and looking at the "features" property of the JSON output.

> A workaround exists:
> Prefix each dependency in [features] table with "dep:".

This is not a workaround, it's applying a potentially breaking change compared to upstream - don't do it.

It looks like there's a misunderstanding about how cargo works:
All optional dependencies (unless hidden explicitly) *are* features.

Please refer to the cargo documentation:
https://doc.rust-lang.org/cargo/reference/features.html#optional-dependencies


Note You need to log in before you can comment on or make changes to this bug.