From f0c08ae3f493046ce95fd9edb516b617597f912d Mon Sep 17 00:00:00 2001 From: Poliorcetics Date: Tue, 23 Apr 2024 15:08:36 +0200 Subject: [PATCH] Fix workspace compilation and features shenanigans (#21) * doc: document postgres on docs.rs * tests: mark `postgres` as a required feature for tests * doc: document feature selection requirement * chore: make the workspace compile when no DB is selected * ci: use postgres feature directly --- .github/workflows/ci.yml | 4 ++-- Cargo.toml | 4 ++++ atmosphere-core/Cargo.toml | 3 +++ atmosphere-core/src/lib.rs | 20 ++------------------ atmosphere-macros/Cargo.toml | 3 +++ atmosphere-macros/src/lib.rs | 2 ++ src/lib.rs | 10 ++++++++++ 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 93cc599..5c8aa42 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: - uses: actions/checkout@v3 - run: rustup update && rustup component add clippy - uses: Swatinem/rust-cache@v2 - - run: cargo clippy --all-targets --workspace --features atmosphere-core/postgres -- -D warnings -D clippy::all + - run: cargo clippy --all-targets --workspace --features postgres -- -D warnings -D clippy::all test: runs-on: ubuntu-latest @@ -35,7 +35,7 @@ jobs: compose-file: "./tests/postgres.yml" - run: rustup update - uses: Swatinem/rust-cache@v2 - - run: cargo test --workspace --features atmosphere-core/postgres + - run: cargo test --workspace --features postgres env: RUST_BACKTRACE: 1 DATABASE_URL: postgres://atmosphere:atmosphere@localhost:5432 diff --git a/Cargo.toml b/Cargo.toml index b9338b1..0ce5d13 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -64,3 +64,7 @@ required-features = ["sqlite"] name = "integration" path = "tests/lib.rs" test = true +required-features = ["postgres"] + +[package.metadata.docs.rs] +features = ["postgres"] diff --git a/atmosphere-core/Cargo.toml b/atmosphere-core/Cargo.toml index 4e277fc..0e34983 100644 --- a/atmosphere-core/Cargo.toml +++ b/atmosphere-core/Cargo.toml @@ -23,3 +23,6 @@ sqlx.workspace = true thiserror.workspace = true lazy_static.workspace = true miette = "5.10.0" + +[package.metadata.docs.rs] +features = ["postgres"] diff --git a/atmosphere-core/src/lib.rs b/atmosphere-core/src/lib.rs index f0bcd3c..c8ab83a 100644 --- a/atmosphere-core/src/lib.rs +++ b/atmosphere-core/src/lib.rs @@ -21,39 +21,31 @@ //! - Code reusability across API layers using generics. //! - Compile-time introspection for type-safe schema generation. -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] +#![cfg(any(feature = "postgres", feature = "mysql", feature = "sqlite"))] + /// Facilitates binding entities to queries, ensuring type safety and ease of use in query construction. pub mod bind; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] /// Defines high-level database error types, offering a structured approach to error handling. pub mod error; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] /// Implements a hook system, allowing custom logic to be executed at different stages of database /// interactions. -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] pub mod hooks; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] /// Offers an abstraction layer for building and executing SQL queries, simplifying complex query /// logic. pub mod query; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] /// Models SQL relationships, providing tools to define and manipulate relationships between /// database entities. pub mod rel; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] /// Manages the runtime environment for database operations, encompassing execution contexts and /// configurations. pub mod runtime; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] /// Contains compile-time generated SQL schema traits, enabling a declarative approach to schema /// definition. pub mod schema; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] /// Provides utilities for automated testing of SQL interactions, ensuring reliability and /// correctness of database operations. pub mod testing; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] pub use driver::{Driver, Pool}; /// Driver System @@ -95,18 +87,10 @@ pub mod driver { #[cfg(all(feature = "sqlite", not(any(feature = "postgres", feature = "mysql"))))] /// Atmosphere Database Pool pub type Pool = sqlx::SqlitePool; - - #[cfg(not(any(feature = "postgres", feature = "mysql", feature = "sqlite")))] - compile_error!( - "you must chose a atmosphere database driver (available: postgres, mysql, sqlite)" - ); } -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] pub use bind::*; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] pub use error::*; -#[cfg(any(feature = "mysql", feature = "postgres", feature = "sqlite"))] pub use schema::*; #[doc(hidden)] diff --git a/atmosphere-macros/Cargo.toml b/atmosphere-macros/Cargo.toml index 02ea798..c018997 100644 --- a/atmosphere-macros/Cargo.toml +++ b/atmosphere-macros/Cargo.toml @@ -26,3 +26,6 @@ sqlite = ["atmosphere-core/sqlite"] [dev-dependencies] chrono = "0.4.31" + +[package.metadata.docs.rs] +features = ["postgres"] diff --git a/atmosphere-macros/src/lib.rs b/atmosphere-macros/src/lib.rs index b1dd28f..16e7744 100644 --- a/atmosphere-macros/src/lib.rs +++ b/atmosphere-macros/src/lib.rs @@ -9,6 +9,8 @@ //! and align with the framework's conventions, making them a powerful tool in the application //! development process. +#![cfg(any(feature = "postgres", feature = "mysql", feature = "sqlite"))] + use proc_macro::TokenStream; use quote::{quote, ToTokens}; use syn::{parse_macro_input, ItemStruct}; diff --git a/src/lib.rs b/src/lib.rs index 60409a7..9e3a00c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -20,6 +20,16 @@ //! - ORM-like CRUD traits. //! - Code reusability across API layers using generics. //! - Compile-time introspection for type-safe schema generation. +//! +//! ## Usage +//! +//! To use this crate you must activate **one** of the following features (else the crate is empty): +//! +//! - `mysql` +//! - `postgres` +//! - `sqlite` + +#![cfg(any(feature = "postgres", feature = "mysql", feature = "sqlite"))] pub use atmosphere_core::*; pub use atmosphere_macros::*;