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 abec745ece ci(bindings/zig): Fix build and test of zig on 0.13 (#5102)
abec745ece is described below
commit abec745ece837f23bcae6c2ca4544072c65cddfe
Author: Xuanwo <[email protected]>
AuthorDate: Sun Sep 8 23:11:07 2024 +0800
ci(bindings/zig): Fix build and test of zig on 0.13 (#5102)
* ci(bindings/zig): Fix build and test of zig on 0.13
Signed-off-by: Xuanwo <[email protected]>
* Add docs
Signed-off-by: Xuanwo <[email protected]>
---------
Signed-off-by: Xuanwo <[email protected]>
---
.github/workflows/ci_bindings_zig.yml | 4 +--
bindings/zig/.gitignore | 1 +
bindings/zig/README.md | 6 +----
bindings/zig/build.zig | 49 ++++++++++++-----------------------
bindings/zig/build.zig.zon | 9 +++++++
bindings/zig/test/bdd.zig | 12 ++++-----
6 files changed, 36 insertions(+), 45 deletions(-)
diff --git a/.github/workflows/ci_bindings_zig.yml
b/.github/workflows/ci_bindings_zig.yml
index 4e3f8f42ec..7d48339ea0 100644
--- a/.github/workflows/ci_bindings_zig.yml
+++ b/.github/workflows/ci_bindings_zig.yml
@@ -22,7 +22,7 @@ on:
branches:
- main
tags:
- - '*'
+ - "*"
pull_request:
branches:
- main
@@ -47,7 +47,7 @@ jobs:
- uses: actions/checkout@v4
- uses: korandoru/setup-zig@v1
with:
- zig-version: 0.11.0
+ zig-version: 0.13.0
- name: Setup Rust toolchain
uses: ./.github/actions/setup
diff --git a/bindings/zig/.gitignore b/bindings/zig/.gitignore
index e73c965f8f..9c8ce95726 100644
--- a/bindings/zig/.gitignore
+++ b/bindings/zig/.gitignore
@@ -1,2 +1,3 @@
zig-cache/
zig-out/
+.zig-cache/
diff --git a/bindings/zig/README.md b/bindings/zig/README.md
index 48fa5c1791..b049373fcd 100644
--- a/bindings/zig/README.md
+++ b/bindings/zig/README.md
@@ -8,11 +8,7 @@
To compile OpenDAL from source code, you need:
-- [Zig](https://ziglang.org/download) 0.11.0 or higher
-
-> **Note**:
->
-> 0.11.0 is not released yet. You can use master instead before the official
0.11.0 released.
+- [Zig](https://ziglang.org/download) 0.13.0 or higher
```bash
# build libopendal_c (underneath call make -C ../c)
diff --git a/bindings/zig/build.zig b/bindings/zig/build.zig
index 327945de04..fc1623ddce 100644
--- a/bindings/zig/build.zig
+++ b/bindings/zig/build.zig
@@ -23,36 +23,40 @@ pub fn build(b: *std.Build) void {
// This function creates a module and adds it to the package's module set,
making
// it available to other packages which depend on this one.
- _ = b.addModule("opendal", .{
- .source_file = .{
- .path = "src/opendal.zig",
- },
- .dependencies = &.{},
+ const opendal_module = b.addModule("opendal", .{
+ .root_source_file = b.path("src/opendal.zig"),
+ .target = target,
+ .optimize = optimize,
});
+ opendal_module.addIncludePath(b.path("../c/include"));
// Creates a step for building the dependent C bindings
- const libopendal_c = buildLibOpenDAL(b);
+ const libopendal_c = b.addSystemCommand(&[_][]const u8{
+ "make",
+ "-C",
+ "../c",
+ "build",
+ });
const build_libopendal_c = b.step("libopendal_c", "Build OpenDAL C
bindings");
build_libopendal_c.dependOn(&libopendal_c.step);
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
const unit_tests = b.addTest(.{
- .root_source_file = .{
- .path = "test/bdd.zig",
- },
+ .root_source_file = b.path("test/bdd.zig"),
.target = target,
.optimize = optimize,
});
- unit_tests.addIncludePath(.{ .path = "../c/include" });
- unit_tests.addModule("opendal", module(b));
+
+ unit_tests.addIncludePath(b.path("../c/include"));
if (optimize == .Debug) {
- unit_tests.addLibraryPath(.{ .path = "../c/target/debug" });
+ unit_tests.addLibraryPath(b.path("../c/target/debug"));
} else {
- unit_tests.addLibraryPath(.{ .path = "../c/target/release" });
+ unit_tests.addLibraryPath(b.path("../c/target/release"));
}
unit_tests.linkSystemLibrary("opendal_c");
unit_tests.linkLibCpp();
+ unit_tests.root_module.addImport("opendal", opendal_module);
// Creates a step for running unit tests.
const run_unit_tests = b.addRunArtifact(unit_tests);
@@ -60,22 +64,3 @@ pub fn build(b: *std.Build) void {
test_step.dependOn(&libopendal_c.step);
test_step.dependOn(&run_unit_tests.step);
}
-
-fn buildLibOpenDAL(b: *std.Build) *std.Build.Step.Run {
- const basedir = comptime std.fs.path.dirname(@src().file) orelse null;
- const c_bindings_dir = basedir ++ "/../c";
- return b.addSystemCommand(&[_][]const u8{
- "make",
- "-C",
- c_bindings_dir,
- "build",
- });
-}
-
-pub fn module(b: *std.Build) *std.Build.Module {
- return b.createModule(.{
- .source_file = .{
- .path = "src/opendal.zig",
- },
- });
-}
diff --git a/bindings/zig/build.zig.zon b/bindings/zig/build.zig.zon
new file mode 100644
index 0000000000..7d7ab51407
--- /dev/null
+++ b/bindings/zig/build.zig.zon
@@ -0,0 +1,9 @@
+.{
+ .name = "opendal",
+ .version = "0.0.1",
+ .paths = .{
+ "build.zig",
+ "build.zig.zon",
+ "src",
+ },
+}
diff --git a/bindings/zig/test/bdd.zig b/bindings/zig/test/bdd.zig
index 68548d1f9f..98d49525ce 100644
--- a/bindings/zig/test/bdd.zig
+++ b/bindings/zig/test/bdd.zig
@@ -35,12 +35,12 @@ test "Opendal BDD test" {
self.path = "test";
self.content = "Hello, World!";
- var options: [*c]opendal.c.opendal_operator_options =
opendal.c.opendal_operator_options_new();
+ const options: [*c]opendal.c.opendal_operator_options =
opendal.c.opendal_operator_options_new();
defer opendal.c.opendal_operator_options_free(options);
opendal.c.opendal_operator_options_set(options, "root", "/myroot");
// Given A new OpenDAL Blocking Operator
- var result = opendal.c.opendal_operator_new(self.scheme, options);
+ const result = opendal.c.opendal_operator_new(self.scheme,
options);
testing.expectEqual(result.@"error", null) catch unreachable;
self.p = result.op;
@@ -67,14 +67,14 @@ test "Opendal BDD test" {
try testing.expectEqual(result, null);
// The blocking file "test" should exist
- var e: opendal.c.opendal_result_is_exist =
opendal.c.opendal_operator_is_exist(testkit.p, testkit.path);
+ const e: opendal.c.opendal_result_is_exist =
opendal.c.opendal_operator_is_exist(testkit.p, testkit.path);
try testing.expectEqual(e.@"error", null);
try testing.expect(e.is_exist);
// The blocking file "test" entry mode must be file
- var s: opendal.c.opendal_result_stat =
opendal.c.opendal_operator_stat(testkit.p, testkit.path);
+ const s: opendal.c.opendal_result_stat =
opendal.c.opendal_operator_stat(testkit.p, testkit.path);
try testing.expectEqual(s.@"error", null);
- var meta: [*c]opendal.c.opendal_metadata = s.meta;
+ const meta: [*c]opendal.c.opendal_metadata = s.meta;
try testing.expect(opendal.c.opendal_metadata_is_file(meta));
// The blocking file "test" content length must be 13
@@ -82,7 +82,7 @@ test "Opendal BDD test" {
defer opendal.c.opendal_metadata_free(meta);
// The blocking file "test" must have content "Hello, World!"
- var r: opendal.c.opendal_result_read =
opendal.c.opendal_operator_read(testkit.p, testkit.path);
+ const r: opendal.c.opendal_result_read =
opendal.c.opendal_operator_read(testkit.p, testkit.path);
defer opendal.c.opendal_bytes_free(r.data);
try testing.expect(r.@"error" == null);
try testing.expectEqual(std.mem.len(testkit.content), r.data.*.len);