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

cmd/go2go: build tags not supported correctly #39998

Closed
rogpeppe opened this issue Jul 2, 2020 · 7 comments
Closed

cmd/go2go: build tags not supported correctly #39998

rogpeppe opened this issue Jul 2, 2020 · 7 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rogpeppe
Copy link
Contributor

rogpeppe commented Jul 2, 2020

commit d014fca

The go2go tool doesn't seem to recognise go build tags, which means that it's not possible to use external packages that use them (I was bitten when trying to import github.com/frankban/quicktest, for the record).

Here's a testscript reproducer:

exec go tool go2go build

-- go.mod --
module example.com/test

go 1.15
-- x_111.go2 --
// +build go1.11

package foo

var x = 34
-- x_112.go2 --
// +build go1.12

package foo

var x = 34
@tdakkota
Copy link

tdakkota commented Jul 2, 2020

It happens because translator does not copy magic comments from .go2 source.

//go:noinline
func Foo() {
}

becomes

//line <original code line>
func Foo() {
}

@josharian
Copy link
Contributor

FWIW, how go-fuzz handles this is by looking for initial comments and //go directives, saving them, manipulating the code (inserting coverage), and then re-inserting the comments. See functions initialComments and trimComments and related code in go-fuzz-build.

@cagedmantis cagedmantis added this to the Unreleased milestone Jul 6, 2020
@cagedmantis cagedmantis added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jul 6, 2020
@cagedmantis
Copy link
Contributor

/cc @ianlancetaylor @griesemer

@griesemer
Copy link
Contributor

I don't know off-hand how much effort is needed to make this work, but we may decide to not do anything about it. Keep in mind this is a prototype to explore the generics mechanisms; anything and everything may change as we go forward.

@ianlancetaylor
Copy link
Contributor

It's not just a matter of magic comments. The type checker gets a list of files, and it expects that build tags have already been applied at that point to remove files that it shouldn't see.

I don't mind if somebody fixes this, but I don't plan to work on it myself. The go2go tool is meant to be an experimental translation tool, it's not meant to handle all details of how Go packages are built.

@ianlancetaylor ianlancetaylor removed their assignment Jul 7, 2020
@maguro
Copy link

maguro commented Mar 21, 2021

I have a submitted a simple PR that should be helpful to most people tinkering with generics via go2go, #45147.

@maguro
Copy link

maguro commented Mar 23, 2021

The PR has been merged.

@golang golang locked and limited conversation to collaborators Mar 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

8 participants