Skip to content

Commit

Permalink
Remake ci (#145)
Browse files Browse the repository at this point in the history
* remake actions

* minor update

* fix

* fix

* fix doc test

* modify dependencies

* typos

* clippy

* clippy auxiliary

* clippy
  • Loading branch information
serendipity-crypto authored Sep 1, 2024
1 parent 315bb52 commit 15caa7e
Show file tree
Hide file tree
Showing 46 changed files with 647 additions and 572 deletions.
219 changes: 141 additions & 78 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,103 +1,166 @@
name: Rust
env:
# We aim to always test with the latest stable Rust toolchain, however we pin to a specific
# version like 1.70. Note that we only specify MAJOR.MINOR and not PATCH so that bugfixes still
# come automatically. If the version specified here is no longer the latest stable version,
# then please feel free to submit a PR that adjusts it along with the potential clippy fixes.
RUST_STABLE_VER: "1.80" # In quotes because otherwise (e.g.) 1.70 would be interpreted as 1.7
# The purpose of checking with the minimum supported Rust toolchain is to detect its staleness.
# If the compilation fails, then the version specified here needs to be bumped up to reality.
# Be sure to also update the rust-version property in the workspace Cargo.toml file,
# plus all the README.md files of the affected packages.
RUST_MIN_VER: "1.79"
# List of packages that will be checked with the minimum supported Rust version.
# This should be limited to packages that are intended for publishing.
RUST_MIN_VER_PKGS: "-p algebra -p lattice -p fhe_core -p zkfhe"
CARGO_TERM_COLOR: always

name: CI

on:
workflow_dispatch:
push:
branches: ["main"]
pull_request:
branches: ["main"]

env:
CARGO_TERM_COLOR: always
merge_group:
# We run on push, even though the commit is the same as when we ran in merge_group.
# This allows the cache to be primed.
# See https://github.com/orgs/community/discussions/66430
push:
branches:
- main

jobs:
compatibility_check:
name: Check with compatibility requirement
fmt:
name: formatting
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master

- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable 6 months ago
components: rustfmt, clippy
# - uses: Swatinem/rust-cache@v2
- run: cargo fmt --all --check
- run: cargo check --workspace --all-targets --no-default-features --features="count_ntt"
- run: cargo check --workspace --all-targets --no-default-features --features="concrete-ntt"
- run: cargo clippy --no-deps --all-targets --no-default-features --features="count_ntt" -- -D warnings
- run: cargo clippy --no-deps --all-targets --no-default-features --features="concrete-ntt" -- -D warnings

# check:
# name: Basic check
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v4
# - uses: dtolnay/rust-toolchain@stable
# with:
# components: rustfmt, clippy
# # - uses: Swatinem/rust-cache@v2
# - run: cargo fmt --all --check
# - run: cargo check --workspace --all-targets --no-default-features --features="count_ntt"
# - run: cargo clippy --no-deps --all-targets --no-default-features --features="count_ntt" -- -D warnings
toolchain: ${{ env.RUST_STABLE_VER }}
components: rustfmt

doc:
name: Document
runs-on: ubuntu-latest
- name: cargo fmt
run: cargo fmt --all --check

clippy-stable:
name: cargo clippy
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
# - uses: Swatinem/rust-cache@v2
- run: cargo test --workspace --doc --features="count_ntt concrete-ntt"
- run: cargo doc --no-deps --workspace --lib --document-private-items --no-default-features --features="count_ntt concrete-ntt"

test:
- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}

- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
components: clippy

- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack

- name: cargo clippy
run: cargo hack clippy --workspace --each-feature --skip nightly --optional-deps -- -D warnings

- name: cargo clippy (auxiliary)
run: cargo hack clippy --workspace --each-feature --skip nightly --optional-deps --tests --benches --examples -- -D warnings

test-stable:
name: cargo test
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
# os: [ubuntu-latest]
name: Test
runs-on: ${{ matrix.os }}
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@master
# We intentionally do not use lfs: true here, instead using the caching method to save LFS bandwidth.

- name: restore cache
uses: Swatinem/rust-cache@v2
with:
toolchain: stable 6 months ago
# - uses: Swatinem/rust-cache@v2
- run: cargo test --workspace --lib --bins --tests --examples --no-default-features --features="count_ntt"
- run: cargo test --workspace --lib --bins --tests --examples --no-default-features --features="concrete-ntt"
save-if: ${{ github.event_name != 'merge_group' }}

