Skip to content

Commit 217199e

Browse files
committed
Nix: Introduce separate shells for cross compilation
- Previously, we used a single `ci-cross` nix shell for all cross-compilation tool chains. This shell takes a very long time to build and is therefore inconvenient to use for cross-compilation on a specific target. - This commit extends the nix flake by architecture specific ci cross shells: - ci-cross-x86_64 - ci-cross-aarch64 - ci-cross-riscv64 - ci-cross-riscv32 - ci-cross-ppc64le - ci-cross-aarch64_be - It also adjusts CI to use those shells. - This commit is port from mlkem-native: - pq-code-package/mlkem-native#1104 Signed-off-by: willieyz <willie.zhao@chelpis.com>
1 parent a7c9c15 commit 217199e

File tree

4 files changed

+106
-11
lines changed

4 files changed

+106
-11
lines changed

.github/workflows/bench.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,23 @@ jobs:
3535
archflags: -mcpu=cortex-a72 -DMLD_SYS_AARCH64_SLOW_BARREL_SHIFTER
3636
cflags: "-flto -DMLD_FORCE_AARCH64"
3737
bench_extra_args: ""
38+
nix_shell: ci-bench
3839
only_no_opt: false
3940
- system: rpi5
4041
name: Arm Cortex-A76 (Raspberry Pi 5) benchmarks
4142
bench_pmu: PERF
4243
archflags: "-mcpu=cortex-a76 -march=armv8.2-a"
4344
cflags: "-flto -DMLD_FORCE_AARCH64"
4445
bench_extra_args: ""
46+
nix_shell: ci-bench
4547
only_no_opt: false
4648
- system: a55
4749
name: Arm Cortex-A55 (Snapdragon 888) benchmarks
4850
bench_pmu: PERF
4951
archflags: "-mcpu=cortex-a55 -march=armv8.2-a"
5052
cflags: "-flto -static -DMLD_FORCE_AARCH64"
5153
bench_extra_args: -w exec-on-a55
54+
nix_shell: ci-bench
5255
only_no_opt: false
5356
- system: bpi
5457
name: SpacemiT K1 8 (Banana Pi F3) benchmarks
@@ -57,13 +60,15 @@ jobs:
5760
cflags: "-static"
5861
bench_extra_args: -w exec-on-bpi
5962
cross_prefix: riscv64-unknown-linux-gnu-
63+
nix_shell: ci-cross-riscv64
6064
only_no_opt: true
6165
- system: m1-mac-mini
6266
name: Mac Mini (M1, 2020) benchmarks
6367
bench_pmu: MAC
6468
archflags: "-mcpu=apple-m1 -march=armv8.4-a+sha3"
6569
cflags: "-flto"
6670
bench_extra_args: "-r"
71+
nix_shell: ci-bench
6772
only_no_opt: false
6873
if: github.repository_owner == 'pq-code-package' && (github.event.label.name == 'benchmark' || github.ref == 'refs/heads/main')
6974
runs-on: self-hosted-${{ matrix.target.system }}
@@ -79,7 +84,7 @@ jobs:
7984
store_results: ${{ github.repository_owner == 'pq-code-package' && github.ref == 'refs/heads/main' }}
8085
bench_extra_args: ${{ matrix.target.bench_extra_args }}
8186
gh_token: ${{ secrets.GITHUB_TOKEN }}
82-
nix-shell: ${{ matrix.target.cross_prefix != '' && 'ci-cross' || 'ci-bench' }}
87+
nix-shell: ${{ matrix.target.nix_shell }}
8388
cross_prefix: ${{ matrix.target.cross_prefix }}
8489
opt: true
8590
- uses: ./.github/actions/bench
@@ -91,7 +96,7 @@ jobs:
9196
store_results: ${{ github.repository_owner == 'pq-code-package' && github.ref == 'refs/heads/main' }}
9297
bench_extra_args: ${{ matrix.target.bench_extra_args }}
9398
gh_token: ${{ secrets.GITHUB_TOKEN }}
94-
nix-shell: ${{ matrix.target.cross_prefix != '' && 'ci-cross' || 'ci-bench' }}
99+
nix-shell: ${{ matrix.target.nix_shell }}
95100
cross_prefix: ${{ matrix.target.cross_prefix }}
96101
opt: false
97102

.github/workflows/ci.yml

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,98 +21,116 @@ jobs:
2121
name: 'MacOS (aarch64)'
2222
arch: mac
2323
mode: native
24+
nix_shell: ci
2425
- runner: macos-13
2526
name: 'MacOS (x86_64)'
2627
arch: mac
2728
mode: native
29+
nix_shell: ci
2830
- runner: pqcp-arm64
2931
name: 'ubuntu-latest (aarch64)'
3032
arch: aarch64
3133
mode: native
34+
nix_shell: ci
3235
- runner: pqcp-arm64
3336
name: 'ubuntu-latest (aarch64)'
3437
arch: x86_64
3538
mode: cross-x86_64
39+
nix_shell: ci-cross-x86_64
3640
- runner: pqcp-arm64
3741
name: 'ubuntu-latest (aarch64)'
3842
arch: riscv64
3943
mode: cross-riscv64
44+
nix_shell: ci-cross-riscv64
4045
- runner: pqcp-arm64
4146
name: 'ubuntu-latest (aarch64)'
4247
arch: riscv32
4348
mode: cross-riscv32
49+
nix_shell: ci-cross-riscv32
4450
- runner: pqcp-arm64
4551
name: 'ubuntu-latest (ppc64le)'
4652
arch: ppc64le
4753
mode: cross-ppc64le
54+
nix_shell: ci-cross-ppc64le
4855
- runner: pqcp-x64
4956
name: 'ubuntu-latest (x86_64)'
5057
arch: x86_64
5158
mode: native
59+
nix_shell: ci
5260
- runner: pqcp-x64
5361
name: 'ubuntu-latest (x86_64)'
5462
arch: aarch64
5563
mode: cross-aarch64
64+
nix_shell: ci-cross-aarch64
5665
- runner: pqcp-x64
5766
name: 'ubuntu-latest (x86_64)'
5867
arch: aarch64_be
5968
mode: cross-aarch64_be
69+
nix_shell: ci-cross-aarch64_be
6070
exclude:
6171
- {external: true,
6272
target: {
6373
runner: pqcp-arm64,
6474
name: 'ubuntu-latest (aarch64)',
6575
arch: aarch64,
66-
mode: native
76+
mode: native,
77+
nix_shell: ci
6778
}}
6879
- {external: true,
6980
target: {
7081
runner: pqcp-arm64,
7182
name: 'ubuntu-latest (aarch64)',
7283
arch: x86_64,
73-
mode: cross-x86_64
84+
mode: cross-x86_64,
85+
nix_shell: ci-cross-x86_64
7486
}}
7587
- {external: true,
7688
target: {
7789
runner: pqcp-arm64,
7890
name: 'ubuntu-latest (aarch64)',
7991
arch: riscv64,
80-
mode: cross-riscv64
92+
mode: cross-riscv64,
93+
nix_shell: ci-corss-riscv64
8194
}}
8295
- {external: true,
8396
target: {
8497
runner: pqcp-arm64,
8598
name: 'ubuntu-latest (aarch64)',
8699
arch: riscv32,
87-
mode: cross-riscv32
100+
mode: cross-riscv32,
101+
nix_shell: ci-cross-riscv32
88102
}}
89103
- {external: true,
90104
target: {
91105
runner: pqcp-arm64,
92106
name: 'ubuntu-latest (ppc64le)',
93107
arch: ppc64le,
94-
mode: cross-ppc64le
108+
mode: cross-ppc64le,
109+
nix_shell: ci-cross-ppc64le
95110
}}
96111
- {external: true,
97112
target: {
98113
runner: pqcp-x64,
99114
name: 'ubuntu-latest (x86_64)',
100115
arch: x86_64,
101-
mode: native
116+
mode: native,
117+
nix_shell: ci
102118
}}
103119
- {external: true,
104120
target: {
105121
runner: pqcp-x64,
106122
name: 'ubuntu-latest (x86_64)',
107123
arch: aarch64,
108-
mode: cross-aarch64
124+
mode: cross-aarch64,
125+
nix_shell: ci-cross-aarch64
109126
}}
110127
- {external: true,
111128
target: {
112129
runner: pqcp-x64,
113130
name: 'ubuntu-latest (x86_64)',
114131
arch: aarch64_be,
115-
mode: cross-aarch64_be
132+
mode: cross-aarch64_be,
133+
nix_shell: ci-cross-aarch64_be
116134
}}
117135
name: Functional tests (${{ matrix.target.arch }}${{ matrix.target.mode != 'native' && ', cross' || ''}})
118136
runs-on: ${{ matrix.target.runner }}
@@ -121,7 +139,7 @@ jobs:
121139
- name: build + test
122140
uses: ./.github/actions/multi-functest
123141
with:
124-
nix-shell: ${{ matrix.target.mode == 'native' && 'ci' || 'ci-cross' }}
142+
nix-shell: ${{ matrix.target.nix_shell }}
125143
nix-cache: ${{ matrix.target.mode == 'native' && 'false' || 'true' }}
126144
gh_token: ${{ secrets.GITHUB_TOKEN }}
127145
compile_mode: ${{ matrix.target.mode }}

