Skip to content

new(cockroachdb): distributed SQL with Pebble storage engine#13122

Open
tannevaled wants to merge 17 commits into
pkgxdev:mainfrom
tannevaled:new/cockroachdb
Open

new(cockroachdb): distributed SQL with Pebble storage engine#13122
tannevaled wants to merge 17 commits into
pkgxdev:mainfrom
tannevaled:new/cockroachdb

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Summary

Add a pantry recipe for cockroachdb/cockroach — a Go-based distributed
SQL database that uses Pebble (pure-Go RocksDB rewrite) as its storage
engine, sidestepping the C++ rocksdb / cgo build hell that complicates
alternatives such as TiKV.

  • Source build (no vendored binaries).
  • Builds the cockroach-short bazel target via bazelisk, which produces
    a fully functional cockroach binary without the embedded JS DB Console
    (the maintainer-recommended "lean" build, cf. docs/building.md).
  • Pins USE_BAZEL_VERSION to match the in-tree .bazelversion (7.6.0).
  • A stub stamp.sh is injected to satisfy bazel's
    workspace_status_command from a tarball checkout that has no .git/.

Build notes

  • The legacy make buildoss target referenced in older Arch AUR PKGBUILDs
    no longer exists in v23+ — the top-level GNUmakefile is a thin wrapper
    around ./dev (bazel).
  • nixpkgs gives up on source builds since v23 and just rewraps the
    upstream binary tarballs — we choose the source-build path instead
    (HARD RULE: no vendoring).
  • Cross-referenced: Arch AUR (legacy v19 make path), nixpkgs (binary-only
    since v23), upstream docs/building.md.

Test plan

  • pkgx +github.com/cockroachdb/cockroach -- cockroach version reports v26.2.1
  • cockroach start-single-node --insecure boots a SQL listener
  • CI green on linux/x86-64, linux/aarch64, darwin/x86-64, darwin/aarch64

🤖 Generated with Claude Code

Add recipe for cockroachdb/cockroach v26.x. CockroachDB is a Go-based
distributed SQL database that uses Pebble (a pure-Go RocksDB rewrite) as
its storage engine, avoiding the C++ rocksdb / cgo build complexity that
plagues TiKV.

Build path: since v23 cockroach moved fully to bazel; the legacy
`make buildoss` target no longer exists. The recipe builds the
`cockroach-short` bazel target via bazelisk, which excludes the
embedded JS web UI but produces a fully functional `cockroach` binary
(this is the maintainer-recommended "lean" build).

Notes:
  - github source tarballs lack a .git dir; stub stamp.sh injects the
    version into bazel's stable-status so the binary reports v{{version}}
  - cross-references: Arch AUR PKGBUILD (v19, legacy make), nixpkgs
    23.1 (gave up on source builds), and upstream docs/building.md.
cockroachdb does not publish GitHub releases; it only pushes git tags.
The default github: <org>/<repo> resolves to .../releases/tags which
returns an empty list, leading to "no versions parsed". Switch to
.../tags so version resolution finds v26.2.1 and friends.
bazel's default sandbox masks /toolchain/gcc on the host, which pkgx's
gcc wrapper script tries to exec at runtime, causing:
  gcc: line 25: /toolchain/gcc: No such file or directory

Use --spawn_strategy=local to bypass the sandbox; the bazel build then
runs against the same toolchain pantry already wired up. Same pattern
is conceptually equivalent to starpls's --action_env hack but works
when actual cgo compilation is needed (cockroach has jemalloc, geos
and proj as c-deps).
bazel's --incompatible_strict_action_env (enabled in cockroach's
.bazelrc) wipes HOME/PATH from spawned compile actions. pkgx's gcc
wrapper at $HOME/toolchain/bin/gcc execs $HOME/toolchain/<tool>, so
HOME=='' degrades to /toolchain/gcc and exits 127.

Drop the HOME override (was clobbering pantry's prepared toolchain
location), preserve the build shell's HOME/PATH and forward both to
bazel via --action_env. Also use a 'EOSTAMP' heredoc with sed
substitution so the stamp script does not expand $() at write time
in the wrong shell context.
tannevaled and others added 6 commits July 7, 2026 20:46
The protobuf/codegen tools compile in bazel's exec ("[for tool]")
configuration, which --action_env does not reach. Without HOME the pkgx
gcc wrapper execs "$HOME/toolchain/gcc" as the absolute "/toolchain/gcc"
and dies with "No such file or directory". Add --host_action_env for
HOME and PATH so host-configuration compiles find the wrapper too.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
With HOME/PATH forwarded the pkgx gcc wrapper now runs, but linking fails
one step later: pkgx's binutils `ld.gold` is itself linked against pkgx's
newer libstdc++ and, without LD_LIBRARY_PATH in the strict action env,
resolves the ancient distro libstdc++ instead (`GLIBCXX_3.4.32 not
found`). Forward LD_LIBRARY_PATH into the target and exec action envs too.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Forwarding HOME/PATH/LD_LIBRARY_PATH cleared the first two failures but
rules_go's GoStdlib cgo build sanitises the env again and the pkgx gcc
wrapper (which needs $HOME to locate $HOME/toolchain/gcc) collapses back
to "/toolchain/gcc: No such file or directory".

