-
Notifications
You must be signed in to change notification settings - Fork 18.5k
Description
Proposal Details
Background
The Go compiler doesn't allow to have C, C++, Objectice-C, and Fortran files in a package unless cgo or SWIG are used. This means that if a Go package contains any of these files, then CGO_ENABLED can't be 0 and there should be at least one Go file with the import "C" statement.
This restriction was added in Go 1.4 in a0785a5. My understanding is that its intention was to prohibit people from using the 6c compiler and guide them to cgo instead.
Proposal
Now that 6c nobody even knows what is is the 6c compiler, I propose to lift the aforementioned restriction.
Motivation
The main motivation here is to allow C files not used in cgo to be copied into the Go vendor directory. Note that only directories with at least one Go file are eligible to be copied to the vendor directory. This conflicts with the requirement of using having to use cgo when Go and C files coexist in the same directory, as cgo might not be desired to avoid compiling unnecessary files or even having runtime dependencies (i.e. C header) available at build time.
There is at least one real project that needs this: microsoft/retina has some Go packages that only exist to hold C files not used with cgo, but that are compiled on-the-fly as bpf objects so that the builder image doesn't require all the BPF machinery installed and to facilitate cross-compilations. These object will then be loaded and attached to the Linux kernel.
Currently microsoft/retina builds with CGO_ENABLED=0 to workaround the Go compiler restrictions, but in the near future cgo will have to be enabled due to other requirements, so this workaround won't work anymore.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status