rust-osdev / cargo-xbuild

Automatically cross-compiles the sysroot crates core, compiler_builtins, and alloc.
Apache License 2.0
260 stars 25 forks source link

ensure copied Cargo.lock is writable #96

Closed sbourdeauducq closed 3 years ago

sbourdeauducq commented 3 years ago

If the path pointed to by XARGO_RUST_SRC contains read-only Cargo lockfiles, then xbuild fails because the copies it makes and attempts to modify are also read-only· The patch below fixes this bug.

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"), "")?;
phil-opp commented 3 years ago

Thanks for reporting! Could you open a pull request with this patch?