Skip to content

Introduce hermetic MinGW, MSYS and bash executable for Windows#51153

Draft
JSGette wants to merge 13 commits into
mainfrom
jsgette/ABLD-487/hermetic_mingw
Draft

Introduce hermetic MinGW, MSYS and bash executable for Windows#51153
JSGette wants to merge 13 commits into
mainfrom
jsgette/ABLD-487/hermetic_mingw

Conversation

@JSGette
Copy link
Copy Markdown
Contributor

@JSGette JSGette commented May 21, 2026

What does this PR do?

Right now we consume MinGW that is installed inside of the Windows Build Image with hard coded paths to MSYS2 and MinGW that are different to the default install location. This PR consumes MSYS2 and MinGW as packages to ensure that the version of the tooling is exactly the same across all environments (including developers) and makes a first major step to make Bazel builds work without the need to use Windows containers.

However, Visual Studio still has to be installed manually and ideally exactly the same version as pinned in visual_studio repository rule in MODULE.bazel.

List of changes worth mentioning:

  • New winlibs_mingw_repository repository rule to download MinGW
  • New msys2_base_repository repository rule to download MSYS2 and a bunch of tools (e.g. autoconf, make, etc.)

Motivation

Describe how you validated your changes

Additional Notes

@JSGette JSGette self-assigned this May 21, 2026
@JSGette JSGette added changelog/no-changelog No changelog entry needed qa/no-code-change No code change in Agent code requiring validation labels May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

@codex review

@github-actions github-actions Bot added the long review PR is complex, plan time to review it label May 21, 2026
@datadog-official
Copy link
Copy Markdown
Contributor

datadog-official Bot commented May 21, 2026

Pipelines

Fix all issues with BitsAI

⚠️ Warnings

🚦 4 Pipeline jobs failed

DataDog/datadog-agent | bazel:run-buildifier-test   View in Datadog   GitLab

🔧 Fix in code (Fix with Cursor). Buildifier generated a syntax error in BUILD.bazel: expected '}', found 'linkopts'.

DataDog/datadog-agent | bazel:run-gazelle   View in Datadog   GitLab

🔧 Fix in code (Fix with Cursor). Bazel rule definition error in bazel/toolchains/msys2/BUILD.bazel: unclosed parentheses and missing elements in cc_binary definition causing the build to fail.

DataDog/datadog-agent | bazel:test:windows-amd64   View in Datadog   GitLab

🛟 This job is unlikely to succeed on retry. Please review your pipeline configuration. Hermetic bash not found. Run 'bazelisk fetch @msys2_base//...' to materialize it.

View all 4 failed jobs.

ℹ️ Info

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 50.33% (-0.02%)

Useful? React with 👍 / 👎

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: aa12205 | Docs | Datadog PR Page | Give us feedback!

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: 639e56f3bb

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread bazel/toolchains/msys2/bash_shim.bat Outdated
Comment on lines +23 to +24
set "MSYS2_ROOT=%cd%\..\..\external\+msys2_base_repository+msys2_base"
set "MINGW_ROOT=%cd%\..\..\external\+winlibs_mingw_repository+winlibs_mingw64"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid hardcoding Bzlmod canonical repo paths

Compute paths from stable repo mappings instead of embedding external\+...+... names. The shim currently hardcodes canonical repository directory names, but Bzlmod canonical-name format is explicitly non-API and can change across Bazel versions or extension identity changes; when that happens, the shim won't find bash.exe/toolchain roots and all Windows run_shell/genrule actions fail before execution.

Useful? React with 👍 / 👎.

