Files that import "C" are not valid Go source files and require preprocessing. Until now, the loader has simply hard-coded CGO_ENABLED=0 (in effect) which causes go/build to use build tags select pure Go implementations where they exist (e.g. in $GOROOT). Where they don't (e.g. arbitrary user code) this leads to masses of spurious type errors. (Reported by Guillaume Charmes, private correspondence.) This change causes the loader to invoke the cgo preprocessor on such files and to load the preprocessed files instead, using the original names. This means that the syntax offset position information is garbage, although thanks to //line directives, the line numbers at least should be good. See comment in cgo.go for details. This CL changes the loader's default behaviour and may make it slower. CGO_ENABLED=0 enables the old behaviour. Tested via stdlib_test, which now loads all standard packages using cgo, and also exercises CGO_ENABLED=0 for "net" and "os/user". LGTM=gri R=gri, rsc CC=golang-codereviews, guillaume.charmes https://golang.org/cl/86140043 |
||
---|---|---|
.. | ||
testdata | ||
cgo.go | ||
importer_test.go | ||
loader.go | ||
pkginfo.go | ||
source_test.go | ||
stdlib_test.go | ||
util.go |