bazel-contrib / rules_go

Go rules for Bazel
Apache License 2.0
1.38k stars 656 forks source link

builder: work around change in filepath.EvalSymlinks behavior #4050

Closed jayconrod closed 1 month ago

jayconrod commented 2 months ago

What type of PR is this?

Bug fix

What does this PR do? Why is it needed?

filepath.EvalSymlinks works differently on Windows in Go 1.23.0: mount points and reparse points are no longer treated as symbolic links by os.Stat. Bazel uses junctions (implemented as reparse points) for inputs, so this means EvalSymlinks can fail with some kinds of inputs where it didn't before.

replicateTree calls EvalSymlinks before constructing an input tree for GoStdlib. This seems to be necessary in some cases, though I'm not altogether sure why. EvalSymlinks fails due to the new behavior though.

This change sets GODEBUG=winsymlink=0 when invoking the builder binary to revert to the old behavior. This should not affect the behavior of user code compiled using the builder. This may not be a permanent solution, but it should work at least through Go 1.25.

Which issues(s) does this PR fix?

Fixes #4049

Other notes for review

No test, but verified locally. Simply running GoStdlib with Go 1.23.0 will cover this. rules_go currently builds with Go 1.21.8 (no longer a version supported by Google!).

jayconrod commented 1 month ago

I've rolled back the changes to replicate.go and switched to GODEBUG=winsymlink=0. That worked at least for no_srcs_test when using Go 1.23.0 in WORKSPACE (not part of this PR).

The error before sounded like we had opened a directory then called io.Copy on it. I started debugging but ran out of time today (lot of plates spinning right now). Probably better to go with a smaller workaround than to attempt a deeper change in replicate.go.

alexeagle commented 3 weeks ago

Thanks @jayconrod !! I was running into this also