rules_go icon indicating copy to clipboard operation
rules_go copied to clipboard

stdlib build on Windows fails with pathmapping enabled

Open malt3 opened this issue 6 months ago • 3 comments

Steps to reproduce:

  • Use Windows (this works fine on macOS or Linux)
  • Create a minimal workspace, as below (use txtar to extract).
  • bazel build //:hello
-- .bazelrc --
build --experimental_output_paths=strip
-- WORKSPACE --
-- MODULE.bazel --
module(
    name = "scratch",
    version = "0.0.0",
)

bazel_dep(
    name = "rules_go",
    version = "0.54.1",
)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
    name = "go_sdk",
    version = "1.24.1",
)

use_repo(go_sdk, "go_sdk")
-- BUILD --
load("@rules_go//go:def.bzl", "go_library")

go_library(
    name = "hello",
    srcs = ["hello.go"],
    importpath = "example.com/hello",
)
-- hello.go --
package hello

I'm not sure if this is supposed to work, considering that pathmapping itself is experimental. The full error message is printed below:

PS C:\Users\user\workspace\test> bazel build //:hello
Starting local Bazel server (8.2.1) and connecting to it...
INFO: Analyzed target //:hello (83 packages loaded, 5973 targets configured).
ERROR: C:/users/malte/_bazel_malte/47xxqnog/external/rules_go+/BUILD.bazel:42:7: GoStdlib external/rules_go+/stdlib_/pkg failed: (Exit -1): builder.exe failed: error executing GoStdlib command (from target @@rules_go+//:stdlib) bazel-out\cfg\bin\external\rules_go++go_sdk+go_sdk\builder_reset\builder.exe stdlib -sdk external/rules_go++go_sdk+go_sdk -goroot external/rules_go++go_sdk+go_sdk -installsuffix windows_amd64 -out ... (remaining 5 arguments skipped)
Action failed to execute: java.io.IOException: ERROR: src/main/native/windows/process.cc(202): CreateProcessW("C:\users\malte\_bazel_malte\47xxqnog\execroot\_main\bazel-out\cfg\bin\external\rules_go++go_sdk+go_sdk\builder_reset\builder.exe" stdlib -sdk external/rules_go++go_sdk+go_sdk -goroot external/rules_go++go_sdk+go_sdk -installsuffix windows_amd64 -out bazel-out/cfg/bin/external/rules_go+/stdlib_ -package std -gcflags ""): The system cannot find the file specified.
 (error: 2)
Target //:hello failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 69.606s, Critical Path: 28.78s
INFO: 6 processes: 5 internal, 1 local.
ERROR: Build did NOT complete successfully                                                                                                                                                                                                                                                                                                                                                                                      
PS C:\Users\user\workspace\test>

malt3 avatar May 30 '25 16:05 malt3

This isn't specific to Go. Path mapping requires a sandboxed execution mode, which on Windows only leaves remote execution (and sandboxed multiplex workers).

fmeum avatar May 30 '25 17:05 fmeum

That makes a lot of sense, and it is what I feared would be the reason. We can close the issue here if you want, since this is a restriction of Bazel on Windows (and not a bug in rules_go). I do wonder if Bazel could be made aware of the capabilities of a spawn strategy, so that the user sees a clear error message explaining that path mapping doesn't work in some scenarios.

malt3 avatar May 31 '25 09:05 malt3

I'll pick up work on https://github.com/bazelbuild/bazel/pull/25430 again.

fmeum avatar May 31 '25 12:05 fmeum

This has been fixed in Bazel (https://github.com/bazelbuild/bazel/commit/a42c98185717661c5425aa4161289381f4811c9c).

fmeum avatar Jul 17 '25 08:07 fmeum