From 2b2e9b0bc4a00db4d179d794604d3440cb7c3bf3 Mon Sep 17 00:00:00 2001 From: Florian Eckert Date: Mon, 13 May 2024 12:37:18 +0200 Subject: [PATCH] rust: fix remote filesystem issue If the download directory is on another filesystem (NFS), then the current implementation of bootstrapping rust fails. Because the 'syscall' (rename) does not work on crossing filesystem boundary. This patch has already been send upstream to the main rust repository and is currently under discussion. https://github.com/rust-lang/rust/pull/124975 Signed-off-by: Florian Eckert --- ...0004-Use-an-helper-to-move-the-files.patch | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 lang/rust/patches/0004-Use-an-helper-to-move-the-files.patch diff --git a/lang/rust/patches/0004-Use-an-helper-to-move-the-files.patch b/lang/rust/patches/0004-Use-an-helper-to-move-the-files.patch new file mode 100644 index 00000000000000..1b0ac42130b18e --- /dev/null +++ b/lang/rust/patches/0004-Use-an-helper-to-move-the-files.patch @@ -0,0 +1,109 @@ +From 2dce9a0aa754dd9406dc02fad5d01bf66b64e384 Mon Sep 17 00:00:00 2001 +From: Luca Barbato +Date: Fri, 10 May 2024 16:38:19 +0200 +Subject: [PATCH] Use an helper to move the files + +In case the source is not in the same filesystem. +--- + src/bootstrap/src/core/build_steps/dist.rs | 6 ++++-- + src/bootstrap/src/core/download.rs | 6 +++--- + src/bootstrap/src/utils/helpers.rs | 16 ++++++++++++++++ + src/bootstrap/src/utils/tarball.rs | 4 ++-- + 4 files changed, 25 insertions(+), 7 deletions(-) + +--- a/src/bootstrap/src/core/build_steps/dist.rs ++++ b/src/bootstrap/src/core/build_steps/dist.rs +@@ -26,7 +26,9 @@ use crate::core::build_steps::tool::{sel + use crate::core::builder::{Builder, Kind, RunConfig, ShouldRun, Step}; + use crate::core::config::TargetSelection; + use crate::utils::channel; +-use crate::utils::helpers::{exe, is_dylib, output, t, target_supports_cranelift_backend, timeit}; ++use crate::utils::helpers::{ ++ exe, is_dylib, move_file, output, t, target_supports_cranelift_backend, timeit ++}; + use crate::utils::tarball::{GeneratedTarball, OverlayKind, Tarball}; + use crate::{Compiler, DependencyType, Mode, LLVM_TOOLS}; + +@@ -1993,7 +1995,7 @@ impl Step for Extended { + builder.run(&mut cmd); + + if !builder.config.dry_run() { +- t!(fs::rename(exe.join(&filename), distdir(builder).join(&filename))); ++ t!(move_file(exe.join(&filename), distdir(builder).join(&filename))); + } + } + } +--- a/src/bootstrap/src/core/download.rs ++++ b/src/bootstrap/src/core/download.rs +@@ -12,7 +12,7 @@ use build_helper::ci::CiEnv; + use xz2::bufread::XzDecoder; + + use crate::core::config::RustfmtMetadata; +-use crate::utils::helpers::{check_run, exe, program_out_of_date}; ++use crate::utils::helpers::{check_run, exe, move_file, program_out_of_date}; + use crate::{core::build_steps::llvm::detect_llvm_sha, utils::helpers::hex_encode}; + use crate::{t, Config}; + +@@ -209,7 +209,7 @@ impl Config { + None => panic!("no protocol in {url}"), + } + t!( +- std::fs::rename(&tempfile, dest_path), ++ move_file(&tempfile, dest_path), + format!("failed to rename {tempfile:?} to {dest_path:?}") + ); + } +@@ -313,7 +313,7 @@ impl Config { + if src_path.is_dir() && dst_path.exists() { + continue; + } +- t!(fs::rename(src_path, dst_path)); ++ t!(move_file(src_path, dst_path)); + } + let dst_dir = dst.join(directory_prefix); + if dst_dir.exists() { +--- a/src/bootstrap/src/utils/helpers.rs ++++ b/src/bootstrap/src/utils/helpers.rs +@@ -150,6 +150,22 @@ pub fn symlink_dir(config: &Config, orig + } + } + ++/// Rename a file if from and to are in the same filesystem or ++/// copy and remove the file otherwise ++pub fn move_file, Q: AsRef>(from: P, to: Q) -> io::Result<()> { ++ if let Err(e) = fs::rename(&from, &to) { ++ // FIXME: Once `ErrorKind::CrossesDevices` is stabilized use ++ // if e.kind() == io::ErrorKind::CrossesDevices { ++ #[cfg(unix)] ++ if e.raw_os_error() == Some(libc::EXDEV) { ++ std::fs::copy(&from, &to)?; ++ std::fs::remove_file(&from)?; ++ } ++ } ++ ++ Ok(()) ++} ++ + pub fn forcing_clang_based_tests() -> bool { + if let Some(var) = env::var_os("RUSTBUILD_FORCE_CLANG_BASED_TESTS") { + match &var.to_string_lossy().to_lowercase()[..] { +--- a/src/bootstrap/src/utils/tarball.rs ++++ b/src/bootstrap/src/utils/tarball.rs +@@ -6,7 +6,7 @@ use std::{ + use crate::core::builder::Builder; + use crate::core::{build_steps::dist::distdir, builder::Kind}; + use crate::utils::channel; +-use crate::utils::helpers::t; ++use crate::utils::helpers::{move_file, t}; + + #[derive(Copy, Clone)] + pub(crate) enum OverlayKind { +@@ -269,7 +269,7 @@ impl<'a> Tarball<'a> { + // name, not "image". We rename the image directory just before passing + // into rust-installer. + let dest = self.temp_dir.join(self.package_name()); +- t!(std::fs::rename(&self.image_dir, &dest)); ++ t!(move_file(&self.image_dir, &dest)); + + self.run(|this, cmd| { + let distdir = distdir(this.builder);