Skip to content

Commit 68aaf8d

Browse files
committed
update for zig 0.16.0
1 parent 01327d4 commit 68aaf8d

File tree

3 files changed

+81
-47
lines changed

3 files changed

+81
-47
lines changed

.github/workflows/ci.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@ jobs:
1717
zig-version: [master]
1818
os: [ubuntu-latest, macos-latest, windows-latest]
1919
include:
20-
- zig-version: "0.14.0"
20+
- zig-version: "0.14.1"
21+
os: ubuntu-latest
22+
- zig-version: "0.15.2"
2123
os: ubuntu-latest
2224
runs-on: ${{ matrix.os }}
2325
steps:
2426
- name: Checkout
25-
uses: actions/checkout@v4
27+
uses: actions/checkout@v6
2628

2729
- name: Setup Zig
28-
uses: mlugg/setup-zig@v1
30+
uses: mlugg/setup-zig@v2
2931
with:
3032
version: ${{ matrix.zig-version }}
3133

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@
44

55
This is [zstd](https://github.com/facebook/zstd), packaged for [Zig](https://ziglang.org/).
66

7+
Compatible with zig `0.14`-`0.16`
8+
79
## Installation
810

911
First, update your `build.zig.zon`:
1012

1113
```
1214
# Initialize a `zig build` project if you haven't already
1315
zig init
14-
zig fetch --save git+https://github.com/allyourcodebase/zstd.git#1.5.7
16+
zig fetch --save git+https://github.com/allyourcodebase/zstd.git#master
1517
```
1618

1719
You can then import `zstd` in your `build.zig` with:
@@ -23,3 +25,30 @@ const zstd_dependency = b.dependency("zstd", .{
2325
});
2426
your_exe.linkLibrary(zstd_dependency.artifact("zstd"));
2527
```
28+
29+
## Options
30+
31+
```
32+
-Dlinkage=[enum] Link mode. Defaults to static
33+
Supported Values:
34+
static
35+
dynamic
36+
-Dstrip=[bool] Omit debug information
37+
-Dpie=[bool] Produce Position Independent Code
38+
-Dcompression=[bool] build compression module
39+
-Ddecompression=[bool] build decompression module
40+
-Ddictbuilder=[bool] build dictbuilder module
41+
-Ddeprecated=[bool] build deprecated module
42+
-Dminify=[bool] Configures a bunch of other options to space-optimized defaults
43+
-Dlegacy-support=[int] makes it possible to decompress legacy zstd formats
44+
-Dmulti-thread=[bool] Enable multi-threading
45+
-Ddisable-assembly=[bool] Assembly support
46+
-Dhuf-force-decompress-x1=[bool]
47+
-Dhuf-force-decompress-x2=[bool]
48+
-Dforce-decompress-sequences-short=[bool]
49+
-Dforce-decompress-sequences-long=[bool]
50+
-Dno-inline=[bool] Disable Inlining
51+
-Dstrip-error-strings=[bool] removes the error messages that are otherwise returned by `ZSTD_getErrorName` (implied by `-Dminify`)
52+
-Dexclude-compressors-dfast-and-up=[bool]
53+
-Dexclude-compressors-greedy-and-up=[bool]
54+
```

build.zig

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void {
55
const target = b.standardTargetOptions(.{});
66
const optimize = b.standardOptimizeOption(.{});
77

8-
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode") orelse .static;
8+
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode. Defaults to static") orelse .static;
99
const strip = b.option(bool, "strip", "Omit debug information");
1010
const pic = b.option(bool, "pie", "Produce Position Independent Code");
1111

@@ -31,62 +31,64 @@ pub fn build(b: *std.Build) void {
3131
const exclude_compressors_dfast_and_up = b.option(bool, "exclude-compressors-dfast-and-up", "") orelse false;
3232
const exclude_compressors_greedy_and_up = b.option(bool, "exclude-compressors-greedy-and-up", "") orelse false;
3333

34+
const module = b.createModule(.{
35+
.target = target,
36+
.optimize = optimize,
37+
.strip = strip,
38+
.pic = pic,
39+
.link_libc = true,
40+
});
3441
const zstd = b.addLibrary(.{
3542
.linkage = linkage,
3643
.name = "zstd",
37-
.root_module = b.createModule(.{
38-
.target = target,
39-
.optimize = optimize,
40-
.strip = strip,
41-
.pic = pic,
42-
.link_libc = true,
43-
}),
44+
.root_module = module,
4445
});
4546
b.installArtifact(zstd);
46-
zstd.root_module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = common_sources });
47+
module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = common_sources });
4748
// zstd does not install into its own subdirectory. :(
4849
zstd.installHeader(upstream.path("lib/zstd.h"), "zstd.h");
4950
zstd.installHeader(upstream.path("lib/zdict.h"), "zdict.h");
5051
zstd.installHeader(upstream.path("lib/zstd_errors.h"), "zstd_errors.h");
51-
if (compression) zstd.addCSourceFiles(.{ .root = upstream.path("lib"), .files = compression_sources });
52-
if (decompression) zstd.addCSourceFiles(.{ .root = upstream.path("lib"), .files = decompress_sources });
53-
if (dictbuilder) zstd.addCSourceFiles(.{ .root = upstream.path("lib"), .files = dict_builder_sources });
54-
if (deprecated) zstd.addCSourceFiles(.{ .root = upstream.path("lib"), .files = deprecated_sources });
52+
if (compression) module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = compression_sources });
53+
if (decompression) module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = decompress_sources });
54+
if (dictbuilder) module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = dict_builder_sources });
55+
if (deprecated) module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = deprecated_sources });
5556
if (legacy_support != 0) {
56-
for (legacy_support..8) |i| zstd.addCSourceFile(.{ .file = upstream.path(b.fmt("lib/legacy/zstd_v0{d}.c", .{i})) });
57+
for (legacy_support..8) |i|
58+
module.addCSourceFile(.{ .file = upstream.path(b.fmt("lib/legacy/zstd_v0{d}.c", .{i})) });
5759
}
5860

5961
if (target.result.cpu.arch == .x86_64) {
6062
if (decompression) {
61-
zstd.root_module.addAssemblyFile(upstream.path("lib/decompress/huf_decompress_amd64.S"));
63+
module.addAssemblyFile(upstream.path("lib/decompress/huf_decompress_amd64.S"));
6264
}
6365
} else {
64-
zstd.root_module.addCMacro("ZSTD_DISABLE_ASM", "");
66+
module.addCMacro("ZSTD_DISABLE_ASM", "");
6567
}
6668

67-
zstd.root_module.addCMacro("ZSTD_LEGACY_SUPPORT", b.fmt("{d}", .{legacy_support}));
68-
if (multi_thread) zstd.root_module.addCMacro("ZSTD_MULTITHREAD", "1");
69-
if (disable_assembly) zstd.root_module.addCMacro("ZSTD_DISABLE_ASM", "");
70-
if (huf_force_decompress_x1) zstd.root_module.addCMacro("HUF_FORCE_DECOMPRESS_X1", "");
71-
if (huf_force_decompress_x2) zstd.root_module.addCMacro("HUF_FORCE_DECOMPRESS_X2", "");
72-
if (force_decompress_sequences_short) zstd.root_module.addCMacro("ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT", "");
73-
if (force_decompress_sequences_long) zstd.root_module.addCMacro("ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG", "");
74-
if (no_inline) zstd.root_module.addCMacro("ZSTD_NO_INLINE", "");
75-
if (strip_error_strings) zstd.root_module.addCMacro("ZSTD_STRIP_ERROR_STRINGS", "");
69+
module.addCMacro("ZSTD_LEGACY_SUPPORT", b.fmt("{d}", .{legacy_support}));
70+
if (multi_thread) module.addCMacro("ZSTD_MULTITHREAD", "1");
71+
if (disable_assembly) module.addCMacro("ZSTD_DISABLE_ASM", "");
72+
if (huf_force_decompress_x1) module.addCMacro("HUF_FORCE_DECOMPRESS_X1", "");
73+
if (huf_force_decompress_x2) module.addCMacro("HUF_FORCE_DECOMPRESS_X2", "");
74+
if (force_decompress_sequences_short) module.addCMacro("ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT", "");
75+
if (force_decompress_sequences_long) module.addCMacro("ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG", "");
76+
if (no_inline) module.addCMacro("ZSTD_NO_INLINE", "");
77+
if (strip_error_strings) module.addCMacro("ZSTD_STRIP_ERROR_STRINGS", "");
7678
if (exclude_compressors_dfast_and_up) {
77-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR", "");
78-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", "");
79-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", "");
80-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", "");
81-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", "");
82-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", "");
79+
module.addCMacro("ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR", "");
80+
module.addCMacro("ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", "");
81+
module.addCMacro("ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", "");
82+
module.addCMacro("ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", "");
83+
module.addCMacro("ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", "");
84+
module.addCMacro("ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", "");
8385
}
8486
if (exclude_compressors_greedy_and_up) {
85-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", "");
86-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", "");
87-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", "");
88-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", "");
89-
zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", "");
87+
module.addCMacro("ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", "");
88+
module.addCMacro("ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", "");
89+
module.addCMacro("ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", "");
90+
module.addCMacro("ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", "");
91+
module.addCMacro("ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", "");
9092
}
9193

9294
{
@@ -103,16 +105,17 @@ pub fn build(b: *std.Build) void {
103105
};
104106

105107
for (examples) |name| {
108+
const mod = b.createModule(.{
109+
.target = target,
110+
.optimize = optimize,
111+
});
106112
const exe = b.addExecutable(.{
107113
.name = name,
108-
.root_module = b.createModule(.{
109-
.target = target,
110-
.optimize = optimize,
111-
}),
114+
.root_module = mod,
112115
});
113-
exe.addCSourceFile(.{ .file = upstream.path(b.fmt("examples/{s}.c", .{name})) });
114-
exe.addIncludePath(upstream.path("examples/common.c"));
115-
exe.linkLibrary(zstd);
116+
mod.addCSourceFile(.{ .file = upstream.path(b.fmt("examples/{s}.c", .{name})) });
117+
mod.addIncludePath(upstream.path("examples/common.c"));
118+
mod.linkLibrary(zstd);
116119
b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{ .dest_dir = .{ .override = .{ .custom = "examples" } } }).step);
117120
}
118121
}

0 commit comments

Comments
 (0)