Skip to content

Commit d6408cd

Browse files
change build script to download the lib
1 parent f9c36f9 commit d6408cd

File tree

2 files changed

+33
-6
lines changed

2 files changed

+33
-6
lines changed

build.zig

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

build.zig.zon

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
// Once all dependencies are fetched, `zig build` no longer requires
3333
// internet connectivity.
3434
.dependencies = .{
35+
.chdb_linux_aarch64_static = .{
36+
.url = "https://github.com/chdb-io/chdb/releases/download/v4.0.0b3/linux-aarch64-libchdb-static.tar.gz",
37+
.hash = "N-V-__8AAOKnSFKj76m8cYgLGoCLZT0pK8gid2LDYVLa6zlJ", // sha256
38+
},
39+
.chdb_linux_x86_64_static = .{
40+
.url = "https://github.com/chdb-io/chdb/releases/download/v4.0.0b3/linux-x86_64-libchdb-static.tar.gz",
41+
.hash = "N-V-__8AABAUSVOH78QNsJCkvrUYKnU0VNZLFNGeAgbHPAiA", // sha256
42+
},
3543
// See `zig fetch --save <url>` for a command-line interface for adding dependencies.
3644
//.example = .{
3745
// // When updating this field to a new URL, be sure to delete the corresponding

0 commit comments

Comments
 (0)