Can Cargo download and build dependencies without also building the application?

前端 未结 4 1005
陌清茗
陌清茗 2020-12-16 10:47

Is there a way to tell Cargo to install and build all my dependencies, but not attempt to build my application?

I thought cargo install would do that, b

4条回答
  •  爱一瞬间的悲伤
    2020-12-16 11:25

    If you add a dummy main or lib file, you can use cargo build to just pull down the dependencies. I'm currently using this solution for my Docker based project:

    COPY Cargo.toml .
    RUN mkdir src \
        && echo "// dummy file" > src/lib.rs \
        && cargo build
    

    I'm using --volumes, so I'm done at this point. The host volumes come in and blow away the dummy file, and cargo uses the cached dependencies when I go to build the source later. This solution will work just as well if you want to add a COPY (or ADD) later and use the cached dependencies though.

提交回复
热议问题