How to install rust-src offline?

I installed rust on a completely offline machine via https://static.rust-lang.org/dist/rust-1.72.0-x86_64-pc-windows-gnu.msi and installed rust-analyzer in vscode, but now I find that

 Failed to spawn one or more proc-macro servers.

 - cannot find proc-macro-srv, the workspace `F:\test1` is missing a sysroot

 Failed to find sysroot for Cargo.toml file F:\test1\Cargo.toml. Is rust-src installed? can't load standard library from sysroot

 C:\Program Files\Rust stable GNU 1.72

 (discovered via `rustc --print sysroot`)

 try installing the Rust source the same way you installed rustc

in vscode

>> rustc --print sysroot
C:\Program Files\Rust stable GNU 1.72

How to install rust-src offline?

2 Likes

this is an rust-analyzer error, not the rust toolchain. to double check, try build the project directly from a shell (either cmd.exe or powershell is ok):

> cd /d F:\test1
> cargo build

please check the files under ${sysroot}/libexec, did you see a file named rust-analyzer-proc-macro-srv.exe there? that's what the error message is referring to, but I think that file should come with the rustc component, not from rust-src, see

if that file is missing, it's probably a offline installer packaging oversight, and I suggest you report the problem to the release team.

the easiest way to resolve the problem is to use rustup to manage the toolchains. but just in case you can't use rustup directly, is it an option to manually download rustup managed packages? the manifest file is located at:

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

where stable can be replaced with beta or nightly. these packages are not digitally signed like the msi package, but the manifest is using https and you should be able verify the sha256 hash of individual packages.

the missing rust-analyzer-proc-macro-srv.exe should be in the rustc package. prefer the xz packages to the gzip package, it is much smaller in size and saves you bandwidth and time, unless of course you don't have xz or 7z installed on your development machine.

I can build it directly.

The file ${sysroot}/libexec/rust-analyzer-proc-macro-srv.exe already exists, and the file in the rustc package is the same as mine.

well then, I guess rust-analyzer does require rust-src to be installed after all. could this possibly be considered a bug of rust-analyzer? I don't know, but I think rust-analyzer should work even if the rust-src is absent. it's just the features are going to be very limited, but it should not completely give up. at least some meta data from the standard library can be loaded and analyzed. just my opinion.

so I think there's no other choice but to download the rust-src pkg using the url from the manifest file and check again. just be pay attention to the location to extract the directories, you should got a ${sysroot}/lib/rustlib/src directory if you extracted it correctly.

just out of curiosity, what the reason you don't use rustup to manage the toolchains?

That computer is not allowed to use the Internet

1 Like

Yes, it's working, but the features is very limited, and only provides features like highlighting.

vscode has basic built in syntax highlighting, if you don't get RA specific features like auto completion, inlay hints overlay, code lenses, quick fixes, etc, rust-analyzer isn't working at all.

try to download the rust-src pkg from the url contained in the manifest file and extract the sources to the correct location, then restart rust-analyzer lsp server.


Do I need to put all these files in ${sysroot}/lib/rustlib/src?

that's not the rust-src pkg, the rust-src pkg contains source code for the standard libraries, namely core, alloc, std, test. etc. what you downloaded the source code of the rust toolchain, sure it contains the source code of the libraries, but it's not packaged in a release format, so I don't know how you can incorporate that into your installation.

check out the manifest file in my previous comment, search for the [pkg.rust-src.target."*"] section, download the archive file from the url in that section, and extract and merge the rust-src directory with the ${sysroot} of your existing installation.

I found the files "core", "alloc", "std", and "test" in the "library" folder. Are these the files I need?

yes, but do you know where you should put them? do you know what else do you need? go the easy way, don't add additional work to yourself. just download the released rust-src package. or easier, setup a working development environment on a machine with internet connection, then transfer the installation to your isolated machine. or even easier, just do the developing work with internet connectivity, just deploy the product to the target machine. why you like to punish yourself?

1 Like

It sounds like the machine in question isn't given access to the internet due to a policy outside OP's control. So they aren't deliberately punishing themselves per-se.

That said, it doesn't really make sense to develop software on a completely air-gapped machine in this day and age... That's like saying your marketing department can't post anything to social media. Sure, it's possible, but you're definitely playing on hard mode.

Even if the rust-src problem is solved, you might meet other problems.

Well, developing rustlang on an offline computer looks too hard, I'll give up! :melting_face:

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.