From 56c94b0855c6378402537c9cc5bda41c411e7a8d Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 13 Oct 2020 18:27:52 +0800 Subject: [PATCH] patch cargo-xbuild to ensure copied Cargo.lock is writable https://github.com/rust-osdev/cargo-xbuild/issues/96 --- default.nix | 4 +++- shell.nix | 2 +- xbuild_writable_lockfile.diff | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 xbuild_writable_lockfile.diff diff --git a/default.nix b/default.nix index 0d5ad56..e668ff4 100644 --- a/default.nix +++ b/default.nix @@ -8,7 +8,9 @@ let src = ./.; cargoSha256 = "1f2psa1g41pl2j8n60hhik2s2pqdfjhr5capimvajf81kxrnn2ck"; - nativeBuildInputs = [ pkgs.cargo-xbuild ]; + nativeBuildInputs = [ + (pkgs.cargo-xbuild.overrideAttrs(oa: { patches = oa.patches ++ [ ./xbuild_writable_lockfile.diff ]; } )) + ]; buildPhase = '' export XARGO_RUST_SRC="${rustPlatform.rust.rustc.src}/library" export CARGO_HOME=$(mktemp -d cargo-home.XXX) diff --git a/shell.nix b/shell.nix index d6479e9..52ec568 100644 --- a/shell.nix +++ b/shell.nix @@ -8,7 +8,7 @@ in rustPlatform.rust.rustc rustPlatform.rust.cargo pkgs.cacert - pkgs.cargo-xbuild + (pkgs.cargo-xbuild.overrideAttrs(oa: { patches = oa.patches ++ [ ./xbuild_writable_lockfile.diff ]; } )) pkgs.openocd pkgs.gdb pkgs.openssh pkgs.rsync diff --git a/xbuild_writable_lockfile.diff b/xbuild_writable_lockfile.diff new file mode 100644 index 0000000..8e8f6f9 --- /dev/null +++ b/xbuild_writable_lockfile.diff @@ -0,0 +1,27 @@ +diff --git a/src/sysroot.rs b/src/sysroot.rs +index 1f3c8d1..422d3d0 100644 +--- a/src/sysroot.rs ++++ b/src/sysroot.rs +@@ -85,10 +85,20 @@ fn build_crate( + } + + util::write(&td.join("Cargo.toml"), &stoml)?; +- fs::copy(lockfile, &td.join("Cargo.lock")).chain_err(|| ++ let dst_file = td.join("Cargo.lock"); ++ fs::copy(lockfile, &dst_file).chain_err(|| + format!("failed to copy Cargo.lock from `{}` to `{}`", +- lockfile.display(), &td.join("Cargo.lock").display()) ++ lockfile.display(), &dst_file.display()) + )?; ++ let mut perms = fs::metadata(&dst_file).chain_err(|| ++ format!("failed to retrieve permissions for `{}`", ++ dst_file.display()) ++ )?.permissions(); ++ perms.set_readonly(false); ++ fs::set_permissions(&dst_file, perms).chain_err(|| ++ format!("failed to update permissions for `{}`", ++ dst_file.display()) ++ ); + util::mkdir(&td.join("src"))?; + util::write(&td.join("src/lib.rs"), "")?; +