Skip to content

Commit 73e0067

Browse files
committed
Add nix setup and compiler tests in CI
Tests the following compilers: - GCC: 4.8, 4.9, 7, 11, 13, 14 - Clang: 18, 19, 20 - Zig: 0.12, 0.13, 0.14
1 parent 8d1d4b2 commit 73e0067

File tree

9 files changed

+792
-0
lines changed

9 files changed

+792
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
2+
3+
name: Functional tests
4+
description: Run functional tests
5+
6+
inputs:
7+
nix-shell:
8+
description: Run in the specified Nix environment if exists
9+
default: "ci"
10+
custom_shell:
11+
description: The shell to use. Only relevant if no nix-shell specified
12+
default: "bash"
13+
nix-cache:
14+
description: Determine whether to enable nix cache
15+
default: 'false'
16+
nix-verbose:
17+
description: Determine wether to suppress nix log or not
18+
default: 'false'
19+
gh_token:
20+
description: Github access token to use
21+
required: true
22+
cflags:
23+
description: CFLAGS to pass to compilation
24+
default: ""
25+
26+
runs:
27+
using: composite
28+
steps:
29+
- uses: ./.github/actions/setup-nix
30+
with:
31+
devShell: ${{ inputs.nix-shell }}
32+
cache: ${{ inputs.nix-cache }}
33+
verbose: ${{ inputs.nix-verbose }}
34+
gh_token: ${{ inputs.gh_token }}
35+
- name: Functional tests
36+
if: ${{ inputs.func == 'true' }}
37+
shell: ${{ env.SHELL }}
38+
run: |
39+
export CFLAGS="${{ inputs.cflags }}"
40+
make clean
41+
make quickcheck
42+
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
2+
3+
name: Multiple Functional tests
4+
description: Run functional tests
5+
6+
inputs:
7+
nix-shell:
8+
description: Run in the specified Nix environment if exists
9+
default: "ci"
10+
custom_shell:
11+
description: The shell to use. Only relevant if no nix-shell specified
12+
default: "bash"
13+
nix-cache:
14+
description: Determine whether to enable nix cache
15+
default: 'false'
16+
nix-verbose:
17+
description: Determine wether to suppress nix log or not
18+
default: 'false'
19+
gh_token:
20+
description: Github access token to use
21+
required: true
22+
cflags:
23+
description: CFLAGS to pass to compilation
24+
default: ""
25+
26+
runs:
27+
using: composite
28+
steps:
29+
- name: Native Tests
30+
uses: ./.github/actions/functest
31+
with:
32+
nix-shell: ${{ inputs.nix-shell }}
33+
nix-cache: ${{ inputs.nix-cache }}
34+
nix-verbose: ${{ inputs.nix-verbose }}
35+
gh_token: ${{ inputs.gh_token }}
36+
custom_shell: ${{ inputs.custom_shell }}
37+
cflags: ${{ inputs.cflags }}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
2+
3+
name: Setup nix
4+
description: Setup nix
5+
6+
inputs:
7+
script:
8+
description: The script to be run in the nix shell
9+
required: false
10+
devShell:
11+
description: The name of the devShell
12+
required: true
13+
cache:
14+
description: Determine whether to enable nix cache
15+
default: 'false'
16+
verbose:
17+
description: Determine wether to suppress nix log or not
18+
default: 'false'
19+
cache_prefix:
20+
description: Fixed prefix of ID of Github cache entries that should be removed.
21+
required: false
22+
save_cache:
23+
description: Determine whether to save cache with primary key or not
24+
required: false
25+
default: 'false'
26+
gh_token:
27+
description: Github access token to use
28+
required: true
29+
install:
30+
required: false
31+
description: Determine how to install nix ('installer' | 'apt')
32+
default: 'installer'
33+
34+
runs:
35+
using: composite
36+
steps:
37+
- name: Pre-check nix
38+
id: nix-pre-check
39+
if: ${{ env.NIX_SHELL == '' }}
40+
shell: bash -lo pipefail {0}
41+
run: |
42+
suppress() {
43+
local exit_code="$?"
44+
local line_no="$1"
45+
echo "Nix check failed at $line_no: $exit_code"
46+
echo "installed=false" >> $GITHUB_OUTPUT
47+
exit 0
48+
}
49+
50+
trap 'suppress $LINENO' ERR
51+
52+
if [[ $USER == 'root' ]]; then
53+
mkdir -p /root
54+
echo "HOME=/root" >> $GITHUB_ENV
55+
fi
56+
57+
nix --version
58+
- name: Install nix via apt
59+
if: ${{ steps.nix-pre-check.outputs.installed == 'false' && inputs.install == 'apt' }}
60+
shell: bash
61+
run: |
62+
if [[ -f /.dockerenv ]]; then
63+
apt install nix -y
64+
else
65+
sudo apt install nix -y
66+
fi
67+
mkdir -p ~/.config/nix
68+
cat >> ~/.config/nix/nix.conf << EOF
69+
experimental-features = nix-command flakes
70+
EOF
71+
72+
if [[ ! -z $GH_TOKEN ]]; then
73+
echo "access-tokens = github.com=$GH_TOKEN" >> ~/.config/nix/nix.conf
74+
fi
75+
- uses: cachix/install-nix-action@08dcb3a5e62fa31e2da3d490afc4176ef55ecd72 # v30
76+
if: ${{ steps.nix-pre-check.outputs.installed == 'false' }}
77+
with:
78+
github_access_token: ${{ inputs.gh_token }}
79+
- name: Post-check nix
80+
id: nix-post-check
81+
continue-on-error: true
82+
shell: bash -lo pipefail {0}
83+
run: |
84+
echo "::group::nix config"
85+
if [[ -z "${{ inputs.cache_prefix }}" ]]; then
86+
cache_prefix="${{ runner.os }}-${{ runner.arch }}"
87+
else
88+
cache_prefix="${{ inputs.cache_prefix }}"
89+
fi
90+
91+
echo "cache_prefix=$cache_prefix" >> $GITHUB_OUTPUT
92+
93+
if [[ "${{ steps.nix-pre-check.outputs.installed }}" == 'false' ]]; then
94+
sudo chown -R $USER:nixbld /nix
95+
fi
96+
97+
nix profile install nixpkgs/nixos-24.11#sqlite
98+
nix config show
99+
echo "::endgroup::"
100+
- uses: nix-community/cache-nix-action@dab0514428ae3988852b7787a6d86a6fc571cc9d #v6.0.0
101+
id: cache
102+
if: ${{ env.NIX_CACHE_ENABLED != 1 && inputs.cache == 'true' }}
103+
continue-on-error: true
104+
with:
105+
primary-key: ${{ steps.nix-post-check.outputs.cache_prefix }}-${{ hashFiles('**/*.nix') }}
106+
restore-prefixes-first-match: ${{ steps.nix-post-check.outputs.cache_prefix }}
107+
gc-max-store-size-linux: 536870912
108+
purge: ${{ inputs.save_cache == 'true' }}
109+
save: ${{ inputs.save_cache == 'true' }}
110+
purge-prefixes: cache-${{ steps.nix-post-check.outputs.cache_prefix }}
111+
purge-created: 0
112+
purge-primary-key: ${{ inputs.save_cache == 'true' && 'always' || 'never' }}
113+
token: ${{ inputs.gh_token }}
114+
- name: Set Shell
115+
shell: bash -lo pipefail {0}
116+
run: |
117+
echo "::group::set nix shell"
118+
if [[ "${{ steps.cache.outputs.hit-primary-key }}" == "true" ]]; then
119+
echo NIX_CACHE_ENABLED=1 >> $GITHUB_ENV
120+
fi
121+
122+
echo NIX_SHELL="${{ inputs.devShell }}" >> $GITHUB_ENV
123+
nix_extra_flags="${{ inputs.verbose == 'false' && '--quiet' || '' }}"
124+
if [[ ${{ inputs.install }} == 'apt' && ! -f /.dockerenv ]]; then
125+
echo SHELL="sudo $(which nix) develop $nix_extra_flags .#${{ inputs.devShell }} -c bash -e {0}" >> $GITHUB_ENV
126+
else
127+
echo SHELL="$(which nix) develop $nix_extra_flags .#${{ inputs.devShell }} -c bash -e {0}" >> $GITHUB_ENV
128+
fi
129+
echo "::endgroup::"
130+
- name: Prepare nix dev shell
131+
shell: ${{ env.SHELL }}
132+
run: |
133+
- name: Dependency check
134+
shell: ${{ env.SHELL }}
135+
if: inputs.script != ''
136+
run: eval ${{ inputs.script }}