Comment thread bazel/toolchains/msys2/bash_shim.bat Outdated
Comment on lines +31 to +34
if not exist "%MINGW_ROOT%\bin\gcc.exe" (
echo bash_shim: hermetic gcc not found at %MINGW_ROOT%\bin\gcc.exe 1>&2
echo bash_shim: run 'bazelisk fetch @winlibs_mingw64//...' to materialise it 1>&2
exit /b 1
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Do not require MinGW for every shell action

The shim exits if @winlibs_mingw64 is missing even when the action only needs Bash. Since toolchain dependencies are loaded lazily, a Windows build that runs shell actions without resolving the C++ toolchain can hit this check and fail unnecessarily; this turns unrelated shell steps into hard failures and forces an unnecessary fetch/availability requirement for MinGW.

Useful? React with 👍 / 👎.

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 21, 2026

Files inventory check summary

File checks results against ancestor 7e031281:

Results for datadog-agent_7.81.0~devel.git.151.aa12205.pipeline.114506598-1_amd64.deb:

No change detected

@cit-pr-commenter-54b7da
Copy link
Copy Markdown

cit-pr-commenter-54b7da Bot commented May 21, 2026

Regression Detector

Regression Detector Results

Metrics dashboard
Target profiles
Run ID: eecbe359-32c1-4534-8e60-0c4fd05c71f8

Baseline: 7e03128
Comparison: aa12205
Diff

Optimization Goals: ✅ No significant changes detected

Experiments ignored for regressions

Regressions in experiments with settings containing erratic: true are ignored.

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization +1.40 [-1.56, +4.37] 1 Logs

Fine details of change detection per experiment

perf experiment goal Δ mean % Δ mean % CI trials links
docker_containers_cpu % cpu utilization +1.40 [-1.56, +4.37] 1 Logs
otlp_ingest_metrics memory utilization +0.60 [+0.45, +0.76] 1 Logs
quality_gate_logs % cpu utilization +0.52 [-0.51, +1.55] 1 Logs bounds checks dashboard
ddot_metrics_sum_cumulative memory utilization +0.49 [+0.33, +0.65] 1 Logs
quality_gate_idle_all_features memory utilization +0.43 [+0.37, +0.49] 1 Logs bounds checks dashboard
ddot_metrics_sum_delta memory utilization +0.21 [+0.02, +0.41] 1 Logs
quality_gate_idle memory utilization +0.17 [+0.12, +0.22] 1 Logs bounds checks dashboard
file_to_blackhole_500ms_latency egress throughput +0.04 [-0.36, +0.44] 1 Logs
file_tree memory utilization +0.04 [-0.00, +0.08] 1 Logs
quality_gate_metrics_logs memory utilization +0.03 [-0.21, +0.27] 1 Logs bounds checks dashboard
file_to_blackhole_0ms_latency egress throughput +0.03 [-0.51, +0.56] 1 Logs
ddot_metrics_sum_cumulativetodelta_exporter memory utilization +0.03 [-0.21, +0.26] 1 Logs
ddot_metrics memory utilization +0.02 [-0.18, +0.21] 1 Logs
ddot_logs memory utilization +0.01 [-0.06, +0.07] 1 Logs
otlp_ingest_logs memory utilization +0.00 [-0.09, +0.09] 1 Logs
uds_dogstatsd_to_api ingress throughput +0.00 [-0.20, +0.20] 1 Logs
tcp_dd_logs_filter_exclude ingress throughput -0.00 [-0.10, +0.10] 1 Logs
file_to_blackhole_100ms_latency egress throughput -0.01 [-0.15, +0.14] 1 Logs
uds_dogstatsd_to_api_v3 ingress throughput -0.04 [-0.25, +0.17] 1 Logs
file_to_blackhole_1000ms_latency egress throughput -0.14 [-0.61, +0.32] 1 Logs
tcp_syslog_to_blackhole ingress throughput -0.20 [-0.38, -0.01] 1 Logs
uds_dogstatsd_20mb_12k_contexts_20_senders memory utilization -0.24 [-0.29, -0.20] 1 Logs
docker_containers_memory memory utilization -0.34 [-0.44, -0.24] 1 Logs

Bounds Checks: ✅ Passed

perf experiment bounds_check_name replicates_passed observed_value links
docker_containers_cpu simple_check_run 10/10 716 ≥ 26
docker_containers_memory memory_usage 10/10 245.44MiB ≤ 370MiB
docker_containers_memory simple_check_run 10/10 684 ≥ 26
file_to_blackhole_0ms_latency memory_usage 10/10 0.16GiB ≤ 1.20GiB
file_to_blackhole_0ms_latency missed_bytes 10/10 0B = 0B
file_to_blackhole_1000ms_latency memory_usage 10/10 0.20GiB ≤ 1.20GiB
file_to_blackhole_1000ms_latency missed_bytes 10/10 0B = 0B
file_to_blackhole_100ms_latency memory_usage 10/10 0.17GiB ≤ 1.20GiB
file_to_blackhole_100ms_latency missed_bytes 10/10 0B = 0B
file_to_blackhole_500ms_latency memory_usage 10/10 0.18GiB ≤ 1.20GiB
file_to_blackhole_500ms_latency missed_bytes 10/10 0B = 0B
quality_gate_idle intake_connections 10/10 3 ≤ 4 bounds checks dashboard
quality_gate_idle memory_usage 10/10 144.21MiB ≤ 147MiB bounds checks dashboard
quality_gate_idle total_bytes_received 10/10 738.84KiB ≤ 819.20KiB bounds checks dashboard
quality_gate_idle_all_features intake_connections 10/10 2 ≤ 4 bounds checks dashboard
quality_gate_idle_all_features memory_usage 10/10 428.23MiB ≤ 495MiB bounds checks dashboard
quality_gate_idle_all_features total_bytes_received 10/10 1.12MiB ≤ 1.25MiB bounds checks dashboard
quality_gate_logs intake_connections 10/10 4 ≤ 6 bounds checks dashboard
quality_gate_logs memory_usage 10/10 179.59MiB ≤ 195MiB bounds checks dashboard
quality_gate_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
quality_gate_logs total_bytes_received 10/10 264.38MiB ≤ 292MiB bounds checks dashboard
quality_gate_metrics_logs cpu_usage 10/10 334.30 ≤ 2000 bounds checks dashboard
quality_gate_metrics_logs intake_connections 10/10 4 ≤ 6 bounds checks dashboard
quality_gate_metrics_logs memory_usage 10/10 385.61MiB ≤ 430MiB bounds checks dashboard
quality_gate_metrics_logs missed_bytes 10/10 0B = 0B bounds checks dashboard
quality_gate_metrics_logs total_bytes_received 10/10 0.94GiB ≤ 1.04GiB bounds checks dashboard

Explanation

Confidence level: 90.00%
Effect size tolerance: |Δ mean %| ≥ 5.00%

Performance changes are noted in the perf column of each table:

  • ✅ = significantly better comparison variant performance
  • ❌ = significantly worse comparison variant performance
  • ➖ = no significant change in performance

A regression test is an A/B test of target performance in a repeatable rig, where "performance" is measured as "comparison variant minus baseline variant" for an optimization goal (e.g., ingress throughput). Due to intrinsic variability in measuring that goal, we can only estimate its mean value for each experiment; we report uncertainty in that value as a 90.00% confidence interval denoted "Δ mean % CI".

For each experiment, we decide whether a change in performance is a "regression" -- a change worth investigating further -- if all of the following criteria are true:

  1. Its estimated |Δ mean %| ≥ 5.00%, indicating the change is big enough to merit a closer look.

  2. Its 90.00% confidence interval "Δ mean % CI" does not contain zero, indicating that if our statistical model is accurate, there is at least a 90.00% chance there is a difference in performance between baseline and comparison variants.

  3. Its configuration does not mark it "erratic".

CI Pass/Fail Decision

Passed. All Quality Gates passed.

  • quality_gate_idle, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_idle_all_features, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check missed_bytes: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check cpu_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check intake_connections: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check memory_usage: 10/10 replicas passed. Gate passed.
  • quality_gate_metrics_logs, bounds check total_bytes_received: 10/10 replicas passed. Gate passed.

@github-actions
Copy link
Copy Markdown
Contributor

@codex review

@dd-octo-sts dd-octo-sts Bot added internal Identify a non-fork PR team/agent-build labels May 21, 2026
@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@github-actions
Copy link
Copy Markdown
Contributor

@codex review

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: f48112f1d1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +30 to +33
filegroup(
name = tool_name,
srcs = ["bin/" + tool_name + ".exe"],
)
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 Expose windres/windmc as executable targets

win_resource/win_messagetable now require _windres and _windmc with executable = True, but the defaults point to filegroup targets created here. filegroup exports files but does not provide an executable target, so Bazel analysis will fail when these rules are used (for example under cmd/*/windows_resources) with a “target is not executable” error. Make these defaults point at executable file labels (or wrapper executable rules) instead of filegroups.

Useful? React with 👍 / 👎.

Comment thread bazel/toolchains/msys2/bash_shim.bat Outdated
Comment on lines +23 to +24
set "MSYS2_ROOT=%cd%\..\..\external\+msys2_base_repository+msys2_base"
set "MINGW_ROOT=%cd%\..\..\external\+winlibs_mingw_repository+winlibs_mingw64"
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Stop hard-coding canonical external repo paths

This shim resolves tool locations via hard-coded canonical repo directory names under external/. In bzlmod those canonical names are explicitly not stable, so a Bazel/bzlmod change (or repo remapping/override) can make these paths wrong and break every Windows run_shell/genrule invocation with “hermetic bash/gcc not found”. The shim should derive repo locations from stable label-based mappings instead of embedding canonical directory strings.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown
Contributor

@codex review

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: 5e2f5af56d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread MODULE.bazel
Comment on lines 105 to 108
patches = [
# Stops rustc_compile_action from leaking default_shell_env into
# CrateInfo.rustc_env, which otherwise clobbers cc_toolchain link_env
# for rust_test(crate = ...). Upstream issue pending.
"//bazel/patches:rules_rust-crateinfo-env-leak.patch",
# Derives `-Cdlltool=<linker-dir>/dlltool.exe` automatically
"//bazel/patches:rules_rust-derive-dlltool-from-linker.patch",
],
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 Restore the CrateInfo rustc_env leak fix patch

Removing //bazel/patches:rules_rust-crateinfo-env-leak.patch here reintroduces the Windows GNU link-env regression that patch was preventing: upstream rules_rust still stores CrateInfo.rustc_env from the merged action env (including default shell env), so downstream rust_test(crate=...) can inherit host PATH/LIB/INCLUDE and override the MinGW toolchain link env instead of using hermetic tool paths. This breaks Windows Rust test/link actions on machines where host env differs from CI, so the patch needs to remain until upstream fixes that provider behavior.

Useful? React with 👍 / 👎.

@github-actions
Copy link
Copy Markdown
Contributor

@codex review

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: c44e5198fa

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread MODULE.bazel
Comment on lines 105 to 108
patches = [
# Stops rustc_compile_action from leaking default_shell_env into
# CrateInfo.rustc_env, which otherwise clobbers cc_toolchain link_env
# for rust_test(crate = ...). Upstream issue pending.
"//bazel/patches:rules_rust-crateinfo-env-leak.patch",
# Derives `-Cdlltool=<linker-dir>/dlltool.exe` automatically
"//bazel/patches:rules_rust-derive-dlltool-from-linker.patch",
],
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 Restore rules_rust rustc_env leak patch

Dropping //bazel/patches:rules_rust-crateinfo-env-leak.patch reintroduces the environment propagation bug that patch was fixing: CrateInfo.rustc_env includes default_shell_env instead of only Rust-specific vars, so downstream rust_test(crate = ...) can inherit host PATH/LIB/INCLUDE and override the MinGW cc_toolchain link environment. In Windows GNU builds this makes linking depend on whatever toolchain is installed on the host and can cause non-hermetic or wrong-linker failures that were previously prevented by the removed patch.

Useful? React with 👍 / 👎.

@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 21, 2026

Static quality checks

✅ Please find below the results from static quality gates
Comparison made with ancestor 7e03128
📊 Static Quality Gates Dashboard
🔗 SQG Job

Successful checks

Info

Quality gate Change Size (prev → curr → max)
agent_msi +58.77 KiB (0.01% increase, -0.39% of buffer) 609.161 → 609.218 → 624.040
32 successful checks with minimal change (< 2 KiB)
Quality gate Current Size
agent_deb_amd64 745.208 MiB
agent_deb_amd64_fips 702.967 MiB
agent_heroku_amd64 310.165 MiB
agent_rpm_amd64 745.192 MiB
agent_rpm_amd64_fips 702.950 MiB
agent_rpm_arm64 722.751 MiB
agent_rpm_arm64_fips 683.679 MiB
agent_suse_amd64 745.192 MiB
agent_suse_amd64_fips 702.950 MiB
agent_suse_arm64 722.751 MiB
agent_suse_arm64_fips 683.679 MiB
docker_agent_amd64 805.349 MiB
docker_agent_arm64 807.730 MiB
docker_agent_jmx_amd64 996.269 MiB
docker_agent_jmx_arm64 987.428 MiB
docker_cluster_agent_amd64 206.995 MiB
docker_cluster_agent_arm64 220.952 MiB
docker_cws_instrumentation_amd64 7.154 MiB
docker_cws_instrumentation_arm64 6.689 MiB
docker_dogstatsd_amd64 39.487 MiB
docker_dogstatsd_arm64 37.690 MiB
docker_host_profiler_amd64 302.187 MiB
docker_host_profiler_arm64 313.675 MiB
dogstatsd_deb_amd64 30.143 MiB
dogstatsd_deb_arm64 28.268 MiB
dogstatsd_rpm_amd64 30.143 MiB
dogstatsd_suse_amd64 30.143 MiB
iot_agent_deb_amd64 44.578 MiB
iot_agent_deb_arm64 41.535 MiB
iot_agent_deb_armhf 42.243 MiB
iot_agent_rpm_amd64 44.578 MiB
iot_agent_suse_amd64 44.578 MiB

@github-actions
Copy link
Copy Markdown
Contributor

@codex review

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: 0a4869485d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread .bazelrc
# multi-line `-c "..."` arguments at the first newline; the .exe forwards
# GetCommandLineW() verbatim to the bash.exe extracted by @msys2_base.
# Needed until bazelbuild/bazel#21089 wires sh_toolchain into run_shell.
common:windows --shell_executable=bazel/toolchains/msys2/bash_shim.exe
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 Commit the Windows shell executable referenced by Bazel

This change points --shell_executable to bazel/toolchains/msys2/bash_shim.exe, but that file is not added anywhere in the commit (only bash_shim.c is). On Windows, any genrule/ctx.actions.run_shell/rules_foreign_cc action will try to launch this path and fail because the executable is missing, which blocks builds as soon as a shell action is needed.

Useful? React with 👍 / 👎.

@JSGette JSGette changed the title Jsgette/abld 487/hermetic mingw Introduce hermetic MinGW, MSYS and bash executable for Windows May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

@codex review

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: aa12205471

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +15 to +16
#define MSYS2_REL L"..\\..\\external\\+msys2_base_repository+msys2_base"
#define MINGW_REL L"..\\..\\external\\+winlibs_mingw_repository+winlibs_mingw64"
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 Stop hardcoding Bazel canonical repo names in shim paths

The shim bakes canonical external repo directory names (+msys2_base_repository+msys2_base, +winlibs_mingw_repository+winlibs_mingw64) into filesystem paths. Bazel’s canonical repo-name format is explicitly not a stable API, and bazel/AGENTS.md also calls out that runfile/canonical-name paths must not be hardcoded. When canonical naming changes (or repo mapping/layout differs), the shim will no longer locate bash.exe/gcc.exe, causing Windows run_shell/genrule actions to fail before command execution.

Useful? React with 👍 / 👎.

Comment thread .bazelrc
common:windows --repo_env=USERPROFILE # used by MSYS2 bash to emulate HOME, needed by git to fetch repositories
common:windows --repo_env=VSTUDIO_ROOT # visual_studio(path_variable) in MODULE.bazel
# Hermetic bash discovery for ctx.actions.run_shell / genrule / rules_foreign_cc.
common:windows --shell_executable=bazel/toolchains/msys2/bash_shim.exe
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 Use an absolute value for --shell_executable

--shell_executable is documented by Bazel as an absolute path, but this change sets it to a relative path. That makes behavior dependent on the caller’s working directory and can break Windows builds when Bazel is launched from a subdirectory or wrapper that doesn’t run at the repo root, because the shim path won’t resolve and shell-backed actions won’t start.

Useful? React with 👍 / 👎.

Comment on lines +44 to +48
wchar_t cwd[MAX_PATH];
if (!GetCurrentDirectoryW(MAX_PATH, cwd)) {
fwprintf(stderr, L"bash_shim: GetCurrentDirectory failed: %lu\n", GetLastError());
return 1;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Handle long Windows paths in bash_shim

The shim allocates cwd with MAX_PATH and calls GetCurrentDirectoryW(MAX_PATH, cwd) without handling the documented “buffer too small” return value. On long workspaces/output-base paths, this yields truncated/invalid paths that then propagate into bash_path/gcc_path, producing false “hermetic tool not found” errors and failing shell actions.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@aiuto aiuto left a comment

Choose a reason for hiding this comment

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

Overall this seems good.

  • Some CRLF differences should get fixed.
  • you might split it in two for easier review and smaller rollback
  • codex left some comments. I did not investigate if they are valid or not.

Comment thread .gitattributes
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

CRLF differences?

Comment thread .bazelrc
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

crlf dif

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/no-changelog No changelog entry needed internal Identify a non-fork PR long review PR is complex, plan time to review it qa/no-code-change No code change in Agent code requiring validation team/agent-build team/agent-devx team/agent-runtimes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants