From 77a252af9018ff272818e8a19ad4ddfce13effed Mon Sep 17 00:00:00 2001 From: peakschris <77508021+peakschris@users.noreply.github.com> Date: Sat, 6 Jun 2026 16:39:45 -0400 Subject: [PATCH] fix(bazel): symlink structure_test binary to .exe on Windows On Windows, the downloaded structure_test binary has no file extension. When a batch script tries to invoke it, Windows does not recognise it as an executable and shows an "Open With" application picker dialog instead of running the binary. The test then appears to pass (exit 0) without actually executing any structure tests. Fix by symlinking the binary to .exe in the Bazel action graph when building on Windows. The binary is a valid Windows PE regardless of its name, so the symlink is safe. The generated launcher scripts already use rlocation to resolve the path at runtime, so they will automatically pick up the .exe copy. --- bazel/container_structure_test.bzl | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/bazel/container_structure_test.bzl b/bazel/container_structure_test.bzl index cd5d0088..1cdb24cd 100644 --- a/bazel/container_structure_test.bzl +++ b/bazel/container_structure_test.bzl @@ -52,6 +52,17 @@ def _structure_test_impl(ctx): test_bin = ctx.toolchains["@container_structure_test//bazel:structure_test_toolchain_type"].st_info.binary jq_bin = ctx.toolchains["@aspect_bazel_lib//lib:jq_toolchain_type"].jqinfo.bin + # On Windows the downloaded binary has no file extension. Windows requires + # a .exe extension to recognise a file as directly executable — without it, + # invoking the binary from a batch script triggers an "Open With" dialog + # instead of running it. Symlink the binary to .exe so the generated + # launcher scripts can call it without this problem. + is_windows = ctx.target_platform_has_constraint(ctx.attr._windows_constraint[platform_common.ConstraintValueInfo]) + if is_windows and not test_bin.basename.endswith(".exe"): + test_bin_exe = ctx.actions.declare_file(test_bin.basename + ".exe") + ctx.actions.symlink(output = test_bin_exe, target_file = test_bin) + test_bin = test_bin_exe + default_info = ctx.attr.image[DefaultInfo] if DefaultInfo in ctx.attr.image else None output_group_info = ctx.attr.image[OutputGroupInfo] if OutputGroupInfo in ctx.attr.image else None image = None