summaryrefslogtreecommitdiff
path: root/.gitlab-ci.yml
blob: 424dc9694792a5e8d3ea52a6b7d055d7b2abb63d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
stages:
  - test
  - build
  - upload artifacts

variables:
  GIT_SUBMODULE_STRATEGY: recursive
  FF_USE_FASTZIP: 1
  CACHE_COMPRESSION_LEVEL: fastest



test:cargo:
  stage: "test"
  needs: []
  image: "rust:latest"
  tags: ["docker"]
  variables:
    CARGO_HOME: "cargohome"
  cache:
    paths:
      - target
      - cargohome
    key: test_cache
  interruptible: true
  before_script:
    - mkdir -p $CARGO_HOME && echo "using $CARGO_HOME to cache cargo deps"
    - apt-get update -yqq
    - apt-get install -yqq --no-install-recommends build-essential libssl-dev pkg-config
    - rustup component add clippy rustfmt
  script:
    - rustc --version && cargo --version  # Print version info for debugging
    - cargo test --workspace --verbose --locked
    - cargo fmt --all -- --check
    - cargo clippy

# --------------------------------------------------------------------- #
#  Cargo: Compiling for different architectures                         #
# --------------------------------------------------------------------- #

.build-cargo-shared-settings:
  stage: "build"
  needs: []
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
  interruptible: true
  image: "rust:latest"
  tags: ["docker"]
  cache:
    paths:
      - cargohome
      - target/
    key: "build_cache-$TARGET"
  before_script:
    - 'echo "Building for target $TARGET"'
    - 'mkdir -p cargohome && CARGOHOME="cargohome"'
    - "cat /etc/*-release && rustc --version && cargo --version"  # Print version info for debugging
    - 'apt-get update -yqq'
    - 'echo "Installing packages: $NEEDED_PACKAGES"'
    - "apt-get install -yqq --no-install-recommends $NEEDED_PACKAGES"
    - "rustup target add $TARGET"
  script:
    # Set some cargo tuning here, because targets overwrite the 'variables'
    - "export CARGO_INCREMENTAL=true"
    - "export CARGO_PROFILE_RELEASE_CODEGEN_UNITS=16"
    - "export CARGO_PROFILE_RELEASE_LTO=thin"
    - time cargo build --target $TARGET --release
    - 'mv "target/$TARGET/release/conduit" "conduit-$TARGET"'
  artifacts:
    name: "conduit-$TARGET"
    expose_as: "Binary"
    paths:
      - "conduit-$TARGET"

build:cargo:x86_64-unknown-linux-gnu:
  extends: .build-cargo-shared-settings
  variables:
    TARGET: "x86_64-unknown-linux-gnu"

build:cargo:armv7-unknown-linux-gnueabihf:
  extends: .build-cargo-shared-settings
  variables:
    TARGET: "armv7-unknown-linux-gnueabihf"
    NEEDED_PACKAGES: "build-essential gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf libc6-dev-armhf-cross"
    CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc
    CC_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-gcc
    CXX_armv7_unknown_linux_gnueabihf: arm-linux-gnueabihf-g++

build:cargo:aarch64-unknown-linux-gnu:
  extends: .build-cargo-shared-settings
  variables:
    TARGET: "aarch64-unknown-linux-gnu"
    NEEDED_PACKAGES: "build-essential gcc-8-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross"
    CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc
    CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc
    CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++
    TARGET_CC: "/usr/bin/aarch64-linux-gnu-gcc-8"
    TARGET_AR: "/usr/bin/aarch64-linux-gnu-gcc-ar-8"


# --------------------------------------------------------------------- #
#  Cargo: Compiling deb packages for different architectures            #
# --------------------------------------------------------------------- #


.build-cargo-deb-shared-settings:
  stage: "build"
  needs: []
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
  interruptible: true
  image: "rust:latest"
  tags: ["docker"]
  cache:
    paths:
      - cargohome
      - target/
    key: "build_cache-deb-$TARGET"
  before_script:
    - 'echo "Building debian package for target $TARGET"'
    - 'mkdir -p cargohome && CARGOHOME="cargohome"'
    - "cat /etc/*-release && rustc --version && cargo --version"  # Print version info for debugging
    - 'apt-get update -yqq'
    - 'echo "Installing packages: $NEEDED_PACKAGES"'
    - "apt-get install -yqq --no-install-recommends $NEEDED_PACKAGES"
    - "rustup target add $TARGET"
    - "cargo install cargo-deb"
  script:
    - time cargo deb --target $TARGET
    - 'mv target/$TARGET/debian/*.deb "conduit-$TARGET.deb"'
  artifacts:
    name: "conduit-$TARGET.deb"
    expose_as: "Debian Package"
    paths:
      - "conduit-$TARGET.deb"

build:cargo-deb:x86_64-unknown-linux-gnu:
  extends: .build-cargo-deb-shared-settings
  variables:
    TARGET: "x86_64-unknown-linux-gnu"
    NEEDED_PACKAGES: ""




# --------------------------------------------------------------------- #
#  Store binaries as package so they have download urls                 #
# --------------------------------------------------------------------- #

publish:package:
  stage: "upload artifacts"
  needs:
    - "build:cargo:x86_64-unknown-linux-gnu"
    - "build:cargo:armv7-unknown-linux-gnueabihf"
    - "build:cargo:aarch64-unknown-linux-gnu"
    - "build:cargo-deb:x86_64-unknown-linux-gnu"
  rules:
    - if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
  image: curlimages/curl:latest
  tags: ["docker"]
  variables:
    GIT_STRATEGY: "none" # Don't need a clean copy of the code, we just operate on artifacts
  script:
    - 'BASE_URL="${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/conduit-${CI_COMMIT_REF_SLUG}/build-${CI_PIPELINE_ID}"'
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file conduit-x86_64-unknown-linux-gnu "${BASE_URL}/conduit-x86_64-unknown-linux-gnu"'
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file conduit-armv7-unknown-linux-gnueabihf "${BASE_URL}/conduit-armv7-unknown-linux-gnueabihf"'
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file conduit-aarch64-unknown-linux-gnu "${BASE_URL}/conduit-aarch64-unknown-linux-gnu"'
    - 'curl --header "JOB-TOKEN: $CI_JOB_TOKEN" --upload-file conduit-x86_64-unknown-linux-gnu.deb "${BASE_URL}/conduit-x86_64-unknown-linux-gnu.deb"'