From 4962757cb4ea197dde32fd7fd3bc03ed8accae82 Mon Sep 17 00:00:00 2001 From: STEVAN Antoine <antoine.stevan@isae-supaero.fr> Date: Thu, 3 Apr 2025 10:10:38 +0000 Subject: [PATCH] use `gitlab.isae-supaero.fr:a.stevan/nob.rs` to build (dragoon/komodo!202) that's an attempt at using Rust to build itself. this is using [`gitlab.isae-supaero.fr:a.stevan/nob.rs@e4b03cdd4f1ba9daf3095930911b12fb28b6a248`](https://gitlab.isae-supaero.fr/a.stevan/nob.rs/-/commit/e4b03cdd4f1ba9daf3095930911b12fb28b6a248). > :bulb: **Note** > > to be honest, this is not a 100% replacement of the `Makefile`... > > `make.rs` does a lot more and provides a full CLI with easy-to-use options, e.g. instead of `make fmt` and `make fmt-check`, we now have `./make.rs fmt` and `./make.rs fmt --check` > > (see the API below) ## the API ``` Usage: make [OPTIONS] [COMMAND] Commands: fmt Formats the code check Checks the code clippy Runs Clippy test Runs the tests version Shows the version of all the tools used, doc Builds the documentation help Print this message or the help of the given subcommand(s) Options: -h, --help Print help -V, --version Print version ``` ``` Usage: make fmt [OPTIONS] Options: -c, --check Only checks instead of really formatting ``` ``` Usage: make check ``` ``` Usage: make clippy ``` ``` Usage: make test [OPTIONS] Options: -v, --verbose Be extra verbose with the output of the tests -e, --examples Run the examples instead of regular tests ``` ``` Usage: make version ``` ``` Usage: make doc [OPTIONS] Options: -o, --open Open the documentation in the browser -p, --private Document private items -f, --features Document all features ``` ## running the pipeline in the GitHub mirror ```bash const GH_API_OPTIONS = [ -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" ] let res = gh api ...$GH_API_OPTIONS /repos/dragoon-rs/komodo/actions/runs | from json ``` ```bash let runs = $res.workflow_runs | where head_branch == "use-nob-to-build" | select id head_sha status conclusion run_started_at | into datetime run_started_at | sort-by run_started_at ``` ```bash $runs | update id { $"[`($in)`]\(https://github.com/($GITHUB_MIRROR)/actions/runs/($in)\)" } | update run_started_at { format date "%Y-%m-%dT%H:%M:%S" } | to md --pretty ``` | id | head_sha | status | conclusion | run_started_at | | ------------------------------------------------------------------------------ | ---------------------------------------- | --------- | ---------- | ------------------- | | [`14237650542`](https://github.com/dragoon-rs/komodo/actions/runs/14237650542) | d67f1cfd3b772a7858512a24261a0725e1d80e1c | completed | success | 2025-04-03T07:44:14 | | [`14237741570`](https://github.com/dragoon-rs/komodo/actions/runs/14237741570) | 9ef598a17f1997e37be81b2c153e0c8b40338441 | completed | success | 2025-04-03T07:49:40 | | [`14238086977`](https://github.com/dragoon-rs/komodo/actions/runs/14238086977) | 0a79edf36f825a76696ba0ae7370426b8c804b41 | completed | success | 2025-04-03T08:09:13 | | [`14238175174`](https://github.com/dragoon-rs/komodo/actions/runs/14238175174) | a84b2b12cec87a9b4ba008007b9269970183b78c | completed | success | 2025-04-03T08:13:52 | | [`14239395984`](https://github.com/dragoon-rs/komodo/actions/runs/14239395984) | 8594c9bfcf33111449ac14d8d424671293ea22d2 | completed | success | 2025-04-03T09:16:00 | --- .github/workflows/ci.yml | 14 ++++- .gitlab-ci.yml | 12 ++-- Makefile | 44 -------------- README.md | 8 +-- make.rs | 123 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 145 insertions(+), 56 deletions(-) delete mode 100644 Makefile create mode 100755 make.rs diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 15af260b..a3326b97 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,8 +17,12 @@ jobs: uses: actions-rs/toolchain@v1 with: toolchain: stable + - name: Install dependencies + run: | + cargo install cargo-script - name: Run fmt check - run: make fmt-check + run: | + ./make.rs fmt --check test: runs-on: ubuntu-latest @@ -31,8 +35,12 @@ jobs: sudo apt update --yes sudo apt upgrade --yes sudo apt install protobuf-compiler --yes + cargo install cargo-script - name: Show configuration - run: make show + run: | + ./make.rs version - name: Run tests run: | - make check clippy test + ./make.rs check + ./make.rs clippy + ./make.rs test diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a1720e8a..d44462d5 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -16,9 +16,10 @@ workflow: fmt: stage: fmt - + before_script: + - cargo install cargo-script script: - - make fmt-check + - ./make.rs fmt --check test: stage: test @@ -28,7 +29,10 @@ test: - apt update --yes - apt upgrade --yes - apt install protobuf-compiler --yes - - make show + - cargo install cargo-script + - ./make.rs version script: - - make check clippy test + - ./make.rs check + - ./make.rs clippy + - ./make.rs test diff --git a/Makefile b/Makefile deleted file mode 100644 index c9913f05..00000000 --- a/Makefile +++ /dev/null @@ -1,44 +0,0 @@ -DEFAULT_GOAL: fmt-check check clippy test - -.PHONY: fmt-check -fmt-check: - cargo fmt --all -- --check - -.PHONY: fmt -fmt: - cargo fmt --all - -.PHONY: check -check: - cargo check --workspace --all-targets - cargo check --workspace --all-targets --features kzg - cargo check --workspace --all-targets --features aplonk - cargo check --workspace --all-targets --all-features - -.PHONY: clippy -clippy: - cargo clippy --workspace --all-targets --all-features -- -D warnings - -.PHONY: test -test: - cargo test --workspace --verbose --all-features - cargo test --examples --verbose - -.PHONY: show -show: - @rustup --version 2> /dev/null - @rustup show active-toolchain - @rustc --version - @cargo --version - @cargo clippy --version - -.PHONY: doc -doc: - RUSTDOCFLAGS="--html-in-header katex.html" cargo doc --no-deps --open - -.PHONY: build-examples -build-examples: - cargo build --examples --release - -print-%: - @echo $($*) diff --git a/README.md b/README.md index f309ec76..2f9badd5 100644 --- a/README.md +++ b/README.md @@ -11,11 +11,9 @@ see `cargo doc` or [the library itself](src/) ## the tests ```shell -make -``` -or -```shell -make check clippy test +./make.rs check +./make.rs clippy +./make.rs test ``` Other examples that showcase the Komodo API are available in [`examples/`](examples/). diff --git a/make.rs b/make.rs new file mode 100755 index 00000000..6fa31a67 --- /dev/null +++ b/make.rs @@ -0,0 +1,123 @@ +#!/usr/bin/env run-cargo-script +//! ```cargo +//! [package] +//! name = "komodo-make" +//! version = "1.0.0" +//! edition = "2021" +//! +//! [dependencies] +//! nob = { git = "https://gitlab.isae-supaero.fr/a.stevan/nob.rs", rev = "e4b03cdd4f1ba9daf3095930911b12fb28b6a248" } +//! clap = { version = "4.5.17", features = ["derive"] } +//! ``` +extern crate clap; + +use clap::{Parser, Subcommand}; + +#[derive(Parser)] +#[command(version, about, long_about = None)] +struct Cli { + #[command(subcommand)] + command: Option<Commands>, +} + +#[derive(Subcommand)] +enum Commands { + /// Formats the code. + Fmt { + /// Only checks instead of really formatting. + #[arg(short, long)] + check: bool, + }, + /// Checks the code. + Check, + /// Runs Clippy. + Clippy, + /// Runs the tests. + Test { + /// Be extra verbose with the output of the tests. + #[arg(short, long)] + verbose: bool, + /// Run the examples instead of regular tests. + #[arg(short, long)] + examples: bool, + }, + /// Shows the version of all the tools used, + Version, + /// Builds the documentation + Doc { + /// Open the documentation in the browser. + #[arg(short, long)] + open: bool, + /// Document private items. + #[arg(short, long)] + private: bool, + /// Document all features. + #[arg(short, long)] + features: bool, + }, +} + +#[rustfmt::skip] +fn main() { + let cli = Cli::parse(); + + match &cli.command { + Some(Commands::Fmt { check }) => { + if *check { + nob::run_cmd_and_fail!("cargo", "fmt", "--all", "--", "--check"); + } else { + nob::run_cmd_and_fail!("cargo", "fmt", "--all"); + } + } + Some(Commands::Check) => { + nob::run_cmd_and_fail!("cargo", "check", "--workspace", "--all-targets"); + nob::run_cmd_and_fail!("cargo", "check", "--workspace", "--all-targets", "--features", "kzg"); + nob::run_cmd_and_fail!("cargo", "check", "--workspace", "--all-targets", "--features", "aplonk"); + nob::run_cmd_and_fail!("cargo", "check", "--workspace", "--all-targets", "--all-features"); + } + Some(Commands::Clippy) => { + nob::run_cmd_and_fail!( + "cargo", + "clippy", + "--workspace", + "--all-targets", + "--all-features", + "--", + "-D", + "warnings" + ) + } + Some(Commands::Test { verbose, examples }) => { + let mut cmd = vec!["cargo", "test"]; + + if *verbose { cmd.push("--verbose") } + if *examples { + cmd.push("--examples"); + } else { + cmd.push("--workspace"); + cmd.push("--all-features"); + } + + nob::run_cmd_as_vec_and_fail!(cmd); + } + Some(Commands::Version) => { + nob::run_cmd_and_fail!(@"rustup", "--version", "2>", "/dev/null"); + nob::run_cmd_and_fail!(@"rustup", "show", "active-toolchain"); + nob::run_cmd_and_fail!(@"rustc", "--version"); + nob::run_cmd_and_fail!(@"cargo", "--version"); + nob::run_cmd_and_fail!(@"cargo", "clippy", "--version"); + } + Some(Commands::Doc { + open, + private, + features, + }) => { + let mut cmd = vec!["cargo", "doc", "--no-deps"]; + if *open { cmd.push("--open") } + if *private { cmd.push("--document-private-items") } + if *features { cmd.push("--all-features") } + nob::run_cmd_as_vec_and_fail!(cmd ; "RUSTDOCFLAGS" => "--html-in-header katex.html"); + }, + None => {} + } +} -- GitLab