Skip to content

Commit

Permalink
fix: Fix build while no-default-features enabled (#442)
Browse files Browse the repository at this point in the history
* fix: Fix build while no-default-features enabled

Signed-off-by: Xuanwo <github@xuanwo.io>

* Fix clippy

Signed-off-by: Xuanwo <github@xuanwo.io>

* Add ci for no default features

Signed-off-by: Xuanwo <github@xuanwo.io>

---------

Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored Jul 6, 2024
1 parent dba6059 commit 5bfb8bd
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ jobs:
- name: Cargo sort
run: make cargo-sort


build:
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions crates/iceberg/src/io/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
21 changes: 17 additions & 4 deletions crates/iceberg/src/io/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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),
Expand Down Expand Up @@ -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)?;

Expand All @@ -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();
Expand All @@ -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",
)),
}
}

Expand Down
10 changes: 10 additions & 0 deletions crates/iceberg/src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub enum JoinHandle<T> {
Tokio(tokio::task::JoinHandle<T>),
#[cfg(all(feature = "async-std", not(feature = "tokio")))]
AsyncStd(async_std::task::JoinHandle<T>),
#[cfg(all(not(feature = "async-std"), not(feature = "tokio")))]
Unimplemented(Box<T>),
}

impl<T: Send + 'static> Future for JoinHandle<T> {
Expand All @@ -39,6 +41,8 @@ impl<T: Send + 'static> Future for JoinHandle<T> {
.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"),
}
}
}
Expand All @@ -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)]
Expand All @@ -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)]
Expand Down

0 comments on commit 5bfb8bd

Please sign in to comment.