Skip to content

Commit

Permalink
ci: make static lib and headers available in releases
Browse files Browse the repository at this point in the history
  • Loading branch information
geonnave committed Jul 21, 2023
1 parent 7651aaa commit fe9528f
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 85 deletions.
211 changes: 126 additions & 85 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Build and test

on:
push:
branches: [main]
# branches: [main]
tags: 'REL-*'
pull_request:

Expand All @@ -20,57 +20,57 @@ jobs:
- name: Check if code is well formatted
run: cargo fmt --check

unit-tests: # run before build because it is faster
needs: check-style
runs-on: ubuntu-latest
# unit-tests: # run before build because it is faster
# needs: check-style
# runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
edhoc_lib: [hacspec, rust]
crypto: [hacspec, psa]
ead: [ead-none, ead-zeroconf]
exclude:
- edhoc_lib: rust
crypto: hacspec
# strategy:
# fail-fast: false
# matrix:
# edhoc_lib: [hacspec, rust]
# crypto: [hacspec, psa]
# ead: [ead-none, ead-zeroconf]
# exclude:
# - edhoc_lib: rust
# crypto: hacspec

steps:
- name: Checkout repo
uses: actions/checkout@v3
# steps:
# - name: Checkout repo
# uses: actions/checkout@v3

- name: Run unit tests # note that we only add `--package edhoc-hacspec` when testing the hacspec version of the lib
run: cargo test --package edhoc-rs --package edhoc-crypto --package edhoc-ead ${{ matrix.edhoc_lib == 'hacspec' && '--package edhoc-hacspec' || '' }} --no-default-features --features="${{ matrix.edhoc_lib }}-${{ matrix.crypto }}, ${{ matrix.ead }}" --no-fail-fast
# - name: Run unit tests # note that we only add `--package edhoc-hacspec` when testing the hacspec version of the lib
# run: cargo test --package edhoc-rs --package edhoc-crypto --package edhoc-ead ${{ matrix.edhoc_lib == 'hacspec' && '--package edhoc-hacspec' || '' }} --no-default-features --features="${{ matrix.edhoc_lib }}-${{ matrix.crypto }}, ${{ matrix.ead }}" --no-fail-fast


build-edhoc-package:
needs: unit-tests
runs-on: ubuntu-latest
# build-edhoc-package:
# needs: unit-tests
# runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
edhoc_lib: [hacspec, rust]
crypto: [hacspec, psa, psa-baremetal, cryptocell310]
ead: [ead-none, ead-zeroconf]
exclude:
- edhoc_lib: rust
crypto: hacspec
# strategy:
# fail-fast: false
# matrix:
# edhoc_lib: [hacspec, rust]
# crypto: [hacspec, psa, psa-baremetal, cryptocell310]
# ead: [ead-none, ead-zeroconf]
# exclude:
# - edhoc_lib: rust
# crypto: hacspec

steps:
- name: Checkout repo
uses: actions/checkout@v3
# steps:
# - name: Checkout repo
# uses: actions/checkout@v3

- name: Install arm targets for Rust
run: rustup target add thumbv7m-none-eabi && rustup target add thumbv7em-none-eabihf
- name: Install arm gcc
run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi
# - name: Install arm targets for Rust
# run: rustup target add thumbv7m-none-eabi && rustup target add thumbv7em-none-eabihf
# - name: Install arm gcc
# run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi

- name: Build
run: cargo build --package edhoc-rs --package edhoc-crypto --package edhoc-ead --no-default-features --features="${{ matrix.edhoc_lib }}-${{ matrix.crypto }}, ${{ matrix.ead }}" --release
# - name: Build
# run: cargo build --package edhoc-rs --package edhoc-crypto --package edhoc-ead --no-default-features --features="${{ matrix.edhoc_lib }}-${{ matrix.crypto }}, ${{ matrix.ead }}" --release


hacspec-to-fstar:
needs: unit-tests
# needs: unit-tests
runs-on: ubuntu-latest
steps:
- name: Checkout edhoc-rs
Expand All @@ -90,84 +90,120 @@ jobs:
working-directory: hacspec-v2-repo

