Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Archive mode does not match when pure = off #4197

Closed
leungster opened this issue Dec 17, 2024 · 4 comments · Fixed by #4203
Closed

Archive mode does not match when pure = off #4197

leungster opened this issue Dec 17, 2024 · 4 comments · Fixed by #4203

Comments

@leungster
Copy link

leungster commented Dec 17, 2024

What version of rules_go are you using?

0.51.0

What version of gazelle are you using?

0.40.0

What version of Bazel are you using?

Bazel 8.0.0

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

Yes

What operating system and processor architecture are you using?

Darwin/ARM

Any other potentially useful information about your toolchain?

What did you do?

When crosscompiling a go_binary with goos, goarch, and pure = "off" I'm getting a mode mismatch error.
This error happens on both our CI runner (linux/amd) and locally on a M1 macbook.

    go_binary(
        name = "target",
        embed = embed,
        goarch = "arm64",
        goos = "darwin",
        pure = "off",
    )

What did you expect to see?

The target should build without error. This worked in 0.50.1.

What did you see instead?

Error in fail: Archive mode does not match @@//:target is darwin_arm64_debug expected darwin_arm64_debug

If I print a.source.mode and go.mode from this line, I get the same struct values.

// Debugged from CI hence different arch/os/linkmode

// a.source.mode
struct(amd64 = "", arm = "", cover_format = "lcov", debug = False, gc_goopts = [], gc_linkopts = [], goarch = "amd64", goos = "linux", linkmode = "pie", msan = False, pgoprofile = None, pure = False, race = False, stamp = False, static = False, strip = True, tags = [])

// go.mode
struct(amd64 = "", arm = "", cover_format = "lcov", debug = False, gc_goopts = [], gc_linkopts = [], goarch = "amd64", goos = "linux", linkmode = "pie", msan = False, pgoprofile = None, pure = False, race = False, stamp = False, static = False, strip = True, tags = [])
@ash2k
Copy link
Contributor

ash2k commented Dec 18, 2024

Have the same issue. Trying to update rules_go from 0.50.1 -> 0.51.0 and getting a build failure:

(12:06:10) ERROR: /builds/gitlab-org/cluster-integration/gitlab-agent/cmd/kas/BUILD.bazel:16:23: in go_binary rule //cmd/kas:kas_linux_amd64_debug: 
Traceback (most recent call last):
	File "/home/ci/.cache/bazel/_bazel_ci/9ca8268df963885560ea55034139bea5/external/rules_go~/go/private/rules/binary.bzl", line 145, column 46, in _go_binary_impl
		archive, executable, runfiles = go.binary(
	File "/home/ci/.cache/bazel/_bazel_ci/9ca8268df963885560ea55034139bea5/external/rules_go~/go/private/actions/binary.bzl", line 43, column 25, in emit_binary
		archive = go.archive(go, source)
	File "/home/ci/.cache/bazel/_bazel_ci/9ca8268df963885560ea55034139bea5/external/rules_go~/go/private/actions/archive.bzl", line 78, column 17, in emit_archive
		fail("Archive mode does not match {} is {} expected {}".format(a.data.label, mode_string(a.source.mode), mode_string(go.mode)))
Error in fail: Archive mode does not match @@//cmd:cmd is linux_amd64_race_stripped expected linux_amd64_race_stripped
(12:06:10) ERROR: /builds/gitlab-org/cluster-integration/gitlab-agent/cmd/kas/BUILD.bazel:16:23: Analysis of target '//cmd/kas:kas_linux_amd64_debug' failed

The target is defined like this (via a layer of macros):

    go_binary(
        name = binary_name,
        embed = binary_embed,
        goarch = "amd64",
        goos = "linux",
        race = "on",
        tags = ["manual"],
        visibility = ["//visibility:public"],
        x_defs = _x_defs,
    )

@fmeum
Copy link
Member

fmeum commented Dec 24, 2024

I think that this broke in 5933f87 since struct and named providers such as GoConfigInfo are considered distinct even if they have the same fields. I don't know why our tests didn't catch this.

We could try to always use GoConfigInfo. @dzbarsky

I will also send a Bazel PR to add the provider type to the debug representation.

@dzbarsky
Copy link
Contributor

Sorry for the breakage, sounds like we may be missing some coverage :) I can probably take a look in the next few days unless @fmeum you get to it first?

@dzbarsky
Copy link
Contributor

I couldn't figure out a way to repro (if yall have an easy repro to add to rules_go, let's do it) but hopefully #4203 should fix it

fmeum pushed a commit that referenced this issue Dec 30, 2024
**What type of PR is this?**
Bug fix 

**What does this PR do? Why is it needed?**
Providers and structs with the same fields don't compare equal

**Which issues(s) does this PR fix?**
Fixes #4197

I wasn't able to figure out a repro in rules_go, it seems like it may
rely on some transitions? Not sure we should block landing on this, it
seems like this should be the right fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants