Skip to content

Commit 07f16c8

Browse files
authored
feat: Add legacy-states-v0 Cargo feature for backward compatibility #1076 (#1135)
feat: Add legacy-states-v0 Cargo feature for backward compatibility
1 parent afea19d commit 07f16c8

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

.github/workflows/_test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ jobs:
3535
uses: Swatinem/rust-cache@v2
3636
with:
3737
key: rust-${{ matrix.platform.runner }}-${{ matrix.python-version }}
38+
- name: Rust tests (no default features)
39+
run: cargo test --no-default-features --verbose
40+
3841
- name: Rust tests
3942
run: cargo test --verbose
4043

@@ -81,4 +84,4 @@ jobs:
8184
if [ $status -ne 0 ]; then
8285
echo "::error::Third-party notices validation failed. Please update /about.toml and rerun."
8386
exit $status
84-
fi
87+
fi

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ lto = true
1515
name = "cocoindex_engine"
1616
crate-type = ["cdylib"]
1717

18+
[features]
19+
default = ["legacy-states-v0"]
20+
legacy-states-v0 = []
21+
1822
[dependencies]
1923
pyo3 = { version = "0.25.1", features = [
2024
"abi3-py311",

src/builder/exec_ctx.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ fn build_import_op_exec_ctx(
5555
let existing_keys_schema: &[schema::ValueType] =
5656
if let Some(keys_schema) = &state.keys_schema {
5757
keys_schema
58-
} else if let Some(key_schema) = &state.key_schema {
59-
std::slice::from_ref(key_schema)
6058
} else {
59+
#[cfg(feature = "legacy-states-v0")]
60+
if let Some(key_schema) = &state.key_schema {
61+
std::slice::from_ref(key_schema)
62+
} else {
63+
&[]
64+
}
65+
#[cfg(not(feature = "legacy-states-v0"))]
6166
&[]
6267
};
6368
if existing_keys_schema == keys_schema_no_attrs.as_ref() {
@@ -83,6 +88,7 @@ fn build_import_op_exec_ctx(
8388

8489
// Keep this field for backward compatibility,
8590
// so users can still swap back to older version if needed.
91+
#[cfg(feature = "legacy-states-v0")]
8692
key_schema: Some(if keys_schema_no_attrs.len() == 1 {
8793
keys_schema_no_attrs[0].clone()
8894
} else {

src/setup/states.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ pub struct SourceSetupState {
176176
pub keys_schema: Option<Box<[schema::ValueType]>>,
177177

178178
/// DEPRECATED. For backward compatibility.
179+
#[cfg(feature = "legacy-states-v0")]
179180
#[serde(default, skip_serializing_if = "Option::is_none")]
180181
pub key_schema: Option<schema::ValueType>,
181182

0 commit comments

Comments
 (0)