Skip to content

Commit 5c48b21

Browse files
committed
chore(lint): add a lint to generate a json file with all enum, struct and upgrade information hashed
1 parent ba11c7e commit 5c48b21

31 files changed

+6980
-72
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# Check that committed backward compatibility snapshots are up to date
2+
name: aws_tfhe_backward_compat_schema
3+
4+
env:
5+
CARGO_TERM_COLOR: always
6+
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
7+
RUSTFLAGS: "-C target-cpu=native"
8+
RUST_BACKTRACE: "full"
9+
RUST_MIN_STACK: "8388608"
10+
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
11+
SLACK_ICON: https://pbs.twimg.com/profile_images/1274014582265298945/OjBKP9kn_400x400.png
12+
SLACK_USERNAME: ${{ secrets.BOT_USERNAME }}
13+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
14+
SLACKIFY_MARKDOWN: true
15+
PULL_REQUEST_MD_LINK: ""
16+
CHECKOUT_TOKEN: ${{ secrets.REPO_CHECKOUT_TOKEN || secrets.GITHUB_TOKEN }}
17+
18+
19+
on:
20+
# Allows you to run this workflow manually from the Actions tab as an alternative.
21+
workflow_dispatch:
22+
pull_request:
23+
24+
permissions:
25+
contents: read
26+
27+
# zizmor: ignore[concurrency-limits] only Zama organization members can trigger this workflow (via manual approval for PR from forks)
28+
29+
jobs:
30+
backward-compat-schema:
31+
name: aws_tfhe_backward_compat_schema/backward-compat-schema (bpr)
32+
if: (github.event_name == 'push' && github.repository == 'zama-ai/tfhe-rs') ||
33+
github.event_name != 'push'
34+
runs-on: "runs-on=${{ github.run_id }}/runner=cpu-small"
35+
concurrency:
36+
group: ${{ github.workflow_ref }}${{ github.ref == 'refs/heads/main' && github.sha || '' }}
37+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
38+
steps:
39+
- name: Checkout tfhe-rs
40+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
41+
with:
42+
persist-credentials: 'false'
43+
token: ${{ env.CHECKOUT_TOKEN }}
44+
45+
- name: Install nightly toolchain
46+
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # zizmor: ignore[stale-action-refs] this action doesn't create releases
47+
with:
48+
toolchain: nightly-2026-01-22
49+
components: llvm-tools-preview, rustc-dev
50+
51+
- name: Generate snapshots from current code
52+
run: |
53+
make backward-snapshot-head
54+
55+
- name: Check backward compatibility snapshots
56+
run: |
57+
make backward-snapshot-check
58+
59+
- name: Set pull-request URL
60+
if: ${{ failure() && github.event_name == 'pull_request' }}
61+
run: |
62+
echo "PULL_REQUEST_MD_LINK=[pull-request](${PR_BASE_URL}${PR_NUMBER}), " >> "${GITHUB_ENV}"
63+
env:
64+
PR_BASE_URL: ${{ vars.PR_BASE_URL }}
65+
PR_NUMBER: ${{ github.event.pull_request.number }}
66+
67+
- name: Slack Notification
68+
if: ${{ failure() || (cancelled() && github.event_name != 'pull_request') }}
69+
continue-on-error: true
70+
uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661
71+
env:
72+
SLACK_COLOR: ${{ job.status }}
73+
SLACK_MESSAGE: "Backward compatibility schema check finished with status: ${{ job.status }}. Snapshots may be outdated — run `make backward-snapshot-base` and commit. (${{ env.PULL_REQUEST_MD_LINK }}[action run](${{ env.ACTION_RUN_URL }}))"
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Check backward-compat snapshot consistency after push to main
2+
name: main_snapshot_change_check
3+
4+
env:
5+
CARGO_TERM_COLOR: always
6+
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
7+
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
8+
SLACK_ICON: https://pbs.twimg.com/profile_images/1274014582265298945/OjBKP9kn_400x400.png
9+
SLACK_USERNAME: ${{ secrets.BOT_USERNAME }}
10+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
11+
SLACKIFY_MARKDOWN: true
12+
13+
on:
14+
push:
15+
branches:
16+
- main
17+
paths:
18+
- 'utils/tfhe-lints/snapshots/lint_enum_snapshots_*_base.json'
19+
20+
permissions:
21+
contents: read
22+
23+
jobs:
24+
snapshot-change-check:
25+
name: main_snapshot_change_check/snapshot-change-check
26+
if: github.repository == 'zama-ai/tfhe-rs'
27+
runs-on: ubuntu-latest
28+
concurrency:
29+
group: ${{ github.workflow }}-${{ github.sha }}
30+
cancel-in-progress: false
31+
steps:
32+
- name: Checkout current commit
33+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
34+
with:
35+
persist-credentials: 'false'
36+
37+
- name: Install nightly toolchain
38+
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # zizmor: ignore[stale-action-refs]
39+
with:
40+
toolchain: nightly-2026-01-22
41+
components: llvm-tools-preview, rustc-dev
42+
43+
- name: Generate head snapshots
44+
run: |
45+
make backward-snapshot-head
46+
47+
- name: Check snapshot consistency
48+
run: |
49+
./scripts/check_snapshot_consistency.sh
50+
51+
- name: Slack Notification
52+
if: ${{ failure() || cancelled() }}
53+
continue-on-error: true
54+
uses: rtCamp/action-slack-notify@e31e87e03dd19038e411e38ae27cbad084a90661
55+
env:
56+
SLACK_COLOR: ${{ job.status }}
57+
SLACK_MESSAGE: "Backward compatibility snapshot consistency check finished with status: ${{ job.status }} on commit [`${{ github.sha }}`](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}) by ${{ github.actor }}. Snapshots may be outdated — run `make backward-snapshot-base` and commit. ([action run](${{ env.ACTION_RUN_URL }}))"
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Warn on PR when backward-compat snapshot base files are modified
2+
name: pr_snapshot_change_warning
3+
4+
on:
5+
pull_request:
6+
paths:
7+
- 'utils/tfhe-lints/snapshots/lint_enum_snapshots_*_base.json'
8+
9+
permissions:
10+
contents: read
11+
12+
concurrency:
13+
group: ${{ github.workflow }}-${{ github.head_ref }}
14+
cancel-in-progress: true
15+
16+
jobs:
17+
snapshot-change-warning:
18+
name: pr_snapshot_change_warning/snapshot-change-warning
19+
runs-on: ubuntu-latest
20+
permissions:
21+
pull-requests: write # To send and modify message in the PR
22+
steps:
23+
- name: Checkout PR head
24+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
25+
with:
26+
persist-credentials: 'false'
27+
path: head
28+
29+
- name: Checkout base branch
30+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
31+
with:
32+
persist-credentials: 'false'
33+
ref: ${{ github.event.pull_request.base.sha }}
34+
path: base
35+
36+
- name: Install stable toolchain
37+
uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 # zizmor: ignore[stale-action-refs]
38+
with:
39+
toolchain: stable
40+
41+
- name: Generate diff report
42+
id: report
43+
working-directory: head
44+
run: |
45+
make backward-snapshot-generate HEAD_FILE=base
46+
47+
if [ -s ../report.md ]; then
48+
echo "has_report=true" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "has_report=false" >> "$GITHUB_OUTPUT"
51+
fi
52+
53+
- name: Find existing comment
54+
id: find-comment
55+
uses: peter-evans/find-comment@3eae4d37986fb5a8592848f6a574fdf654e61f9e # v3.1.0
56+
with:
57+
issue-number: ${{ github.event.pull_request.number }}
58+
body-includes: '**Backward-compat snapshot base files'
59+
60+
- name: Comment on PR
61+
if: steps.report.outputs.has_report == 'true'
62+
uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0
63+
with:
64+
comment-id: ${{ steps.find-comment.outputs.comment-id }}
65+
issue-number: ${{ github.event.pull_request.number }}
66+
body-path: report.md
67+
edit-mode: replace

.linelint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ ignore:
99
- tfhe/web_wasm_parallel_tests/dist
1010
- keys
1111
- coverage
12-
- utils/tfhe-lints/tests/*/main.stderr
12+
- utils/tfhe-lints/**/main.stderr
13+
- utils/tfhe-lints/**/*.json
1314
- utils/tfhe-backward-compat-data/**/*.ron # ron files are autogenerated
1415

1516
rules:

Cargo.toml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,28 @@
11
[workspace]
22
resolver = "3"
33
members = [
4+
"apps/test-vectors",
5+
"backends/tfhe-cuda-backend",
6+
"backends/tfhe-hpu-backend",
7+
"backends/zk-cuda-backend",
8+
"mockups/tfhe-hpu-mockup",
9+
"tasks",
10+
"tests",
411
"tfhe",
512
"tfhe-benchmark",
13+
"tfhe-csprng",
614
"tfhe-fft",
715
"tfhe-ntt",
816
"tfhe-zk-pok",
9-
"tasks",
10-
"tfhe-csprng",
11-
"backends/tfhe-cuda-backend",
12-
"backends/zk-cuda-backend",
13-
"backends/tfhe-hpu-backend",
14-
"utils/tfhe-versionable",
15-
"utils/tfhe-versionable-derive",
17+
"utils/param_dedup",
18+
"utils/tfhe-backward-compat-checker",
1619
"utils/tfhe-backward-compat-data",
1720
"utils/tfhe-backward-compat-data/crates/add_new_version",
18-
"utils/param_dedup",
21+
"utils/tfhe-versionable",
22+
"utils/tfhe-versionable-derive",
1923
"utils/wasm-par-mq",
20-
"utils/wasm-par-mq/web_tests",
2124
"utils/wasm-par-mq/examples/msm",
22-
"tests",
23-
"mockups/tfhe-hpu-mockup",
24-
"apps/test-vectors",
25+
"utils/wasm-par-mq/web_tests",
2526
]
2627