- name: Generate fstar
run: docker run --rm -v ${{ github.workspace }}:/edhoc-rs hacspec-v2 bash -c "cd edhoc-rs/hacspec && cargo-hax into fstar"
run: |
docker run --rm -v ${{ github.workspace }}:/edhoc-rs hacspec-v2 bash -c "cd edhoc-rs/hacspec && cargo-hax into fstar"
zip -j -r ./target/edhoc-rs-fstar.zip ./hacspec/out
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: fstar-code
path: ./hacspec/out/*
path: ./target/edhoc-rs-fstar.zip


run-example-on-qemu:
needs: unit-tests
build-static-lib-and-headers:
# needs: unit-tests
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
config: [hacspec-psa, rust-psa]
ead: [ead-none, ead-zeroconf]
edhoc_lib: [rust]
crypto: [psa-baremetal, cryptocell310]

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Install arm targets for Rust
run: rustup target add thumbv7m-none-eabi
run: rustup target add thumbv7em-none-eabihf
- name: Install arm gcc
run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi
- name: Install QEMU ARM emulator
run: sudo apt-get -y install qemu-system-arm

- name: Run tests in QEMU
# FIXME: still failing
run: cd examples/edhoc-rs-no_std && cargo run --target="thumbv7m-none-eabi" --no-default-features --features="${{ matrix.config }}, ${{ matrix.ead }}" --release
- name: Build static library, generate headers, and zip to file
run: ./build_for_c.sh "${{ matrix.edhoc_lib }}-${{ matrix.crypto }}"

- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: static-lib-and-headers
path: ./target/staticlib-*.zip

build-example-for-cortex-m4:
needs: unit-tests
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
edhoc_lib: [hacspec, rust]
crypto: [psa, cryptocell310]
ead: [ead-none, ead-zeroconf]
# run-example-on-qemu:
# needs: unit-tests
# runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3
# strategy:
# fail-fast: false
# matrix:
# config: [hacspec-psa, rust-psa]
# ead: [ead-none, ead-zeroconf]

- name: Install arm targets for Rust
run: rustup target add thumbv7em-none-eabihf
- name: Install arm gcc
run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi
# steps:
# - name: Checkout repo
# uses: actions/checkout@v3

- name: Build example
# FIXME: still failing
run: cd examples/edhoc-rs-no_std && cargo build --target="thumbv7em-none-eabihf" --no-default-features --features="${{ matrix.edhoc_lib }}-${{ matrix.crypto }}, ${{ matrix.ead }}, rtt" --release
# - name: Install arm targets for Rust
# run: rustup target add thumbv7m-none-eabi
# - name: Install arm gcc
# run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi
# - name: Install QEMU ARM emulator
# run: sudo apt-get -y install qemu-system-arm

# - name: Run tests in QEMU
# # FIXME: still failing
# run: cd examples/edhoc-rs-no_std && cargo run --target="thumbv7m-none-eabi" --no-default-features --features="${{ matrix.config }}, ${{ matrix.ead }}" --release

build-coap-example:
needs: unit-tests
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3
# build-example-for-cortex-m4:
# needs: unit-tests
# runs-on: ubuntu-latest

# strategy:
# fail-fast: false
# matrix:
# edhoc_lib: [hacspec, rust]
# crypto: [psa, cryptocell310]
# ead: [ead-none, ead-zeroconf]

# steps:
# - name: Checkout repo
# uses: actions/checkout@v3

# - name: Install arm targets for Rust
# run: rustup target add thumbv7em-none-eabihf
# - name: Install arm gcc
# run: sudo apt-get -y update && sudo apt-get -y install gcc-arm-none-eabi

# - name: Build example
# run: cd examples/edhoc-rs-no_std && cargo build --target="thumbv7em-none-eabihf" --no-default-features --features="${{ matrix.edhoc_lib }}-${{ matrix.crypto }}, ${{ matrix.ead }}, rtt" --release


- name: Build server
run: cargo build --bin coapserver
# build-coap-example:
# needs: unit-tests
# runs-on: ubuntu-latest

- name: Build client
run: cargo build --bin coapclient
# steps:
# - name: Checkout repo
# uses: actions/checkout@v3

# - name: Build server
# run: cargo build --bin coapserver

release:
# - name: Build client
# run: cargo build --bin coapclient


# release:
# runs-on: ubuntu-latest
# needs: [build-edhoc-package, hacspec-to-fstar, run-example-on-qemu, build-example-for-cortex-m4, build-coap-example]
# if: >-
# github.event_name == 'push' &&
# startsWith(github.event.ref, 'refs/tags')
release-test:
runs-on: ubuntu-latest
needs: [build-edhoc-package, hacspec-to-fstar, run-example-on-qemu, build-example-for-cortex-m4, build-coap-example]
needs: [hacspec-to-fstar, build-static-lib-and-headers]
if: >-
github.event_name == 'push' &&
startsWith(github.event.ref, 'refs/tags')
Expand All @@ -178,10 +214,15 @@ jobs:
uses: actions/download-artifact@v3
with:
name: fstar-code
path: ./fstar-code
path: ./release-artifacts
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: static-lib-and-headers
path: ./release-artifacts
- name: Release
uses: ncipollo/release-action@v1
with:
generateReleaseNotes: true
artifacts: "fstar-code/*"
artifacts: "release-artifacts/*"
token: ${{ secrets.RELEASE_TOKEN }}
6 changes: 6 additions & 0 deletions build_for_c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,11 @@ cargo build --target thumbv7em-none-eabihf --package edhoc-rs --package edhoc-cr
cbindgen --config consts/cbindgen.toml --crate edhoc-consts --output ./target/include/edhoc_consts.h -v
cbindgen --config lib/cbindgen.toml --crate edhoc-rs --output ./target/include/edhoc_rs.h -v

# zip to a single file
cd target
zip -r staticlib-"$cargo_features"-thumbv7em-none-eabihf.zip include/
zip -u -j staticlib-"$cargo_features"-thumbv7em-none-eabihf.zip thumbv7em-none-eabihf/release/libedhoc_rs.a
cd -

echo "Reverting crate-type to original value: $original_value"
sed -i -E "s/crate-type.*/$original_value/" lib/Cargo.toml

0 comments on commit fe9528f

Please sign in to comment.