@@ -21,6 +21,25 @@ pub fn build(b: *std.Build) void {
2121 // target and optimize options) will be listed when running `zig build --help`
2222 // in this directory.
2323
24+ // Determine the dependency name based on the target OS and CPU
25+ const target_os = target .result .os .tag ;
26+ const target_arch = target .result .cpu .arch ;
27+
28+ const dep_name = if (target_os == .linux and target_arch == .x86_64 )
29+ "chdb_linux_x86_64_static"
30+ else if (target_os == .linux and target_arch == .aarch64 )
31+ "chdb_linux_aarch64_static"
32+ else {
33+ // Fallback or error for unsupported platforms
34+ @panic ("Unsupported platform for chDB" );
35+ };
36+
37+ // This ONLY fetches the selected binary
38+ const chdb_bin = b .dependency (dep_name , .{});
39+
40+ // Link the paths from the fetched dependency
41+ // Note: Adjust folder names ("lib" or "include") based on the .tar.gz structure
42+
2443 // This creates a module, which represents a collection of source files alongside
2544 // some compilation options, such as optimization mode and linked system libraries.
2645 // Zig modules are the preferred way of making Zig code available to consumers.
@@ -41,8 +60,8 @@ pub fn build(b: *std.Build) void {
4160 .target = target ,
4261 .optimize = optimize ,
4362 });
44- mod .addIncludePath (b .path ("vendor/chdb " ));
45- mod .addObjectFile (b .path ("vendor/chdb/ libchdb.a" ));
63+ mod .addIncludePath (chdb_bin .path (". " ));
64+ mod .addObjectFile (chdb_bin .path ("libchdb.a" ));
4665 mod .link_libc = true ;
4766
4867 // Here we define an executable. An executable needs to have a root module
@@ -130,8 +149,8 @@ pub fn build(b: *std.Build) void {
130149 });
131150
132151 // The test runner needs to know where the C headers and library are
133- mod_tests .addIncludePath (b .path ("vendor/chdb " ));
134- mod_tests .addObjectFile (b .path ("vendor/chdb/ libchdb.a" ));
152+ mod_tests .addIncludePath (chdb_bin .path (". " ));
153+ mod_tests .addObjectFile (chdb_bin .path ("libchdb.a" ));
135154 mod_tests .linkLibC ();
136155
137156 // A run step that will run the test executable.
@@ -145,8 +164,8 @@ pub fn build(b: *std.Build) void {
145164 .use_llvm = true ,
146165 });
147166
148- exe_tests .addIncludePath (b .path ("vendor/chdb " ));
149- exe_tests .addObjectFile (b .path ("vendor/chdb/ libchdb.a" ));
167+ exe_tests .addIncludePath (chdb_bin .path (". " ));
168+ exe_tests .addObjectFile (chdb_bin .path ("libchdb.a" ));
150169 exe_tests .linkLibC ();
151170
152171 // A run step that will run the second test executable.
0 commit comments