Skip to content

Take darts-clone from the Bazel Central Registry - #1312

Merged
taku910 merged 1 commit into
google:masterfrom
BYVoid:claude/darts-clone-bcr
Sep 3, 2026
Merged

taku910 merged 1 commit into
google:masterfrom
BYVoid:claude/darts-clone-bcr

Conversation

@BYVoid

@BYVoid BYVoid commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

The Bazel build depends on the darts-clone BCR module instead of compiling third_party/darts_clone/darts.h. The CMake build is unchanged and still compiles the vendored copy.

0.32h.bcr.1 vs. third_party/darts_clone/darts.h

Both declare DARTS_VERSION "0.32" and both carry the copy_array() and validate(max_value_limit) helpers this repo added — the module's darts_header_compat.patch is derived from those, and its compat test cites commit d685ef31. diff between the two headers is 108 lines:

vendored 0.32h.bcr.1
copy_array() ✓ ✓
validate(max_value_limit) ✓ ✓
commonLongestPrefixSearch() ✗ ✓
save() offset argument ignored (unnamed parameter) honoured via fseek
BLOCK_SIZE, UPPER_MASK, … static constexpr int enum
size_t → id_type narrowing implicit explicit static_cast

The vendored copy predates the v0.32h tag, which is where commonLongestPrefixSearch() and the save() offset fix landed; the module is that tag plus the two helpers above. The remaining differences are the enum/constexpr spelling, the added static_casts, and validate()'s else { if } rewritten as else if — same semantics.

SentencePiece calls build, set_array, copy_array, validate, exactMatchSearch, commonPrefixSearch, traverse, array and size. All behave identically. commonLongestPrefixSearch() and save() are never called, so the two additions are inert here.

Why the module rather than the vendored header

Known provenance. The module records exactly what it is: s-yata/darts-clone v0.32h, pinned by SHA-256 of the release tarball, plus four named patches that are themselves hash-pinned. third_party/darts_clone/darts.h is an undated snapshot of an unrecorded revision with local edits folded in — the only way to learn what was changed, as the table above shows, is to diff it against upstream and guess which side each difference came from.

Upgrades become a version bump. The vendored copy has drifted behind v0.32h and silently lost the save() offset fix along the way. Moving it forward today means re-applying the two helpers by hand onto a new upstream drop and re-reviewing the result; with the module it is one line in MODULE.bazel, and the helpers travel as a patch that fails loudly if it stops applying.

One copy per build. Bazel consumers that depend on both SentencePiece and darts-clone currently get two Darts::DoubleArray definitions from two include paths. Going through the registry lets minimal version selection resolve them to a single copy, which matters for a header-only library whose types cross the ABI boundary in normalizer.h and model_interface.h.

The helpers are covered. The module ships darts_clone_compat_test.cc, which exercises validate() and copy_array() — the two additions this repo depends on — so a bad patch rebase is caught in the registry's presubmit rather than here.

Visible in dependency tooling. A bazel_dep with a version appears in MODULE.bazel.lock, bazel mod graph, and any SBOM generated from them. A checked-in header does not.

The vendored copy is not deleted: the CMake build still compiles it, so this change reduces the number of builds that depend on the unlabelled snapshot from two to one rather than to zero. Retiring it entirely would mean giving CMake its own way to fetch darts-clone, which is out of scope here.

Include path

The module exports the header as darts.h (strip_include_prefix = "include"), so the seven #include "third_party/darts_clone/darts.h" lines lose the prefix. src/CMakeLists.txt gains third_party/darts_clone on its include path so the CMake build resolves the same spelling against the vendored copy.

Verified locally on macOS/arm64: bazel test //... 22/22 pass, cmake --build succeeds.

🤖 Generated with Claude Code

@BYVoid
BYVoid marked this pull request as ready for review August 26, 2026 19:42
The Bazel build now depends on the darts-clone BCR module instead of
compiling third_party/darts_clone/darts.h. Module 0.32h.bcr.1 is upstream
darts-clone v0.32h plus the copy_array() and validate() helpers the vendored
header carries, so every entry point SentencePiece uses (build, set_array,
copy_array, validate, exactMatchSearch, commonPrefixSearch, traverse, array,
size) behaves identically; the module additionally has commonLongestPrefixSearch
and an honoured save() offset, neither of which SentencePiece calls.

The module exports the header as "darts.h", so the includes lose the
third_party/darts_clone prefix. The CMake build still compiles the vendored
copy and gains that directory on its include path.
@BYVoid
BYVoid force-pushed the claude/darts-clone-bcr branch from 50738c3 to 6d52aa4 Compare August 31, 2026 19:20
@taku910
taku910 merged commit 9e90862 into google:master Sep 3, 2026
6 checks passed
@BYVoid
BYVoid deleted the claude/darts-clone-bcr branch September 3, 2026 18:46
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.

2 participants