flake.nix

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@
6666
packages.slothy = util.slothy;
6767
packages.toolchains = util.toolchains;
6868
packages.toolchains_native = util.toolchains_native;
69+
packages.toolchain_x86_64 = util.toolchain_x86_64;
70+
packages.toolchain_aarch64 = util.toolchain_aarch64;
71+
packages.toolchain_riscv64 = util.toolchain_riscv64;
72+
packages.toolchain_riscv32 = util.toolchain_riscv32;
73+
packages.toolchain_ppc64le = util.toolchain_ppc64le;
74+
packages.toolchain_aarch64_be = util.toolchain_aarch64_be;
6975

7076
devShells.default = util.mkShell {
7177
packages = builtins.attrValues
@@ -98,6 +104,24 @@
98104
devShells.ci-cross = util.mkShell {
99105
packages = builtins.attrValues { inherit (config.packages) linters toolchains; };
100106
};
107+
devShells.ci-cross-x86_64 = util.mkShell {
108+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_x86_64; };
109+
};
110+
devShells.ci-cross-aarch64 = util.mkShell {
111+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_aarch64; };
112+
};
113+
devShells.ci-cross-riscv64 = util.mkShell {
114+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_riscv64; };
115+
};
116+
devShells.ci-cross-riscv32 = util.mkShell {
117+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_riscv32; };
118+
};
119+
devShells.ci-cross-ppc64le = util.mkShell {
120+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_ppc64le; };
121+
};
122+
devShells.ci-cross-aarch64_be = util.mkShell {
123+
packages = builtins.attrValues { inherit (config.packages) linters toolchain_aarch64_be; };
124+
};
101125
devShells.ci-linter = util.mkShellNoCC {
102126
packages = builtins.attrValues { inherit (config.packages) linters; };
103127
};

nix/util.nix

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,54 @@ rec {
103103
s2n_bignum = pkgs.callPackage ./s2n_bignum { };
104104
slothy = pkgs.callPackage ./slothy { };
105105

106+
# Helper function to build individual cross toolchains
107+
_individual_toolchain = { name, cross_compilers }:
108+
let
109+
common_deps = builtins.attrValues
110+
{
111+
inherit (pkgs.python3Packages) sympy pyyaml;
112+
inherit (pkgs)
113+
gnumake
114+
python3
115+
qemu;
116+
} ++ pkgs.lib.optionals (pkgs.stdenv.isDarwin) [ pkgs.git ];
117+
in
118+
pkgs.symlinkJoin {
119+
name = "toolchain-${name}";
120+
paths = cross_compilers ++ common_deps ++ [ native-gcc ];
121+
};
122+
123+
# Individual cross toolchains
124+
toolchain_x86_64 = _individual_toolchain {
125+
name = "x86_64";
126+
cross_compilers = [ (wrap-gcc pkgs.pkgsCross.gnu64) ];
127+
};
128+
129+
toolchain_aarch64 = _individual_toolchain {
130+
name = "aarch64";
131+
cross_compilers = [ (wrap-gcc pkgs.pkgsCross.aarch64-multiplatform) ];
132+
};
133+
134+
toolchain_riscv64 = _individual_toolchain {
135+
name = "riscv64";
136+
cross_compilers = [ (wrap-gcc pkgs.pkgsCross.riscv64) ];
137+
};
138+
139+
toolchain_riscv32 = _individual_toolchain {
140+
name = "riscv32";
141+
cross_compilers = [ (wrap-gcc pkgs.pkgsCross.riscv32) ];
142+
};
143+
144+
toolchain_ppc64le = _individual_toolchain {
145+
name = "ppc64le";
146+
cross_compilers = [ (wrap-gcc pkgs.pkgsCross.powernv) ];
147+
};
148+
149+
toolchain_aarch64_be = _individual_toolchain {
150+
name = "aarch64_be";
151+
cross_compilers = pkgs.lib.optionals (pkgs.stdenv.isLinux && pkgs.stdenv.isx86_64) [ (pkgs.callPackage ./aarch64_be-none-linux-gnu-gcc.nix { }) ];
152+
};
153+
106154
toolchains = pkgs.symlinkJoin {
107155
name = "toolchains";
108156
paths = _toolchains { };

0 commit comments

Comments
 (0)