Skip to content

Build and test OpenCC with Bazel on Windows#1082

Merged
BYVoid merged 7 commits intomasterfrom
copilot/build-test-opencc-bazel
Mar 31, 2026
Merged

Build and test OpenCC with Bazel on Windows#1082
BYVoid merged 7 commits intomasterfrom
copilot/build-test-opencc-bazel

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 30, 2026

bazel build //:opencc and the test suite were broken on Windows due to POSIX-only APIs, Unix-specific runfiles path discovery, and missing C++17 flags for MSVC. Additionally, a cmd.exe quote-stripping bug caused CommandLineConvertTest to fail in CMake builds on Windows.

CI

  • Added windows-latest to the Bazel CI matrix (.github/workflows/bazel.yml)

Build config

  • New .bazelrc: sets build:windows --cxxopt=/std:c++17 — MSVC defaults to C++14 under Bazel

test/CommandLineConvertTest.cpp

  • Replaced bare getcwd/chdir with portable_getcwd()/portable_chdir() wrappers (_getcwd/_chdir from <direct.h> on MSVC)
  • On Windows in Bazel mode, try command_line.exe first in OpenccCommand() (Bazel runfiles manifest uses .exe for cc_binary)
  • Wrap all file paths with QuotePath() to handle spaces
  • Wrap the entire command in outer quotes on _WIN32 in TestCommand():
    #ifdef _WIN32
    return "\"" + cmd + "\"";
    Why: system() calls cmd.exe /C <cmd>. When <cmd> starts with " (quoted exe path) but doesn't end with ", cmd.exe strips the leading " and removes the last " anywhere in the string — corrupting the output file path and producing "The filename, directory name, or volume label syntax is incorrect." Wrapping in outer quotes makes cmd.exe strip only that outer pair, leaving the inner quoted paths intact.

data/dictionary/DictionaryTest.cpp + BUILD.bazel

  • Replaced manual .runfiles/_main suffix-search on argv[0] with Runfiles::CreateForTest() + Rlocation() — the symlink-based layout assumed by the old approach doesn't exist on Windows; Bazel uses a manifest file instead
  • Added @bazel_tools//tools/cpp/runfiles dep to dictionary_test

Copilot AI and others added 2 commits March 30, 2026 13:43
Copilot AI changed the title [WIP] Build and test Opencc with Bazel on Windows Add Windows support for Bazel build and test Mar 30, 2026
Copilot AI requested a review from BYVoid March 30, 2026 13:51
Copilot AI changed the title Add Windows support for Bazel build and test Build and test OpenCC with Bazel on Windows Mar 30, 2026
@BYVoid BYVoid marked this pull request as ready for review March 30, 2026 14:25
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 07dfe2d91c

ℹ️ 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".

Comment thread .bazelrc
Comment on lines +2 to +3
build:windows --cxxopt=/std:c++17
build:windows --host_cxxopt=/std:c++17
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Enable platform-specific Bazel config

The new build:windows entries are never applied unless Bazel is invoked with --config=windows (or --enable_platform_specific_config), and this workflow still runs plain bazel build / bazel test on windows-latest. Since Bazel’s --enable_platform_specific_config defaults to false, the /std:c++17 flags in this file won’t reach MSVC, so the Windows CI job can still compile with the wrong language standard.

Useful? React with 👍 / 👎.

BYVoid added 2 commits March 30, 2026 23:29
All other paths passed to the shell command are already quoted via
QuotePath(), but the -c config path was left unquoted. This could
break on CMake builds where CMAKE_SOURCE_DIR contains spaces.

https://claude.ai/code/session_01FUbRQbj3PxYv445SuwXDm2
…lied

The build:windows config block requires --enable_platform_specific_config
(or explicit --config=windows) to take effect. Without it, the /std:c++17
flags never reach MSVC on Windows CI. Adding the enable flag makes Bazel
automatically apply the matching platform config.

https://claude.ai/code/session_01FUbRQbj3PxYv445SuwXDm2
…dent fopen

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@BYVoid BYVoid merged commit dfc241c into master Mar 31, 2026
33 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.

2 participants