Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Append existing CFLAGS and LDFLAGS for CGO #367

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

deuill
Copy link
Contributor

@deuill deuill commented Dec 5, 2024

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.

My own, specific use-case here is using GoPy in slidge-whatsapp, and using go-fitz, which links against libmupdf, which in turn requires a number of different libraries (libjpeg, libharfbuzz, etc.)

Infuriatingly enough, Debian doesn't provide a package containing a shared library for MuPDF, only a static library, which requires that we declare any shared libraries specifically at the time of compilation; otherwise builds work but you get undefined reference errors at runtime.

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.
Copy link
Member

@rcoreilly rcoreilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable -- thanks!

@rcoreilly rcoreilly merged commit fc6df6c into go-python:master Dec 6, 2024
2 of 3 checks passed
@deuill
Copy link
Contributor Author

deuill commented Dec 6, 2024

Thanks so much for pushing this through, @rcoreilly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants