@@ -21,14 +21,30 @@ pub fn build(b: *std.Build) void {
21
21
const target = b .standardTargetOptions (.{});
22
22
const optimize = b .standardOptimizeOption (.{});
23
23
24
+ const use_llvm = b .option (bool , "use-llvm" , "Use LLVM backend (default: true)" ) orelse true ;
25
+ const use_clang = b .option (bool , "use-clang" , "Use libclang in translate-c (default: true)" ) orelse true ;
26
+
27
+ // Generate the Zig bindings for OpenDAL C bindings
28
+ const opendal_binding = b .addTranslateC (.{
29
+ .optimize = optimize ,
30
+ .target = target ,
31
+ .link_libc = true ,
32
+ .root_source_file = b .path ("../c/include/opendal.h" ),
33
+ .use_clang = use_clang , // TODO: set 'false' use fno-llvm/fno-clang (may be zig v1.0)
34
+ });
35
+
36
+ // ZigCoro - (stackful) Coroutine for Zig (library)
37
+ const zigcoro = b .dependency ("zigcoro" , .{}).module ("libcoro" );
38
+
24
39
// This function creates a module and adds it to the package's module set, making
25
40
// it available to other packages which depend on this one.
26
41
const opendal_module = b .addModule ("opendal" , .{
27
42
.root_source_file = b .path ("src/opendal.zig" ),
28
43
.target = target ,
29
44
.optimize = optimize ,
30
45
});
31
- opendal_module .addIncludePath (b .path ("../c/include" ));
46
+ opendal_module .addImport ("opendal_c_header" , opendal_binding .addModule ("opendal_c_header" ));
47
+ opendal_module .addImport ("libcoro" , zigcoro );
32
48
33
49
// Creates a step for building the dependent C bindings
34
50
const libopendal_c_cmake = b .addSystemCommand (&[_ ][]const u8 { "cmake" , "-S" , "../c" , "-B" , "../c/build" });
@@ -41,25 +57,46 @@ pub fn build(b: *std.Build) void {
41
57
42
58
// Creates a step for unit testing. This only builds the test executable
43
59
// but does not run it.
44
- const unit_tests = b .addTest (.{
60
+ const lib_test = b .addTest (.{
61
+ .root_source_file = b .path ("src/opendal.zig" ),
62
+ .target = target ,
63
+ .optimize = optimize ,
64
+ .use_llvm = use_llvm ,
65
+ .test_runner = b .dependency ("test_runner" , .{}).path ("test_runner.zig" ),
66
+ });
67
+ if (optimize == .Debug ) {
68
+ lib_test .addLibraryPath (b .path ("../c/target/debug" ));
69
+ } else {
70
+ lib_test .addLibraryPath (b .path ("../c/target/release" ));
71
+ }
72
+ lib_test .linkSystemLibrary ("opendal_c" );
73
+ lib_test .linkLibCpp ();
74
+ lib_test .root_module .addImport ("opendal_c_header" , opendal_binding .addModule ("opendal_c_header" ));
75
+ lib_test .root_module .addImport ("libcoro" , zigcoro );
76
+
77
+ const bdd_test = b .addTest (.{
78
+ .name = "bdd_test" ,
45
79
.root_source_file = b .path ("test/bdd.zig" ),
46
80
.target = target ,
47
81
.optimize = optimize ,
82
+ .use_llvm = use_llvm ,
83
+ .test_runner = b .dependency ("test_runner" , .{}).path ("test_runner.zig" ),
48
84
});
49
85
50
- unit_tests .addIncludePath (b .path ("../c/include" ));
51
86
if (optimize == .Debug ) {
52
- unit_tests .addLibraryPath (b .path ("../c/target/debug" ));
87
+ bdd_test .addLibraryPath (b .path ("../c/target/debug" ));
53
88
} else {
54
- unit_tests .addLibraryPath (b .path ("../c/target/release" ));
89
+ bdd_test .addLibraryPath (b .path ("../c/target/release" ));
55
90
}
56
- unit_tests .linkSystemLibrary ("opendal_c" );
57
- unit_tests .linkLibCpp ();
58
- unit_tests .root_module .addImport ("opendal" , opendal_module );
91
+ bdd_test .linkSystemLibrary ("opendal_c" );
92
+ bdd_test .linkLibCpp ();
93
+ bdd_test .root_module .addImport ("opendal" , opendal_module );
59
94
60
95
// Creates a step for running unit tests.
61
- const run_unit_tests = b .addRunArtifact (unit_tests );
96
+ const run_lib_test = b .addRunArtifact (lib_test );
97
+ const run_bdd_test = b .addRunArtifact (bdd_test );
62
98
const test_step = b .step ("test" , "Run OpenDAL Zig bindings tests" );
63
99
test_step .dependOn (& libopendal_c .step );
64
- test_step .dependOn (& run_unit_tests .step );
100
+ test_step .dependOn (& run_lib_test .step );
101
+ test_step .dependOn (& run_bdd_test .step );
65
102
}
0 commit comments