-
Notifications
You must be signed in to change notification settings - Fork 2
Update for Zig 0.16.0 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -4,14 +4,16 @@ | |||||
|
|
||||||
| 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`: | ||||||
|
|
||||||
| ``` | ||||||
| # 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 | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will tag a new release of this PR has been merged. This should be reverted.
Suggested change
|
||||||
| ``` | ||||||
|
|
||||||
| 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] | ||||||
| ``` | ||||||
|
Comment on lines
+28
to
+54
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can run |
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
Comment on lines
-37
to
+44
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the diff unnecessarily complicated. Can you keep the |
||
| }); | ||
| 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, | ||
|
Comment on lines
-108
to
+114
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the diff unnecessarily complicated. Can you keep the |
||
| }); | ||
| 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); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A statement like "Compatible with zig 0.16" is misleading because there is no 0.16.0 release (yet). You would have to mention the exact Zig version this has been tested with or say
0.16.0-dev. This can easily get outdated over time so I'd suggest to remove this statement entirely and let the user test whether it works with their Zig version instead.Also, projects in allyourcodebase only need to guarantee support for the latest tagged release. Anything beyond that may change over time.