Skip to content

Commit f59b6e9

Browse files
authored
Add reproducible build setup (#15)
* Add reproducible build setup * Fix CI * Skip unsupported LDFLAGS in macOS * Restore to latest LLVM * Fix typo * Yet another fix * Try using lld on macOS * Use lld linker * Update rust.yml macOS uses a different LLVM version, so we will skip the fmt part since different clang version might format the code differently * Fix description
1 parent 0a991f3 commit f59b6e9

File tree

4 files changed

+93
-4
lines changed

4 files changed

+93
-4
lines changed

.github/workflows/rust.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ jobs:
2323
- name: git diff
2424
run: git diff --exit-code
2525

26+
reproducible-build:
27+
28+
runs-on: ubuntu-latest
29+
30+
steps:
31+
- uses: actions/checkout@v4
32+
with:
33+
submodules: "true"
34+
- name: Reproducible build
35+
run: ./scripts/reproducible_build_docker
36+
2637
macos-build:
2738

2839
runs-on: macos-latest
@@ -34,7 +45,5 @@ jobs:
3445
- name: Install latest llvm & lld
3546
run: brew install llvm lld
3647
- uses: actions-rust-lang/setup-rust-toolchain@v1
37-
- name: Prepare, build, test, clippy, format
38-
run: make prepare build test clippy fmt
39-
- name: git diff
40-
run: git diff --exit-code
48+
- name: Prepare, build, test, clippy
49+
run: make prepare build test clippy

checksums.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
59a4c25e6185f906ba379db530fc08c1e1f8aa23db2bcb265a6ab321a0d5b527 build/release/c-sphincs-all-in-one-lock
2+
55fbe64ca9dfc17335ee9af56083dde6bbdf23c79a967d37805b8467b86d458e build/release/c-sphincs-all-in-one-lock.debug
3+
313f3122a5ad662a9f7cf81d18d3ec4fd3ba3ea5af43fb3ac405844731d6306a build/release/hybrid-sphincs-all-in-one-lock
4+
7cfd89954d36dc22381b3d5179eb7c75556abe8c576bf3551cdda3d5d60ace0d build/release/hybrid-sphincs-all-in-one-lock.debug
5+
67e27355b90b19e4768ef83d771d085aaee451942eb84c88f7383e23e7ec80ac build/release/nist-vector-tester
6+
a0999aac87383e8ac3191f6d9472d2e94b61e9077b1bcd00f510d6cf67e3ab7f build/release/nist-vector-tester.debug
7+
fb6448fc699653474620c041b0be05b0393b612a023221010f39a61c47c9102f build/release/spawn-exec-test-runner
8+
0ceeffed81973224e315953147012c3fe6a058f0f24c605fc53deefd7564d72b build/release/spawn-exec-test-runner.debug
9+
45946de1491b199b2975b6c7bff7a5149e384337db1ced7a366c9ef7299f0884 build/release/sphincs-all-in-one-lock
10+
6dadb87af0433b1045a5271f1efca6420e1408df6668498043ca3e2a91c37c54 build/release/sphincs-all-in-one-lock.debug

contracts/c-sphincs-all-in-one-lock/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ CFLAGS += --target=riscv64 -march=rv64imc_zba_zbb_zbc_zbs \
5050
CFLAGS += -I $(SPHINCS_PLUS_DIR) -I $(CUR_BUILD) -I $(cur_dir)/utils
5151
# CFLAGS += -DCKB_C_STDLIB_PRINTF
5252

53+
OS := $(shell uname -s)
5354
LDFLAGS := -static -Wl,--gc-sections
55+
ifeq ($(OS),Darwin)
56+
LDFLAGS += -fuse-ld=lld
57+
endif
5458

5559
default: build
5660

scripts/reproducible_build_docker

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
#
3+
# An utility script helping with reproducible script builds via docker.
4+
# Note that this utility serves only as one example, docker is not
5+
# necessarily THE way to do reproducible build, nor is it the best way
6+
# to do reproducible build.
7+
set -ex
8+
9+
DOCKER="${DOCKER:-docker}"
10+
# docker pull docker.io/cryptape/llvm-n-rust:20250617
11+
DOCKER_IMAGE="${DOCKER_IMAGE:-docker.io/cryptape/llvm-n-rust@sha256:d6d1f9a6656039273210de91913c828f5b4aa4a3282d2c93ed19bcb7bbf728fe}"
12+
CHECKSUM_FILE_PATH="${CHECKSUM_FILE_PATH:-checksums.txt}"
13+
14+
# We are parsing command line arguments based on tips from:
15+
# https://stackoverflow.com/a/14203146
16+
17+
while [[ $# -gt 0 ]]; do
18+
case $1 in
19+
-p|--proxy)
20+
PROXY="$2"
21+
shift # past argument
22+
shift # past value
23+
;;
24+
-u|--update)
25+
UPDATE="yes"
26+
shift # past argument
27+
;;
28+
--no-clean)
29+
NOCLEAN="yes"
30+
shift # past argument
31+
;;
32+
-*|--*)
33+
echo "Unknown option $1"
34+
exit 1
35+
;;
36+
*)
37+
echo "Unknown argument $1"
38+
exit 1
39+
;;
40+
esac
41+
done
42+
43+
if [[ -n "${PROXY}" ]]; then
44+
DOCKER_RUN_ARGS="-e ALL_PROXY=${PROXY} -e HTTPS_PROXY=${PROXY} -e HTTP_PROXY=${PROXY} ${DOCKER_RUN_ARGS}"
45+
fi
46+
47+
TASKS=""
48+
if [[ "${NOCLEAN}" != "yes" ]]; then
49+
TASKS+=" clean "
50+
fi
51+
52+
if [[ "${UPDATE}" = "yes" ]]; then
53+
TASKS+=" checksum CHECKSUM_FILE=${CHECKSUM_FILE_PATH} "
54+
else
55+
TASKS+=" build "
56+
fi
57+
58+
$DOCKER run --rm $DOCKER_RUN_ARGS -v `pwd`:/code $DOCKER_IMAGE make $TASKS
59+
# Reset file ownerships for all files docker might touch
60+
$DOCKER run --rm $DOCKER_RUN_ARGS -e UID=`id -u` -e GID=`id -g` -v `pwd`:/code $DOCKER_IMAGE bash -c 'chown -R -f $UID:$GID checksums.txt build target'
61+
62+
if [[ "${UPDATE}" = "yes" ]]; then
63+
echo "${CHECKSUM_FILE_PATH} file is updated with latest binary hashes!"
64+
else
65+
shasum -a 256 -c ${CHECKSUM_FILE_PATH}
66+
fi

0 commit comments

Comments
 (0)