Skip to content

Commit

Permalink
Fix workspace compilation and features shenanigans (#21)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
poliorcetics authored Apr 23, 2024
1 parent 71fe584 commit f0c08ae
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ required-features = ["sqlite"]
name = "integration"
path = "tests/lib.rs"
test = true
required-features = ["postgres"]

[package.metadata.docs.rs]
features = ["postgres"]
3 changes: 3 additions & 0 deletions atmosphere-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ sqlx.workspace = true
thiserror.workspace = true
lazy_static.workspace = true
miette = "5.10.0"

[package.metadata.docs.rs]
features = ["postgres"]
20 changes: 2 additions & 18 deletions atmosphere-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)]
Expand Down
3 changes: 3 additions & 0 deletions atmosphere-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ sqlite = ["atmosphere-core/sqlite"]

[dev-dependencies]
chrono = "0.4.31"

[package.metadata.docs.rs]
features = ["postgres"]
2 changes: 2 additions & 0 deletions atmosphere-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
10 changes: 10 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down

0 comments on commit f0c08ae

Please sign in to comment.