diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7442d64..c300ddd 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,15 +17,17 @@ jobs: zig-version: [master] os: [ubuntu-latest, macos-latest, windows-latest] include: - - zig-version: "0.14.0" + - zig-version: "0.14.1" + os: ubuntu-latest + - zig-version: "0.15.2" os: ubuntu-latest runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Setup Zig - uses: mlugg/setup-zig@v1 + uses: mlugg/setup-zig@v2 with: version: ${{ matrix.zig-version }} diff --git a/README.md b/README.md index 716727d..fd02101 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,8 @@ This is [zstd](https://github.com/facebook/zstd), packaged for [Zig](https://ziglang.org/). +Compatible with zig `0.14`-`0.16` + ## Installation First, update your `build.zig.zon`: @@ -11,7 +13,7 @@ First, update your `build.zig.zon`: ``` # Initialize a `zig build` project if you haven't already zig init -zig fetch --save git+https://github.com/allyourcodebase/zstd.git#1.5.7 +zig fetch --save git+https://github.com/allyourcodebase/zstd.git#master ``` You can then import `zstd` in your `build.zig` with: @@ -23,3 +25,30 @@ const zstd_dependency = b.dependency("zstd", .{ }); your_exe.linkLibrary(zstd_dependency.artifact("zstd")); ``` + +## Options + +``` + -Dlinkage=[enum] Link mode. Defaults to static + Supported Values: + static + dynamic + -Dstrip=[bool] Omit debug information + -Dpie=[bool] Produce Position Independent Code + -Dcompression=[bool] build compression module + -Ddecompression=[bool] build decompression module + -Ddictbuilder=[bool] build dictbuilder module + -Ddeprecated=[bool] build deprecated module + -Dminify=[bool] Configures a bunch of other options to space-optimized defaults + -Dlegacy-support=[int] makes it possible to decompress legacy zstd formats + -Dmulti-thread=[bool] Enable multi-threading + -Ddisable-assembly=[bool] Assembly support + -Dhuf-force-decompress-x1=[bool] + -Dhuf-force-decompress-x2=[bool] + -Dforce-decompress-sequences-short=[bool] + -Dforce-decompress-sequences-long=[bool] + -Dno-inline=[bool] Disable Inlining + -Dstrip-error-strings=[bool] removes the error messages that are otherwise returned by `ZSTD_getErrorName` (implied by `-Dminify`) + -Dexclude-compressors-dfast-and-up=[bool] + -Dexclude-compressors-greedy-and-up=[bool] +``` diff --git a/build.zig b/build.zig index ccb9860..fdc68d8 100644 --- a/build.zig +++ b/build.zig @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode") orelse .static; + const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode. Defaults to static") orelse .static; const strip = b.option(bool, "strip", "Omit debug information"); const pic = b.option(bool, "pie", "Produce Position Independent Code"); @@ -31,62 +31,64 @@ pub fn build(b: *std.Build) void { const exclude_compressors_dfast_and_up = b.option(bool, "exclude-compressors-dfast-and-up", "") orelse false; const exclude_compressors_greedy_and_up = b.option(bool, "exclude-compressors-greedy-and-up", "") orelse false; + const module = b.createModule(.{ + .target = target, + .optimize = optimize, + .strip = strip, + .pic = pic, + .link_libc = true, + }); const zstd = b.addLibrary(.{ .linkage = linkage, .name = "zstd", - .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, - .strip = strip, - .pic = pic, - .link_libc = true, - }), + .root_module = module, }); b.installArtifact(zstd); - zstd.root_module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = common_sources }); + module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = common_sources }); // zstd does not install into its own subdirectory. :( zstd.installHeader(upstream.path("lib/zstd.h"), "zstd.h"); zstd.installHeader(upstream.path("lib/zdict.h"), "zdict.h"); zstd.installHeader(upstream.path("lib/zstd_errors.h"), "zstd_errors.h"); - if (compression) zstd.addCSourceFiles(.{ .root = upstream.path("lib"), .files = compression_sources }); - if (decompression) zstd.addCSourceFiles(.{ .root = upstream.path("lib"), .files = decompress_sources }); - if (dictbuilder) zstd.addCSourceFiles(.{ .root = upstream.path("lib"), .files = dict_builder_sources }); - if (deprecated) zstd.addCSourceFiles(.{ .root = upstream.path("lib"), .files = deprecated_sources }); + if (compression) module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = compression_sources }); + if (decompression) module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = decompress_sources }); + if (dictbuilder) module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = dict_builder_sources }); + if (deprecated) module.addCSourceFiles(.{ .root = upstream.path("lib"), .files = deprecated_sources }); if (legacy_support != 0) { - for (legacy_support..8) |i| zstd.addCSourceFile(.{ .file = upstream.path(b.fmt("lib/legacy/zstd_v0{d}.c", .{i})) }); + for (legacy_support..8) |i| + module.addCSourceFile(.{ .file = upstream.path(b.fmt("lib/legacy/zstd_v0{d}.c", .{i})) }); } if (target.result.cpu.arch == .x86_64) { if (decompression) { - zstd.root_module.addAssemblyFile(upstream.path("lib/decompress/huf_decompress_amd64.S")); + module.addAssemblyFile(upstream.path("lib/decompress/huf_decompress_amd64.S")); } } else { - zstd.root_module.addCMacro("ZSTD_DISABLE_ASM", ""); + module.addCMacro("ZSTD_DISABLE_ASM", ""); } - zstd.root_module.addCMacro("ZSTD_LEGACY_SUPPORT", b.fmt("{d}", .{legacy_support})); - if (multi_thread) zstd.root_module.addCMacro("ZSTD_MULTITHREAD", "1"); - if (disable_assembly) zstd.root_module.addCMacro("ZSTD_DISABLE_ASM", ""); - if (huf_force_decompress_x1) zstd.root_module.addCMacro("HUF_FORCE_DECOMPRESS_X1", ""); - if (huf_force_decompress_x2) zstd.root_module.addCMacro("HUF_FORCE_DECOMPRESS_X2", ""); - if (force_decompress_sequences_short) zstd.root_module.addCMacro("ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT", ""); - if (force_decompress_sequences_long) zstd.root_module.addCMacro("ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG", ""); - if (no_inline) zstd.root_module.addCMacro("ZSTD_NO_INLINE", ""); - if (strip_error_strings) zstd.root_module.addCMacro("ZSTD_STRIP_ERROR_STRINGS", ""); + module.addCMacro("ZSTD_LEGACY_SUPPORT", b.fmt("{d}", .{legacy_support})); + if (multi_thread) module.addCMacro("ZSTD_MULTITHREAD", "1"); + if (disable_assembly) module.addCMacro("ZSTD_DISABLE_ASM", ""); + if (huf_force_decompress_x1) module.addCMacro("HUF_FORCE_DECOMPRESS_X1", ""); + if (huf_force_decompress_x2) module.addCMacro("HUF_FORCE_DECOMPRESS_X2", ""); + if (force_decompress_sequences_short) module.addCMacro("ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT", ""); + if (force_decompress_sequences_long) module.addCMacro("ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG", ""); + if (no_inline) module.addCMacro("ZSTD_NO_INLINE", ""); + if (strip_error_strings) module.addCMacro("ZSTD_STRIP_ERROR_STRINGS", ""); if (exclude_compressors_dfast_and_up) { - zstd.root_module.addCMacro("ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR", ""); - zstd.root_module.addCMacro("ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", ""); - zstd.root_module.addCMacro("ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", ""); - zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", ""); - zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", ""); - zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_DFAST_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", ""); } if (exclude_compressors_greedy_and_up) { - zstd.root_module.addCMacro("ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", ""); - zstd.root_module.addCMacro("ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", ""); - zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", ""); - zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", ""); - zstd.root_module.addCMacro("ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_GREEDY_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_LAZY2_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_BTLAZY2_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_BTOPT_BLOCK_COMPRESSOR", ""); + module.addCMacro("ZSTD_EXCLUDE_BTULTRA_BLOCK_COMPRESSOR", ""); } { @@ -103,16 +105,17 @@ pub fn build(b: *std.Build) void { }; for (examples) |name| { + const mod = b.createModule(.{ + .target = target, + .optimize = optimize, + }); const exe = b.addExecutable(.{ .name = name, - .root_module = b.createModule(.{ - .target = target, - .optimize = optimize, - }), + .root_module = mod, }); - exe.addCSourceFile(.{ .file = upstream.path(b.fmt("examples/{s}.c", .{name})) }); - exe.addIncludePath(upstream.path("examples/common.c")); - exe.linkLibrary(zstd); + mod.addCSourceFile(.{ .file = upstream.path(b.fmt("examples/{s}.c", .{name})) }); + mod.addIncludePath(upstream.path("examples/common.c")); + mod.linkLibrary(zstd); b.getInstallStep().dependOn(&b.addInstallArtifact(exe, .{ .dest_dir = .{ .override = .{ .custom = "examples" } } }).step); } }