Skip to content

Fix Windows Bazel test failures for //data/... and //python/...#1086

Merged
BYVoid merged 1 commit intomasterfrom
fix/windows-bazel-test-failures
Mar 31, 2026
Merged

Fix Windows Bazel test failures for //data/... and //python/...#1086
BYVoid merged 1 commit intomasterfrom
fix/windows-bazel-test-failures

Conversation

@BYVoid
Copy link
Copy Markdown
Owner

@BYVoid BYVoid commented Mar 31, 2026

Summary

Two test targets were failing on Windows under Bazel:

1. //data/config:config_dict_validation_test

Error: hk2s.json not found or not accessible

Cause: Runfiles::Rlocation() on a bare directory path (e.g. _main/data/config) returns an empty string on Windows in manifest-only mode (RUNFILES_MANIFEST_ONLY=1). Only file paths have entries in the runfiles manifest.

Fix: Look up a known file inside the directory and derive the directory path via find_last_of("/\\"):

// Before
configDir_ = runfiles_->Rlocation("_main/data/config");

// After
const std::string configFile = runfiles_->Rlocation("_main/data/config/hk2s.json");
configDir_ = configFile.substr(0, configFile.find_last_of("/\\"));

2. //python/tests:test_opencc

Error: ModuleNotFoundError: No module named 'opencc_clib'

Cause: On Windows, pybind_extension outputs opencc_clib.pyd.dll (Bazel appends .dll to all shared libraries). Python's import machinery on Windows only loads .pyd files, so the module cannot be found even though it's on sys.path.

Fix: Add a genrule in src/pyd/ that copies opencc_clib.pyd.dllopencc_clib.pyd, and use select() in py_opencc to use the renamed file on Windows (with imports = ["pyd"]) and the original pybind_extension output on other platforms.

3. Suppress bzlmod version warning

Update rules_python from 0.40.0 to 1.9.0 to match the version resolved by bzlmod, suppressing the startup warning.

Test plan

  • bazel test //data/config:config_dict_validation_test passes on Windows
  • bazel test //python/tests:test_opencc passes on Windows
  • Linux/macOS builds are unaffected (select() falls through to the original targets)

🤖 Generated with Claude Code

Two issues prevented tests from passing on Windows:

1. ConfigDictValidationTest (//data/config): `Runfiles::Rlocation()` on a
   directory path returns an empty string in Windows manifest-only mode
   (RUNFILES_MANIFEST_ONLY=1). Fixed by looking up a known file within the
   directory and deriving the directory via find_last_of("/\\").

2. Python extension (//python/tests): `pybind_extension` on Windows outputs
   `opencc_clib.pyd.dll`, but Python's import machinery only loads `.pyd`
   files. Fixed by adding a genrule in `src/pyd/` that copies the `.pyd.dll`
   to `opencc_clib.pyd`, and using `select()` in `py_opencc` to point at the
   renamed file on Windows (with `imports = ["pyd"]`) and the original target
   on other platforms.

Also update rules_python to 1.9.0 to match the version resolved by bzlmod
(suppresses the version mismatch warning).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@BYVoid
Copy link
Copy Markdown
Owner Author

BYVoid commented Mar 31, 2026

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@BYVoid BYVoid self-assigned this Mar 31, 2026
@BYVoid BYVoid merged commit 1c0fd0c into master Mar 31, 2026
32 of 34 checks passed
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