bazelbuild / rules_go

Go rules for Bazel
Apache License 2.0
1.37k stars 651 forks source link

gc_goopts seems buggy or has unexpected behavior #3926

Open rickystewart opened 5 months ago

rickystewart commented 5 months ago

What version of rules_go are you using?

0.42

What version of gazelle are you using?

0.33

What version of Bazel are you using?

6.2.1

Does this issue reproduce with the latest releases of all the above?

I haven't checked, but presumably yes.

What operating system and processor architecture are you using?

macOS arm64

Any other potentially useful information about your toolchain?

None

What did you do?

Try to run bazel build ... "--@io_bazel_rules_go//go/config:gc_goopts=all=-N -l"

What did you expect to see?

Successful build with -N and -l set for -gcflags

What did you see instead?

A bunch of errors that look like this:

# log/slog/internal
open all=-N -l: no such file or directory
# reflect/internal/example2
open all=-N -l: no such file or directory
# runtime/race
open all=-N -l: no such file or directory
# maps
open all=-N -l: no such file or directory

I also tried with a few variations on the quoting (--@io_bazel_rules_go//go/config:gc_goopts="all=-N -l", --@io_bazel_rules_go//go/config:gc_goopts='"all=-N -l"'), and none of them seem to work.

It seems like these arguments aren't getting propagated down to -gcflags correctly and are instead getting interpreted by the compiler as filenames. I can't speak to why that happens.

If you're passing only a single argument to gc_goopts (like --@io_bazel_rules_go//go/config:gc_goopts=-S), it seems to work fine.

(I understand that --@io_bazel_rules_go//go/config:debug is an appropriate workaround for -N -l specifically, however, it seems like the basic approach using gc_goopts should still work either way.)