Package: dh-rust
Version: 0.0.8
Severity: important

See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1081879 for the very long explanation of why I'm filing this bug.

I believe https://salsa.debian.org/build-common-team/dh-rust/-/commit/d7848d2c62d58219d1d8475f3d89014c061f4c72 should be reverted, as it broke the compilation of rust-safe-arch, and it's rather hard to work around.

I was at first a bit hesitant to suggest this as it's late in the release cycle, but it seems it's not as bad as I initially thought. While there are 133 packages depending on dh-rust, I believe that only those that are modifying flags through the [build] target would be affected by this change.

Taking that into account, these are the packages that include a [build] target in their .cargo/config.toml file:
https://codesearch.debian.net/search?q=%5Bbuild%5D+path%3A.cargo%2Fconfig.toml&literal=1&perpkg=1

rust-safe-arch
corrosion
rustc
pydantic-core
rust-rend
rust-git-cinnabar
golang-github-google-flatbuffers
chromium
rust-inquire
rust-rancor
rust-hstr
pendulum
flatbuffers

Out of these, only the following build-depend on dh-sequence-rust:

rust-safe-arch
rust-inquire
rust-hstr

In the case of rust-hstr, these are the contents:

[build]

rustdocflags = ["--cfg", "docsrs"]
#rustflags    = ["-Zshare-generics=y"]

Which I think are redundant by now.

In the case of rust-inquire, these are the contents:
[build]
target-dir = "target"
rustdocflags = [
    "-Arustdoc::private_intra_doc_links",
    "-Drustdoc::broken_intra_doc_links",
]

[target.'cfg(all())']
rustflags = [
... a lot of flags ...
]

To check if the change would cause problems, I have built rust-inquire with a patched version of dh-rust (patch attached) and it built successfully. I didn't perform any additional tests, though, as I don't know what the package does.

So, to the best of my knowledge, reverting that patch will fix rust-safe-arch and won't break any other packages, thus, I suggest that this is done asap to fix rust-safe-arch in time for trixie.

--
Regards,
Marga
--- a/bin/cargo	2024-08-23 14:16:55.000000000 +0000
+++ b/bin/cargo	2025-04-12 15:59:29.101321602 +0000
@@ -83,7 +83,7 @@
 def sourcepath(p=None):
     return os.path.join(os.getcwd(), p) if p else os.getcwd()
 
-def prepare_debian(cargo_home, registry, host_gnu_type, ldflags):
+def prepare_debian(cargo_home, registry, host_gnu_type, ldflags, extra_rustflags):
     registry_path = sourcepath(registry)
     log("linking %s/* into %s/" % (SYSTEM_REGISTRY, registry_path))
     os.makedirs(registry_path, exist_ok=True)
@@ -98,6 +98,7 @@
     for f in ldflags:
         rustflags.extend(["-C", "link-arg=%s" % f])
     rustflags.extend(["--remap-path-prefix", "%s=%s" % (registry_path, SYSTEM_REGISTRY)])
+    rustflags.extend(extra_rustflags.split())
 
     # TODO: we cannot enable this until dh_shlibdeps works correctly; atm we get:
     # dpkg-shlibdeps: warning: can't extract name and version from library name 'libstd-XXXXXXXX.so'
@@ -113,7 +114,7 @@
 [source.dh-cargo-registry]
 directory = "{0}"
 
-[target.'cfg(all())']
+[build]
 rustflags = {1}
 """.format(registry_path, repr(rustflags)))
 
@@ -194,11 +195,19 @@
     log("options, profiles, parallel, lto:", build_options, build_profiles, parallel, lto)
     log("rust_type, gnu_type:", ", ".join([host_rust_type, host_gnu_type]))
 
+    if "RUSTFLAGS" in os.environ:
+        # see https://github.com/rust-lang/cargo/issues/6338 for explanation on why we must do this
+        log("unsetting RUSTFLAGS and assuming it will be (or already was) added to $CARGO_HOME/config.toml")
+        extra_rustflags = os.environ["RUSTFLAGS"]
+        del os.environ["RUSTFLAGS"]
+    else:
+        extra_rustflags = ""
+
     if args[0] == "prepare-debian":
         registry = args[1]
         return prepare_debian(cargo_home, registry,
             host_gnu_type,
-            os.getenv("LDFLAGS", "").split())
+            os.getenv("LDFLAGS", "").split(), extra_rustflags)
 
     newargs = []
     subcmd = None

Reply via email to