diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd21474..1f0e2ee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,7 +10,7 @@ permissions: contents: read env: - RUSTFLAGS: -Dwarnings + RUSTFLAGS: -Dwarnings -A rust_2024_compatibility CARGO_TERM_COLOR: always jobs: @@ -42,7 +42,7 @@ jobs: - name: Enable nightly-only tests run: echo RUSTFLAGS=${RUSTFLAGS}\ --cfg=thiserror_nightly_testing >> $GITHUB_ENV if: matrix.rust == 'nightly' - - run: cargo xtask ci + - run: cargo xtask ci --no-extended - uses: actions/upload-artifact@v4 if: matrix.rust == 'nightly' && always() with: diff --git a/ferrunix-core/src/dependencies.rs b/ferrunix-core/src/dependencies.rs index 379fc35..61b4d30 100644 --- a/ferrunix-core/src/dependencies.rs +++ b/ferrunix-core/src/dependencies.rs @@ -9,7 +9,7 @@ //! inner type via `.get`. //! //! # Examples -//! ```no_run +//! ```ignore,no_run //! use ferrunix_core::{Registry, Singleton, Transient}; //! //! struct Template { diff --git a/ferrunix-core/src/registration.rs b/ferrunix-core/src/registration.rs index c319bd2..8b61bb3 100644 --- a/ferrunix-core/src/registration.rs +++ b/ferrunix-core/src/registration.rs @@ -115,7 +115,7 @@ mod sync { /// thread). /// /// # Example - /// ```no_run + /// ```ignore,no_run /// # use ferrunix_core::*; /// # use ferrunix_core::registration::*; /// #[derive(Debug)] diff --git a/ferrunix/Cargo.toml b/ferrunix/Cargo.toml index 0314c46..d251cbb 100644 --- a/ferrunix/Cargo.toml +++ b/ferrunix/Cargo.toml @@ -28,7 +28,7 @@ ferrunix-macros = { path = "../ferrunix-macros", optional = true, version = "=0. [dev-dependencies] thiserror = "1" -tokio = { version = "1", features = ["full"] } +tokio = { version = "=1.21", features = ["full"] } async-trait = "0.1" # [package.metadata."docs.rs"] diff --git a/ferrunix/README.md b/ferrunix/README.md index fdefe28..9584159 100644 --- a/ferrunix/README.md +++ b/ferrunix/README.md @@ -69,14 +69,18 @@ fn main() { } ``` -## Features +## Cargo Feature Flags Ferrunix has the following features to enable further functionality. -Default features are marked with `*`. - -- `multithread` (`*`): Enable support for access to the registry from multiple threads. - This adds a bound that all registered types must be `Send` and `Sync`. -- `derive` (`*`): Enable support for the `#[derive(Inject)]` macro. +Features enabled by default are marked with `*`. + +- `multithread`: Enables support for accessing the registry from multiple + threads. This adds a bound that all registered types must be `Send` and + `Sync`. +- `derive` (`*`): Enables support for the `#[derive(Inject)]` macro. +- `tokio`: Enables support for `async` constructors. Bumps the MSRV up to + `1.75.0` because some of the internal traits require + [RPITIT](https://blog.rust-lang.org/2023/12/21/async-fn-rpit-in-traits.html#whats-stabilizing). #### License diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml index e752d32..752b94c 100644 --- a/xtask/Cargo.toml +++ b/xtask/Cargo.toml @@ -14,4 +14,4 @@ workspace = true [dependencies] xshell = "0.2" anyhow = "1" -clap = { version = "4", features = ["derive"] } +clap = { version = "=4.1.14", features = ["derive"] } diff --git a/xtask/src/ci.rs b/xtask/src/ci.rs index 2ca58be..ceec9a8 100644 --- a/xtask/src/ci.rs +++ b/xtask/src/ci.rs @@ -4,35 +4,60 @@ use anyhow::Result; use xshell::{cmd, Shell}; +/// How tests are run. +#[derive(Debug, Clone, clap::ValueEnum)] +pub(super) enum TestRunner { + /// Use the default cargo test runner. + Cargo, + /// Use nextest, requires installing `cargo-nextest`. + Nextest, +} + +/// Arguments for `xtask ci`. +#[derive(Debug, Clone, clap::Args)] +pub(super) struct CiArgs { + /// Which test runner to use + #[arg(short, long)] + testrunner: Option, + + /// Whether to skip extended tests, e.g., `clippy`, `cargo outdated`, and + /// `cargo-semver-checks`. Useful in CI, when these run as a separate task. + #[arg(long, default_value_t = false)] + no_extended: bool, +} + /// Run all tests, similar to the GitHub Actions in `ci.yml`. -pub(super) fn run() -> Result<()> { +pub(super) fn run(args: &CiArgs) -> Result<()> { let sh = Shell::new()?; // sh.set_var("RUSTFLAGS", "-Dwarnings"); // sh.set_var("CARGO_INCREMENTAL", "0"); // sh.set_var("CARGO_TERM_COLOR", "always"); - let has_cargo_outdated = - if let Err(err) = cmd!(sh, "cargo outdated --version").output() { - eprintln!("failed to find `cargo-outdated`: {err}"); - eprintln!( - "try installing it with: cargo install --locked cargo-outdated" - ); - false - } else { - true - }; + let has_cargo_outdated = if args.no_extended { + false + } else if let Err(err) = cmd!(sh, "cargo outdated --version").output() { + eprintln!("failed to find `cargo-outdated`: {err}"); + eprintln!( + "try installing it with: cargo install --locked cargo-outdated" + ); + false + } else { + true + }; - let has_cargo_semver = - if let Err(err) = cmd!(sh, "cargo semver-checks --version").output() { - eprintln!("failed to find `cargo-semver-checks`: {err}"); - eprintln!( - "try installing it with: cargo install --locked \ + let has_cargo_semver = if args.no_extended { + false + } else if let Err(err) = cmd!(sh, "cargo semver-checks --version").output() + { + eprintln!("failed to find `cargo-semver-checks`: {err}"); + eprintln!( + "try installing it with: cargo install --locked \ cargo-semver-checks" - ); - false - } else { - true - }; + ); + false + } else { + true + }; let test_matrix = [ ("ferrunix", ""), @@ -50,8 +75,10 @@ pub(super) fn run() -> Result<()> { ("ferrunix-macros", "development,multithread"), ]; - let testrunner = &["nextest", "run"]; - // let testrunner = &["test"]; + let testrunner: &[&str] = match args.testrunner { + Some(TestRunner::Nextest) => &["nextest", "run"], + None | Some(TestRunner::Cargo) => &["test"], + }; for (proj, features) in test_matrix { if features.is_empty() { cmd!(sh, "cargo {testrunner...} -p {proj} --no-default-features") @@ -67,15 +94,17 @@ pub(super) fn run() -> Result<()> { } // cmd!(sh, "cargo test --all").run()?; - if cmd!(sh, "cargo clippy --version").output().is_ok() { + + if !args.no_extended && cmd!(sh, "cargo clippy --version").output().is_ok() + { cmd!(sh, "cargo clippy --tests --workspace").run()?; } - if has_cargo_outdated { + if !args.no_extended && has_cargo_outdated { cmd!(sh, "cargo outdated --workspace --exit-code 1").run()?; } - if has_cargo_semver { + if !args.no_extended && has_cargo_semver { cmd!(sh, "cargo semver-checks").run()?; } diff --git a/xtask/src/main.rs b/xtask/src/main.rs index bc85b1a..f2c9018 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -21,7 +21,7 @@ struct Cli { #[derive(Debug, Subcommand)] enum CliCommands { /// Build the workspace, similar to how the CI would build it. - CI, + CI(ci::CiArgs), /// Publish all packages in the workspace to crates.io. Publish(publish::PublishArgs) } @@ -30,7 +30,7 @@ fn main() -> anyhow::Result<()> { let cli = Cli::parse(); match cli.command { - CliCommands::CI => ci::run()?, + CliCommands::CI(ref args) => ci::run(args)?, CliCommands::Publish(ref args) => publish::run(args)?, }