From 5bfb8bdd4ec124e005e86af7331e8da08c1445ed Mon Sep 17 00:00:00 2001 From: Xuanwo Date: Sat, 6 Jul 2024 18:12:25 +0800 Subject: [PATCH] fix: Fix build while no-default-features enabled (#442) * fix: Fix build while no-default-features enabled Signed-off-by: Xuanwo * Fix clippy Signed-off-by: Xuanwo * Add ci for no default features Signed-off-by: Xuanwo --------- Signed-off-by: Xuanwo --- .github/workflows/ci.yml | 14 +++++++++++++- crates/iceberg/src/io/mod.rs | 4 ++++ crates/iceberg/src/io/storage.rs | 21 +++++++++++++++++---- crates/iceberg/src/runtime/mod.rs | 10 ++++++++++ 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5be609c0b..536089fce 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -50,7 +50,6 @@ jobs: - name: Cargo sort run: make cargo-sort - build: runs-on: ${{ matrix.os }} strategy: @@ -64,6 +63,19 @@ jobs: - name: Build run: cargo build + build_with_no_default_features: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: + - ubuntu-latest + - macos-latest + - windows-latest + steps: + - uses: actions/checkout@v4 + - name: Build + run: cargo build -p iceberg --no-default-features + unit: runs-on: ubuntu-latest steps: diff --git a/crates/iceberg/src/io/mod.rs b/crates/iceberg/src/io/mod.rs index 6da605d74..914293da3 100644 --- a/crates/iceberg/src/io/mod.rs +++ b/crates/iceberg/src/io/mod.rs @@ -52,7 +52,11 @@ mod file_io; pub use file_io::*; mod storage; +#[cfg(feature = "storage-s3")] mod storage_s3; +#[cfg(feature = "storage-s3")] pub use storage_s3::*; +#[cfg(feature = "storage-fs")] mod storage_fs; +#[cfg(feature = "storage-fs")] use storage_fs::*; diff --git a/crates/iceberg/src/io/storage.rs b/crates/iceberg/src/io/storage.rs index b188c2908..8d7df45b8 100644 --- a/crates/iceberg/src/io/storage.rs +++ b/crates/iceberg/src/io/storage.rs @@ -15,16 +15,20 @@ // specific language governing permissions and limitations // under the License. -use super::{FileIOBuilder, FsConfig, S3Config}; +use super::FileIOBuilder; +#[cfg(feature = "storage-fs")] +use super::FsConfig; +#[cfg(feature = "storage-s3")] +use super::S3Config; use crate::{Error, ErrorKind}; use opendal::{Operator, Scheme}; /// The storage carries all supported storage services in iceberg #[derive(Debug)] pub(crate) enum Storage { - LocalFs { - config: FsConfig, - }, + #[cfg(feature = "storage-fs")] + LocalFs { config: FsConfig }, + #[cfg(feature = "storage-s3")] S3 { /// s3 storage could have `s3://` and `s3a://`. /// Storing the scheme string here to return the correct path. @@ -40,9 +44,11 @@ impl Storage { let scheme = Self::parse_scheme(&scheme_str)?; match scheme { + #[cfg(feature = "storage-fs")] Scheme::Fs => Ok(Self::LocalFs { config: FsConfig::new(props), }), + #[cfg(feature = "storage-s3")] Scheme::S3 => Ok(Self::S3 { scheme_str, config: S3Config::new(props), @@ -73,6 +79,7 @@ impl Storage { ) -> crate::Result<(Operator, &'a str)> { let path = path.as_ref(); match self { + #[cfg(feature = "storage-fs")] Storage::LocalFs { config } => { let op = config.build(path)?; @@ -82,6 +89,7 @@ impl Storage { Ok((op, &path[1..])) } } + #[cfg(feature = "storage-s3")] Storage::S3 { scheme_str, config } => { let op = config.build(path)?; let op_info = op.info(); @@ -97,6 +105,11 @@ impl Storage { )) } } + #[cfg(all(not(feature = "storage-s3"), not(feature = "storage-fs")))] + _ => Err(Error::new( + ErrorKind::FeatureUnsupported, + "No storage service has been enabled", + )), } } diff --git a/crates/iceberg/src/runtime/mod.rs b/crates/iceberg/src/runtime/mod.rs index 453b1564a..65c30e82c 100644 --- a/crates/iceberg/src/runtime/mod.rs +++ b/crates/iceberg/src/runtime/mod.rs @@ -26,6 +26,8 @@ pub enum JoinHandle { Tokio(tokio::task::JoinHandle), #[cfg(all(feature = "async-std", not(feature = "tokio")))] AsyncStd(async_std::task::JoinHandle), + #[cfg(all(not(feature = "async-std"), not(feature = "tokio")))] + Unimplemented(Box), } impl Future for JoinHandle { @@ -39,6 +41,8 @@ impl Future for JoinHandle { .map(|h| h.expect("tokio spawned task failed")), #[cfg(all(feature = "async-std", not(feature = "tokio")))] JoinHandle::AsyncStd(handle) => Pin::new(handle).poll(cx), + #[cfg(all(not(feature = "async-std"), not(feature = "tokio")))] + JoinHandle::Unimplemented(_) => unimplemented!("no runtime has been enabled"), } } } @@ -54,6 +58,9 @@ where #[cfg(all(feature = "async-std", not(feature = "tokio")))] return JoinHandle::AsyncStd(async_std::task::spawn(f)); + + #[cfg(all(not(feature = "async-std"), not(feature = "tokio")))] + unimplemented!("no runtime has been enabled") } #[allow(dead_code)] @@ -67,6 +74,9 @@ where #[cfg(all(feature = "async-std", not(feature = "tokio")))] return JoinHandle::AsyncStd(async_std::task::spawn_blocking(f)); + + #[cfg(all(not(feature = "async-std"), not(feature = "tokio")))] + unimplemented!("no runtime has been enabled") } #[cfg(test)]