2728
exclude = ["utils/tfhe-lints", "apps/trivium"]
@@ -74,7 +75,10 @@ lto = "off"
7475
debug-assertions = false
7576

7677
[workspace.metadata.dylint]
77-
libraries = [{ path = "utils/tfhe-lints" }]
78+
libraries = [
79+
{ path = "utils/tfhe-lints/lints" },
80+
{ path = "utils/tfhe-lints/snapshot" },
81+
]
7882

7983
[profile.debug_lto_off]
8084
inherits = "dev"

Makefile

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ ZIZMOR_VERSION=1.22.0
3939
# copy paste the command in the terminal and change them if required without forgetting the flags
4040
export RUSTFLAGS?=-C target-cpu=native
4141

42+
include utils/tfhe-lints/Makefile
43+
4244
ifeq ($(GEN_KEY_CACHE_MULTI_BIT_ONLY),TRUE)
4345
MULTI_BIT_ONLY=--multi-bit-only
4446
else
@@ -609,10 +611,11 @@ check_rust_bindings_did_not_change:
609611

610612
.PHONY: tfhe_lints # Run custom tfhe-rs lints
611613
tfhe_lints: install_cargo_dylint
612-
RUSTFLAGS="$(RUSTFLAGS) -Dwarnings" cargo dylint --all -p tfhe --no-deps -- \
614+
RUSTFLAGS="$(RUSTFLAGS) -Dwarnings" cargo dylint --lib tfhe_lints -p tfhe --no-deps -- \
613615
--features=boolean,shortint,integer,strings,zk-pok
614-
RUSTFLAGS="$(RUSTFLAGS) -Dwarnings" cargo dylint --all -p tfhe-zk-pok --no-deps -- \
616+
RUSTFLAGS="$(RUSTFLAGS) -Dwarnings" cargo dylint --lib tfhe_lints -p tfhe-zk-pok --no-deps -- \
615617
--features=experimental
618+
RUSTFLAGS="$(RUSTFLAGS) -Dwarnings" cargo dylint --lib tfhe_lints -p tfhe-csprng --no-deps --
616619

617620
.PHONY: audit_dependencies # Run cargo audit to check vulnerable dependencies
618621
audit_dependencies: install_cargo_audit
@@ -2364,4 +2367,11 @@ bench_ntt: install_rs_check_toolchain
23642367

23652368
.PHONY: help # Generate list of targets with descriptions
23662369
help:
2367-
@grep '^\.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1\t\2/' | expand -t30 | sort
2370+
@find . \( -name 'Makefile' -o -name '*.mk' \) | sort | while read f; do \
2371+
matches=$$(grep '^\.PHONY: .* #' "$$f" || true); \
2372+
if [ -n "$$matches" ]; then \
2373+
echo ""; \
2374+
echo "--- $$f ---"; \
2375+
echo "$$matches" | sed 's/\.PHONY: \(.*\) # \(.*\)/\1\t\2/' | expand -t30 | sort; \
2376+
fi \
2377+
done
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
SNAPSHOT_DIR="utils/tfhe-lints/snapshots"
6+
7+
mismatch=0
8+
for head_file in "${SNAPSHOT_DIR}"/head/*_head.json; do
9+
base_name=$(basename "$head_file" | sed 's/_head\.json/_base.json/')
10+
base_file="${SNAPSHOT_DIR}/${base_name}"
11+
if [ ! -f "$base_file" ]; then
12+
echo "::error::Missing base snapshot: $base_file"
13+
mismatch=1
14+
continue
15+
fi
16+
if ! diff -q "$base_file" "$head_file" >/dev/null 2>&1; then
17+
echo "::error::Snapshot mismatch: $base_name"
18+
diff "$base_file" "$head_file" || true
19+
mismatch=1
20+
fi
21+
done
22+
23+
if [ "$mismatch" -ne 0 ]; then
24+
echo "::error::Snapshots are inconsistent — run 'make backward-snapshot-base' and commit."
25+
exit 1
26+
fi
27+
28+
echo "All snapshots are consistent."
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "tfhe-backward-compat-checker"
3+
version = "0.1.0"
4+
edition = "2024"
5+
rust-version.workspace = true
6+
7+
[dependencies]
8+
clap = { version = "4", features = ["derive"] }
9+
serde = { version = "1", features = ["derive"] }
10+
serde_json = "1"

0 commit comments

Comments
 (0)