aboutsummaryrefslogtreecommitdiff
path: root/.github/workflows/build.yml
blob: 00086ff541dfc67d00d28f0cd91aaecf11761530 (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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
name: Build
on:
  push:
    branches:
      - master
      - ghatest
  pull_request:
    branches:
      - master
      - ghatest

env:
  CARGO_TERM_COLOR: always

jobs:
  # Run cargo fmt --check, includes macros/
  style:
    name: Check Style with cargo fmt
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v1

      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          components: rustfmt

      - name: cargo fmt --check
        uses: actions-rs/cargo@v1
        with:
          command: fmt
          args: --all -- --check

  # Compilation check
  check:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - thumbv7m-none-eabi
          - thumbv6m-none-eabi
          - x86_64-unknown-linux-gnu
        toolchain:
          - stable
          - 1.36.0
          - nightly
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Install Rust ${{ matrix.toolchain }} with target (${{ matrix.target }})
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.toolchain }}
          target: ${{ matrix.target }}
          override: true

      - name: Disable optimisation profiles
        if: matrix.toolchain == '1.36.0'
        run: sed -i '/^\[profile.*build-override]$/,/^$/{/^#/!{/^$/!d}}' Cargo.toml

      - name: cargo check
        uses: actions-rs/cargo@v1
        with:
          use-cross: false
          command: check
          args: --target=${{ matrix.target }}

  # Verify all examples
  checkexamples:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - thumbv7m-none-eabi
          - thumbv6m-none-eabi
        toolchain:
          - stable
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Install Rust ${{ matrix.toolchain }} with target (${{ matrix.target }})
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.toolchain }}
          target: ${{ matrix.target }}
          override: true
      - uses: actions-rs/cargo@v1
        with:
          use-cross: false
          command: check
          args: --examples --target=${{ matrix.target }} --features __min_r1_43

      - name: cargo check -p homogeneous
        uses: actions-rs/cargo@v1
        with:
          use-cross: false
          command: check
          args: -p homogeneous --examples --target=${{ matrix.target }}

      - name: Install QEMU
        run: |
          mkdir qemu
          curl -L https://github.com/japaric/qemu-bin/raw/master/14.04/qemu-system-arm-2.12.0 > qemu/qemu-system-arm
          chmod +x qemu/qemu-system-arm

      - name: Setup arm-none-eabi-gcc
        uses: fiam/arm-none-eabi-gcc@v1
        with:
          release: '9-2019-q4' # The arm-none-eabi-gcc release to use.

      - name: Run-pass tests
        run: |
          # Add QEMU to the path
          echo $PATH
          PATH=$(pwd)/qemu:$PATH
          arm_example() {
              local COMMAND=$1
              local EXAMPLE=$2
              local BUILD_MODE=$3
              local FEATURES=$4
              local BUILD_NUM=$5

              if [ $BUILD_MODE = "release" ]; then
                  local RELEASE_FLAG="--release"
              else
                  local RELEASE_FLAG=""
              fi

              if [ -n "$FEATURES" ]; then
                  local FEATURES_FLAG="--features $FEATURES"
                  local FEATURES_STR=${FEATURES/,/_}_
              else
                  local FEATURES_FLAG=""
                  local FEATURES_STR=""
              fi
              local CARGO_FLAGS="--example $EXAMPLE --target ${{ matrix.target }} $RELEASE_FLAG $FEATURES_FLAG"

              if [ $COMMAND = "run" ]; then
                  cargo $COMMAND $CARGO_FLAGS | diff -u ci/expected/$EXAMPLE.run -
              else
                  cargo $COMMAND $CARGO_FLAGS
              fi
              arm-none-eabi-objcopy -O ihex target/${{ matrix.target }}/$BUILD_MODE/examples/$EXAMPLE ci/builds/${EXAMPLE}_${FEATURES_STR}${BUILD_MODE}_${BUILD_NUM}.hex
          }

          mkdir -p ci/builds
          exs=(
              idle
              init
              hardware
              preempt
              binds

              resource
              lock
              late
              only-shared-access

              task
              message
              capacity

              types
              not-send
              not-sync
              shared-with-init

              generics
              cfg
              pool
              ramfunc
          )

          for ex in ${exs[@]}; do
              if [ $ex = pool ]; then
                  if [ ${{ matrix.target }} = thumbv6m-none-eabi ]; then
                      continue
                  fi

                  td=$(mktemp -d)

                  cargo run --example $ex --target ${{ matrix.target }} --features __v7 >\
                          $td/pool.run
                  grep 'foo(0x2' $td/pool.run
                  grep 'bar(0x2' $td/pool.run
                  arm-none-eabi-objcopy -O ihex target/${{ matrix.target }}/debug/examples/$ex \
                                          ci/builds/${ex}___v7_debug_1.hex

                  cargo run --example $ex --target ${{ matrix.target }} --features __v7 --release >\
                          $td/pool.run
                  grep 'foo(0x2' $td/pool.run
                  grep 'bar(0x2' $td/pool.run
                  arm-none-eabi-objcopy -O ihex target/${{ matrix.target }}/release/examples/$ex \
                                          ci/builds/${ex}___v7_release_1.hex

                  rm -rf $td

                  continue
              fi

              if [ $ex = types ]; then
                  if [ ${{ matrix.target }} = thumbv6m-none-eabi ]; then
                      continue
                  fi

                  arm_example "run" $ex "debug" "__v7" "1"
                  arm_example "run" $ex "release" "__v7" "1"

                  continue
              fi

              arm_example "run" $ex "debug" "" "1"
              if [ $ex = types ]; then
                  arm_example "run" $ex "release" "" "1"
              else
                  arm_example "build" $ex "release" "" "1"
              fi
          done

          built=()
          cargo clean
          for ex in ${exs[@]}; do
              if [ $ex = types ] || [ $ex = pool ]; then
                  if [ ${{ matrix.target }} = thumbv6m-none-eabi ]; then
                      continue
                  fi

                  arm_example "build" $ex "debug" "__v7" "2"
                  cmp ci/builds/${ex}___v7_debug_1.hex \
                      ci/builds/${ex}___v7_debug_2.hex
                  arm_example "build" $ex "release" "__v7" "2"
                  cmp ci/builds/${ex}___v7_release_1.hex \
                      ci/builds/${ex}___v7_release_2.hex
              else
                  arm_example "build" $ex "debug" "" "2"
                  cmp ci/builds/${ex}_debug_1.hex \
                      ci/builds/${ex}_debug_2.hex
                  arm_example "build" $ex "release" "" "2"
                  cmp ci/builds/${ex}_release_1.hex \
                      ci/builds/${ex}_release_2.hex
              fi

              built+=( $ex )
          done

          ( cd target/${{ matrix.target }}/release/examples/ && size ${built[@]} )


  # Check the correctness of macros/ crate
  checkmacros:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - x86_64-unknown-linux-gnu
        toolchain:
          - stable
          - 1.36.0
          - nightly
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install Rust ${{ matrix.toolchain }} with target (${{ matrix.target }})
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.toolchain }}
          target: ${{ matrix.target }}
          override: true

      - name: Disable optimisation profiles
        if: matrix.toolchain == '1.36.0'
        run: sed -i '/^\[profile.*build-override]$/,/^$/{/^#/!{/^$/!d}}' Cargo.toml

      - name: cargo check
        uses: actions-rs/cargo@v1
        with:
          use-cross: false
          command: check
          args: --manifest-path macros/Cargo.toml --target=${{ matrix.target }}

  # Run test suite for thumbv7m
  testv7:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: 1.36.0
          target: thumbv7m-none-eabi
          override: true

      - name: Disable optimisation profiles
        run: sed -i '/^\[profile.*build-override]$/,/^$/{/^#/!{/^$/!d}}' Cargo.toml

      - uses: actions-rs/cargo@v1
        with:
          use-cross: false
          command: test
          args: --test single --features __v7

  # Run test suite for thumbv6m
  testv6:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v2
      - name: Install Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: 1.36.0
          target: thumbv6m-none-eabi
          override: true

      - name: Disable optimisation profiles
        run: sed -i '/^\[profile.*build-override]$/,/^$/{/^#/!{/^$/!d}}' Cargo.toml

      - uses: actions-rs/cargo@v1
        with:
          use-cross: false
          command: test
          args: --test single

  # Verify all multicore examples
  checkmulticore:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        target:
          - x86_64-unknown-linux-gnu
        toolchain:
          - nightly
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Install Rust ${{ matrix.toolchain }} with x86_64-unknown-linux-gnu
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.toolchain }}
          target: x86_64-unknown-linux-gnu
          override: true
      - name: Install Rust ${{ matrix.toolchain }} with thumbv7m-none-eabi
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.toolchain }}
          target: thumbv7m-none-eabi
          override: true
      - name: Install Rust ${{ matrix.toolchain }} with thumbv6m-none-eabi
        uses: actions-rs/toolchain@v1
        with:
          toolchain: ${{ matrix.toolchain }}
          target: thumbv6m-none-eabi
          override: true
      - uses: actions-rs/cargo@v1
        with:
          command: install
          args: microamp-tools --version 0.1.0-alpha.3

      - name: Check multi-core examples
        run: |
          cd heterogeneous
          exs=(
              smallest
              x-init-2
              x-init
              x-schedule
              x-spawn
          )
          for ex in ${exs[@]}; do
              cargo-microamp --example=$ex --target thumbv7m-none-eabi,thumbv6m-none-eabi --check
          done