.github/workflows/all.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ jobs:
2121
id-token: 'write'
2222
uses: ./.github/workflows/base.yml
2323
secrets: inherit
24+
ci:
25+
name: Extended
26+
permissions:
27+
contents: 'read'
28+
id-token: 'write'
29+
needs: [ base ]
30+
uses: ./.github/workflows/ci.yml
31+
secrets: inherit

.github/workflows/ci.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# SPDX-License-Identifier: Apache-2.0 OR ISC OR MIT
2+
3+
name: Extended
4+
permissions:
5+
contents: read
6+
on:
7+
workflow_call:
8+
workflow_dispatch:
9+
10+
jobs:
11+
compiler_tests:
12+
name: Compiler tests (${{ matrix.compiler.name }}, ${{ matrix.target.name }}, ${{ matrix.cflags }})
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
cflags: [ "-O0", "-Os", "-O3" ]
17+
target:
18+
- runner: pqcp-arm64
19+
name: 'aarch64'
20+
archflags: ''
21+
- runner: ubuntu-latest
22+
name: 'x86_64'
23+
archflags: '-mavx2 -mbmi2 -mpopcnt -maes'
24+
- runner: macos-latest
25+
name: 'macos'
26+
archflags: ''
27+
compiler:
28+
- name: gcc-4.8
29+
shell: ci_gcc48
30+
darwin: False
31+
c17: False
32+
c23: False
33+
- name: gcc-4.9
34+
shell: ci_gcc49
35+
darwin: False
36+
c17: False
37+
c23: False
38+
- name: gcc-7
39+
shell: ci_gcc7
40+
darwin: False
41+
c17: False
42+
c23: False
43+
- name: gcc-11
44+
shell: ci_gcc11
45+
darwin: True
46+
c17: True
47+
c23: False
48+
- name: gcc-13
49+
shell: ci_gcc13
50+
darwin: True
51+
c17: True
52+
c23: False
53+
- name: gcc-14
54+
shell: ci_gcc14
55+
darwin: True
56+
c17: True
57+
c23: True
58+
- name: clang-18
59+
shell: ci_clang18
60+
darwin: True
61+
c17: True
62+
c23: True
63+
- name: clang-19
64+
shell: ci_clang19
65+
darwin: True
66+
c17: True
67+
c23: True
68+
- name: clang-20
69+
shell: ci_clang20
70+
darwin: True
71+
c17: True
72+
c23: True
73+
# CPU flags are not correctly passed to the zig assembler
74+
# https://github.com/ziglang/zig/issues/23576
75+
# We therefore only test the C backend
76+
#
77+
# We omit all examples since there is currently no way to run
78+
# only those examples not involving native code.
79+
- name: zig-0.12
80+
shell: ci_zig0_12
81+
darwin: True
82+
c17: True
83+
c23: False
84+
- name: zig-0.13
85+
shell: ci_zig0_13
86+
darwin: True
87+
c17: True
88+
c23: False
89+
- name: zig-0.14
90+
shell: ci_zig0_14
91+
darwin: True
92+
c17: True
93+
c23: True
94+
runs-on: ${{ matrix.target.runner }}
95+
steps:
96+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
97+
- name: build+functest (default)
98+
uses: ./.github/actions/multi-functest
99+
with:
100+
gh_token: ${{ secrets.GITHUB_TOKEN }}
101+
nix-shell: ${{ matrix.compiler.shell }}
102+
cflags: "${{ matrix.cflags }} ${{ matrix.target.archflags }}"
103+
- name: native build+functest (C90)
104+
uses: ./.github/actions/multi-functest
105+
with:
106+
gh_token: ${{ secrets.GITHUB_TOKEN }}
107+
opt: ${{ matrix.compiler.opt }}
108+
nix-shell: ${{ matrix.compiler.shell }}
109+
cflags: "-std=c90 ${{ matrix.cflags }} ${{ matrix.target.archflags }}"
110+
- name: native build+functest (C99)
111+
uses: ./.github/actions/multi-functest
112+
with:
113+
gh_token: ${{ secrets.GITHUB_TOKEN }}
114+
nix-shell: ${{ matrix.compiler.shell }}
115+
cflags: "-std=c99 ${{ matrix.cflags }} ${{ matrix.target.archflags }}"
116+
- name: native build+functest (C11)
117+
uses: ./.github/actions/multi-functest
118+
with:
119+
gh_token: ${{ secrets.GITHUB_TOKEN }}
120+
nix-shell: ${{ matrix.compiler.shell }}
121+
cflags: "-std=c11 ${{ matrix.cflags }} ${{ matrix.target.archflags }}"
122+
- name: native build+functest (C17)
123+
if: ${{ matrix.compiler.c17 }}
124+
uses: ./.github/actions/multi-functest
125+
with:
126+
gh_token: ${{ secrets.GITHUB_TOKEN }}
127+
nix-shell: ${{ matrix.compiler.shell }}
128+
cflags: "-std=c17 ${{ matrix.cflags }} ${{ matrix.target.archflags }}"
129+
- name: native build+functest (C23)
130+
if: ${{ matrix.compiler.c23 }}
131+
uses: ./.github/actions/multi-functest
132+
with:
133+
gh_token: ${{ secrets.GITHUB_TOKEN }}
134+
nix-shell: ${{ matrix.compiler.shell }}
135+
cflags: "-std=c23 ${{ matrix.cflags }} ${{ matrix.target.archflags }}"

0 commit comments

Comments
 (0)