rust-cross / rust-musl-cross

Docker images for compiling static Rust binaries using musl-cross
MIT License
620 stars 68 forks source link

enable to cache cargo's registry and build in gitlab ci #42

Closed jm-observer closed 2 years ago

jm-observer commented 2 years ago

if somebody need, it is my ci's script that can enable to cache.

  1. because ci's cache only can use paths that are in the local working copy, so we must mkdir a folder in our project for cargo's registry (it is "target/registry" in my script), and it is my project structure:
    .
    ├── Cargo.toml
    ├── src
    │       ├── main.rs
    ├── target
    │   └── registry
  2. the script:
    build-job:
    stage: build
    only:
    refs:
      - master
    tags:
    - maven
    image: messense/rust-musl-cross:x86_64-musl
    script:
    - ln -s $(pwd)/target/registry /root/.cargo/registry
    - export CARGO_BUILD_DEP_INFO_BASEDIR=.
    - cargo build --package endpoint --bin endpoint --release --target=x86_64-unknown-linux-musl
    cache:
    key: moss-endpoint-cache
    paths:
      # cache for cargo registry
      - target/registry/
      # cache for build
      - target/x86_64-unknown-linux-musl/
      - target/release/