Stop chasing HOME through every bazel action kind: set CC/CXX to the real
gcc/g++ from the bottle and hand the compiler its include/lib/loader
search paths directly. Exporting CC/CXX makes bazel's C++ autoconf select
the real compiler; forwarding CC/CXX/CPATH/LIBRARY_PATH/LD_LIBRARY_PATH
into both target and exec action envs covers the go cgo compiles. The
wrapper — and its HOME dependency — is no longer on the critical path.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The real-gcc CC/CXX override got past the C++ compiles, but rules_go's
GoStdlib cgo step still failed: gcc shells out to `as`, found on PATH as
brewkit's wrapper (`.../share/toolchain/bin/as`), which re-execs
"$HOME/toolchain/as" — and rules_go scrubs HOME from its subprocess env,
so it collapses to "/toolchain/as: No such file or directory". Remove the
wrapper dir from the PATH forwarded to bazel actions so the real binutils
(already on PATH under /opt) is used directly; no wrapper needs HOME.

Also drop the darwin platforms: cockroach's rules_go go_sdk has no darwin
toolchain (`unsupported platform darwin_amd64`); it's a Linux server build.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The cleaned PATH got the build through every compile; it now fails at the
final Go-tool links. gcc's default linker in the pkgx binutils is ld.gold,
a C++ program that needs pkgx's newer libstdc++ to run — and rules_go's
link builder scrubs LD_LIBRARY_PATH from the linker subprocess, so ld.gold
picks up the distro's ancient libstdc++ (`GLIBCXX_3.4.32 not found`).
ld.bfd is plain C with no such dependency; force it via CGO_LDFLAGS for
cgo links and --linkopt/--host_linkopt for bazel's own C/C++ links.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
ld.bfd was a dead end (bazel/protobuf link with gold/lld-only --start-lib).
So keep ld.gold, but fix the reason it fails inside rules_go's link step:
ld.gold needs pkgx's newer libstdc++ and rules_go scrubs LD_LIBRARY_PATH
from the linker subprocess. Install pkgx's libstdc++ into the system
library dir + ldconfig before building, so ld.gold resolves it via the
default loader path regardless of the (scrubbed) action env. libstdc++ is
backward compatible, so the distro's own tools are unaffected.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
tannevaled and others added 7 commits July 7, 2026 22:00
With the toolchain issues resolved the build now compiles cleanly and
fails in codegen: cockroach's goyacc genrules write fixed-name scratch
files (types_regex.tmp), and under --spawn_strategy=local they all share
the exec root and race (`sed: couldn't open file types_regex.tmp`).
Sandbox just the genrules (--strategy=Genrule=sandboxed) so each gets an
isolated dir; their tools are declared inputs so they don't need the /opt
toolchain that forced local strategy for the compile actions.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The genrule sandboxing let the whole build+link complete — the only
remaining failure was the install step, which hard-coded
`cockroach-short_/cockroach-short`, a rules_go output layout that this
version doesn't use (`install: cannot stat ...`). Find the built
executable under bazel-bin instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`bazel build` now completes all 3278 actions; only the install failed
because bazel-bin points at the default-config output tree while
--config=ci builds under a different config dir, so the binary isn't under
bazel-bin. Use `cquery --output=files` to get the config-correct path
(with a bazel-out find as fallback).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Build succeeds (all 3278 actions); bazel reports the output at
_bazel/bin/pkg/cmd/cockroach-short/cockroach-short_/cockroach-short —
cockroach's .bazelrc sets --symlink_prefix=_bazel/, so the convenience
symlink is _bazel/bin, not the default bazel-bin the recipe searched.
Look under _bazel/bin (with bazel-bin as fallback).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Build+install now succeed; the smoke test failed because the cgo binary
(Pebble/RocksDB C++) needs the pkgx toolchain's libstdc++ at runtime and
the recipe declared no runtime deps, so `cockroach version` aborted on the
distro's older libstdc++ (its stderr hidden by the `| grep` pipe). Add the
libstdcxx runtime dependency, and make the test capture stderr + echo it
so any future loader error is visible, accepting the version or the
CockroachDB banner.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`cockroach version` exits non-zero with empty stdout+stderr — a crash
before any output, not a loader message. Print file/ldd of the installed
binary and the captured exit code so CI reveals whether a shared lib is
missing or it's a signal, while still asserting on the banner.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diagnosis showed `cockroach version` exits 139 (SIGSEGV) with a clean ldd
— not a missing library but an ABI crash. The binary's cgo C++ is built
with the pkgx gcc, while the standalone gnu.org/gcc/libstdcxx bottle is an
older gcc series; loading the freshly-built objects against that
mismatched libstdc++ faults at startup. Depend on gnu.org/gcc so the
runtime libstdc++ matches the one the objects were compiled against.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant