Commit 92f69769 authored by Thibaud-Vdb's avatar Thibaud-Vdb
Browse files

Merge branch '435-new-job-cargo-build' into 'latest'

feat:[New job] cargo_build

Closes #345

See merge request r2devops/hub!297
parents 351bbca9 acc99556
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
## Objective

This job will compile local packages and all of their dependencies on Rust project.

## How to use it

1. Ensure that your project have a [`cargo.toml`](https://doc.rust-lang.org/cargo/reference/manifest.html){:target="_blank"} file which contains the requirements.
1. Add this job URL inside the `include` list of your `.gitlab-ci.yml` file (see the [quick setup](/use-the-hub/#quick-setup)). You can specify [a fixed version](#changelog) instead of `latest`.
    ```yaml
      - remote: 'https://jobs.r2devops.io/latest/cargo_build.yml'
    ```
1. If you need to customize the job (stage, variables, ...) 👉 check the [jobs
   customization](/use-the-hub/#jobs-customization)
1. Well done, your job is ready to work ! 😀

## Job details

* Job name: `cargo_build`
* Docker image:
[`rust:1.57-buster`](https://hub.docker.com/r/_/rust)
* Default stage: `build`
* When: `always`

### Variables

!!! note
    All paths defined in variables are relative and start from the root of your
    repository.

| Name | Description | Default |
| ---- | ----------- | ------- |
| `RELEASE_MODE` | Build optimized artifacts with the release profile. See also the [--profile](https://doc.rust-lang.org/cargo/commands/cargo-build.html#compilation-options) option for choosing a specific profile by name. | `true` |
| `CARGO_EXCLUDE` | Exclusion of packages in the build process, separated by `,`. Must be used in conjunction with the `CARGO_WORKSPACE` flag. | ` ` |
| `CARGO_INCLUDE` | Inclusion of packages in the build process, separated by `,` | ` ` | 
| `PROJECT_ROOT` | Relative path to the directory containing `cargo.toml` | `.` |
| `CARGO_WORKSPACE` | Build all members in the workspace | `false` |
| `OUTPUT_DIR` | Directory for all generated artifacts and intermediate files | `target` | 
| `ADDITIONAL_OPTIONS` | [Additional options](https://doc.rust-lang.org/cargo/commands/cargo-build.html) available for the user, they are added just after the build command | ` ` | 
+35 −0
Original line number Diff line number Diff line
# Job from R2Devops hub --> r2devops.io

stages:
  - build

cargo_build:
  image:
    name: rust:1.57-buster
    entrypoint: [""]

  stage: build

  variables:
    RELEASE_MODE: "true"
    CARGO_EXCLUDE: ""
    CARGO_INCLUDE: ""
    PROJECT_ROOT: "."
    CARGO_WORKSPACE: "false"
    OUTPUT_DIR: "target"
    ADDITIONAL_OPTIONS: ""

  script:
    # Working directory
    - cd $PROJECT_ROOT
    - if [[ (${CARGO_WORKSPACE} == "true") ]]; then CARGO_WORKSPACE="--workspace"; else CARGO_WORKSPACE=""; fi
    - if [[ (${CARGO_INCLUDE} != "") ]]; then CARGO_INCLUDE="--package $CARGO_INCLUDE"; fi
    - if [[ (${CARGO_EXCLUDE} != "") ]]; then CARGO_EXCLUDE="--exclude $CARGO_EXCLUDE" CARGO_WORKSPACE="--workspace"; fi
    - if [[ ($RELEASE_MODE) ]]; then RELEASE_MODE="--release"; else RELEASE_MODE=""; fi

    - cargo build $RELEASE_MODE $CARGO_WORKSPACE $CARGO_INCLUDE $CARGO_EXCLUDE $ADDITIONAL_OPTIONS --target-dir ${OUTPUT_DIR}

  artifacts:
    when: always
    paths:
      - $PROJECT_ROOT/$OUTPUT_DIR
 No newline at end of file
+14 −0
Original line number Diff line number Diff line
name: cargo_build
description: This job will compile local packages and all of their dependencies on Rust project
default_stage: build
icon: 🧱
maintainer: alexiaognard
license: Apache-2.0
images:
  rust:1.57-buster
tools:
labels:
  - GitLab
  - Build
  - Cargo
  - Rust
 No newline at end of file
+0 −0

Empty file added.

+1 −0
Original line number Diff line number Diff line
* Initial version
 No newline at end of file