This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new 822fe3089 feat(bindings/c)!: Make features configurable via CMakeLists
(#6143)
822fe3089 is described below
commit 822fe308979a33230d40c971e85bd52b92536ceb
Author: Asuka Minato <[email protected]>
AuthorDate: Tue May 20 15:19:53 2025 +0900
feat(bindings/c)!: Make features configurable via CMakeLists (#6143)
* try split feature
* try fix test && cache
* pass ci
* add flags
* cache first
* fix zig build
* fix syntax
* SERVICES_ALL
* sccache
* Update ci_bindings_c.yml
* use ENV
* Update Cargo.toml
* Update README.md
* Update Cargo.toml
* Update ci_bindings_c.yml
* zig all features
* typo
* env
* rm sccache
* show multiple
* -DFEATURES
* c ci
* zig ci
---
.github/workflows/ci_bindings_c.yml | 5 ++++-
bindings/c/CMakeLists.txt | 5 ++++-
bindings/c/Cargo.toml | 23 ++++-------------------
bindings/c/README.md | 2 ++
bindings/zig/build.zig | 2 +-
5 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/.github/workflows/ci_bindings_c.yml
b/.github/workflows/ci_bindings_c.yml
index b972d1eed..47b288b81 100644
--- a/.github/workflows/ci_bindings_c.yml
+++ b/.github/workflows/ci_bindings_c.yml
@@ -47,16 +47,19 @@ jobs:
- name: Setup Rust toolchain
uses: ./.github/actions/setup
+
- name: Clippy Check
working-directory: "bindings/c"
+
run: |
cargo clippy -- -D warnings
+
- name: Build C binding
working-directory: "bindings/c"
run: |
mkdir build && cd build
- cmake .. -DTEST_ENABLE_ASAN=ON
+ cmake .. -DTEST_ENABLE_ASAN=ON -DFEATURES=opendal/services-memory
make -j$(nproc)
- name: Check diff
diff --git a/bindings/c/CMakeLists.txt b/bindings/c/CMakeLists.txt
index b8e15dd50..48b7039c0 100644
--- a/bindings/c/CMakeLists.txt
+++ b/bindings/c/CMakeLists.txt
@@ -25,6 +25,9 @@ if (NOT CMAKE_BUILD_TYPE)
endif()
option(TEST_ENABLE_ASAN "Enable AddressSanitizer for tests" OFF)
+set(FEATURES "" CACHE STRING "opendal features")
+
+set(CARGO_FEATURES_FLAG "--features=${FEATURES}")
# force the compiler to support these standards
set(CMAKE_C_STANDARD 11)
@@ -59,7 +62,7 @@ message(NOTICE "-- OpenDAL C shared lib:
${OPENDAL_SHARED_LIB}")
# custom target for cargo build
add_custom_target(cargo_build
- COMMAND sh -c "cargo build ${CARGO_BUILD_TYPE}"
+ COMMAND sh -c "cargo build ${CARGO_BUILD_TYPE} ${CARGO_FEATURES_FLAG}"
BYPRODUCTS ${OPENDAL_STATIC_LIB} ${OPENDAL_SHARED_LIB}
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
diff --git a/bindings/c/Cargo.toml b/bindings/c/Cargo.toml
index 98e8341b8..1480fed07 100644
--- a/bindings/c/Cargo.toml
+++ b/bindings/c/Cargo.toml
@@ -36,23 +36,8 @@ cbindgen = "0.26.0"
[dependencies]
bytes = "1.4.0"
# this crate won't be published, we always use the local version
-opendal = { version = ">=0", path = "../../core", features = [
- "layers-blocking",
- # These are default features before v0.46. TODO: change to optional features
#4313
- "services-azblob",
- "services-azdls",
- "services-cos",
- "services-fs",
- "services-gcs",
- "services-ghac",
- "services-http",
- "services-ipmfs",
- "services-memory",
- "services-obs",
- "services-oss",
- "services-s3",
- "services-webdav",
- "services-webhdfs",
- "services-azfile",
-] }
+opendal = { version = ">=0", path = "../../core", default-features = false,
features = ["layers-blocking"] }
tokio = { version = "1.27", features = ["fs", "macros", "rt-multi-thread"] }
+
+[features]
+default = []
diff --git a/bindings/c/README.md b/bindings/c/README.md
index abd7d97f3..c56b8c2f2 100644
--- a/bindings/c/README.md
+++ b/bindings/c/README.md
@@ -98,6 +98,8 @@ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- The library is under `../../target/debug` after building.
+ - use `FEATURES` to enable services, like `cmake ..
-DFEATURES="opendal/services-memory,opendal/services-fs"`
+
- To **clean** the build results.
```sh
diff --git a/bindings/zig/build.zig b/bindings/zig/build.zig
index 3b57cbdd2..1c62235cf 100644
--- a/bindings/zig/build.zig
+++ b/bindings/zig/build.zig
@@ -62,7 +62,7 @@ pub fn build(b: *std.Build) void {
// =============== OpenDAL C bindings ===============
// Creates a step for building the dependent C bindings
- const libopendal_c_cmake = b.addSystemCommand(&[_][]const u8{ "cmake",
"-S", "../c", "-B", "../c/build" });
+ const libopendal_c_cmake = b.addSystemCommand(&[_][]const u8{ "cmake",
"-S", "../c", "-B", "../c/build", "-DFEATURES=opendal/services-memory" });
const config_libopendal_c = b.step("libopendal_c_cmake", "Generate OpenDAL
C binding CMake files");
config_libopendal_c.dependOn(&libopendal_c_cmake.step);
const libopendal_c = b.addSystemCommand(&[_][]const u8{ "make", "-C",
"../c/build" });