Proper Offline Install

So I'm on a pretty airgapped system (Company Policy) and want to do an offline install of rust with the msvc toolchain. So far so good, i can install it, use cargo to create a new package and compile it but when I try to use vscode with rust-analyzer i get this error

can't load standard library from sysroot\n{sysroot_path}\n(discovered via `rustc --print sysroot`)\ntry installing the Rust source the same way you installed rustc

So my question is where do I download the rust-src component from and where do I put it on my System

1 Like

it is not recommended to develop rust code on a airgapped machine, you might encounter various unexpected problems of rust-analyzer. one such example is #12499.

but anyway, you can find the urls for each individual component in the manifest.

for stable channel, the manifest is located at:

https://static.rust-lang.org/dist/channel-rust-stable.toml

for nightly channle, the manifest is located at:

(latest) static.rust-lang.org/dist/channel-rust-nightly.toml
(replace the date) https://static.rust-lang.org/dist/2024-01-01/channel-rust-nightly.toml

3 Likes

I am aware but sadlyI have no influence over if it's airgapped or not, as it's company policy, and I'm tasked with setting up a rust dev environment on it

Once I downloaded it, where do I need to put it?

it is a toml file, you just open it with your text editor and search the component you wish to download. for example, the rust-src component can be found at this section:

[pkg.rust-src]
version = "1.80.1 (3f5fd8dd4 2024-08-06)"
git_commit_hash = "3f5fd8dd41153bc5fdca9427e9e05be2c767ba23"
[pkg.rust-src.target."*"]
available = true
url = "https://static.rust-lang.org/dist/2024-08-08/rust-src-1.80.1.tar.gz"
hash = "c33eae6921b22be6520bbba9dc0b1ea21250ea3054bf15006dba30bab97eba9f"
xz_url = "https://static.rust-lang.org/dist/2024-08-08/rust-src-1.80.1.tar.xz"
xz_hash = "842bc48c2b95cc25b3ce6ddba73045490c6d306a1688e46821628ebcbfa5d2d5"

as you can see, the rust-src component is target independent (.target."*") and there are urls for gzip and xz compressed tar balls. usually, xz should be preferred for better compression ratio, but if your system doesn't support xz, you can always use the gzip format.

download the tar ball of the component and extract it to a temporary location. you can either:

  • manually copy the content of the directory with the same name as the component (e.g. rust-src) to your rust installation location; or
  • run the install.sh script.
    • typically, you just need to specify the --destdir and/or --prefix at the command line. use --help to see the full list of supported options.

I just realized that the offline install doesn't include clippy or rustfmt. The manifest has download Paths for clippy-preview and rustfmt-preview, not for a normal, non preview version. where do i get those?

The internal names of the clippy and rustfmt components are clippy-preview and rustfmt-preview. Rustup does a renaming in the user facing ui. These components used to be unstable and we kept the -preview suffix in the internal name to avoid, once these components got stabilized, breaking updates of existing installations that have those components installed.

2 Likes

Thank you! Another problem: The install scripts are all bash scripts, but I'm on windows. is there some way to run them on win?

Each tar file contains a directory named after the component itself. You can copy the contents of this directory for each component into the same directory (merging the contents of subdirectories).

1 Like

And just copy those in the rust install directory?

Yes

I tried both putting the rustfmt-preview directory into the rust directory and placing it directly in the program files directory but both result in

cargo fmt
error: no such command: `fmt`

        Did you mean `fix`?

        View all installed commands with `cargo --list`
        Find a package to install `fmt` with `cargo search cargo-fmt`

Try putting the contents of the rustfmt-preview dir there rather than the dir itself.

1 Like

That worked, thanks