Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/bazel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: bazel

permissions:
contents: read

on:
pull_request:
branches:
- dev
push:
branches:
- dev

concurrency:
group: bazel-ref
cancel-in-progress: true

jobs:
build:
name: bazel build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Bazel
uses: bazel-contrib/setup-bazel@0.14.0
with:
bazelisk-cache: true
disk-cache: enabled
repository-cache: true

- name: Build libzstd
run: bazel build //lib:zstd
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ projects/
bin/
.buckd/
buck-out/
bazel-*
MODULE.bazel.lock
build-*
*.gcda
cmakebuild/
Expand Down
5 changes: 5 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module(
name = "zstd",
version = "1.6.0",
)
bazel_dep(name = "platforms", version = "0.0.11")
46 changes: 46 additions & 0 deletions build/bazel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Bazel build

This directory documents the Bazel build for zstd. Like the CMake and Meson
builds under `build/`, it is community maintained.

## Building from the repository root

```sh
bazel build //lib:zstd
```

This produces a static library (`libzstd.a` on Linux/macOS, `zstd.lib` on
Windows).

## Layout

- `MODULE.bazel` must stay at the repository root, because Bazel treats the
root as the workspace and pre-1.0 modules do not accept it anywhere else.
It is the only file Bazel requires at the root.
- `lib/BUILD.bazel` defines the `zstd` target next to the existing
`lib/BUCK`, `Makefile` and `libzstd.mk`.
- `.github/workflows/bazel.yml` builds `//lib:zstd` on every change to keep
the build description from bit-rotting.

## Configuration

`ZSTD_LEGACY_SUPPORT` is disabled and multithreading is off by default,
matching the static library built by `make lib`. The MSVC C11 flag is applied
through `select()` in `lib/BUILD.bazel`, so no `.bazelrc` is needed.

## Using zstd from another Bazel workspace

With Bzlmod, depend on the module and use the `zstd` target:

```python
bazel_dep(name = "zstd", version = "1.6.0")
```

When zstd is vendored with `local_path_override` or `archive_override`, the
same `//lib:zstd` target is available.

## Adding languages or features

The target currently builds the C library only. The command line tools in
`programs/` are not wired into Bazel yet; a follow-up can add them as a
`cc_binary` if there is demand.
31 changes: 31 additions & 0 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package(default_visibility = ["//visibility:public"])

licenses(["notice"])

cc_library(
name = "zstd",
srcs = glob([
"common/*.c",
"compress/*.c",
"decompress/*.c",
"deprecated/*.c",
"dictBuilder/*.c",
]),
hdrs = glob([
"*.h",
"common/*.h",
"compress/*.h",
"decompress/*.h",
"deprecated/*.h",
"dictBuilder/*.h",
]),
copts = select({
"@platforms//os:windows": ["/std:c11"],
"//conditions:default": [],
}),
includes = ["."],
local_defines = [
"XXH_NAMESPACE=ZSTD_",
"ZSTD_LEGACY_SUPPORT=0",
],
)