Skip to content

Commit d709cba

Browse files
committed
build: Append existing CFLAGS and LDFLAGS for CGO
Underlying `go build` commands can pass custom `CFLAGS` and `LDFLAGS` to CGO invocations, which GoPy uses in order to pass some of its own command-line arguments to builds. However, there are cases where additional, build-specific parameters may need to be used (e.g. in the case where we're linking against a static library which itself links to other dynamic libraries, which aren't set as options in the packages themselves); this commit respects any existing uses of the `CGO_CFLAGS` and `CGO_LDFLAGS` environment variables, and appends their values to ones used internally by GoPy if needed.
1 parent 1d7f3a2 commit d709cba

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cmd_build.go

+6
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ func runBuild(mode bind.BuildMode, cfg *BuildCfg) error {
235235
if include, exists := os.LookupEnv("GOPY_INCLUDE"); exists {
236236
cflags = append(cflags, "-I"+filepath.ToSlash(include))
237237
}
238+
if oldcflags, exists := os.LookupEnv("CGO_CFLAGS"); exists {
239+
cflags = append(cflags, oldcflags)
240+
}
238241
var ldflags []string
239242
if cfg.DynamicLinking {
240243
ldflags = strings.Fields(strings.TrimSpace(pycfg.LdDynamicFlags))
@@ -250,6 +253,9 @@ func runBuild(mode bind.BuildMode, cfg *BuildCfg) error {
250253
if libname, exists := os.LookupEnv("GOPY_PYLIB"); exists {
251254
ldflags = append(ldflags, "-l"+filepath.ToSlash(libname))
252255
}
256+
if oldldflags, exists := os.LookupEnv("CGO_LDFLAGS"); exists {
257+
ldflags = append(ldflags, oldldflags)
258+
}
253259

254260
removeEmpty := func(src []string) []string {
255261
o := make([]string, 0, len(src))

0 commit comments

Comments
 (0)