You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While most Go programmers use the go tool, there are alternative build systems such as Bazel. In order to build existing Go code, those build systems have to analyze build constraints in the same way as the go tool does. For most purposes that can be done by calling go/build.*Context.MatchFile. However, there is a case that is not handled by that API: #cgo directives in file that use cgo. A #cgo directive appears in the special comment ad looks like #cgo, an optional build constraint, a flag name, a colon, a list of flags. A build tool like Bazel needs a mechanism to take a file that uses cgo and return any #cgo flags appropriate for the current environment. Currently those tools must do this by recreating the build constraint evaluation process themselves. The go/build package already contains the code that does this for the go tool, but it is not exposed in a usable form; it is only exposed as part of creating a go/build.Package, but that assumes that directory layout used by the go tool but not by Bazel.
I propose that we add a new exported method to go/build similar to the existing saveCgo method.
// CgoFlags extracts #cgo flags from an import "C" comment that has already been parsed by the caller.// Each element of the resulting slice will contain a flag name followed by the arguments for that flag.// For example, given a comment containing//// #cgo CFLAGS: -DDEBUG// #cgo linux CFLAGS: -DLINUX//// then on a Linux system the result will be [][]string{[]string{"CFLAGS", "-DDEBUG", "-DLINUX"}}.//// This method does not validate the #cgo flag names in any way, it simply returns them.// It will return an error for a malformed #cgo line.func (ctx*Context) CgoFlags(filepathstring, cg*ast.CommentGroup) ([][]string, error)
The text was updated successfully, but these errors were encountered:
This proposal has been added to the active column of the proposals project
and will now be reviewed at the weekly proposal review meetings.
— rsc for the proposal review group
While most Go programmers use the go tool, there are alternative build systems such as Bazel. In order to build existing Go code, those build systems have to analyze build constraints in the same way as the go tool does. For most purposes that can be done by calling go/build.*Context.MatchFile. However, there is a case that is not handled by that API:
#cgo
directives in file that use cgo. A#cgo
directive appears in the special comment ad looks like#cgo
, an optional build constraint, a flag name, a colon, a list of flags. A build tool like Bazel needs a mechanism to take a file that uses cgo and return any#cgo
flags appropriate for the current environment. Currently those tools must do this by recreating the build constraint evaluation process themselves. The go/build package already contains the code that does this for the go tool, but it is not exposed in a usable form; it is only exposed as part of creating ago/build.Package
, but that assumes that directory layout used by the go tool but not by Bazel.I propose that we add a new exported method to go/build similar to the existing
saveCgo
method.The text was updated successfully, but these errors were encountered: