Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo metadata fails in read only filesystem #14386

Closed
StealthyKamereon opened this issue Aug 10, 2024 · 2 comments
Closed

cargo metadata fails in read only filesystem #14386

StealthyKamereon opened this issue Aug 10, 2024 · 2 comments
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@StealthyKamereon
Copy link

Problem

cargo metadata fails when the target Cargo.toml is inside a read-only filesystem.

I'm on Nixos and I'd like to write a compiler plugin so I need rustc sources.
In particular, I need rust-analyzer to load rustc sources.
To do so, RA uses cargo metadata to locate the rustc sources.
However, when running cargo metadata it attempts to create a Cargo.lock file which fails because Rust is installed in the nix store which is read-only.

Here is the command output :

$ "/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"
    Updating crates.io index
error: failed to write /nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.lock

Caused by:
  failed to open: /nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.lock

Caused by:
  Read-only file system (os error 30)

Here is the rust-analyzer log from which I got the command :

2024-08-10T20:19:02.972263Z ERROR project_model::workspace: Failed to read Cargo metadata from rustc source at /nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml e=Failed to run `cd "<project dir>" && RUSTUP_TOOLCHAIN="/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20" "/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/bin/cargo" "metadata" "--format-version" "1" "--manifest-path" "/nix/store/v0769idpz76l6b3xff8ps98bcsy5ymjb-rust-default-1.80.0-nightly-2024-05-20/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml" "--filter-platform" "x86_64-unknown-linux-gnu"

Steps

  1. Have or install Nix:
curl -L https://nixos.org/nix/install | sh
  1. Create a directory for testing and the corresponding nix shell:
mkdir cargo-bug-ro-fs && cd cargo-bug-ro-fs

Create a shell.nix with the following content:

{ nixpkgs ? import <nixpkgs> { }}:

let
rustOverlay = builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz";
pinnedPkgs = nixpkgs.fetchFromGitHub {
  owner  = "NixOS";
  repo   = "nixpkgs";
  rev    = "b3fcfcfabd01b947a1e4f36622bbffa3985bdac6";
  sha256 = "0va68ddkrqb6j349rsbkjhdq7m243kg9njcqhnx9p2sbrcl2g5l8";
};
pkgs = import pinnedPkgs {
  overlays = [ (import rustOverlay) ];
};
rust_pkg = pkgs.rust-bin.nightly."2024-05-20".default.override {
  extensions = ["rust-src" "rustc" "rustc-dev" "llvm-tools" "rust-analyzer" "cargo"];
};
in
pkgs.mkShell {
  buildInputs = with pkgs; [
    (
      rust_pkg
    )
    openssl
    pkg-config
  ];

  RUST_PKG="${rust_pkg}";
}
  1. Enter the shell and run the following command:
nix-shell
cargo metadata --manifest-path $RUST_PKG/lib/rustlib/rustc-src/rust/compiler/rustc/Cargo.toml

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.80.0-nightly (0de7f2ec6 2024-05-17)
release: 1.80.0-nightly
commit-hash: 0de7f2ec6c39d68022e6b97a39559d2f4dbf3930
commit-date: 2024-05-17
host: x86_64-unknown-linux-gnu
libgit2: 1.7.2 (sys:0.18.3 vendored)
libcurl: 8.6.0-DEV (sys:0.4.72+curl-8.6.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: NixOS 24.11.0 [64-bit]
@StealthyKamereon StealthyKamereon added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Aug 10, 2024
@StealthyKamereon
Copy link
Author

@weihanglo
Copy link
Member

Thanks for the detailed use case. Really appreciate that!

This is a duplicate of #10096 as far as I can tell. We are working on providing a new flag --lockfile-path for an alternative location to write lockfile. That is expected to improve the situation. The implementation is almost done in #14326

I am going to close this in favour of #10096. Let's discuss the problem in one place then!

@weihanglo weihanglo closed this as not planned Won't fix, can't repro, duplicate, stale Aug 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants