|
| 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 | +} |
0 commit comments