From 0d46839c04cf0e75e383b7cbfb43a88520a8f5c1 Mon Sep 17 00:00:00 2001 From: Oleks Date: Mon, 16 Mar 2026 14:39:36 +0200 Subject: [PATCH] fix: override both rustc-unwrapped and rustc wrapper for symlink_file patch to propagate --- flake.nix | 15 +++++++++------ patches/rustc-symlink-file-eexist.patch | 11 +++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) create mode 100644 patches/rustc-symlink-file-eexist.patch diff --git a/flake.nix b/flake.nix index 99b0fe9..1aa1291 100644 --- a/flake.nix +++ b/flake.nix @@ -97,13 +97,16 @@ # Rustc bootstrap: symlink_file panics with "File exists" during # s390x cross-compilation. Multiple call sites use t!(symlink_file(...)). # Patch the symlink_file method body to remove existing dest first. - (final: prev: { + (final: prev: let + patchedRustcUnwrapped = prev.rustc-unwrapped.overrideAttrs (old: { + patches = (old.patches or [ ]) ++ [ + ./patches/rustc-symlink-file-eexist.patch + ]; + }); + in { + rustc-unwrapped = patchedRustcUnwrapped; rustc = prev.rustc.override { - rustc-unwrapped = prev.rustc.unwrapped.overrideAttrs (old: { - postPatch = (old.postPatch or "") + '' - sed -i "s|if !self.config.dry_run() { symlink_file(src.as_ref(), link.as_ref()) }|if !self.config.dry_run() { let _ = std::fs::remove_file(link.as_ref()); symlink_file(src.as_ref(), link.as_ref()) }|" src/bootstrap/src/lib.rs - ''; - }); + rustc-unwrapped = patchedRustcUnwrapped; }; }) ]; diff --git a/patches/rustc-symlink-file-eexist.patch b/patches/rustc-symlink-file-eexist.patch new file mode 100644 index 0000000..cdf3917 --- /dev/null +++ b/patches/rustc-symlink-file-eexist.patch @@ -0,0 +1,11 @@ +--- a/src/bootstrap/src/lib.rs ++++ b/src/bootstrap/src/lib.rs +@@ -1990,7 +1990,7 @@ impl Build { + use std::os::unix::fs::symlink as symlink_file; + #[cfg(windows)] + use std::os::windows::fs::symlink_file; +- if !self.config.dry_run() { symlink_file(src.as_ref(), link.as_ref()) } else { Ok(()) } ++ if !self.config.dry_run() { let _ = std::fs::remove_file(link.as_ref()); symlink_file(src.as_ref(), link.as_ref()) } else { Ok(()) } + } + + /// Returns if config.ninja is enabled, and checks for ninja existence,