Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor nix configuration on ci and the aarch64 gcc dependency on x86_64 machines #89

Merged
merged 8 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/bench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jobs:
name: Arm Cortex-A55 (Snapdragon 888) benchmarks
cmd: tests bench -c PERF --cflags "-static -mcpu=cortex-a55" --arch-flags -march=armv8.2-a -w exec-on-a55 -v --output output.json
runs-on: self-hosted-${{ matrix.target.system }}
defaults:
run:
shell: nix develop .#ci -c bash -e {0}
permissions:
contents: write
if: github.repository_owner == 'pq-code-package' && (github.event.label.name == 'benchmark' || github.ref == 'refs/heads/main')
Expand All @@ -48,7 +51,6 @@ jobs:
$(cat /proc/cpuinfo)
EOF
- name: Run benchmark
shell: nix develop .#ci -c bash -e {0}
run: |
${{ matrix.target.cmd }}
- name: Store benchmark result
Expand Down
24 changes: 14 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ jobs:
- system: ${{ github.repository_owner != 'pq-code-package' && 'pqcp-arm64' }}
name: build_kat (${{ matrix.system }})
runs-on: ${{ matrix.system }}
defaults:
run:
shell: nix develop .#ci -c bash -e {0}
env:
CROSS_PREFIX: "${{ (matrix.system == 'ubuntu-latest' && 'aarch64-none-linux-gnu-') || ' ' }}"
CROSS_PREFIX: "${{ (matrix.system == 'ubuntu-latest' && 'aarch64-unknown-linux-gnu-') || ' ' }}"
EXPECT_ARCH: "${{ (matrix.system == 'macos-latest' && 'arm64') || (matrix.system == 'pqcp-arm64' && 'aarch64') || (matrix.system == 'ubuntu-latest' && 'x86_64') }}"
steps:
- uses: actions/checkout@v4
Expand All @@ -43,33 +46,33 @@ jobs:
fi
- name: Run functional tests
id: func_test
shell: nix develop .#ci -c bash -e {0}
run: |
tests func -v
tests func --cross-prefix $CROSS_PREFIX -v
- name: Run KAT tests
id: kat_test
if: |
success()
|| steps.func_test.conclusion == 'failure'
shell: nix develop .#ci -c bash -e {0}
run: |
tests kat -v
tests kat --cross-prefix $CROSS_PREFIX -v
- name: Run Nistkat tests
id: nistkat_test
if: |
success()
|| steps.func_test.conclusion == 'failure'
|| steps.kat_test.conclusion == 'failure'
shell: nix develop .#ci -c bash -e {0}
run: |
tests nistkat -v
tests nistkat --cross-prefix $CROSS_PREFIX -v
lint:
strategy:
matrix:
system: [ubuntu-latest]
runs-on: ${{ matrix.system }}
defaults:
run:
shell: nix develop .#ci-linter -c bash -e {0}
env:
CROSS_PREFIX: "${{ (matrix.system == 'ubuntu-latest' && 'aarch64-none-linux-gnu-') || '' }}"
CROSS_PREFIX: "${{ (matrix.system == 'ubuntu-latest' && 'aarch64-unknown-linux-gnu-') || '' }}"
steps:
- uses: actions/checkout@v4
- name: Setup nix
Expand All @@ -87,7 +90,6 @@ jobs:
- $(bash --version | grep -m1 "")
EOF
- name: Lint
shell: nix develop .#ci-linter -c bash -e {0}
run: |
echo "## Lint & Checks" >> $GITHUB_STEP_SUMMARY
lint
Expand All @@ -96,6 +98,9 @@ jobs:
matrix:
system: [macos-latest]
runs-on: ${{ matrix.system }}
defaults:
run:
shell: nix develop .#ci-cbmc -c bash -e {0}
steps:
- uses: actions/checkout@v4
- name: Setup nix
Expand All @@ -114,7 +119,6 @@ jobs:
- $(bash --version | grep -m1 "")
EOF
- name: Run CBMC proofs
shell: nix develop .#ci-cbmc -c bash -e {0}
run: |
cd cbmc/proofs;
KYBER_K=2 ./run-cbmc-proofs.py --summarize;
Expand Down
35 changes: 0 additions & 35 deletions arm-gnu-gcc.nix

This file was deleted.

25 changes: 13 additions & 12 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,21 @@

