Cargo rustc ... how do you fetch the dependencies?


#1

cargo rustc is great addition!

But the help text includes this tidbit: “This command requires that a lockfile is available and dependencies have been fetched.”

How would I direct a user to fetch the dependencies before running cargo rustc, but without building anything?


#2

Maybe cargo generate-lockfile? I’m not entirely sure this will do what you want, but it seems to be the right command.


#3

In order to have a truly valid lockfile, you need to build, or have built in the past. That’s what a lockfile represents: the exact versions for a successful build.


#4

There’s a cargo fetch command, which will generate a lockfile and download dependencies as needed.


#5

Fabulous, thank you!


#6

Ah that description on the issue is actually out of date and isn’t actually true any more, the help page for cargo rustc is more descriptive now:

Compile a package and all of its dependencies

Usage:
    cargo rustc [options] [--] [<opts>...]

Options:
    -h, --help               Print this message
    -p SPEC, --package SPEC  The profile to compile for
    -j N, --jobs N           The number of jobs to run in parallel
    --lib                    Build only this package's library
    --bin NAME               Build only the specified binary
    --example NAME           Build only the specified example
    --test NAME              Build only the specified test
    --bench NAME             Build only the specified benchmark
    --release                Build artifacts in release mode, with optimizations
    --features FEATURES      Features to compile for the package
    --no-default-features    Do not compile default features for the package
    --target TRIPLE          Target triple which compiles will be for
    --manifest-path PATH     Path to the manifest to fetch depednencies for
    -v, --verbose            Use verbose output

The specified target for the current package (or package specified by SPEC if
provided) will be compiled along with all of its dependencies. The specified
<opts>... will all be passed to the final compiler invocation, not any of the
dependencies. Note that the compiler will still unconditionally receive
arguments such as -L, --extern, and --crate-type, and the specified <opts>...
will simply be added to the compiler invocation.

This command requires that only one target is being compiled. If more than one
target is available for the current package the filters of --lib, --bin, etc,
must be used to select which target is compiled.