-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Proposal Details
The main goal of this proposal is to make it easy to include C header files from other Go modules.
Similarly to ${SRCDIR}
, something like ${REPODIR}
could help using C/cgo headers and libraries from other Go modules. One would then be able to include a header file using:
// #cgo CFLAGS: -I${REPODIR}
// #include <github.com/someuser/modname/cgo/a_fancy_header.h> // Accessed via ${REPODIR}
import "C"
where ${REPODIR}
would contain all the dependencies of the project at the correct version specified by go.mod
.
Alternatively, the documentation available on Go project layout and cgo (wiki or cmd) does not seem to cover the case of projects with multiple Go modules exporting cgo code to other Go modules. At the moment, one has to rely on trials and errors to come up with a layout, what path to use in header files, etc.
Adding some guidance to https://go.dev/doc/modules/layout would help tremendously, specifically what conventions to use so that cgo can use headers and libraries from other Go modules. Perhaps better documentation can make this proposal unnecessary.