From cb5d5f8fbb63d83ac13127e8df471b5be984f3d1 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 15:24:31 +0200 Subject: [PATCH 01/28] scripts: Convert run-checks script into a Rust binary --- scripts/run-checks.rs | 284 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 284 insertions(+) create mode 100644 scripts/run-checks.rs diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs new file mode 100644 index 0000000000..9930fedfa9 --- /dev/null +++ b/scripts/run-checks.rs @@ -0,0 +1,284 @@ +//! This script is run before a PR is created. +//! +//! It is used to check that the code compiles and passes all tests. +//! +//! It is also used to check that the code is formatted correctly and passes clippy. +//! +//! To build this script, run the following command: +//! +//! rustc scripts/run-checks.rs --crate-type bin --out-dir scripts +//! +//! To run the script: +//! +//! ./scripts/run-checks environment +//! +//! where `environment` can assume **ONLY** the following values: +//! - `std` to perform checks using `libstd` +//! - `no_std` to perform checks on an embedded environment using `libcore` +//! - `all` to perform checks using both `libstd` and `libcore` + +use std::env; +use std::io::{self, Write}; +use std::process::{Command, Output}; +use std::str; +use std::time::Instant; + +// If stdout is not empty, write it, otherwise +// write stderr and exit with code error 1 +fn stdout_and_stderr_write(output: Output, message_stdout: &str, message_stderr: &str) { + if !output.stdout.is_empty() { + io::stdout() + .write_all(&output.stdout) + .expect(message_stdout); + } + + if !output.stderr.is_empty() { + io::stderr() + .write_all(&output.stderr) + .expect(message_stderr); + std::process::exit(1); + } +} + +// Run rustup command +fn rustup(target: &str) { + // Run rustup + let rustup = Command::new("rustup") + .args(["target", "add", target]) + .output() + .expect("Failed to run rustup"); + + // Write rustup output either on stdout or on stderr + stdout_and_stderr_write( + rustup, + "Failed to write rustup output on stdout", + "Failed to write rustup output on stderr", + ); +} + +// Run a cargo command +fn run_cargo(command: &str, params: &[&str], error: &str, stdout_error: &str, stderr_error: &str) { + // Run cargo + let cargo = Command::new("cargo") + .arg(command) + .args(params) + .output() + .expect(error); + + // Write cargo output either on stdout or on stderr + stdout_and_stderr_write(cargo, stdout_error, stderr_error); +} + +// Run cargo build command +fn cargo_build(params: &[&str]) { + // Run cargo build + run_cargo( + "build", + params, + "Failed to run cargo build", + "Failed to write cargo build output on stdout", + "Failed to write cargo build output on stderr", + ); +} + +// Run cargo test command +fn cargo_test(params: &[&str]) { + // Run cargo test + run_cargo( + "test", + params, + "Failed to run cargo test", + "Failed to write cargo test output on stdout", + "Failed to write cargo test output on stderr", + ); +} + +// Run cargo fmt command +fn cargo_fmt() { + // Run cargo fmt + run_cargo( + "fmt", + &["--check", "--all"], + "Failed to run cargo fmt", + "Failed to write cargo fmt output on stdout", + "Failed to write cargo fmt output on stderr", + ); +} + +// Run cargo clippy command +fn cargo_clippy() { + // Run cargo clippy + run_cargo( + "clippy", + &["--", "-D", "warnings"], + "Failed to run cargo clippy", + "Failed to write cargo clippy output on stdout", + "Failed to write cargo clippy output on stderr", + ); +} + +// Run cargo doc command +fn cargo_doc(params: &[&str]) { + // Run cargo doc + run_cargo( + "doc", + params, + "Failed to run cargo doc", + "Failed to write cargo doc output on stdout", + "Failed to write cargo doc output on stderr", + ); +} + +// Build and test a crate in a no_std environment +fn build_and_test_no_std(crate_name: &str) { + println!("\nRun checks for `{}` crate", crate_name); + + println!("\nBuild without defaults"); + // Run cargo build --no-default-features + cargo_build(&["-p", crate_name, "--no-default-features"]); + + println!("\nTest without defaults"); + // Run cargo test --no-default-features + cargo_test(&["-p", crate_name, "--no-default-features"]); + + println!("\nBuild for WebAssembly"); + // Run cargo build --no-default-features --target wasm32-unknown-unknowns + cargo_build(&[ + "-p", + crate_name, + "--no-default-features", + "--target", + "wasm32-unknown-unknowns", + ]); + + println!("\nBuild for ARM"); + // Run cargo build --no-default-features --target thumbv7m-none-eabi + cargo_build(&[ + "-p", + crate_name, + "--no-default-features", + "--target", + "thumbv7m-none-eabi", + ]); +} + +// Run no_std checks +fn no_std_checks() { + println!("Checks for no_std environment...\n\n"); + + println!("Install Wasm32 target\n"); + // Install wasm32 target + rustup("wasm32-unknown-unknown"); + + println!("\nInstall ARM target\n"); + // Install ARM target + rustup("thumbv7m-none-eabi"); + + // Run checks for the following crates + build_and_test_no_std("burn"); + build_and_test_no_std("burn-core"); + build_and_test_no_std("burn-common"); + build_and_test_no_std("burn-tensor"); + build_and_test_no_std("burn-ndarray"); + build_and_test_no_std("burn-no-std-tests"); +} + +// Test burn-core with tch and wgpu backend +fn burn_core_std() { + println!("\n\nRun checks for burn-core crate with tch and wgpu backend"); + + println!("\nTest with tch backend"); + // Run cargo test --features test-tch + cargo_test(&["-p", "burn-core", "--features", "test-tch"]); + + println!("\nTest with wgpu backend"); + // Run cargo test --features test-wgpu + cargo_test(&["-p", "burn-core", "--features", "test-wgpu"]); +} + +// Test burn-dataset features +fn burn_dataset_features_std() { + println!("\n\nRun checks for burn-dataset features"); + + println!("\nBuild with all features"); + // Run cargo build --all-features + cargo_build(&["-p", "burn-dataset", "--all-features"]); + + println!("\nTest with all features"); + // Run cargo test --all-features + cargo_test(&["-p", "burn-dataset", "--all-features"]); + + println!("\nCheck documentation with all features"); + // Run cargo doc --all-features + cargo_doc(&["-p", "burn-dataset", "--all-features"]); +} + +fn std_checks() { + // Set RUSTDOCFLAGS environment variable to treat warnings as errors + // for the documentation build + env::set_var("RUSTDOCFLAGS", "-D warnings"); + + println!("\n\nRunning std checks"); + + println!("\nBuild each workspace"); + // Build each workspace + cargo_build(&["--workspace"]); + + println!("\nTest each workspace"); + // Test each workspace + cargo_test(&["--workspace"]); + + println!("\nCheck format"); + // Check format + cargo_fmt(); + + println!("\nCheck clippy lints"); + // Check clippy lints + cargo_clippy(); + + println!("\nProduce documentation for each workspace"); + // Produce documentation for each workspace + cargo_doc(&["--workspace"]); + + // Test burn-dataset features + burn_dataset_features_std(); + + // Test burn-core with tch and wgpu backend + burn_core_std(); +} + +fn main() { + // Get the environment + let environment = env::args() + .nth(1) // Index of the first argument, because 0 is the binary name + .expect("You need to pass the environment as first argument!"); + + // Start time measurement + let start = Instant::now(); + + // The environment can assume ONLY "all", "std" and "no_std" as values. + // + // Depending on the input argument, the respective environment checks + // are run. + // + // If a wrong argument is passed, the program panics. + match environment.as_str() { + "all" => { + std_checks(); + no_std_checks(); + } + "std" => std_checks(), + "no_std" => no_std_checks(), + _ => { + panic!("You can pass only 'all', 'std' and 'no_std' as values for the first argument!") + } + } + + // Stop time measurement + // + // Compute runtime duration + let duration = start.elapsed(); + + // Print duration + println!("Time elapsed for the current execution: {:?}", duration); +} From a454043a7fba544cff931c5cb17620559a16df96 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 15:24:58 +0200 Subject: [PATCH 02/28] Remove shell script --- run-checks.sh | 144 -------------------------------------------------- 1 file changed, 144 deletions(-) delete mode 100755 run-checks.sh diff --git a/run-checks.sh b/run-checks.sh deleted file mode 100755 index d9269f05ba..0000000000 --- a/run-checks.sh +++ /dev/null @@ -1,144 +0,0 @@ -#!/bin/bash - -# This script is run before a PR is created. -# It is used to check that the code compiles and passes all tests. -# It is also used to check that the code is formatted correctly and passes clippy. - -# Usage: ./run-checks.sh {all|no_std|std} (default: all) - -# Exit immediately if a command exits with a non-zero status. -set -euo pipefail - -# Function to handle errors -error_handler() { - local exit_status=$? - local line_number=$1 - local command=$2 - - echo "Error on line $line_number" - echo "Command '$command' exited with status $exit_status" -} - -# Signal trap to call error_handler when a command fails -trap 'error_handler $LINENO $BASH_COMMAND' ERR - -# Function to build and test no_std -build_and_test_no_std() { - local dir=$1 - - echo "$dir" - cd $dir || exit - - echo "Build without defaults" - cargo build --no-default-features - - echo "Test without defaults" - cargo test --no-default-features - - echo "Build for WebAssembly" - cargo build --no-default-features --target wasm32-unknown-unknown - - echo "Build for ARM" - cargo build --no-default-features --target thumbv7m-none-eabi - - cd .. || exit -} - -# Function to build and test all features -build_and_test_all_features() { - local dir=$1 - - echo "$dir" - cd $dir || exit - - echo "Build with all defaults" - cargo build --all-features - - echo "Test with all features" - cargo test --all-features - - echo "Check documentation with all features" - cargo doc --all-features - - cd .. || exit -} - -# Set RUSTDOCFLAGS to treat warnings as errors for the documentation build -export RUSTDOCFLAGS="-D warnings" - -# Run the checks for std and all features with std -std_func() { - echo "Running std checks" - - cargo build --workspace - cargo test --workspace - cargo fmt --check --all - cargo clippy -- -D warnings - cargo doc --workspace - - # all features - echo "Running all-features checks" - build_and_test_all_features "burn-dataset" - - cd burn-core || exit - - echo "Test burn-core with tch backend" - cargo test --features test-tch - - echo "Test burn-core with wgpu backend" - cargo test --features test-wgpu - - cd .. || exit -} - -# Run the checks for no_std -no_std_func() { - echo "Running no_std checks" - - # Add wasm32 target for compiler. - rustup target add wasm32-unknown-unknown - rustup target add thumbv7m-none-eabi - - build_and_test_no_std "burn" - build_and_test_no_std "burn-core" - build_and_test_no_std "burn-common" - build_and_test_no_std "burn-tensor" - build_and_test_no_std "burn-ndarray" - build_and_test_no_std "burn-no-std-tests" -} - -# Save the script start time -start_time=$(date +%s) - -# If no arguments were supplied or if it's empty, set the default as 'all' -if [ -z "${1-}" ]; then - arg="all" -else - arg=$1 -fi - -# Check the argument and call the appropriate functions -case $arg in -all) - no_std_func - std_func - ;; -no_std) - no_std_func - ;; -std) - std_func - ;; -*) - echo "Error: Invalid argument" - echo "Usage: $0 {all|no_std|std}" - exit 1 - ;; -esac - -# Calculate and print the script execution time -end_time=$(date +%s) -execution_time=$((end_time - start_time)) -echo "Script executed in $execution_time seconds." - -exit 0 From 10037c6aea34908586986775fcc8a78541abcef3 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 15:25:16 +0200 Subject: [PATCH 03/28] misc: Improve README --- README.md | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5074f57497..510b32d33c 100644 --- a/README.md +++ b/README.md @@ -285,7 +285,29 @@ recommended to read our [architecture document](https://github.com/burn-rs/burn/tree/main/ARCHITECTURE.md), which explains our architectural decisions. Please see more details in our [contributing guide](/CONTRIBUTING.md). -## CI +## Continuous Integration + +### Run checks + +Compile `scripts/run-checks.rs` using this command + +``` +rustc scripts/run-checks.rs --crate-type bin --out-dir scripts +``` + +Run `scripts/run-checks` using this command + +``` +./scripts/run-checks environment +``` + +where `environment` can assume **ONLY** the following values: + +- `std` to perform checks using `libstd` +- `no_std` to perform checks on an embedded environment using `libcore` +- `all` to perform checks using both `libstd` and `libcore` + +## Continuous Deployment ### Publish crates @@ -295,6 +317,15 @@ Compile `scripts/publish.rs` using this command: rustc scripts/publish.rs --crate-type bin --out-dir scripts ``` +Run `scripts/publish` using this command + +``` +./scripts/publish crate_name +``` + +where `crate_name` is the name of the crate to publish + + ## Disclaimer Burn is currently in active development, and there will be breaking changes. While any resulting From c3f31e3066ca1f3f8b04fb496a3b44e2eb77ed65 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 15:26:58 +0200 Subject: [PATCH 04/28] misc: Make git ignore scripts binaries --- .gitignore | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index c97e4a4529..6802474234 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,8 @@ Cargo.lock .cargo/config.toml .idea -.vscode \ No newline at end of file +.vscode + +# Ignore binaries contained in the `scripts` directory +scripts/publish +scripts/run-checks From 6993fc546a18efd558965bf80b91eaf92437df4a Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 15:28:04 +0200 Subject: [PATCH 05/28] misc: Update pull request template --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index fe09f1173a..57cf32c708 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,7 +2,7 @@ ### Checklist -- [ ] Confirm that `run-checks.sh` has been executed. +- [ ] Confirm that `run-checks` has been executed. ### Related Issues/PRs From 151bb2f401bded9a58674c6b5a8e414b83cfd51d Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 15:32:59 +0200 Subject: [PATCH 06/28] ci: Use run-checks binary to run ci checks --- .github/workflows/test.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b30cd033e0..8c0c87b1bd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,9 @@ jobs: with: components: rustfmt, clippy + - name: compile run-checks binary + run: rustc scripts/run-checks.rs --crate-type bin --out-dir scripts + - name: caching uses: Swatinem/rust-cache@v2 with: @@ -40,7 +43,7 @@ jobs: sudo apt install -y libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers - name: run checks & tests - run: ./run-checks.sh std + run: ./scripts/run-checks std test-burn-no-std: runs-on: ubuntu-latest @@ -61,10 +64,13 @@ jobs: with: components: rustfmt, clippy + - name: compile run-checks binary + run: rustc scripts/run-checks.rs --crate-type bin --out-dir scripts + - name: caching uses: Swatinem/rust-cache@v2 with: key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} - name: run checks & tests - run: ./run-checks.sh no_std + run: ./scripts/run-checks no_std From fc8872b816c28c97e8f1e0242599679d78e9ef87 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 15:54:09 +0200 Subject: [PATCH 07/28] scripts: Exit only when command result is not a success --- scripts/run-checks.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 9930fedfa9..8455579659 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -36,6 +36,10 @@ fn stdout_and_stderr_write(output: Output, message_stdout: &str, message_stderr: io::stderr() .write_all(&output.stderr) .expect(message_stderr); + } + + // If exit status is not a success, exit the binary with an error + if !output.status.success() { std::process::exit(1); } } @@ -218,7 +222,7 @@ fn std_checks() { // for the documentation build env::set_var("RUSTDOCFLAGS", "-D warnings"); - println!("\n\nRunning std checks"); + println!("Running std checks"); println!("\nBuild each workspace"); // Build each workspace From 1a7c56b87fe6f07f8fdc96bb3b51a0d965fb0325 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 16:01:36 +0200 Subject: [PATCH 08/28] scripts: Fix stdout and stderr function --- scripts/run-checks.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 8455579659..38c4654508 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -23,8 +23,9 @@ use std::process::{Command, Output}; use std::str; use std::time::Instant; -// If stdout is not empty, write it, otherwise -// write stderr and exit with code error 1 +// Write stdout and stderr output on shell. +// If there exit status of a command is not a success, terminate the process +// with an error. fn stdout_and_stderr_write(output: Output, message_stdout: &str, message_stderr: &str) { if !output.stdout.is_empty() { io::stdout() @@ -38,9 +39,11 @@ fn stdout_and_stderr_write(output: Output, message_stdout: &str, message_stderr: .expect(message_stderr); } - // If exit status is not a success, exit the binary with an error + // If exit status is not a success, terminate the process with an error if !output.status.success() { - std::process::exit(1); + // Use the exit code associated to a command to terminate the process, + // if any exit code had been found, use the default value 1 + std::process::exit(output.status.code().unwrap_or(1)); } } From 85b78bca0dfb104b60e1fb507fa3b3facde6dc91 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 16:02:31 +0200 Subject: [PATCH 09/28] scripts: Fix wrong target --- scripts/run-checks.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 38c4654508..184efbd4c5 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -155,7 +155,7 @@ fn build_and_test_no_std(crate_name: &str) { crate_name, "--no-default-features", "--target", - "wasm32-unknown-unknowns", + "wasm32-unknown-unknown", ]); println!("\nBuild for ARM"); From 7acc0870dacd7dfd11aa2dedc9ea76c91bebe3ed Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Fri, 11 Aug 2023 16:09:02 +0200 Subject: [PATCH 10/28] scripts: Use constants for no_std targets --- scripts/run-checks.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 184efbd4c5..339eff4e42 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -23,6 +23,10 @@ use std::process::{Command, Output}; use std::str; use std::time::Instant; +// Targets constants +const WASM32_TARGET: &str = "wasm32-unknown-unknown"; +const ARM_TARGET: &str = "thumbv7m-none-eabi"; + // Write stdout and stderr output on shell. // If there exit status of a command is not a success, terminate the process // with an error. @@ -155,7 +159,7 @@ fn build_and_test_no_std(crate_name: &str) { crate_name, "--no-default-features", "--target", - "wasm32-unknown-unknown", + WASM32_TARGET, ]); println!("\nBuild for ARM"); @@ -165,7 +169,7 @@ fn build_and_test_no_std(crate_name: &str) { crate_name, "--no-default-features", "--target", - "thumbv7m-none-eabi", + ARM_TARGET, ]); } @@ -175,11 +179,11 @@ fn no_std_checks() { println!("Install Wasm32 target\n"); // Install wasm32 target - rustup("wasm32-unknown-unknown"); + rustup(WASM32_TARGET); println!("\nInstall ARM target\n"); // Install ARM target - rustup("thumbv7m-none-eabi"); + rustup(ARM_TARGET); // Run checks for the following crates build_and_test_no_std("burn"); From 91fe7b0146e3869a4ece0e564b58d00030434c41 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Sat, 12 Aug 2023 18:54:53 +0200 Subject: [PATCH 11/28] scripts: Always color cargo output --- scripts/run-checks.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 339eff4e42..96190806a7 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -72,6 +72,7 @@ fn run_cargo(command: &str, params: &[&str], error: &str, stdout_error: &str, st // Run cargo let cargo = Command::new("cargo") .arg(command) + .arg("--color=always") .args(params) .output() .expect(error); From 22a5ca98a1978f30eb1df6d5589ef944ee2335c6 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Sat, 12 Aug 2023 18:57:17 +0200 Subject: [PATCH 12/28] scripts: Remove superfluous prints --- scripts/run-checks.rs | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 96190806a7..ebefe8beab 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -145,15 +145,12 @@ fn cargo_doc(params: &[&str]) { fn build_and_test_no_std(crate_name: &str) { println!("\nRun checks for `{}` crate", crate_name); - println!("\nBuild without defaults"); // Run cargo build --no-default-features cargo_build(&["-p", crate_name, "--no-default-features"]); - println!("\nTest without defaults"); // Run cargo test --no-default-features cargo_test(&["-p", crate_name, "--no-default-features"]); - println!("\nBuild for WebAssembly"); // Run cargo build --no-default-features --target wasm32-unknown-unknowns cargo_build(&[ "-p", @@ -163,7 +160,6 @@ fn build_and_test_no_std(crate_name: &str) { WASM32_TARGET, ]); - println!("\nBuild for ARM"); // Run cargo build --no-default-features --target thumbv7m-none-eabi cargo_build(&[ "-p", @@ -176,7 +172,7 @@ fn build_and_test_no_std(crate_name: &str) { // Run no_std checks fn no_std_checks() { - println!("Checks for no_std environment...\n\n"); + println!("\n\nChecks for no_std environment...\n\n"); println!("Install Wasm32 target\n"); // Install wasm32 target @@ -199,11 +195,9 @@ fn no_std_checks() { fn burn_core_std() { println!("\n\nRun checks for burn-core crate with tch and wgpu backend"); - println!("\nTest with tch backend"); // Run cargo test --features test-tch cargo_test(&["-p", "burn-core", "--features", "test-tch"]); - println!("\nTest with wgpu backend"); // Run cargo test --features test-wgpu cargo_test(&["-p", "burn-core", "--features", "test-wgpu"]); } @@ -212,15 +206,12 @@ fn burn_core_std() { fn burn_dataset_features_std() { println!("\n\nRun checks for burn-dataset features"); - println!("\nBuild with all features"); // Run cargo build --all-features cargo_build(&["-p", "burn-dataset", "--all-features"]); - println!("\nTest with all features"); // Run cargo test --all-features cargo_test(&["-p", "burn-dataset", "--all-features"]); - println!("\nCheck documentation with all features"); // Run cargo doc --all-features cargo_doc(&["-p", "burn-dataset", "--all-features"]); } @@ -232,23 +223,18 @@ fn std_checks() { println!("Running std checks"); - println!("\nBuild each workspace"); // Build each workspace cargo_build(&["--workspace"]); - println!("\nTest each workspace"); // Test each workspace cargo_test(&["--workspace"]); - println!("\nCheck format"); // Check format cargo_fmt(); - println!("\nCheck clippy lints"); // Check clippy lints cargo_clippy(); - println!("\nProduce documentation for each workspace"); // Produce documentation for each workspace cargo_doc(&["--workspace"]); From 49bb0543bc8d398c83bf5d251fc449e68360b3a7 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Sat, 12 Aug 2023 18:59:46 +0200 Subject: [PATCH 13/28] scripts: Flush stdout and stderr --- scripts/run-checks.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index ebefe8beab..03ec40d249 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -35,12 +35,14 @@ fn stdout_and_stderr_write(output: Output, message_stdout: &str, message_stderr: io::stdout() .write_all(&output.stdout) .expect(message_stdout); + io::stdout().flush().expect("Failed to flush stdout"); } if !output.stderr.is_empty() { io::stderr() .write_all(&output.stderr) .expect(message_stderr); + io::stderr().flush().expect("Failed to flush stderr"); } // If exit status is not a success, terminate the process with an error From b076e8007f9d20cedddcf93ae3ce2835f46d38ec Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Sat, 12 Aug 2023 19:20:23 +0200 Subject: [PATCH 14/28] scripts: Print commands coherently --- scripts/run-checks.rs | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 03ec40d249..adfcf2c71e 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -53,11 +53,17 @@ fn stdout_and_stderr_write(output: Output, message_stdout: &str, message_stderr: } } -// Run rustup command +// Define and run rustup command fn rustup(target: &str) { - // Run rustup + // Rustup arguments + let args = ["target", "add", target]; + + // Print rustup command + println!("rustup {}\n", args.join(" ")); + + // Run rustup command let rustup = Command::new("rustup") - .args(["target", "add", target]) + .args(args) .output() .expect("Failed to run rustup"); @@ -69,12 +75,18 @@ fn rustup(target: &str) { ); } -// Run a cargo command +// Define and run a cargo command fn run_cargo(command: &str, params: &[&str], error: &str, stdout_error: &str, stderr_error: &str) { + // Cargo option to always print colored output + let color_option = "--color=always"; + + // Print cargo command + println!("\ncargo {} {} {}", color_option, command, params.join(" ")); + // Run cargo let cargo = Command::new("cargo") + .arg(color_option) .arg(command) - .arg("--color=always") .args(params) .output() .expect(error); From ba9915f0959582bf1cf244cd773db7e4a4d483e3 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Sat, 12 Aug 2023 20:09:04 +0200 Subject: [PATCH 15/28] scripts: Use println instead of std::io --- scripts/run-checks.rs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index adfcf2c71e..b3f525e5a4 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -18,7 +18,6 @@ //! - `all` to perform checks using both `libstd` and `libcore` use std::env; -use std::io::{self, Write}; use std::process::{Command, Output}; use std::str; use std::time::Instant; @@ -32,17 +31,11 @@ const ARM_TARGET: &str = "thumbv7m-none-eabi"; // with an error. fn stdout_and_stderr_write(output: Output, message_stdout: &str, message_stderr: &str) { if !output.stdout.is_empty() { - io::stdout() - .write_all(&output.stdout) - .expect(message_stdout); - io::stdout().flush().expect("Failed to flush stdout"); + println!("{}", str::from_utf8(&output.stdout).expect(message_stdout)); } if !output.stderr.is_empty() { - io::stderr() - .write_all(&output.stderr) - .expect(message_stderr); - io::stderr().flush().expect("Failed to flush stderr"); + println!("{}", str::from_utf8(&output.stderr).expect(message_stderr)); } // If exit status is not a success, terminate the process with an error From 5c59075c5495d01fb27618a9e5127c19748d2227 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Sat, 12 Aug 2023 20:10:23 +0200 Subject: [PATCH 16/28] scripts: Fix output --- scripts/run-checks.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index b3f525e5a4..b488ff184e 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -52,7 +52,7 @@ fn rustup(target: &str) { let args = ["target", "add", target]; // Print rustup command - println!("rustup {}\n", args.join(" ")); + println!("rustup {}\n\n", args.join(" ")); // Run rustup command let rustup = Command::new("rustup") @@ -74,7 +74,12 @@ fn run_cargo(command: &str, params: &[&str], error: &str, stdout_error: &str, st let color_option = "--color=always"; // Print cargo command - println!("\ncargo {} {} {}", color_option, command, params.join(" ")); + println!( + "\ncargo {} {} {}\n", + color_option, + command, + params.join(" ") + ); // Run cargo let cargo = Command::new("cargo") From fae60662e9a29fdd7d69f37708a4408736f2b24e Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Sat, 12 Aug 2023 20:45:06 +0200 Subject: [PATCH 17/28] scripts: Print colored output for all commands --- scripts/run-checks.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index b488ff184e..ab81b7b70f 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -69,23 +69,27 @@ fn rustup(target: &str) { } // Define and run a cargo command -fn run_cargo(command: &str, params: &[&str], error: &str, stdout_error: &str, stderr_error: &str) { - // Cargo option to always print colored output - let color_option = "--color=always"; - +fn run_cargo( + command: &str, + first_params: &[&str], + second_params: &[&str], + error: &str, + stdout_error: &str, + stderr_error: &str, +) { // Print cargo command println!( "\ncargo {} {} {}\n", - color_option, command, - params.join(" ") + first_params.join(" "), + second_params.join(" ") ); // Run cargo let cargo = Command::new("cargo") - .arg(color_option) .arg(command) - .args(params) + .args(first_params) + .args(second_params) .output() .expect(error); @@ -99,6 +103,7 @@ fn cargo_build(params: &[&str]) { run_cargo( "build", params, + &["--color=always"], "Failed to run cargo build", "Failed to write cargo build output on stdout", "Failed to write cargo build output on stderr", @@ -111,6 +116,7 @@ fn cargo_test(params: &[&str]) { run_cargo( "test", params, + &["--color=always", "--", "--color=always"], "Failed to run cargo test", "Failed to write cargo test output on stdout", "Failed to write cargo test output on stderr", @@ -123,6 +129,7 @@ fn cargo_fmt() { run_cargo( "fmt", &["--check", "--all"], + &["--", "--color=always"], "Failed to run cargo fmt", "Failed to write cargo fmt output on stdout", "Failed to write cargo fmt output on stderr", @@ -134,6 +141,7 @@ fn cargo_clippy() { // Run cargo clippy run_cargo( "clippy", + &["--color=always"], &["--", "-D", "warnings"], "Failed to run cargo clippy", "Failed to write cargo clippy output on stdout", @@ -147,6 +155,7 @@ fn cargo_doc(params: &[&str]) { run_cargo( "doc", params, + &["--color=always"], "Failed to run cargo doc", "Failed to write cargo doc output on stdout", "Failed to write cargo doc output on stderr", From 8e6fab22c034f9455336c26e128516989dfb1678 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Sat, 12 Aug 2023 20:57:45 +0200 Subject: [PATCH 18/28] scripts: Remove unused println --- scripts/run-checks.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index ab81b7b70f..7c64d909ef 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -193,13 +193,11 @@ fn build_and_test_no_std(crate_name: &str) { // Run no_std checks fn no_std_checks() { - println!("\n\nChecks for no_std environment...\n\n"); + println!("Checks for no_std environment...\n\n"); - println!("Install Wasm32 target\n"); // Install wasm32 target rustup(WASM32_TARGET); - println!("\nInstall ARM target\n"); // Install ARM target rustup(ARM_TARGET); From 00a0120e6fec1e12a4ca59c85dc29f4833183ef3 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 09:17:48 +0200 Subject: [PATCH 19/28] scripts: Add a shell script for Unix systems --- run-checks.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 run-checks.sh diff --git a/run-checks.sh b/run-checks.sh new file mode 100755 index 0000000000..d451d811f9 --- /dev/null +++ b/run-checks.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# +# This script runs all `burn` checks locally +# +# Run `run-checks` using this command: +# +# ./scripts/run-checks environment +# +# where `environment` can assume **ONLY** the following values: +# +# - `std` to perform checks using `libstd` +# - `no_std` to perform checks on an embedded environment using `libcore` +# - `all` to perform checks using both `libstd` and `libcore` + +# Compile run-checks binary +rustc scripts/run-checks.rs --crate-type bin --out-dir scripts + +# Run binary passing the first input parameter, who is mandatory. +# If the input parameter is missing or wrong, it will be the `run-checks` +# binary which will be responsible of arising an error. +./scripts/run-checks $1 From 624597dd1b796319bf815e468d00c4c043b6b592 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 09:20:10 +0200 Subject: [PATCH 20/28] scripts: Add a shell script for Windows --- run-checks.ps1 | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 run-checks.ps1 diff --git a/run-checks.ps1 b/run-checks.ps1 new file mode 100644 index 0000000000..837ea84303 --- /dev/null +++ b/run-checks.ps1 @@ -0,0 +1,19 @@ +# This script runs all `burn` checks locally +# +# Run `run-checks` using this command: +# +# ./scripts/run-checks environment +# +# where `environment` can assume **ONLY** the following values: +# +# - `std` to perform checks using `libstd` +# - `no_std` to perform checks on an embedded environment using `libcore` +# - `all` to perform checks using both `libstd` and `libcore` + +# Compile run-checks binary +rustc scripts/run-checks.rs --crate-type bin --out-dir scripts + +# Run binary passing the first input parameter, who is mandatory. +# If the input parameter is missing or wrong, it will be the `run-checks` +# binary which will be responsible of arising an error. +./scripts/run-checks $args[0] From 8e96e51fcbd9ef85b4d179ac9c86a8a0be53d6b1 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 09:28:01 +0200 Subject: [PATCH 21/28] ci: Simplify scripts --- .github/workflows/test.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8c0c87b1bd..ea9f6d8aba 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,9 +27,6 @@ jobs: with: components: rustfmt, clippy - - name: compile run-checks binary - run: rustc scripts/run-checks.rs --crate-type bin --out-dir scripts - - name: caching uses: Swatinem/rust-cache@v2 with: @@ -43,7 +40,7 @@ jobs: sudo apt install -y libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers - name: run checks & tests - run: ./scripts/run-checks std + run: run-checks.sh std test-burn-no-std: runs-on: ubuntu-latest @@ -64,13 +61,10 @@ jobs: with: components: rustfmt, clippy - - name: compile run-checks binary - run: rustc scripts/run-checks.rs --crate-type bin --out-dir scripts - - name: caching uses: Swatinem/rust-cache@v2 with: key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} - name: run checks & tests - run: ./scripts/run-checks no_std + run: run-checks.sh no_std From 0695137abba7e96e7737000260f2a1bda7a8a0b9 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 09:30:13 +0200 Subject: [PATCH 22/28] Update README --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 510b32d33c..b7dfc0ea26 100644 --- a/README.md +++ b/README.md @@ -289,19 +289,19 @@ our architectural decisions. Please see more details in our [contributing guide] ### Run checks -Compile `scripts/run-checks.rs` using this command +On Unix systems, run `run-checks.sh` using this command ``` -rustc scripts/run-checks.rs --crate-type bin --out-dir scripts +run-checks.sh environment ``` -Run `scripts/run-checks` using this command +On Windows systems, run `run-checks.ps1` using this command: ``` -./scripts/run-checks environment +run-checks.ps1 environment ``` -where `environment` can assume **ONLY** the following values: +The `environment` argument can assume **ONLY** the following values: - `std` to perform checks using `libstd` - `no_std` to perform checks on an embedded environment using `libcore` From 6a08e8eb662f45aaf283b42f0ccb70acd012ec4e Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 09:31:27 +0200 Subject: [PATCH 23/28] ci: Missing directory --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ea9f6d8aba..b30cd033e0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -40,7 +40,7 @@ jobs: sudo apt install -y libegl1-mesa libgl1-mesa-dri libxcb-xfixes0-dev mesa-vulkan-drivers - name: run checks & tests - run: run-checks.sh std + run: ./run-checks.sh std test-burn-no-std: runs-on: ubuntu-latest @@ -67,4 +67,4 @@ jobs: key: ${{ runner.os }}-rust-${{ hashFiles('**/Cargo.lock') }} - name: run checks & tests - run: run-checks.sh no_std + run: ./run-checks.sh no_std From 6dab9c55ed3429d734c1facd976c32c57c3a087d Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 09:32:15 +0200 Subject: [PATCH 24/28] Use bash --- run-checks.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/run-checks.sh b/run-checks.sh index d451d811f9..adf4ac9d58 100755 --- a/run-checks.sh +++ b/run-checks.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # This script runs all `burn` checks locally # From 62d787e6648c5dfd9b68edb28330789f4b79877e Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 20:27:53 +0200 Subject: [PATCH 25/28] scripts: Set all as default value --- scripts/run-checks.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 7c64d909ef..0e5429a7a2 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -265,10 +265,17 @@ fn std_checks() { } fn main() { - // Get the environment - let environment = env::args() - .nth(1) // Index of the first argument, because 0 is the binary name - .expect("You need to pass the environment as first argument!"); + // Get the environment. + // + // If any environment is passed, then the `all` argument is the default + // value. + let environment = if let Some(argument) = env::args().nth( + 1, /* Index of the first argument, because 0 is the binary name */ + ) { + argument + } else { + "all".to_string() + }; // Start time measurement let start = Instant::now(); From 223f6cb8cf89d1347d9728b9c20fdc4c6537f23e Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 20:28:56 +0200 Subject: [PATCH 26/28] ci: Define a new message for pull_request template --- .github/pull_request_template.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 57cf32c708..25042bc38f 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,7 +2,7 @@ ### Checklist -- [ ] Confirm that `run-checks` has been executed. +- [ ] Confirm that `run-checks` script has been executed. ### Related Issues/PRs From b62511c3de8a2cc5c9154a80ae5aeb94c79dbfd8 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 20:47:21 +0200 Subject: [PATCH 27/28] scripts: Use spawn and child process to run commands --- scripts/run-checks.rs | 62 +++++++++++++------------------------------ 1 file changed, 19 insertions(+), 43 deletions(-) diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 0e5429a7a2..273ea127c3 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -18,7 +18,7 @@ //! - `all` to perform checks using both `libstd` and `libcore` use std::env; -use std::process::{Command, Output}; +use std::process::{Child, Command, Stdio}; use std::str; use std::time::Instant; @@ -26,23 +26,16 @@ use std::time::Instant; const WASM32_TARGET: &str = "wasm32-unknown-unknown"; const ARM_TARGET: &str = "thumbv7m-none-eabi"; -// Write stdout and stderr output on shell. -// If there exit status of a command is not a success, terminate the process -// with an error. -fn stdout_and_stderr_write(output: Output, message_stdout: &str, message_stderr: &str) { - if !output.stdout.is_empty() { - println!("{}", str::from_utf8(&output.stdout).expect(message_stdout)); - } - - if !output.stderr.is_empty() { - println!("{}", str::from_utf8(&output.stderr).expect(message_stderr)); - } +// Handle child process +fn handle_child_process(mut child: Child, error: &str) { + // Wait for the child process to finish + let status = child.wait().expect(error); // If exit status is not a success, terminate the process with an error - if !output.status.success() { + if !status.success() { // Use the exit code associated to a command to terminate the process, // if any exit code had been found, use the default value 1 - std::process::exit(output.status.code().unwrap_or(1)); + std::process::exit(status.code().unwrap_or(1)); } } @@ -54,29 +47,20 @@ fn rustup(target: &str) { // Print rustup command println!("rustup {}\n\n", args.join(" ")); - // Run rustup command + // Run rustup command as child process let rustup = Command::new("rustup") .args(args) - .output() + .stdout(Stdio::inherit()) // Send stdout directly to terminal + .stderr(Stdio::inherit()) // Send stderr directly to terminal + .spawn() .expect("Failed to run rustup"); - // Write rustup output either on stdout or on stderr - stdout_and_stderr_write( - rustup, - "Failed to write rustup output on stdout", - "Failed to write rustup output on stderr", - ); + // Handle rustup child process + handle_child_process(rustup, "Failed to wait for rustup child process"); } // Define and run a cargo command -fn run_cargo( - command: &str, - first_params: &[&str], - second_params: &[&str], - error: &str, - stdout_error: &str, - stderr_error: &str, -) { +fn run_cargo(command: &str, first_params: &[&str], second_params: &[&str], error: &str) { // Print cargo command println!( "\ncargo {} {} {}\n", @@ -90,11 +74,13 @@ fn run_cargo( .arg(command) .args(first_params) .args(second_params) - .output() + .stdout(Stdio::inherit()) // Send stdout directly to terminal + .stderr(Stdio::inherit()) // Send stderr directly to terminal + .spawn() .expect(error); - // Write cargo output either on stdout or on stderr - stdout_and_stderr_write(cargo, stdout_error, stderr_error); + // Handle cargo child process + handle_child_process(cargo, "Failed to wait for cargo child process"); } // Run cargo build command @@ -105,8 +91,6 @@ fn cargo_build(params: &[&str]) { params, &["--color=always"], "Failed to run cargo build", - "Failed to write cargo build output on stdout", - "Failed to write cargo build output on stderr", ); } @@ -118,8 +102,6 @@ fn cargo_test(params: &[&str]) { params, &["--color=always", "--", "--color=always"], "Failed to run cargo test", - "Failed to write cargo test output on stdout", - "Failed to write cargo test output on stderr", ); } @@ -131,8 +113,6 @@ fn cargo_fmt() { &["--check", "--all"], &["--", "--color=always"], "Failed to run cargo fmt", - "Failed to write cargo fmt output on stdout", - "Failed to write cargo fmt output on stderr", ); } @@ -144,8 +124,6 @@ fn cargo_clippy() { &["--color=always"], &["--", "-D", "warnings"], "Failed to run cargo clippy", - "Failed to write cargo clippy output on stdout", - "Failed to write cargo clippy output on stderr", ); } @@ -157,8 +135,6 @@ fn cargo_doc(params: &[&str]) { params, &["--color=always"], "Failed to run cargo doc", - "Failed to write cargo doc output on stdout", - "Failed to write cargo doc output on stderr", ); } From d2c7baf0aed00375780b787182074c866f15b305 Mon Sep 17 00:00:00 2001 From: Luni-4 Date: Mon, 14 Aug 2023 21:01:41 +0200 Subject: [PATCH 28/28] Remove all option --- README.md | 3 ++- run-checks.ps1 | 3 ++- run-checks.sh | 3 ++- scripts/run-checks.rs | 34 ++++++++++++---------------------- 4 files changed, 18 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index b7dfc0ea26..990e538a89 100644 --- a/README.md +++ b/README.md @@ -305,7 +305,8 @@ The `environment` argument can assume **ONLY** the following values: - `std` to perform checks using `libstd` - `no_std` to perform checks on an embedded environment using `libcore` -- `all` to perform checks using both `libstd` and `libcore` + +If no `environment` value has been passed, run both `std` and `no_std` checks. ## Continuous Deployment diff --git a/run-checks.ps1 b/run-checks.ps1 index 837ea84303..985ef8cf96 100644 --- a/run-checks.ps1 +++ b/run-checks.ps1 @@ -8,7 +8,8 @@ # # - `std` to perform checks using `libstd` # - `no_std` to perform checks on an embedded environment using `libcore` -# - `all` to perform checks using both `libstd` and `libcore` +# +# If no `environment` value has been passed, run both `std` and `no_std` checks. # Compile run-checks binary rustc scripts/run-checks.rs --crate-type bin --out-dir scripts diff --git a/run-checks.sh b/run-checks.sh index adf4ac9d58..e3e9c7d4c8 100755 --- a/run-checks.sh +++ b/run-checks.sh @@ -10,7 +10,8 @@ # # - `std` to perform checks using `libstd` # - `no_std` to perform checks on an embedded environment using `libcore` -# - `all` to perform checks using both `libstd` and `libcore` +# +# If no `environment` value has been passed, run both `std` and `no_std` checks. # Compile run-checks binary rustc scripts/run-checks.rs --crate-type bin --out-dir scripts diff --git a/scripts/run-checks.rs b/scripts/run-checks.rs index 273ea127c3..e415b640e4 100644 --- a/scripts/run-checks.rs +++ b/scripts/run-checks.rs @@ -15,7 +15,6 @@ //! where `environment` can assume **ONLY** the following values: //! - `std` to perform checks using `libstd` //! - `no_std` to perform checks on an embedded environment using `libcore` -//! - `all` to perform checks using both `libstd` and `libcore` use std::env; use std::process::{Child, Command, Stdio}; @@ -241,37 +240,28 @@ fn std_checks() { } fn main() { - // Get the environment. - // - // If any environment is passed, then the `all` argument is the default - // value. - let environment = if let Some(argument) = env::args().nth( - 1, /* Index of the first argument, because 0 is the binary name */ - ) { - argument - } else { - "all".to_string() - }; - // Start time measurement let start = Instant::now(); - // The environment can assume ONLY "all", "std" and "no_std" as values. + // The environment can assume ONLY "std" and "no_std" as values. // // Depending on the input argument, the respective environment checks // are run. // - // If a wrong argument is passed, the program panics. - match environment.as_str() { - "all" => { + // If no environment has been passed, run both "std" and "no_std" checks. + match env::args() + .nth( + 1, /* Index of the first argument, because 0 is the binary name */ + ) + .as_deref() + { + Some("std") => std_checks(), + Some("no_std") => no_std_checks(), + Some(_) | None => { + /* Run both "std" and "no_std" checks" */ std_checks(); no_std_checks(); } - "std" => std_checks(), - "no_std" => no_std_checks(), - _ => { - panic!("You can pass only 'all', 'std' and 'no_std' as values for the first argument!") - } } // Stop time measurement