core =
let
# for x86_64 machine, cross compiled gcc needed to be wrapped with glibc this way for static compilation
cross-gcc = with pkgs; wrapCCWith {
cc = callPackage ./arm-gnu-gcc.nix { };
bintools = with pkgsCross.aarch64-multiplatform; wrapBintoolsWith {
bintools = binutils-unwrapped;
libc = glibc.static;
};
};
aarch64-gcc =
if pkgs.stdenv.isx86_64
then [ cross-gcc ]
else [ (pkgs.gcc13.override { propagateDoc = true; isGNU = true; }) pkgs.glibc pkgs.glibc.static ];
pkgs.lib.optionals
(! (pkgs.stdenv.isDarwin && pkgs.stdenv.isAarch64))
[
(
pkgs.pkgsCross.aarch64-multiplatform.buildPackages.gcc13.override {
propagateDoc = true;
isGNU = true;
}
)
pkgs.pkgsCross.aarch64-multiplatform.glibc
pkgs.pkgsCross.aarch64-multiplatform.glibc.static
];
in
pkgs.lib.optionals pkgs.stdenv.isLinux aarch64-gcc ++
aarch64-gcc ++
builtins.attrValues {
inherit (pkgs)
yq
Expand Down
27 changes: 21 additions & 6 deletions scripts/tests
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def sha256sum(result):
def base_compile(
bin,
verbose,
cross_prefix,
extra_make_envs={},
extra_make_args=[],
):
Expand All @@ -44,7 +45,7 @@ def base_compile(

args = [
"make",
"CROSS_PREFIX=aarch64-none-linux-gnu-",
f"CROSS_PREFIX={cross_prefix}",
f"{bin}",
] + extra_make_args

Expand Down Expand Up @@ -140,6 +141,7 @@ def test_schemes(
process_result,
force_qemu,
verbose,
cross_prefix,
run_as_root=False,
exec_wrapper=None,
extra_make_envs={},
Expand All @@ -157,7 +159,7 @@ def test_schemes(
results = {}
for scheme in SCHEME:
bin = scheme2file(scheme)
base_compile(bin, verbose, extra_make_envs, extra_make_args)
base_compile(bin, verbose, cross_prefix, extra_make_envs, extra_make_args)
result = base_run(
bin,
force_qemu,
Expand Down Expand Up @@ -239,6 +241,14 @@ _shared_options = [
type=bool,
help="Show verbose output or not",
),
click.option(
"-cp",
"--cross-prefix",
show_default=True,
default="aarch64-unknown-linux-gnu-",
nargs=1,
help="Cross prefix for compilation on non-aarch64 machines",
),
potsrevennil marked this conversation as resolved.
Show resolved Hide resolved
click.option(
"--cflags",
nargs=1,
Expand Down Expand Up @@ -267,7 +277,7 @@ def add_options(options):
type=click.Path(),
help="The binary file that you wanted to test.",
)
def run(bin, force_qemu, verbose, cflags, arch_flags):
def run(bin, force_qemu, verbose, cross_prefix, cflags, arch_flags):
config_logger(verbose)

base_compile(bin, verbose, process_make_envs(cflags, arch_flags))
Expand All @@ -284,7 +294,7 @@ def run(bin, force_qemu, verbose, cflags, arch_flags):
context_settings={"show_default": True},
)
@add_options(_shared_options)
def func(force_qemu, verbose, cflags, arch_flags):
def func(force_qemu, verbose, cross_prefix, cflags, arch_flags):
config_logger(verbose)

def expect(scheme):
Expand All @@ -306,6 +316,7 @@ def func(force_qemu, verbose, cflags, arch_flags):
process_test,
force_qemu,
verbose,
cross_prefix,
process_make_envs(cflags, arch_flags),
)

Expand All @@ -315,7 +326,7 @@ def func(force_qemu, verbose, cflags, arch_flags):
context_settings={"show_default": True},
)
@add_options(_shared_options)
def nistkat(force_qemu, verbose, cflags, arch_flags):
def nistkat(force_qemu, verbose, cross_prefix, cflags, arch_flags):
config_logger(verbose)

test_schemes(
Expand All @@ -326,6 +337,7 @@ def nistkat(force_qemu, verbose, cflags, arch_flags):
process_test,
force_qemu,
verbose,
cross_prefix,
process_make_envs(cflags, arch_flags),
)

Expand All @@ -335,7 +347,7 @@ def nistkat(force_qemu, verbose, cflags, arch_flags):
context_settings={"show_default": True},
)
@add_options(_shared_options)
def kat(force_qemu, verbose, cflags, arch_flags):
def kat(force_qemu, verbose, cross_prefix, cflags, arch_flags):
config_logger(verbose)

test_schemes(
Expand All @@ -346,6 +358,7 @@ def kat(force_qemu, verbose, cflags, arch_flags):
process_test,
force_qemu,
verbose,
cross_prefix,
process_make_envs(cflags, arch_flags),
)

Expand Down Expand Up @@ -398,6 +411,7 @@ def bench(
force_qemu,
verbose,
cycles,
cross_prefix,
cflags,
arch_flags,
output,
Expand All @@ -422,6 +436,7 @@ def bench(
process_bench,
force_qemu,
verbose,
cross_prefix,
run_as_root,
exec_wrapper,
process_make_envs(cflags, arch_flags),
Expand Down