How to use vendor to build project offline?

I have downloaded rust-std project and use "cargo vendor" to download dependencies. I copy vendor folder to ~.cargo folder, and config config.toml in the project's folder as readme.md. But I still failed when I use cargo doc.

You shouldn't need to do this. The example config assumes that the vendor directory is in the project directory, not in ~/.cargo.

config.toml should be located in a .cargo folder inside the project's folder.

Here's an example project including the vendor directory and the .cargo/config file. You can clone that Git repository and build it with cargo build --offline.

The only steps you need to do this in your own project are:

  1. Run cargo vendor.
  2. Paste the example config into .cargo/config.toml inside your project directory.

Failed how? Please include the error messages.

Did you run cargo doc --offline?

1 Like

Thanks! I followed your suggestion, and "cargo doc --offline" can execute . but show many compiling errors, such as :
error[E0554]: #![feature] may not be used on the stable release channel
--> src\libcore\lib.rs:91:1
|
91 | #![feature(no_core)]
| ^^^^^^^^^^^^^^^^^^^^

error[E0554]: #![feature] may not be used on the stable release channel
--> src\libcore\lib.rs:92:1
|
92 | #![feature(on_unimplemented)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: #![feature] may not be used on the stable release channel
--> src\libcore\lib.rs:93:1
|
93 | #![feature(optin_builtin_traits)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error[E0554]: #![feature] may not be used on the stable release channel
--> src\libcore\lib.rs:94:1
|
94 | #![feature(prelude_import)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^

For more information about this error, try `rustc --explain E0554`.

You should be seeing this message. Did you execute rustc --explain E0554?

It seems to be trying to compile a pretty old version of the standard library on stable. You should never try to compile the standard library directly. Either use the pre-compiled standard library, or if you are on nightly and trying to build for a target which for which no pre-compiled standard library is available cargo build -Zbuild-std (or the older xargo). What project are you trying to vendor? What dependencies does it have?

Yes,my std version is old. I only want to use std document offline, How to get?Thanks!

rustup doc --std will open a browser tab pointing to the local html files.

2 Likes

I installed Rust offline version. I can't find rustup in ~/.cargo/bin. So I can't use the command about rustup.

If you installed with the installer from Other Installation Methods - Rust Forge, it should have put the docs into $PREFIX/share/doc/rust (where $PREFIX is the root for the installation, usually /usr/local or /usr).