Skip to content

Commit 10c93ce

Browse files
committed
c-blosc2: initial build.zig for v2.21.3
Is not a full port of all the features in the c-blosc2 CMake files.
0 parents  commit 10c93ce

File tree

3 files changed

+121
-0
lines changed

3 files changed

+121
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.zig-cache
2+
zig-out/

build.zig

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const std = @import("std");
2+
3+
pub fn build(b: *std.Build) void {
4+
const target = b.standardTargetOptions(.{});
5+
const optimize = b.standardOptimizeOption(.{});
6+
const linkage = b.option(std.builtin.LinkMode, "linkage", "linkage to use (default: static)") orelse .static;
7+
const zstd = b.option(bool, "zstd", "Compile with support for Zstd compression (default: true)") orelse true;
8+
9+
const lz4_dep = b.dependency("lz4", .{
10+
.target = target,
11+
.optimize = optimize,
12+
.linkage = linkage,
13+
});
14+
const zstd_dep = b.dependency("zstd", .{
15+
.target = target,
16+
.optimize = optimize,
17+
.linkage = linkage,
18+
});
19+
const c_blosc2_source = b.dependency("c_blosc2", .{});
20+
21+
const config_header = b.addConfigHeader(.{
22+
.style = .{ .cmake = c_blosc2_source.path("blosc/config.h.in") },
23+
}, .{
24+
.HAVE_ZLIB = false,
25+
.HAVE_ZLIB_NG = false,
26+
.HAVE_ZSTD = zstd,
27+
.HAVE_IPP = false,
28+
.DLL_EXPORT = if (target.result.os.tag == .windows and linkage == .dynamic)
29+
"__declspec(dllexport)"
30+
else
31+
"",
32+
.HAVE_PLUGINS = false,
33+
});
34+
35+
const c_blosc2_module = b.createModule(.{
36+
.target = target,
37+
.optimize = optimize,
38+
.link_libc = true,
39+
});
40+
// Tells "blosc2.h" to include the "config.h"
41+
c_blosc2_module.addCMacro("USING_CMAKE", "1");
42+
c_blosc2_module.addConfigHeader(config_header);
43+
c_blosc2_module.addIncludePath(c_blosc2_source.path("blosc"));
44+
c_blosc2_module.addIncludePath(c_blosc2_source.path("include"));
45+
c_blosc2_module.addCSourceFiles(.{
46+
.root = c_blosc2_source.path("blosc"),
47+
.files = &.{
48+
"blosc2.c",
49+
"blosclz.c",
50+
"fastcopy.c",
51+
"schunk.c",
52+
"frame.c",
53+
"stune.c",
54+
"delta.c",
55+
"shuffle-generic.c",
56+
"bitshuffle-generic.c",
57+
"trunc-prec.c",
58+
"timestamp.c",
59+
"sframe.c",
60+
"directories.c",
61+
"blosc2-stdio.c",
62+
"b2nd.c",
63+
"b2nd_utils.c",
64+
},
65+
});
66+
67+
c_blosc2_module.addCSourceFile(.{ .file = c_blosc2_source.path("blosc/shuffle.c") });
68+
switch (target.result.cpu.arch) {
69+
.x86_64 => {
70+
c_blosc2_module.addCSourceFile(.{ .file = c_blosc2_source.path("blosc/shuffle-sse2.c") });
71+
c_blosc2_module.addCSourceFile(.{ .file = c_blosc2_source.path("blosc/bitshuffle-sse2.c") });
72+
c_blosc2_module.addCSourceFile(.{ .file = c_blosc2_source.path("blosc/shuffle-avx2.c") });
73+
c_blosc2_module.addCSourceFile(.{ .file = c_blosc2_source.path("blosc/bitshuffle-avx2.c") });
74+
c_blosc2_module.addCSourceFile(.{ .file = c_blosc2_source.path("blosc/bitshuffle-avx512.c") });
75+
},
76+
.aarch64 => {
77+
c_blosc2_module.addCSourceFile(.{ .file = c_blosc2_source.path("blosc/shuffle-neon.c") });
78+
},
79+
else => {},
80+
}
81+
82+
c_blosc2_module.linkLibrary(lz4_dep.artifact("lz4"));
83+
if (zstd) {
84+
c_blosc2_module.linkLibrary(zstd_dep.artifact("zstd"));
85+
}
86+
87+
const c_blosc2_library = b.addLibrary(.{
88+
.name = "blosc2",
89+
.linkage = linkage,
90+
.root_module = c_blosc2_module,
91+
});
92+
c_blosc2_library.installHeadersDirectory(c_blosc2_source.path("include"), ".", .{});
93+
94+
b.installArtifact(c_blosc2_library);
95+
}

build.zig.zon

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.{
2+
.name = .c_blosc2,
3+
.version = "2.21.3",
4+
.dependencies = .{
5+
.c_blosc2 = .{
6+
.url = "git+https://github.com/Blosc/c-blosc2?ref=v2.21.3#0c853a639ba97997e33e29db9eed202459ebc6f0",
7+
.hash = "N-V-__8AABtlIQEWY9A8rCWuxQog0nf3MXG0TBWr3HNyRqjv",
8+
},
9+
.lz4 = .{
10+
.url = "git+https://github.com/allyourcodebase/lz4.git#873969ee73aecb3c35203feaf0b5727b9d02b864",
11+
.hash = "lz4-1.10.0-5-ewyzw7YNAADOUkQ7M9fjW005oGzxt9b6m0uPd_kQC48z",
12+
},
13+
.zstd = .{
14+
.url = "git+https://github.com/allyourcodebase/zstd.git?ref=1.5.7#01327d49cbc56dc24c20a167bb0055d7fc23de84",
15+
.hash = "zstd-1.5.7-KEItkJ8vAAC5_rRlKmLflYQ-eKXbAIQBWZNmmJtS18q0",
16+
},
17+
},
18+
.minimum_zig_version = "0.15.2",
19+
.paths = .{
20+
"build.zig",
21+
"build.zig.zon",
22+
},
23+
.fingerprint = 0x44d08dca0c10c5a2,
24+
}

0 commit comments

Comments
 (0)