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

Fix release builds for musl targets #35

Closed
wants to merge 1 commit into from

Conversation

JamesGuthrie
Copy link

The libpg_query.a static archive fails to link during a release build for musl targets with errors like: "undefined reference to `_longjmp_chk'".

This appears to be caused by the fact that the static archive is compiled with the default toolchain, and so has references to symbols provided by glibc (but not musl libc).

This change switches to use the musl-gcc wrapper as CC when the target triple ends with -musl.

The `libpg_query.a` static archive fails to link during a release build
for musl targets with errors like: "undefined reference to
`_longjmp_chk'".

This appears to be caused by the fact that the static archive is
compiled with the default toolchain, and so has references to symbols
provided by glibc (but not musl libc).

This change switches to use the `musl-gcc` wrapper as `CC` when the
target triple ends with `-musl`.
@lfittl
Copy link
Member

lfittl commented Dec 22, 2023

Seems reasonable - @msepga @seanlinsley any concerns with adding that?

@@ -39,6 +39,10 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

make.env_remove("PROFILE").arg("-C").arg(&out_dir).arg("build");

if env::var("TARGET").unwrap().ends_with("-musl") {
make.env("CC", "musl-gcc");
Copy link
Member

@lfittl lfittl Dec 23, 2023

Choose a reason for hiding this comment

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

Could we change this so it respects CC if set in the environment? (i.e. only hardcode CC to musl-gcc if CC is not set, and we're on a target ending in -musl)

(per separate discussion with @msepga, who is better versed at Rust than I am 😄)

@lfittl
Copy link
Member

lfittl commented Jan 7, 2024

@JamesGuthrie As an alternate approach to special casing musl, I'm curious if changing to the cc crate would also fix the issue addressed here?

If you could give #39 a try, that changes to using the cc crate instead of the Makefile (see f32528e)

@JamesGuthrie
Copy link
Author

@lfittl Thanks for your work on this issue. I've tested building my code for the x86_64-unknown-linux-musl target against the windows-support branch (#39), and I was able to get it to work. I did need to override the CC env var:

CC=musl-gcc cargo build --release --target x86_64-unknown-linux-musl

I will close this PR in preference of #39 or f32528e.

@JamesGuthrie JamesGuthrie deleted the fix-build-rs branch January 9, 2024 10:00
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