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

前端 未结 4 1001
陌清茗
陌清茗 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:11

    Based on a GitHub comment

    FROM rust:1.37
    
    WORKDIR /usr/src
    
    # Create blank project
    RUN USER=root cargo new PROJ
    
    # We want dependencies cached, so copy those first.
    COPY Cargo.toml /usr/src/PROJ/
    COPY Cargo.lock /usr/src/PROJ/
    
    WORKDIR /usr/src/PROJ
    
    # This is a dummy build to get the dependencies cached.
    RUN cargo build --release
    
    # Now copy in the rest of the sources
    COPY MyPROJECT/src /usr/src/PROJ/src/
    
    # This is the actual build.
    RUN cargo build --release \
        && mv target/release/appname /bin \
        && rm -rf /usr/src/PROJ
    
    WORKDIR /
    
    EXPOSE 8888
    
    CMD ["/bin/appname"]
    

提交回复
热议问题