Bug 2329304

Summary: spec-files created with rust2rpm contain sub-packages for dependencies
Product: [Fedora] Fedora Reporter: Uri Lublin <uril>
Component: rust2rpmAssignee: Rust SIG <rust-sig>
Status: CLOSED NOTABUG QA Contact:
Severity: medium Docs Contact:
Priority: unspecified    
Version: rawhideCC: decathorpe, rust-sig
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2024-11-28 09:46:08 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

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