Skip to content

Instantly share code, notes, and snippets.

@evanj
Created August 9, 2023 12:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evanj/5f9619ace7a18a5acb8a1be9b9d4df23 to your computer and use it in GitHub Desktop.
Save evanj/5f9619ace7a18a5acb8a1be9b9d4df23 to your computer and use it in GitHub Desktop.
Bazel rules_go bug workaround for github.com/DataDog/zstd
diff -u orig/BUILD.bazel new/BUILD.bazel
--- orig/BUILD.bazel 2023-08-09 08:39:50
+++ new/BUILD.bazel 2023-08-09 08:42:02
@@ -1,102 +1,26 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
+load("@rules_cc//cc:defs.bzl", "cc_library")
+cc_library(
+ name = "zstd_cc",
+ srcs = glob([
+ "*.c",
+ "*.h",
+ "*.S",
+ ]),
+ copts = ["-DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1"],
+)
+
go_library(
name = "zstd",
- srcs = [
- "allocations.h",
- "bits.h",
- "bitstream.h",
- "clevels.h",
- "compiler.h",
- "cover.c",
- "cover.h",
- "cpu.h",
- "debug.c",
- "debug.h",
- "divsufsort.c",
- "divsufsort.h",
- "entropy_common.c",
- "error_private.c",
- "error_private.h",
- "errors.go",
- "fastcover.c",
- "fse.h",
- "fse_compress.c",
- "fse_decompress.c",
- "hist.c",
- "hist.h",
- "huf.h",
- "huf_compress.c",
- "huf_decompress.c",
- "huf_decompress_amd64.S",
- "mem.h",
- "pool.c",
- "pool.h",
- "portability_macros.h",
- "threading.c",
- "threading.h",
- "xxhash.c",
- "xxhash.h",
- "zbuff.h",
- "zbuff_common.c",
- "zbuff_compress.c",
- "zbuff_decompress.c",
- "zdict.c",
- "zdict.h",
- "zstd.go",
- "zstd.h",
- "zstd_bulk.go",
- "zstd_common.c",
- "zstd_compress.c",
- "zstd_compress_internal.h",
- "zstd_compress_literals.c",
- "zstd_compress_literals.h",
- "zstd_compress_sequences.c",
- "zstd_compress_sequences.h",
- "zstd_compress_superblock.c",
- "zstd_compress_superblock.h",
- "zstd_ctx.go",
- "zstd_cwksp.h",
- "zstd_ddict.c",
- "zstd_ddict.h",
- "zstd_decompress.c",
- "zstd_decompress_block.c",
- "zstd_decompress_block.h",
- "zstd_decompress_internal.h",
- "zstd_deps.h",
- "zstd_double_fast.c",
- "zstd_double_fast.h",
- "zstd_errors.h",
- "zstd_fast.c",
- "zstd_fast.h",
- "zstd_internal.h",
- "zstd_lazy.c",
- "zstd_lazy.h",
- "zstd_ldm.c",
- "zstd_ldm.h",
- "zstd_ldm_geartab.h",
- "zstd_legacy.h",
- "zstd_opt.c",
- "zstd_opt.h",
- "zstd_stream.go",
- "zstd_trace.h",
- "zstd_v01.c",
- "zstd_v01.h",
- "zstd_v02.c",
- "zstd_v02.h",
- "zstd_v03.c",
- "zstd_v03.h",
- "zstd_v04.c",
- "zstd_v04.h",
- "zstd_v05.c",
- "zstd_v05.h",
- "zstd_v06.c",
- "zstd_v06.h",
- "zstd_v07.c",
- "zstd_v07.h",
- "zstdmt_compress.c",
- "zstdmt_compress.h",
- ],
+ srcs = glob(
+ ["*.go"],
+ exclude = [
+ "*_test.go",
+ "external_zstd.go",
+ ],
+ ) + ["zstd.h"],
+ cdeps = [":zstd_cc"],
cgo = True,
copts = ["-DZSTD_LEGACY_SUPPORT=4 -DZSTD_MULTITHREAD=1"],
importpath = "github.com/DataDog/zstd",
@evanj
Copy link
Author

evanj commented Aug 9, 2023

See bazelbuild/rules_go#3411 (comment) for discussion on how to use this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment