Skip to content

Commit 020b329

Browse files
authored
ci: use cargo-hack and build all valid feature combos (#1653)
I've added [cargo-hack](https://github.com/taiki-e/cargo-hack) which seems extremely popular, e.g. futures-util uses it for their CI builds. It actually will go build each of your workspace projects individually. I've setup a build matrix that uses cargo-hack to run builds with all valid feature combos we care about: * default * all-features * wasm32 * tokio * compio * tokio+compio
1 parent 7873c9d commit 020b329

File tree

6 files changed

+58
-60
lines changed

6 files changed

+58
-60
lines changed

.github/workflows/ci.yml

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -87,42 +87,45 @@ jobs:
8787
- name: Docs
8888
run: cargo doc --no-deps
8989

90-
build-default:
91-
name: "Build (default)"
92-
runs-on: ubuntu-latest
93-
steps:
94-
- uses: actions/checkout@v4
95-
- uses: ./.github/actions/cleanup
96-
- uses: rui314/setup-mold@v1
97-
- uses: ./.github/actions/setup-rust
98-
- name: Rust Build (Default features)
99-
run: cargo build --all-targets
100-
101-
build-wasm32:
102-
name: "Build (wasm32-unknown-unknown)"
90+
build-rust:
91+
name: "Rust build (${{matrix.config.name}})"
10392
runs-on: ubuntu-latest
93+
strategy:
94+
fail-fast: false
95+
matrix:
96+
config:
97+
- name: "all-features"
98+
command: "build"
99+
args: "--all-features --all-targets"
100+
- name: "default features"
101+
command: "build"
102+
args: "--all-targets"
103+
- name: "with tokio dispatcher"
104+
command: "build"
105+
args: "--no-default-features --features tokio --all-targets --ignore-unknown-features"
106+
- name: "with compio dispatcher"
107+
command: "build"
108+
args: "--no-default-features --features compio --all-targets --ignore-unknown-features"
109+
- name: "with tokio+compio dispatcher"
110+
command: "build"
111+
args: "--no-default-features --features tokio,compio --all-targets --ignore-unknown-features"
112+
- name: "wasm32 with default features"
113+
command: "build"
114+
target: wasm32-unknown-unknown
115+
args: "--target wasm32-unknown-unknown --exclude vortex-roaring --exclude vortex-datafusion "
104116
steps:
105117
- uses: actions/checkout@v4
106118
- uses: ./.github/actions/cleanup
107119
- uses: rui314/setup-mold@v1
108120
- uses: ./.github/actions/setup-rust
109121
with:
110-
targets: wasm32-unknown-unknown
111-
- name: Rust Build vortex
112-
run: cargo build -p vortex --target wasm32-unknown-unknown
122+
targets: ${{matrix.config.target || ''}}
123+
- name: Install cargo-hack
124+
uses: taiki-e/install-action@cargo-hack
125+
- name: Rust Build (${{matrix.config.name}})
126+
run: cargo hack ${{matrix.config.command}} ${{matrix.config.args}} --ignore-private
113127

114128

115-
build-all:
116-
name: "Build (all-features)"
117-
runs-on: ubuntu-latest
118-
steps:
119-
- uses: actions/checkout@v4
120-
- uses: ./.github/actions/cleanup
121-
- uses: rui314/setup-mold@v1
122-
- uses: ./.github/actions/setup-rust
123-
- name: Rust Build (All Features)
124-
run: cargo build --all-features --all-targets
125-
126129
rust-test:
127130
name: "Rust (tests)"
128131
runs-on: ubuntu-latest

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ async-trait = "0.1"
6262
backtrace = "0.3.74"
6363
bytes = "1.6.0"
6464
bzip2 = "0.5.0"
65+
cfg-if = "1"
6566
chrono = "0.4.38"
6667
clap = "4.5.13"
6768
compio = "0.13"

vortex-io/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ categories.workspace = true
1515

1616
[dependencies]
1717
bytes = { workspace = true }
18+
cfg-if = { workspace = true }
1819
compio = { workspace = true, features = ["bytes", "macros"], optional = true }
1920
pin-project = { workspace = true }
20-
# this is the maximum subset of fetaures that is safe for wasm32-wasip1 targets
21+
# this is the maximum subset of fetaures that is safe for wasm32 targets
2122
tokio = { workspace = true, features = ["io-util", "rt", "sync"] }
2223
tracing = { workspace = true, optional = true }
2324
futures = { workspace = true, features = ["std"] }

vortex-io/src/dispatcher/mod.rs

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
11
#[cfg(feature = "compio")]
22
mod compio;
3-
#[cfg(feature = "tokio")]
3+
#[cfg(not(target_arch = "wasm32"))]
44
mod tokio;
55
#[cfg(target_arch = "wasm32")]
66
mod wasm;
77

88
use std::future::Future;
99
use std::task::Poll;
1010

11+
use cfg_if::cfg_if;
1112
use futures::channel::oneshot;
1213
use futures::FutureExt;
13-
#[cfg(not(any(feature = "compio", feature = "tokio", target_arch = "wasm32")))]
14-
use vortex_error::vortex_panic;
1514
use vortex_error::{vortex_err, VortexResult};
1615

1716
#[cfg(feature = "compio")]
1817
use self::compio::*;
19-
#[cfg(feature = "tokio")]
18+
#[cfg(not(target_arch = "wasm32"))]
2019
use self::tokio::*;
2120
#[cfg(target_arch = "wasm32")]
2221
use self::wasm::*;
@@ -29,7 +28,7 @@ mod sealed {
2928
#[cfg(feature = "compio")]
3029
impl Sealed for super::CompioDispatcher {}
3130

32-
#[cfg(feature = "tokio")]
31+
#[cfg(not(target_arch = "wasm32"))]
3332
impl Sealed for super::TokioDispatcher {}
3433

3534
#[cfg(target_arch = "wasm32")]
@@ -89,7 +88,7 @@ impl<R> Future for JoinHandle<R> {
8988

9089
#[derive(Debug)]
9190
enum Inner {
92-
#[cfg(feature = "tokio")]
91+
#[cfg(not(target_arch = "wasm32"))]
9392
Tokio(TokioDispatcher),
9493
#[cfg(feature = "compio")]
9594
Compio(CompioDispatcher),
@@ -98,19 +97,16 @@ enum Inner {
9897
}
9998

10099
impl Default for IoDispatcher {
101-
#[cfg(target_arch = "wasm32")]
102100
fn default() -> Self {
103-
return Self(Inner::Wasm(WasmDispatcher::new()));
104-
}
105-
106-
#[cfg(not(target_arch = "wasm32"))]
107-
fn default() -> Self {
108-
#[cfg(feature = "tokio")]
109-
return Self(Inner::Tokio(TokioDispatcher::new(1)));
110-
#[cfg(all(feature = "compio", not(feature = "tokio")))]
111-
return Self(Inner::Compio(CompioDispatcher::new(1)));
112-
#[cfg(not(any(feature = "compio", feature = "tokio")))]
113-
vortex_panic!("must enable one of compio or tokio to use IoDispatcher");
101+
cfg_if! {
102+
if #[cfg(target_arch = "wasm32")] {
103+
Self(Inner::Wasm(WasmDispatcher::new()))
104+
} else if #[cfg(not(feature = "compio"))] {
105+
Self(Inner::Tokio(TokioDispatcher::new(1)))
106+
} else {
107+
Self(Inner::Compio(CompioDispatcher::new(1)))
108+
}
109+
}
114110
}
115111
}
116112

@@ -123,7 +119,7 @@ impl Dispatch for IoDispatcher {
123119
R: Send + 'static,
124120
{
125121
match self.0 {
126-
#[cfg(feature = "tokio")]
122+
#[cfg(not(target_arch = "wasm32"))]
127123
Inner::Tokio(ref tokio_dispatch) => tokio_dispatch.dispatch(task),
128124
#[cfg(feature = "compio")]
129125
Inner::Compio(ref compio_dispatch) => compio_dispatch.dispatch(task),
@@ -134,7 +130,7 @@ impl Dispatch for IoDispatcher {
134130

135131
fn shutdown(self) -> VortexResult<()> {
136132
match self.0 {
137-
#[cfg(feature = "tokio")]
133+
#[cfg(not(target_arch = "wasm32"))]
138134
Inner::Tokio(tokio_dispatch) => tokio_dispatch.shutdown(),
139135
#[cfg(feature = "compio")]
140136
Inner::Compio(compio_dispatch) => compio_dispatch.shutdown(),
@@ -150,7 +146,7 @@ impl IoDispatcher {
150146
///
151147
/// A handle to the dispatcher can be passed freely among threads, allowing multiple parties to
152148
/// perform dispatching across different threads.
153-
#[cfg(feature = "tokio")]
149+
#[cfg(not(target_arch = "wasm32"))]
154150
pub fn new_tokio(num_thread: usize) -> Self {
155151
Self(Inner::Tokio(TokioDispatcher::new(num_thread)))
156152
}

vortex-io/src/dispatcher/tokio.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,28 +118,24 @@ impl Dispatch for TokioDispatcher {
118118

119119
#[cfg(test)]
120120
mod tests {
121-
use std::io::Write;
122-
123-
use tempfile::NamedTempFile;
121+
use std::sync::atomic::{AtomicU32, Ordering};
122+
use std::sync::Arc;
124123

125124
use super::TokioDispatcher;
126125
use crate::dispatcher::Dispatch;
127-
use crate::{TokioFile, VortexReadAt};
128126

129127
#[tokio::test]
130128
async fn test_tokio_dispatch_simple() {
131129
let dispatcher = TokioDispatcher::new(4);
132-
let mut tmpfile = NamedTempFile::new().unwrap();
133-
write!(tmpfile, "5678").unwrap();
134-
130+
let atomic_number = Arc::new(AtomicU32::new(0));
131+
let atomic_number_clone = Arc::clone(&atomic_number);
135132
let rx = dispatcher
136133
.dispatch(|| async move {
137-
let file = TokioFile::open(tmpfile.path()).unwrap();
138-
139-
file.read_byte_range(0, 4).await.unwrap()
134+
atomic_number_clone.fetch_add(1, Ordering::SeqCst);
140135
})
141136
.unwrap();
142137

143-
assert_eq!(&rx.await.unwrap(), "5678".as_bytes());
138+
rx.await.unwrap();
139+
assert_eq!(atomic_number.load(Ordering::SeqCst), 1u32);
144140
}
145141
}

0 commit comments

Comments
 (0)