SHELL:=$(shell /usr/bin/env which bash) RS_CHECK_TOOLCHAIN:=$(shell cat toolchain.txt | tr -d '\n') CARGO_RS_CHECK_TOOLCHAIN:=+$(RS_CHECK_TOOLCHAIN) RS_BUILD_TOOLCHAIN:=stable CARGO_RS_BUILD_TOOLCHAIN:=+$(RS_BUILD_TOOLCHAIN) MIN_RUST_VERSION:=1.65 AVX512_SUPPORT?=OFF # This is done to avoid forgetting it, we still precise the RUSTFLAGS in the commands to be able to # copy paste the command in the terminal and change them if required without forgetting the flags export RUSTFLAGS?=-C target-cpu=native ifeq ($(AVX512_SUPPORT),ON) AVX512_FEATURE=nightly else AVX512_FEATURE= endif .PHONY: rs_check_toolchain # Echo the rust toolchain used for checks rs_check_toolchain: @echo $(RS_CHECK_TOOLCHAIN) .PHONY: rs_build_toolchain # Echo the rust toolchain used for builds rs_build_toolchain: @echo $(RS_BUILD_TOOLCHAIN) .PHONY: install_rs_check_toolchain # Install the toolchain used for checks install_rs_check_toolchain: @rustup toolchain list | grep -q "$(RS_CHECK_TOOLCHAIN)" || \ rustup toolchain install --profile default "$(RS_CHECK_TOOLCHAIN)" || \ ( echo "Unable to install $(RS_CHECK_TOOLCHAIN) toolchain, check your rustup installation. \ Rustup can be downloaded at https://rustup.rs/" && exit 1 ) .PHONY: install_rs_build_toolchain # Install the toolchain used for builds install_rs_build_toolchain: @( rustup toolchain list | grep -q "$(RS_BUILD_TOOLCHAIN)" && \ ./scripts/check_cargo_min_ver.sh \ --rust-toolchain "$(CARGO_RS_BUILD_TOOLCHAIN)" \ --min-rust-version "$(MIN_RUST_VERSION)" ) || \ rustup toolchain install --profile default "$(RS_BUILD_TOOLCHAIN)" || \ ( echo "Unable to install $(RS_BUILD_TOOLCHAIN) toolchain, check your rustup installation. \ Rustup can be downloaded at https://rustup.rs/" && exit 1 ) .PHONY: fmt # Format rust code fmt: install_rs_check_toolchain cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" fmt .PHONY: check_fmt # Check rust code format check_fmt: install_rs_check_toolchain cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" fmt --check .PHONY: clippy # Run clippy lints clippy: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \ -- --no-deps -D warnings @# nightly RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \ --features=nightly -- --no-deps -D warnings @# no-std RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \ --no-default-features -- --no-deps -D warnings @# no-std nightly RUSTFLAGS="$(RUSTFLAGS)" cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" clippy --all-targets \ --no-default-features --features=nightly -- --no-deps -D warnings .PHONY: build build: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --release .PHONY: build_no_std build_no_std: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) build --release \ --no-default-features .PHONY: build_bench build_bench: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench \ --no-run .PHONY: test test: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --release .PHONY: test_nightly test_nightly: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) test --release \ --features=nightly .PHONY: test_no_std test_no_std: install_rs_build_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_BUILD_TOOLCHAIN) test --release \ --no-default-features .PHONY: test_no_std_nightly test_no_std_nightly: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) test --release \ --no-default-features \ --features=nightly .PHONY: test_all test_all: test test_nightly test_no_std test_no_std_nightly .PHONY: doc # Build rust doc doc: install_rs_check_toolchain RUSTDOCFLAGS="--html-in-header katex-header.html -Dwarnings" \ cargo "$(CARGO_RS_CHECK_TOOLCHAIN)" doc --no-deps .PHONY: bench # Run benchmarks bench: install_rs_check_toolchain RUSTFLAGS="$(RUSTFLAGS)" cargo $(CARGO_RS_CHECK_TOOLCHAIN) bench --bench ntt \ --features=$(AVX512_FEATURE) .PHONY: pcc # pcc stands for pre commit checks pcc: check_fmt doc clippy .PHONY: conformance # Automatically fix problems that can be fixed conformance: fmt .PHONY: help # Generate list of targets with descriptions help: @grep '^\.PHONY: .* #' Makefile | sed 's/\.PHONY: \(.*\) # \(.*\)/\1\t\2/' | expand -t30 | sort