build:
- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}

- name: Install cargo-nextest
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest

- name: cargo test
run: cargo nextest run --workspace --no-default-features

- name: cargo test
run: cargo nextest run --workspace

check-msrv:
name: cargo check (msrv)
runs-on: ${{ matrix.os }}
strategy:
matrix:
platform:
- os: ubuntu-latest
target: x86_64-unknown-linux-gnu
command: build

- os: windows-latest
target: x86_64-pc-windows-msvc
command: build

# - os: macos-latest
# target: x86_64-apple-darwin
# command: build

# - os: ubuntu-latest
# target: aarch64-unknown-linux-gnu
# command: build

- os: macos-latest
target: aarch64-apple-darwin
command: build
name: Build
runs-on: ${{ matrix.platform.os }}
os: [windows-latest, macos-latest, ubuntu-latest]
steps:
- uses: actions/checkout@v4

- name: restore cache
uses: Swatinem/rust-cache@v2
with:
save-if: ${{ github.event_name != 'merge_group' }}

- name: install msrv toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_MIN_VER }}

- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack

- name: cargo check
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --each-feature --skip nightly --optional-deps

doc:
name: cargo doc
# NOTE: We don't have any platform specific docs in this workspace, so we only run on Ubuntu.
# If we get per-platform docs (win/macos/linux/wasm32/..) then doc jobs should match that.
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build binary
uses: houseabsolute/actions-rust-cross@v0

- name: restore cache
uses: Swatinem/rust-cache@v2
with:
command: ${{ matrix.platform.command }}
target: ${{ matrix.platform.target }}
# args: "--locked --release"
# strip: true
- uses: Swatinem/rust-cache@v2
save-if: ${{ github.event_name != 'merge_group' }}

- name: install nightly toolchain
uses: dtolnay/rust-toolchain@nightly

- name: cargo test doc
run: cargo test --doc --workspace --all-features

# We test documentation using nightly to match docs.rs. This prevents potential breakages
- name: cargo doc
run: cargo doc --workspace --no-default-features --features="count_ntt concrete-ntt" --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples

# If this fails, consider changing your text or adding something to .typos.toml
typos:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: check typos
uses: crate-ci/[email protected]
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ once_cell = "1.19"
rand = "0.8"
rand_distr = "0.4"
rand_core = "0.6.4"
rand_chacha = "0.3.1"
rayon = "1"
bytemuck = { version = "1.16", features = ["derive"] }
bytemuck = { version = "1.17", features = ["derive"] }
merlin = { version = "3.0.0", default-features = false }
serde = { version = "1.0", features = ["derive"] }
bincode = "1.3"
itertools = "0.13.0"
sha2 = { version = "0.10.8" }
itertools = "0.13"
sha2 = { version = "0.10" }

criterion = "0.5"

Expand Down
6 changes: 3 additions & 3 deletions algebra/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ thiserror = { workspace = true }
num-traits = { workspace = true }
once_cell = { workspace = true }
rand = { workspace = true }
rand_core = { workspace = true }
rand_distr = { workspace = true }
bytemuck = { workspace = true }
rand_core = { workspace = true }
merlin = { workspace = true }
serde = { workspace = true }
bincode = { workspace = true }
concrete-ntt = { git = "https://github.com/pado-labs/concrete-ntt", branch = "main", optional = true }
itertools = "0.13.0"
itertools = { workspace = true }

[features]
default = ["concrete-ntt"]
Expand All @@ -29,7 +29,7 @@ count_ntt = []

[dev-dependencies]
criterion = { workspace = true }
rand_chacha = "0.3.1"
rand_chacha = { workspace = true }

[[bench]]
name = "ntt_bench"
Expand Down
2 changes: 1 addition & 1 deletion algebra/src/field/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub trait DecomposableField: Field {
/// A trait defined for specific fields used and optimized for FHE.
pub trait FheField: DecomposableField {
/// Creates a new instance.
/// Can be overloaded with optimized implemetation.
/// Can be overloaded with optimized implementation.
#[inline]
fn lazy_new(value: Self::Value) -> Self {
Self::new(value)
Expand Down
2 changes: 1 addition & 1 deletion algebra/src/field/ntt_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub trait NTTField: PrimeField + FheField + From<usize> {

/// Try to get the minimal primitive `degree`-th root of unity reduce `p`.
///
/// For ease of introduction we use `n` for `degreee` and `p` for prime number.
/// For ease of introduction we use `n` for `degree` and `p` for prime number.
///
/// Let `n` be a power of 2 and `p` a prime with `p ≡ 1 (mod 2n)`.
///
Expand Down
20 changes: 10 additions & 10 deletions algebra/src/modulus/barrett/internal_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ macro_rules! impl_barrett_modulus {
impl $crate::reduce::LazyReduce<BarrettModulus<Self>> for $SelfT {
type Output = Self;

/// Caculates `self (mod 2*modulus)`.
/// Calculates `self (mod 2*modulus)`.
///
/// ## Procedure
///
Expand Down Expand Up @@ -133,7 +133,7 @@ macro_rules! impl_barrett_modulus {
impl $crate::reduce::Reduce<BarrettModulus<Self>> for $SelfT {
type Output = Self;

/// Caculates `self (mod 2*modulus)`.
/// Calculates `self (mod 2*modulus)`.
///
/// ## Procedure
///
Expand Down Expand Up @@ -173,7 +173,7 @@ macro_rules! impl_barrett_modulus {
impl $crate::reduce::LazyReduce<BarrettModulus<$SelfT>> for [$SelfT; 2] {
type Output = $SelfT;

/// Caculates `self (mod 2*modulus)`.
/// Calculates `self (mod 2*modulus)`.
///
/// ## Procedure
///
Expand Down Expand Up @@ -237,7 +237,7 @@ macro_rules! impl_barrett_modulus {
impl $crate::reduce::Reduce<BarrettModulus<$SelfT>> for [$SelfT; 2] {
type Output = $SelfT;

/// Caculates `self (mod modulus)`.
/// Calculates `self (mod modulus)`.
///
/// ## Procedure
///
Expand Down Expand Up @@ -277,7 +277,7 @@ macro_rules! impl_barrett_modulus {
impl $crate::reduce::LazyReduce<BarrettModulus<$SelfT>> for ($SelfT, $SelfT) {
type Output = $SelfT;

/// Caculates `self (mod 2*modulus)`.
/// Calculates `self (mod 2*modulus)`.
///
/// ## Procedure
///
Expand Down Expand Up @@ -341,7 +341,7 @@ macro_rules! impl_barrett_modulus {
impl $crate::reduce::Reduce<BarrettModulus<$SelfT>> for ($SelfT, $SelfT) {
type Output = $SelfT;

/// Caculates `self (mod modulus)`.
/// Calculates `self (mod modulus)`.
///
/// ## Procedure
///
Expand Down Expand Up @@ -381,7 +381,7 @@ macro_rules! impl_barrett_modulus {
impl $crate::reduce::LazyReduce<BarrettModulus<$SelfT>> for &[$SelfT] {
type Output = $SelfT;

/// Caculates `self (mod 2*modulus)` when value's length > 0.
/// Calculates `self (mod 2*modulus)` when value's length > 0.
fn lazy_reduce(self, modulus: BarrettModulus<$SelfT>) -> Self::Output {
match self {
&[] => unreachable!(),
Expand All @@ -402,7 +402,7 @@ macro_rules! impl_barrett_modulus {
impl $crate::reduce::Reduce<BarrettModulus<$SelfT>> for &[$SelfT] {
type Output = $SelfT;

/// Caculates `self (mod modulus)` when value's length > 0.
/// Calculates `self (mod modulus)` when value's length > 0.
fn reduce(self, modulus: BarrettModulus<$SelfT>) -> Self::Output {
match self {
&[] => unreachable!(),
Expand All @@ -421,7 +421,7 @@ macro_rules! impl_barrett_modulus {
}

impl $crate::reduce::LazyReduceAssign<BarrettModulus<Self>> for $SelfT {
/// Caculates `self (mod 2*modulus)`.
/// Calculates `self (mod 2*modulus)`.
///
/// ## Procedure
///
Expand Down Expand Up @@ -453,7 +453,7 @@ macro_rules! impl_barrett_modulus {
}

impl $crate::reduce::ReduceAssign<BarrettModulus<Self>> for $SelfT {
/// Caculates `self (mod modulus)`.
/// Calculates `self (mod modulus)`.
///
/// ## Procedure
///
Expand Down
Loading

0 comments on commit 15caa7e

Please sign in to comment.