diff --git a/.github/workflows/codspeed.yml b/.github/workflows/codspeed.yml index 285c8c9fbd54..8df4048a17f5 100644 --- a/.github/workflows/codspeed.yml +++ b/.github/workflows/codspeed.yml @@ -31,7 +31,7 @@ jobs: run: cargo codspeed build -p schema --features all_connectors - name: "Build the benchmark targets: request-handlers" - run: cargo codspeed build -p request-handlers --features native,all + run: cargo codspeed build -p request-handlers --features all - name: Run the benchmarks uses: CodSpeedHQ/action@v2 diff --git a/.github/workflows/test-quaint.yml b/.github/workflows/test-quaint.yml index 0b4e2688c684..e744e727d1de 100644 --- a/.github/workflows/test-quaint.yml +++ b/.github/workflows/test-quaint.yml @@ -16,7 +16,7 @@ jobs: fail-fast: false matrix: features: - - "--lib --features=all" + - "--lib --features=all-native" env: TEST_MYSQL: "mysql://root:prisma@localhost:3306/prisma" TEST_MYSQL8: "mysql://root:prisma@localhost:3307/prisma" diff --git a/Cargo.lock b/Cargo.lock index d3aa22a1b839..0015879cf0e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -518,6 +518,18 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "cfg_aliases" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" + +[[package]] +name = "cfg_aliases" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77e53693616d3075149f4ead59bdeecd204ac6b8192d8969757601b74bddf00f" + [[package]] name = "chrono" version = "0.4.26" @@ -3578,6 +3590,7 @@ dependencies = [ "bit-vec", "byteorder", "bytes", + "cfg_aliases 0.1.1", "chrono", "connection-string", "crosstarget-utils", @@ -4242,6 +4255,7 @@ name = "request-handlers" version = "0.1.0" dependencies = [ "bigdecimal", + "cfg_aliases 0.2.0", "codspeed-criterion-compat", "connection-string", "dmmf", @@ -5913,7 +5927,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "97fee6b57c6a41524a810daee9286c02d7752c4253064d0b05472833a438f675" dependencies = [ "cfg-if", - "rand 0.7.3", + "rand 0.8.5", "static_assertions", ] diff --git a/libs/user-facing-errors/Cargo.toml b/libs/user-facing-errors/Cargo.toml index c679567cf931..250ba63fb434 100644 --- a/libs/user-facing-errors/Cargo.toml +++ b/libs/user-facing-errors/Cargo.toml @@ -16,3 +16,13 @@ quaint = { path = "../../quaint", default-features = false, optional = true } [features] default = [] sql = ["quaint"] +all-native = [ + "postgresql-native", + "mssql-native", + "mysql-native", + "sqlite-native", +] +postgresql-native = ["quaint/postgresql-native"] +mssql-native = ["quaint/mssql-native"] +mysql-native = ["quaint/mysql-native"] +sqlite-native = ["quaint/sqlite-native"] diff --git a/libs/user-facing-errors/src/quaint.rs b/libs/user-facing-errors/src/quaint.rs index b125f2114618..6089449ced1a 100644 --- a/libs/user-facing-errors/src/quaint.rs +++ b/libs/user-facing-errors/src/quaint.rs @@ -2,7 +2,12 @@ use crate::{common, query_engine, KnownError}; use indoc::formatdoc; use quaint::{error::ErrorKind, prelude::ConnectionInfo}; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(any( + feature = "mssql-native", + feature = "mysql-native", + feature = "postgresql-native", + feature = "sqlite-native" +))] use quaint::{connector::NativeConnectionInfo, error::NativeErrorKind}; impl From<&quaint::error::DatabaseConstraint> for query_engine::DatabaseConstraint { @@ -43,8 +48,10 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - match (kind, connection_info) { (ErrorKind::DatabaseDoesNotExist { .. }, ConnectionInfo::External(_)) => default_value, - #[cfg(not(target_arch = "wasm32"))] + #[cfg(any(feature = "mssql-native", feature = "mysql-native", feature = "postgresql-native"))] + #[allow(unused_variables)] (ErrorKind::DatabaseDoesNotExist { db_name }, _) => match connection_info { + #[cfg(feature = "postgresql-native")] ConnectionInfo::Native(NativeConnectionInfo::Postgres(url)) => { Some(KnownError::new(common::DatabaseDoesNotExist::Postgres { database_name: db_name.to_string(), @@ -52,6 +59,7 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - database_port: url.port(), })) } + #[cfg(feature = "mysql-native")] ConnectionInfo::Native(NativeConnectionInfo::Mysql(url)) => { Some(KnownError::new(common::DatabaseDoesNotExist::Mysql { database_name: url.dbname().to_owned(), @@ -59,6 +67,7 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - database_port: url.port(), })) } + #[cfg(feature = "mssql-native")] ConnectionInfo::Native(NativeConnectionInfo::Mssql(url)) => { Some(KnownError::new(common::DatabaseDoesNotExist::Mssql { database_name: url.dbname().to_owned(), @@ -70,7 +79,7 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - }, (ErrorKind::DatabaseAccessDenied { .. }, ConnectionInfo::External(_)) => default_value, - #[cfg(not(target_arch = "wasm32"))] + #[cfg(any(feature = "mysql-native", feature = "postgresql-native"))] (ErrorKind::DatabaseAccessDenied { .. }, _) => match connection_info { ConnectionInfo::Native(NativeConnectionInfo::Postgres(url)) => { Some(KnownError::new(common::DatabaseAccessDenied { @@ -88,8 +97,9 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - }, (ErrorKind::DatabaseAlreadyExists { .. }, ConnectionInfo::External(_)) => default_value, - #[cfg(not(target_arch = "wasm32"))] + #[cfg(any(feature = "mysql-native", feature = "postgresql-native"))] (ErrorKind::DatabaseAlreadyExists { db_name }, _) => match connection_info { + #[cfg(feature = "postgresql-native")] ConnectionInfo::Native(NativeConnectionInfo::Postgres(url)) => { Some(KnownError::new(common::DatabaseAlreadyExists { database_name: format!("{db_name}"), @@ -97,6 +107,7 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - database_port: url.port(), })) } + #[cfg(feature = "mysql-native")] ConnectionInfo::Native(NativeConnectionInfo::Mysql(url)) => { Some(KnownError::new(common::DatabaseAlreadyExists { database_name: format!("{db_name}"), @@ -108,7 +119,7 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - }, (ErrorKind::AuthenticationFailed { .. }, ConnectionInfo::External(_)) => default_value, - #[cfg(not(target_arch = "wasm32"))] + #[cfg(any(feature = "mysql-native", feature = "postgresql-native"))] (ErrorKind::AuthenticationFailed { user }, _) => match connection_info { ConnectionInfo::Native(NativeConnectionInfo::Postgres(url)) => { Some(KnownError::new(common::IncorrectDatabaseCredentials { @@ -126,7 +137,7 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - }, (ErrorKind::SocketTimeout { .. }, ConnectionInfo::External(_)) => default_value, - #[cfg(not(target_arch = "wasm32"))] + #[cfg(any(feature = "mssql-native", feature = "mysql-native", feature = "postgresql-native"))] (ErrorKind::SocketTimeout, _) => match connection_info { ConnectionInfo::Native(NativeConnectionInfo::Postgres(url)) => { let time = match url.socket_timeout() { @@ -168,12 +179,14 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - }, (ErrorKind::TableDoesNotExist { .. }, ConnectionInfo::External(_)) => default_value, - #[cfg(not(target_arch = "wasm32"))] + #[cfg(any(feature = "mssql-native", feature = "mysql-native", feature = "postgresql-native"))] (ErrorKind::TableDoesNotExist { table: model }, _) => match connection_info { + #[cfg(feature = "postgresql-native")] ConnectionInfo::Native(NativeConnectionInfo::Postgres(_)) => Some(KnownError::new(common::InvalidModel { model: format!("{model}"), kind: common::ModelKind::Table, })), + #[cfg(feature = "postgresql-native")] ConnectionInfo::Native(NativeConnectionInfo::Mysql(_)) => Some(KnownError::new(common::InvalidModel { model: format!("{model}"), kind: common::ModelKind::Table, @@ -215,20 +228,28 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - })) } - #[cfg(not(target_arch = "wasm32"))] + #[cfg(any( + feature = "mssql-native", + feature = "mysql-native", + feature = "postgresql-native", + feature = "sqlite-native" + ))] (ErrorKind::Native(native_error_kind), _) => match (native_error_kind, connection_info) { + #[cfg(feature = "postgresql-native")] (NativeErrorKind::ConnectionError(_), ConnectionInfo::Native(NativeConnectionInfo::Postgres(url))) => { Some(KnownError::new(common::DatabaseNotReachable { database_port: url.port(), database_host: url.host().to_owned(), })) } + #[cfg(feature = "mysql-native")] (NativeErrorKind::ConnectionError(_), ConnectionInfo::Native(NativeConnectionInfo::Mysql(url))) => { Some(KnownError::new(common::DatabaseNotReachable { database_port: url.port(), database_host: url.host().to_owned(), })) } + #[cfg(feature = "mssql-native")] (NativeErrorKind::ConnectionError(_), ConnectionInfo::Native(NativeConnectionInfo::Mssql(url))) => { Some(KnownError::new(common::DatabaseNotReachable { database_port: url.port(), @@ -238,18 +259,21 @@ pub fn render_quaint_error(kind: &ErrorKind, connection_info: &ConnectionInfo) - (NativeErrorKind::TlsError { message }, _) => Some(KnownError::new(common::TlsConnectionError { message: message.into(), })), + #[cfg(feature = "postgresql-native")] (NativeErrorKind::ConnectTimeout, ConnectionInfo::Native(NativeConnectionInfo::Postgres(url))) => { Some(KnownError::new(common::DatabaseNotReachable { database_host: url.host().to_owned(), database_port: url.port(), })) } + #[cfg(feature = "mysql-native")] (NativeErrorKind::ConnectTimeout, ConnectionInfo::Native(NativeConnectionInfo::Mysql(url))) => { Some(KnownError::new(common::DatabaseNotReachable { database_host: url.host().to_owned(), database_port: url.port(), })) } + #[cfg(feature = "mssql-native")] (NativeErrorKind::ConnectTimeout, ConnectionInfo::Native(NativeConnectionInfo::Mssql(url))) => { Some(KnownError::new(common::DatabaseNotReachable { database_host: url.host().to_owned(), diff --git a/quaint/Cargo.toml b/quaint/Cargo.toml index eebd14e62775..66f917c90af2 100644 --- a/quaint/Cargo.toml +++ b/quaint/Cargo.toml @@ -28,9 +28,12 @@ docs = [] # way to access database-specific methods when you need extra control. expose-drivers = [] -native = ["postgresql-native", "mysql-native", "mssql-native", "sqlite-native"] - -all = ["native", "pooled"] +all-native = [ + "postgresql-native", + "mysql-native", + "mssql-native", + "sqlite-native", +] vendored-openssl = [ "postgres-native-tls/vendored-openssl", @@ -177,3 +180,6 @@ optional = true version = "0.6" features = ["compat"] optional = true + +[build-dependencies] +cfg_aliases = "0.1.0" diff --git a/quaint/build.rs b/quaint/build.rs new file mode 100644 index 000000000000..b47f6f1a0554 --- /dev/null +++ b/quaint/build.rs @@ -0,0 +1,14 @@ +use cfg_aliases::cfg_aliases; + +fn main() { + cfg_aliases! { + native: { + any( + feature = "mssql-native", + feature = "mysql-native", + feature = "postgresql-native", + feature = "sqlite-native" + ) + } + } +} diff --git a/quaint/quaint-test-setup/Cargo.toml b/quaint/quaint-test-setup/Cargo.toml index a5ef732f6dfe..eb47bd587e95 100644 --- a/quaint/quaint-test-setup/Cargo.toml +++ b/quaint/quaint-test-setup/Cargo.toml @@ -10,4 +10,4 @@ bitflags = "1.2.1" async-trait.workspace = true names = "0.11" tokio = { version = "1.0", features = ["rt-multi-thread"] } -quaint = { path = "..", features = ["all"] } +quaint = { path = "..", features = ["all-native", "pooled"] } diff --git a/quaint/src/connector.rs b/quaint/src/connector.rs index 475856936566..5248708b2a93 100644 --- a/quaint/src/connector.rs +++ b/quaint/src/connector.rs @@ -13,7 +13,7 @@ mod connection_info; pub mod external; pub mod metrics; -#[cfg(feature = "native")] +#[cfg(native)] pub mod native; mod queryable; mod result_set; @@ -25,13 +25,14 @@ mod type_identifier; pub use self::result_set::*; pub use connection_info::*; -#[cfg(feature = "native")] +#[cfg(native)] pub use native::*; pub use external::*; pub use queryable::*; pub use transaction::*; -#[cfg(any(feature = "mssql-native", feature = "postgresql-native", feature = "mysql-native"))] + +#[cfg(native)] #[allow(unused_imports)] pub(crate) use type_identifier::*; diff --git a/quaint/src/connector/connection_info.rs b/quaint/src/connector/connection_info.rs index 90b123106d89..4389e5ea2e55 100644 --- a/quaint/src/connector/connection_info.rs +++ b/quaint/src/connector/connection_info.rs @@ -18,7 +18,7 @@ use std::convert::TryFrom; use super::ExternalConnectionInfo; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(native)] use super::NativeConnectionInfo; /// General information about a SQL connection. @@ -267,12 +267,9 @@ impl ConnectionInfo { pub fn version(&self) -> Option<&str> { match self { - #[cfg(not(target_arch = "wasm32"))] - ConnectionInfo::Native(nt) => match nt { - NativeConnectionInfo::Mysql(m) => m.version(), - _ => None, - }, - ConnectionInfo::External(_) => None, + #[cfg(feature = "mysql-native")] + ConnectionInfo::Native(NativeConnectionInfo::Mysql(m)) => m.version(), + _ => None, } } } diff --git a/quaint/src/connector/native.rs b/quaint/src/connector/native.rs index 4a1a12a2733b..d70f710da8d8 100644 --- a/quaint/src/connector/native.rs +++ b/quaint/src/connector/native.rs @@ -31,6 +31,7 @@ pub enum NativeConnectionInfo { } impl NativeConnectionInfo { + #[allow(unused)] pub fn set_version(&mut self, version: Option) { #[cfg(feature = "mysql")] if let NativeConnectionInfo::Mysql(c) = self { diff --git a/quaint/src/connector/timeout.rs b/quaint/src/connector/timeout.rs index a0445c4c7a26..bb88220ec70a 100644 --- a/quaint/src/connector/timeout.rs +++ b/quaint/src/connector/timeout.rs @@ -2,7 +2,7 @@ use crate::error::{Error, ErrorKind}; use futures::Future; use std::time::Duration; -#[cfg(feature = "native")] +#[cfg(native)] pub async fn connect(duration: Option, f: F) -> crate::Result where F: Future>, diff --git a/quaint/src/pooled.rs b/quaint/src/pooled.rs index 2dc1a843eba1..3e7e58c05e52 100644 --- a/quaint/src/pooled.rs +++ b/quaint/src/pooled.rs @@ -152,11 +152,11 @@ mod manager; pub use manager::*; -#[cfg(feature = "native")] -use crate::{connector::NativeConnectionInfo, error::NativeErrorKind}; +#[cfg(native)] +use crate::error::NativeErrorKind; use crate::{ - connector::{ConnectionInfo, PostgresFlavour}, + connector::ConnectionInfo, error::{Error, ErrorKind}, }; use mobc::Pool; @@ -305,7 +305,9 @@ impl Builder { /// - Unknown: Always add a network roundtrip by setting the search path through a database query. /// /// - Defaults to `PostgresFlavour::Unknown`. - pub fn set_postgres_flavour(&mut self, flavour: PostgresFlavour) { + #[cfg(feature = "postgresql-native")] + pub fn set_postgres_flavour(&mut self, flavour: crate::connector::PostgresFlavour) { + use crate::connector::NativeConnectionInfo; if let ConnectionInfo::Native(NativeConnectionInfo::Postgres(ref mut url)) = self.connection_info { url.set_flavour(flavour); } diff --git a/quaint/src/prelude.rs b/quaint/src/prelude.rs index 6b28926a5f43..1fe867ccd4cc 100644 --- a/quaint/src/prelude.rs +++ b/quaint/src/prelude.rs @@ -6,5 +6,5 @@ pub use crate::connector::{ }; pub use crate::{col, val, values}; -#[cfg(feature = "native")] +#[cfg(native)] pub use crate::connector::NativeConnectionInfo; diff --git a/quaint/src/single.rs b/quaint/src/single.rs index 653ac990b2e2..6e76a8003f09 100644 --- a/quaint/src/single.rs +++ b/quaint/src/single.rs @@ -10,7 +10,7 @@ use std::{fmt, sync::Arc}; #[cfg(feature = "sqlite-native")] use std::convert::TryFrom; -#[cfg(feature = "native")] +#[cfg(native)] use crate::connector::NativeConnectionInfo; /// The main entry point and an abstraction over a database connection. @@ -128,7 +128,7 @@ impl Quaint { /// - `isolationLevel` the transaction isolation level. Possible values: /// `READ UNCOMMITTED`, `READ COMMITTED`, `REPEATABLE READ`, `SNAPSHOT`, /// `SERIALIZABLE`. - #[cfg(feature = "native")] + #[cfg(native)] #[allow(unreachable_code)] pub async fn new(url_str: &str) -> crate::Result { let inner = match url_str { @@ -186,7 +186,7 @@ impl Quaint { &self.connection_info } - #[cfg(feature = "native")] + #[cfg(native)] fn log_start(info: &ConnectionInfo) { let family = info.sql_family(); let pg_bouncer = if info.pg_bouncer() { " in PgBouncer mode" } else { "" }; diff --git a/query-engine/connectors/sql-query-connector/Cargo.toml b/query-engine/connectors/sql-query-connector/Cargo.toml index c7152688629c..c617800a966e 100644 --- a/query-engine/connectors/sql-query-connector/Cargo.toml +++ b/query-engine/connectors/sql-query-connector/Cargo.toml @@ -5,13 +5,27 @@ version = "0.1.0" [features] postgresql = ["relation_joins", "quaint/postgresql", "psl/postgresql"] +postgresql-native = ["postgresql", "quaint/postgresql-native", "quaint/pooled"] mysql = ["relation_joins", "quaint/mysql", "psl/mysql"] +mysql-native = ["mysql", "quaint/mysql-native", "quaint/pooled"] sqlite = ["quaint/sqlite", "psl/sqlite"] +sqlite-native = ["sqlite", "quaint/sqlite-native", "quaint/pooled"] mssql = ["quaint/mssql"] +mssql-native = ["mssql", "quaint/mssql-native", "quaint/pooled"] cockroachdb = ["relation_joins", "quaint/postgresql", "psl/cockroachdb"] +cockroachdb-native = [ + "cockroachdb", + "quaint/postgresql-native", + "quaint/pooled", +] vendored-openssl = ["quaint/vendored-openssl"] -all = ["sqlite", "mysql", "postgresql", "mssql", "cockroachdb", "native"] -native = ["quaint/native", "quaint/pooled"] +all-native = [ + "sqlite-native", + "mysql-native", + "postgresql-native", + "mssql-native", + "cockroachdb-native", +] # TODO: At the moment of writing (rustc 1.77.0), can_have_capability from psl does not eliminate joins # code from bundle for some reason, so we are doing it explicitly. Check with a newer version of compiler - if elimination # happens successfully, we don't need this feature anymore @@ -31,7 +45,7 @@ rand.workspace = true serde_json.workspace = true thiserror = "1.0" tokio = { version = "1.0", features = ["macros", "time"] } -tracing.workspace = true +tracing = { workspace = true, features = ["log"] } tracing-futures = "0.2" uuid.workspace = true opentelemetry = { version = "0.17", features = ["tokio"] } diff --git a/query-engine/connectors/sql-query-connector/src/database/mod.rs b/query-engine/connectors/sql-query-connector/src/database/mod.rs index e0ec3f7e29e5..e7e755562806 100644 --- a/query-engine/connectors/sql-query-connector/src/database/mod.rs +++ b/query-engine/connectors/sql-query-connector/src/database/mod.rs @@ -3,7 +3,12 @@ mod connection; mod js; mod transaction; -#[cfg(feature = "native")] +#[cfg(any( + feature = "mssql-native", + feature = "mysql-native", + feature = "postgresql-native", + feature = "sqlite-native" +))] pub(crate) mod native { #[cfg(feature = "mssql")] pub(crate) mod mssql; @@ -23,16 +28,16 @@ use connector_interface::{error::ConnectorError, Connector}; #[cfg(feature = "driver-adapters")] pub use js::*; -#[cfg(all(feature = "native", feature = "mssql"))] +#[cfg(feature = "mssql-native")] pub use native::mssql::*; -#[cfg(all(feature = "native", feature = "mysql"))] +#[cfg(feature = "mysql-native")] pub use native::mysql::*; -#[cfg(all(feature = "native", feature = "postgresql"))] +#[cfg(feature = "postgresql-native")] pub use native::postgresql::*; -#[cfg(all(feature = "native", feature = "sqlite"))] +#[cfg(feature = "sqlite-native")] pub use native::sqlite::*; #[async_trait] diff --git a/query-engine/connectors/sql-query-connector/src/lib.rs b/query-engine/connectors/sql-query-connector/src/lib.rs index 52bc33a51b0c..da2bbe996e8b 100644 --- a/query-engine/connectors/sql-query-connector/src/lib.rs +++ b/query-engine/connectors/sql-query-connector/src/lib.rs @@ -27,16 +27,16 @@ pub use database::FromSource; pub use database::Js; pub use error::SqlError; -#[cfg(all(feature = "native", feature = "mssql"))] +#[cfg(feature = "mssql-native")] pub use database::Mssql; -#[cfg(all(feature = "native", feature = "mysql"))] +#[cfg(feature = "mysql-native")] pub use database::Mysql; -#[cfg(all(feature = "native", feature = "postgresql"))] +#[cfg(feature = "postgresql-native")] pub use database::PostgreSql; -#[cfg(all(feature = "native", feature = "sqlite"))] +#[cfg(feature = "sqlite-native")] pub use database::Sqlite; type Result = std::result::Result; diff --git a/query-engine/core-tests/Cargo.toml b/query-engine/core-tests/Cargo.toml index 2d02ddbf3e1a..6c616771373c 100644 --- a/query-engine/core-tests/Cargo.toml +++ b/query-engine/core-tests/Cargo.toml @@ -8,7 +8,7 @@ edition = "2021" [dev-dependencies] dissimilar = "1.0.4" user-facing-errors = { path = "../../libs/user-facing-errors" } -request-handlers = { path = "../request-handlers", features=["native"] } +request-handlers = { path = "../request-handlers", features = ["all"] } query-core = { path = "../core", features = ["metrics"] } schema = { path = "../schema" } psl.workspace = true diff --git a/query-engine/query-engine-c-abi/.gitignore b/query-engine/query-engine-c-abi/.gitignore index 2974fad5812d..849b6e986177 100644 --- a/query-engine/query-engine-c-abi/.gitignore +++ b/query-engine/query-engine-c-abi/.gitignore @@ -2,6 +2,5 @@ QueryEngine.xcframework simulator_fat # Artifacts of the C ABI engine *.tar.gz -openssl-3.1.4 libs include \ No newline at end of file diff --git a/query-engine/query-engine-c-abi/Cargo.toml b/query-engine/query-engine-c-abi/Cargo.toml index 6b58e43175aa..21e127519ddb 100644 --- a/query-engine/query-engine-c-abi/Cargo.toml +++ b/query-engine/query-engine-c-abi/Cargo.toml @@ -13,8 +13,7 @@ anyhow = "1" async-trait = "0.1" query-core = { path = "../core" } request-handlers = { path = "../request-handlers", features = [ - "sqlite", - "native", + "sqlite-native", ] } query-connector = { path = "../connectors/query-connector" } query-engine-common = { path = "../../libs/query-engine-common" } diff --git a/query-engine/query-engine-c-abi/build-android-target.sh b/query-engine/query-engine-c-abi/build-android-target.sh index 823888f02473..db9b7d226a9b 100755 --- a/query-engine/query-engine-c-abi/build-android-target.sh +++ b/query-engine/query-engine-c-abi/build-android-target.sh @@ -16,44 +16,16 @@ if [ "$TARGET" = "armv7-linux-androideabi" ]; then NDK_TARGET="armv7a-linux-androideabi" fi -OPENSSL_ARCH="android-arm64" -# if [ "$TARGET" = "aarch64-linux-android" ]; then -# fi - -if [ "$TARGET" = "x86_64-linux-android" ]; then - OPENSSL_ARCH="android-x86_64" -fi - -if [ "$TARGET" = "armv7-linux-androideabi" ]; then - OPENSSL_ARCH="android-arm" -fi - -if [ "$TARGET" = "i686-linux-android" ]; then - OPENSSL_ARCH="android-x86" -fi - - API_VERSION="21" -NDK_VERSION="26.0.10792818" NDK_HOST="darwin-x86_64" -if [ -z "$ANDROID_SDK_ROOT" ]; then - echo "ANDROID SDK IS MISSING 🟥" +if [ -z "$ANDROID_NDK_ROOT" ]; then + echo "ANDROID NDK IS MISSING 🟥" exit 1 fi -if [ -z "$NDK" ]; then - NDK="$ANDROID_SDK_ROOT/ndk/$NDK_VERSION" -fi - -TOOLS="$NDK/toolchains/llvm/prebuilt/$NDK_HOST" - -CWD=$(pwd) - -export OPENSSL_DIR=$CWD/libs/$OPENSSL_ARCH -export OPENSSL_STATIC=1 +TOOLS="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$NDK_HOST" -# OPENSSL_DIR=./libs/android/clang/${OPENSSL_ARCH} \ AR=$TOOLS/bin/llvm-ar \ CC=$TOOLS/bin/${NDK_TARGET}${API_VERSION}-clang \ CXX=$TOOLS/bin/${NDK_TARGET}${API_VERSION}-clang++ \ diff --git a/query-engine/query-engine-c-abi/build-openssl.sh b/query-engine/query-engine-c-abi/build-openssl.sh deleted file mode 100755 index 878d4ed727ae..000000000000 --- a/query-engine/query-engine-c-abi/build-openssl.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/bash - -#set -v -set -ex - -export OPENSSL_VERSION="openssl-3.1.4" -rm -rf ${OPENSSL_VERSION} -# check if the tar is already downloaded and if not download and extract it -if [ ! -d ${OPENSSL_VERSION}.tar.gz ]; then - curl -O "https://www.openssl.org/source/${OPENSSL_VERSION}.tar.gz" - tar xfz "${OPENSSL_VERSION}.tar.gz" -fi - -PATH_ORG=$PATH -OUTPUT_DIR="libs" - -# Clean output: -rm -rf $OUTPUT_DIR -mkdir $OUTPUT_DIR - -build_android_clang() { - - echo "" - echo "----- Build libcrypto & libssl.so for $1 -----" - echo "" - - ARCHITECTURE=$1 - TOOLCHAIN=$2 - - # Set toolchain - export TOOLCHAIN_ROOT=$ANDROID_NDK_HOME/toolchains/llvm/prebuilt/darwin-x86_64 - export SYSROOT=$TOOLCHAIN_ROOT/sysroot - export CC=${TOOLCHAIN}21-clang - export CXX=${TOOLCHAIN}21-clang++ - export CXXFLAGS="-fPIC" - export CPPFLAGS="-DANDROID -fPIC" - - export PATH=$TOOLCHAIN_ROOT/bin:$SYSROOT/usr/local/bin:$PATH - - cd "${OPENSSL_VERSION}" - - ./Configure "$ARCHITECTURE" no-asm no-shared -D__ANDROID_API__=21 - - make clean - # Apply patch that fixes the armcap instruction - # Linux version - # sed -e '/[.]hidden.*OPENSSL_armcap_P/d; /[.]extern.*OPENSSL_armcap_P/ {p; s/extern/hidden/ }' -i -- crypto/*arm*pl crypto/*/asm/*arm*pl - # macOS version - sed -E -i '' -e '/[.]hidden.*OPENSSL_armcap_P/d' -e '/[.]extern.*OPENSSL_armcap_P/ {p; s/extern/hidden/; }' crypto/*arm*pl crypto/*/asm/*arm*pl - - make - - mkdir -p ../$OUTPUT_DIR/"${ARCHITECTURE}"/lib - mkdir -p ../$OUTPUT_DIR/"${ARCHITECTURE}"/include - - # file libcrypto.so - # file libssl.so - - cp libcrypto.a ../$OUTPUT_DIR/"${ARCHITECTURE}"/lib/libcrypto.a - cp libssl.a ../$OUTPUT_DIR/"${ARCHITECTURE}"/lib/libssl.a - # cp libcrypto.so ../$OUTPUT_DIR/${ARCHITECTURE}/lib/libcrypto.so - # cp libssl.so ../$OUTPUT_DIR/${ARCHITECTURE}/lib/libssl.so - - cp -R include/openssl ../$OUTPUT_DIR/"${ARCHITECTURE}"/include - - cd .. -} - -build_android_clang "android-arm" "armv7a-linux-androideabi" -build_android_clang "android-x86" "i686-linux-android" -build_android_clang "android-x86_64" "x86_64-linux-android" -build_android_clang "android-arm64" "aarch64-linux-android" - -export PATH=$PATH_ORG - -# pingme "OpenSSL finished compiling" \ No newline at end of file diff --git a/query-engine/query-engine-node-api/Cargo.toml b/query-engine/query-engine-node-api/Cargo.toml index e5233fea4c03..cbe4f455b58b 100644 --- a/query-engine/query-engine-node-api/Cargo.toml +++ b/query-engine/query-engine-node-api/Cargo.toml @@ -20,17 +20,13 @@ driver-adapters = [ anyhow = "1" async-trait.workspace = true query-core = { path = "../core", features = ["metrics"] } -request-handlers = { path = "../request-handlers", features = [ - "native", - "all", -] } +request-handlers = { path = "../request-handlers", features = ["all"] } query-connector = { path = "../connectors/query-connector" } query-engine-common = { path = "../../libs/query-engine-common" } user-facing-errors = { path = "../../libs/user-facing-errors" } psl = { workspace = true, features = ["all"] } sql-connector = { path = "../connectors/sql-query-connector", package = "sql-query-connector", features = [ - "native", - "all", + "all-native", ] } query-structure = { path = "../query-structure" } driver-adapters = { path = "../driver-adapters", features = [ diff --git a/query-engine/query-engine/Cargo.toml b/query-engine/query-engine/Cargo.toml index 72ff363e5ada..e3fd4768ed76 100644 --- a/query-engine/query-engine/Cargo.toml +++ b/query-engine/query-engine/Cargo.toml @@ -4,9 +4,7 @@ name = "query-engine" version = "0.1.0" [features] -default = ["sql", "mongodb"] -mongodb = ["mongodb-connector"] -sql = ["sql-connector", "sql-connector/all", "sql-connector/native"] +sql = ["sql-connector", "sql-connector/all-native"] vendored-openssl = ["sql-connector/vendored-openssl"] [dependencies] @@ -21,10 +19,7 @@ psl = { workspace = true, features = ["all"] } graphql-parser = { git = "https://github.com/prisma/graphql-parser" } mongodb-connector = { path = "../connectors/mongodb-query-connector", optional = true, package = "mongodb-query-connector" } query-core = { path = "../core", features = ["metrics"] } -request-handlers = { path = "../request-handlers", features = [ - "native", - "all", -] } +request-handlers = { path = "../request-handlers", features = ["all"] } serde.workspace = true serde_json.workspace = true sql-connector = { path = "../connectors/sql-query-connector", optional = true, package = "sql-query-connector" } diff --git a/query-engine/request-handlers/Cargo.toml b/query-engine/request-handlers/Cargo.toml index 802d72344f7e..fe9a66b449a5 100644 --- a/query-engine/request-handlers/Cargo.toml +++ b/query-engine/request-handlers/Cargo.toml @@ -33,28 +33,50 @@ codspeed-criterion-compat = "1.1.0" [features] mongodb = ["mongodb-query-connector", "psl/mongodb"] -sql = ["sql-query-connector"] +sql = ["dep:sql-query-connector"] postgresql = ["sql", "sql-query-connector/postgresql", "psl/postgresql"] +postgresql-native = [ + "postgresql", + "sql-query-connector/postgresql-native", + "user-facing-errors/postgresql-native", +] mysql = ["sql", "sql-query-connector/mysql", "psl/mysql"] +mysql-native = [ + "mysql", + "sql-query-connector/mysql-native", + "user-facing-errors/mysql-native", +] sqlite = ["sql", "sql-query-connector/sqlite", "psl/sqlite"] +sqlite-native = ["sqlite", "sql-query-connector/sqlite-native"] cockroachdb = ["sql", "sql-query-connector/postgresql", "psl/cockroachdb"] +cockroachdb-native = [ + "cockroachdb", + "sql-query-connector/cockroachdb", + "user-facing-errors/postgresql-native", +] mssql = ["sql", "sql-query-connector/mssql", "psl/mssql"] +mssql-native = [ + "mssql", + "sql-query-connector/mssql-native", + "user-facing-errors/mssql-native", +] driver-adapters = ["sql-query-connector/driver-adapters"] -native = ["sql-query-connector/native"] all = [ "mongodb", - "mysql", - "sqlite", - "postgresql", - "cockroachdb", - "mssql", + "mysql-native", + "sqlite-native", + "postgresql-native", + "cockroachdb-native", + "mssql-native", "graphql-protocol", - "sql-query-connector/all", "psl/all", "query-core/metrics", ] graphql-protocol = ["query-core/graphql-protocol", "dep:graphql-parser"] +[build-dependencies] +cfg_aliases = "0.2.0" + [[bench]] name = "query_planning_bench" harness = false diff --git a/query-engine/request-handlers/build.rs b/query-engine/request-handlers/build.rs new file mode 100644 index 000000000000..17ea32bcf551 --- /dev/null +++ b/query-engine/request-handlers/build.rs @@ -0,0 +1,16 @@ +use cfg_aliases::cfg_aliases; + +fn main() { + cfg_aliases! { + native: { + any( + feature = "mongodb", + feature = "mssql-native", + feature = "mysql-native", + feature = "postgresql-native", + feature = "sqlite-native", + feature = "cockroachdb-native" + ) + } + } +} diff --git a/query-engine/request-handlers/src/load_executor.rs b/query-engine/request-handlers/src/load_executor.rs index 0a289cd80adc..7a4b0351af68 100644 --- a/query-engine/request-handlers/src/load_executor.rs +++ b/query-engine/request-handlers/src/load_executor.rs @@ -11,7 +11,7 @@ use std::sync::Arc; use url::Url; pub enum ConnectorKind<'a> { - #[cfg(feature = "native")] + #[cfg(native)] Rust { url: String, datasource: &'a Datasource }, Js { adapter: Arc, @@ -33,7 +33,7 @@ pub async fn load( #[cfg(feature = "driver-adapters")] ConnectorKind::Js { adapter, _phantom } => driver_adapter(adapter, features).await, - #[cfg(feature = "native")] + #[cfg(native)] ConnectorKind::Rust { url, datasource } => { if let Ok(value) = env::var("PRISMA_DISABLE_QUAINT_EXECUTORS") { let disable = value.to_uppercase(); @@ -43,15 +43,15 @@ pub async fn load( } match datasource.active_provider { - #[cfg(feature = "sqlite")] + #[cfg(feature = "sqlite-native")] p if SQLITE.is_provider(p) => native::sqlite(datasource, &url, features).await, - #[cfg(feature = "mysql")] + #[cfg(feature = "mysql-native")] p if MYSQL.is_provider(p) => native::mysql(datasource, &url, features).await, - #[cfg(feature = "postgresql")] + #[cfg(feature = "postgresql-native")] p if POSTGRES.is_provider(p) => native::postgres(datasource, &url, features).await, - #[cfg(feature = "mssql")] + #[cfg(feature = "mssql-native")] p if MSSQL.is_provider(p) => native::mssql(datasource, &url, features).await, - #[cfg(feature = "cockroachdb")] + #[cfg(feature = "cockroachdb-native")] p if COCKROACH.is_provider(p) => native::postgres(datasource, &url, features).await, #[cfg(feature = "mongodb")] p if MONGODB.is_provider(p) => native::mongodb(datasource, &url, features).await, @@ -75,12 +75,12 @@ async fn driver_adapter( Ok(executor_for(js, false)) } -#[cfg(feature = "native")] +#[cfg(native)] mod native { use super::*; use tracing::trace; - #[cfg(feature = "sqlite")] + #[cfg(feature = "sqlite-native")] pub(crate) async fn sqlite( source: &Datasource, url: &str, @@ -92,7 +92,7 @@ mod native { Ok(executor_for(sqlite, false)) } - #[cfg(feature = "postgresql")] + #[cfg(feature = "postgresql-native")] pub(crate) async fn postgres( source: &Datasource, url: &str, @@ -115,7 +115,7 @@ mod native { Ok(executor_for(psql, force_transactions)) } - #[cfg(feature = "mysql")] + #[cfg(feature = "mysql-native")] pub(crate) async fn mysql( source: &Datasource, url: &str, @@ -126,7 +126,7 @@ mod native { Ok(executor_for(mysql, false)) } - #[cfg(feature = "mssql")] + #[cfg(feature = "mssql-native")] pub(crate) async fn mssql( source: &Datasource, url: &str, diff --git a/schema-engine/cli/Cargo.toml b/schema-engine/cli/Cargo.toml index 8bd6c3f65b96..bfb136f582df 100644 --- a/schema-engine/cli/Cargo.toml +++ b/schema-engine/cli/Cargo.toml @@ -6,7 +6,9 @@ edition = "2021" [dependencies] schema-connector = { path = "../connectors/schema-connector" } schema-core = { path = "../core" } -user-facing-errors = { path = "../../libs/user-facing-errors" } +user-facing-errors = { path = "../../libs/user-facing-errors", features = [ + "all-native", +] } backtrace = "0.3.59" base64 = "0.13" @@ -32,7 +34,7 @@ url.workspace = true indoc.workspace = true connection-string.workspace = true expect-test = "1.4.0" -quaint = { workspace = true, features = ["native"] } +quaint = { workspace = true, features = ["all-native"] } [[bin]] name = "schema-engine" diff --git a/schema-engine/connectors/mongodb-schema-connector/Cargo.toml b/schema-engine/connectors/mongodb-schema-connector/Cargo.toml index c23ad970bd16..111ece4d6ea3 100644 --- a/schema-engine/connectors/mongodb-schema-connector/Cargo.toml +++ b/schema-engine/connectors/mongodb-schema-connector/Cargo.toml @@ -9,7 +9,9 @@ mongodb-client = { path = "../../../libs/mongodb-client" } mongodb-schema-describer = { path = "../../mongodb-schema-describer" } datamodel-renderer = { path = "../../datamodel-renderer" } schema-connector = { path = "../schema-connector" } -user-facing-errors = { path = "../../../libs/user-facing-errors" } +user-facing-errors = { path = "../../../libs/user-facing-errors", features = [ + "all-native", +] } enumflags2.workspace = true futures = "0.3" diff --git a/schema-engine/connectors/schema-connector/Cargo.toml b/schema-engine/connectors/schema-connector/Cargo.toml index f023fe4f49e9..5c40185f2a3b 100644 --- a/schema-engine/connectors/schema-connector/Cargo.toml +++ b/schema-engine/connectors/schema-connector/Cargo.toml @@ -5,10 +5,12 @@ edition = "2021" [dependencies] psl.workspace = true -quaint = { workspace = true, features = ["native", "pooled"] } +quaint = { workspace = true, features = ["all-native", "pooled"] } serde.workspace = true serde_json.workspace = true -user-facing-errors = { path = "../../../libs/user-facing-errors" } +user-facing-errors = { path = "../../../libs/user-facing-errors", features = [ + "all-native", +] } chrono.workspace = true enumflags2.workspace = true diff --git a/schema-engine/connectors/sql-schema-connector/Cargo.toml b/schema-engine/connectors/sql-schema-connector/Cargo.toml index d2347d8bfec6..956b90a42a40 100644 --- a/schema-engine/connectors/sql-schema-connector/Cargo.toml +++ b/schema-engine/connectors/sql-schema-connector/Cargo.toml @@ -9,7 +9,7 @@ vendored-openssl = ["quaint/vendored-openssl"] [dependencies] psl.workspace = true quaint = { workspace = true, features = [ - "native", + "all-native", "expose-drivers", "pooled", "fmt-sql", @@ -26,6 +26,7 @@ datamodel-renderer = { path = "../../datamodel-renderer" } sql-ddl = { path = "../../../libs/sql-ddl" } user-facing-errors = { path = "../../../libs/user-facing-errors", features = [ "sql", + "all-native", ] } chrono.workspace = true diff --git a/schema-engine/core/Cargo.toml b/schema-engine/core/Cargo.toml index bd9a33247af3..6814bf60ed23 100644 --- a/schema-engine/core/Cargo.toml +++ b/schema-engine/core/Cargo.toml @@ -8,7 +8,9 @@ psl = { workspace = true, features = ["all"] } schema-connector = { path = "../connectors/schema-connector" } mongodb-schema-connector = { path = "../connectors/mongodb-schema-connector" } sql-schema-connector = { path = "../connectors/sql-schema-connector" } -user-facing-errors = { path = "../../libs/user-facing-errors" } +user-facing-errors = { path = "../../libs/user-facing-errors", features = [ + "all-native", +] } async-trait.workspace = true chrono.workspace = true diff --git a/schema-engine/sql-introspection-tests/Cargo.toml b/schema-engine/sql-introspection-tests/Cargo.toml index f537eae61b7b..2822dfb3fd38 100644 --- a/schema-engine/sql-introspection-tests/Cargo.toml +++ b/schema-engine/sql-introspection-tests/Cargo.toml @@ -9,7 +9,9 @@ sql-schema-connector = { path = "../connectors/sql-schema-connector" } sql-schema-describer = { path = "../sql-schema-describer" } psl = { workspace = true, features = ["all"] } test-macros = { path = "../../libs/test-macros" } -user-facing-errors = { path = "../../libs/user-facing-errors" } +user-facing-errors = { path = "../../libs/user-facing-errors", features = [ + "all-native", +] } test-setup = { path = "../../libs/test-setup" } enumflags2.workspace = true @@ -21,7 +23,7 @@ tracing.workspace = true indoc.workspace = true expect-test = "1.1.0" url.workspace = true -quaint = { workspace = true, features = ["native"] } +quaint = { workspace = true, features = ["all-native"] } [dependencies.barrel] git = "https://github.com/prisma/barrel.git" diff --git a/schema-engine/sql-migration-tests/Cargo.toml b/schema-engine/sql-migration-tests/Cargo.toml index 5b99906acc05..710ef1ebbd3b 100644 --- a/schema-engine/sql-migration-tests/Cargo.toml +++ b/schema-engine/sql-migration-tests/Cargo.toml @@ -8,7 +8,9 @@ psl = { workspace = true, features = ["all"] } schema-core = { path = "../core" } sql-schema-connector = { path = "../connectors/sql-schema-connector" } sql-schema-describer = { path = "../sql-schema-describer" } -user-facing-errors = { path = "../../libs/user-facing-errors" } +user-facing-errors = { path = "../../libs/user-facing-errors", features = [ + "all-native", +] } test-macros = { path = "../../libs/test-macros" } test-setup = { path = "../../libs/test-setup" } prisma-value = { path = "../../libs/prisma-value" } @@ -30,4 +32,4 @@ tokio.workspace = true tracing.workspace = true tracing-futures = "0.2" url.workspace = true -quaint = { workspace = true, features = ["native"] } +quaint = { workspace = true, features = ["all-native"] } diff --git a/schema-engine/sql-schema-describer/Cargo.toml b/schema-engine/sql-schema-describer/Cargo.toml index bfd1de7f359f..514eac9daecf 100644 --- a/schema-engine/sql-schema-describer/Cargo.toml +++ b/schema-engine/sql-schema-describer/Cargo.toml @@ -20,7 +20,7 @@ tracing.workspace = true tracing-error = "0.2" tracing-futures = "0.2" quaint = { workspace = true, features = [ - "native", + "all-native", "pooled", "expose-drivers", "fmt-sql",