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

go-fuzz-build: add module support #219

Closed
iwasaki-kenta opened this issue Mar 11, 2019 · 7 comments
Closed

go-fuzz-build: add module support #219

iwasaki-kenta opened this issue Mar 11, 2019 · 7 comments

Comments

@iwasaki-kenta
Copy link

Is there any support to allow for go-fuzz-build to checkout and build a custom branch of a repository?

Additionally, is there any support to specify a directory to go-fuzz-build comprising of a Go module?

The reason I'm trying to checkout and build a custom branch is that go-fuzz-build seems to only work when executed within GOROOT, though my project makes use of Go modules extensively right now.

@josharian
Copy link
Collaborator

Is there any support to allow for go-fuzz-build to checkout and build a custom branch of a repository?

No. This is the same as regular go build. I’m afraid you’ll have to write a script to do that. Or you might want to look at fuzzbuzz.io. (No affiliation.)

Additionally, is there any support to specify a directory to go-fuzz-build comprising of a Go module?

go-fuzz does not yet support modules; my apologies.

go-fuzz-build seems to only work when executed within GOROOT

I’m not sure offhand why that would work, but if you’re using modules, that does explain why go-fuzz-build isn’t working for you in normal circumstances.

@iwasaki-kenta
Copy link
Author

Is there any support to allow for go-fuzz-build to checkout and build a custom branch of a repository?

No. This is the same as regular go build. I’m afraid you’ll have to write a script to do that. Or you might want to look at fuzzbuzz.io. (No affiliation.)

Additionally, is there any support to specify a directory to go-fuzz-build comprising of a Go module?

go-fuzz does not yet support modules; my apologies.

go-fuzz-build seems to only work when executed within GOROOT

I’m not sure offhand why that would work, but if you’re using modules, that does explain why go-fuzz-build isn’t working for you in normal circumstances.

Pardon for the late reply; would the project be open to contributions right now for supporting projects that use Go modules?

@dvyukov
Copy link
Owner

dvyukov commented Mar 22, 2019

How complex is that approximately?
I can't think of any objections and I guess we should support modules. The only problem that I can think of is that we will re-implement another large, non-trivial, fragile part of go tool. Can we reuse bulk of the logic from go tool? @josharian do you know if that packages package support modules?

@iwasaki-kenta
Copy link
Author

iwasaki-kenta commented Mar 22, 2019

How complex is that approximately?
I can't think of any objections and I guess we should support modules. The only problem that I can think of is that we will re-implement another large, non-trivial, fragile part of go tool. Can we reuse bulk of the logic from go tool? @josharian do you know if that packages package support modules?

From a brief skim of how go-fuzz-build works currently (type-checking a provided package directory, and afterwards packaging up stdlibs + the source code), it seems that the /x/tools/go/packages pkg is outdated and presently doesn't support modules.

As an alternative, it is possible to use the type-checking and package import resolver straight from the current Go standard library which also resolves import paths to packages that use Go modules.

The complexity would be moderate, as the APIs are mostly the same.

For resolving build src paths: https://golang.org/pkg/go/build/
For type-checking pkgs: https://golang.org/pkg/go/types/

For functions of interest:

Resolving build paths: https://golang.org/pkg/go/build/#Context.Import
Type-checking: https://golang.org/pkg/go/types/#Config.Check

Though, if there are reasons as to why /x/tools/go/packages is used instead, would love to know.

@josharian
Copy link
Collaborator

Package go/build is deprecated. x/tools/go/packages is very much the preferred path going forward, and it definitely supports modules. In fact, module support was a major factor in the decision to write go/packages; it was not reasonable to retrofit it into go/build.

I suspect (but have not tried) that all that is required to add module support is to (a) copy go.mod if present while copying packages and (b) synthesize a go.mod alongside our synthesized package main.

I intend to work on module support at some point, but it isn't high on my list at the moment. I suppose it should be higher. I'd be happy to review a PR.

@dvyukov
Copy link
Owner

dvyukov commented Mar 25, 2019

From you said it seems that the modules support will be moderate amount of code and no significant duplication with std lib. Modules support is welcome. @iwasaki-kenta go ahead.

@josharian josharian changed the title go-fuzz-build: allow for checking out custom branch go-fuzz-build: add module support Mar 25, 2019
@josharian
Copy link
Collaborator

I’m going to close this as a duplicate of #195.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants