Skip to content

proposal: introduce a ${REPODIR} as a possible variable to extend in #cgo directives #74795

@tdegris

Description

@tdegris

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LanguageProposalIssues describing a requested change to the Go language specification.Proposal

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions