From a81286fed77d8f4f738862e660b95992f10b8f1b Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Thu, 11 Jun 2026 13:58:44 +0800 Subject: [PATCH] feat(build): gate DuckDB behind optional feature, support --no-default-features --- CONTRIBUTING.md | 12 ++++++++++++ README.md | 7 +++++++ README.zh-CN.md | 14 ++++++++++++++ src-tauri/Cargo.toml | 8 ++++++-- src-tauri/src/commands/connection.rs | 6 ++++++ src-tauri/src/commands/query.rs | 1 + src-tauri/src/lib.rs | 1 + 7 files changed, 47 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 87187e9bbb..7891ee181d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -50,6 +50,18 @@ cargo fmt --check cargo check --workspace --locked ``` +> [!TIP] +> DuckDB compiles from source and takes a while. Skip it during routine +> development when you're not touching DuckDB features: +> +> ```bash +> cargo check --workspace --no-default-features +> cargo test --workspace --no-default-features +> pnpm tauri dev -- --no-default-features +> ``` +> +> Release builds and CI should always include DuckDB (omit the flag). + For package changes, also run: ```bash diff --git a/README.md b/README.md index 47ec19dd34..ca0f1224ee 100644 --- a/README.md +++ b/README.md @@ -246,9 +246,16 @@ pnpm dev:tauri > skip it to speed up local builds: > > ```bash +> # Fast checks (skip DuckDB) > cargo check --no-default-features > cargo test --no-default-features +> +> # Tauri dev without DuckDB +> pnpm tauri dev -- --no-default-features > ``` +> +> The `--no-default-features` flag only affects local development. +> Release builds (`pnpm tauri build`) always include DuckDB. Web version: diff --git a/README.zh-CN.md b/README.zh-CN.md index bbd473d68d..01c6c5750e 100644 --- a/README.zh-CN.md +++ b/README.zh-CN.md @@ -241,6 +241,20 @@ pnpm install pnpm dev:tauri ``` +> [!TIP] +> DuckDB 从源码编译较慢。如果不涉及 DuckDB 功能,可以跳过以加速本地构建: +> +> ```bash +> # 快速检查(跳过 DuckDB) +> cargo check --no-default-features +> cargo test --no-default-features +> +> # Tauri 开发模式跳过 DuckDB +> pnpm tauri dev -- --no-default-features +> ``` +> +> `--no-default-features` 仅影响本地开发,发布构建(`pnpm tauri build`)始终包含 DuckDB。 + Web 版本: ```bash diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index f0dbdb1d43..3d7e7a736c 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -12,6 +12,10 @@ rust-version = "1.77.2" name = "dbx_lib" crate-type = ["staticlib", "cdylib", "rlib"] +[features] +default = ["duckdb-bundled"] +duckdb-bundled = ["duckdb", "dbx-core/duckdb-bundled"] + [build-dependencies] tauri-build = { version = "2.5.6", features = [] } @@ -40,7 +44,7 @@ tauri-plugin-window-state = "2" redis = { version = "0.32.2", features = ["tokio-comp", "tls-rustls", "tokio-rustls-comp", "cluster-async"] } rustls = { version = "0.23", features = ["aws-lc-rs"] } portpicker = "0.1.1" -duckdb = "1.3.2" +duckdb = { version = "1.3.2", optional = true } tiberius = { version = "0.12.3", default-features = false, features = ["tds73", "chrono", "rust_decimal", "rustls", "sql-browser-tokio"] } tokio-util = { version = "0.7", features = ["compat"] } reqwest = { version = "0.12", features = ["json", "stream"] } @@ -51,6 +55,6 @@ russh = "0.60" csv = "1.4.0" calamine = "0.30.1" zip = "4.6.1" -dbx-core = { path = "../crates/dbx-core" } +dbx-core = { path = "../crates/dbx-core", default-features = false } font-kit = "0.14.3" tauri-plugin-clipboard-manager = "2.3.2" diff --git a/src-tauri/src/commands/connection.rs b/src-tauri/src/commands/connection.rs index b9ea5b3f85..f0e2993c8c 100644 --- a/src-tauri/src/commands/connection.rs +++ b/src-tauri/src/commands/connection.rs @@ -318,6 +318,7 @@ pub async fn test_connection(state: State<'_, Arc>, config: Connection drop(con); Ok("Connection successful".to_string()) } + #[cfg(feature = "duckdb-bundled")] DatabaseType::DuckDb => { if state.duckdb_existing_pool_is_usable_for_config(&config).await? { Ok("Connection successful".to_string()) @@ -327,6 +328,8 @@ pub async fn test_connection(state: State<'_, Arc>, config: Connection Ok("Connection successful".to_string()) } } + #[cfg(not(feature = "duckdb-bundled"))] + DatabaseType::DuckDb => Err("DuckDB support not compiled (enable duckdb-bundled feature)".to_string()), DatabaseType::MongoDb => { let native_err = match db::mongo_driver::connect(&url, connect_timeout, idle_timeout).await { Ok(client) => { @@ -522,6 +525,7 @@ pub async fn connect_db(state: State<'_, Arc>, config: ConnectionConfi }; con } + #[cfg(feature = "duckdb-bundled")] DatabaseType::DuckDb => { let con = db::duckdb_driver::connect_path(&expand_tilde(&db_config.host))?; { @@ -532,6 +536,8 @@ pub async fn connect_db(state: State<'_, Arc>, config: ConnectionConfi } PoolKind::DuckDb(con) } + #[cfg(not(feature = "duckdb-bundled"))] + DatabaseType::DuckDb => return Err("DuckDB support not compiled (enable duckdb-bundled feature)".to_string()), DatabaseType::MongoDb => { let native_err = match db::mongo_driver::connect(&url, connect_timeout, idle_timeout).await { Ok(client) => { diff --git a/src-tauri/src/commands/query.rs b/src-tauri/src/commands/query.rs index 428f0842d2..c69e78d271 100644 --- a/src-tauri/src/commands/query.rs +++ b/src-tauri/src/commands/query.rs @@ -276,6 +276,7 @@ pub fn build_create_database_sql(options: dbx_core::db_admin_sql::CreateDatabase Ok(dbx_core::db_admin_sql::build_create_database_sql(options)) } +#[cfg(feature = "duckdb-bundled")] #[tauri::command] pub fn build_duckdb_attach_database_sql( options: dbx_core::db_admin_sql::DuckDbAttachDatabaseSqlOptions, diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index e09012ff8b..05a3f93403 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -394,6 +394,7 @@ pub fn run() { commands::query::build_search_result_where, commands::query::build_rename_object_sql, commands::query::build_create_database_sql, + #[cfg(feature = "duckdb-bundled")] commands::query::build_duckdb_attach_database_sql, commands::query::build_drop_object_sql, commands::query::build_drop_table_sql,