Skip to content

Comments

Fix building on Alpine#821

Merged
Jake-Shadle merged 1 commit intoEmbarkStudios:mainfrom
yuvald-sweet-security:fix-alpine-build
Jan 7, 2026
Merged

Fix building on Alpine#821
Jake-Shadle merged 1 commit intoEmbarkStudios:mainfrom
yuvald-sweet-security:fix-alpine-build

Conversation

@yuvald-sweet-security
Copy link
Contributor

Hey,

The current version on main doesn't build on Alpine linux, failing with the error:

cannot produce proc-macro for `clap_derive v4.5.49` as the target `x86_64-unknown-linux-musl` does not support these crate types

Researching a little into this issue (one, two) seems to point to the fact that proc-macro crates cannot be compiled statically. This is not usually a problem because proc-macro crates are built to the host's target, and I assume your hosts are all x86_64-unknown-linux-gnu, and thus they don't get the target.'cfg(target_env = "musl")' clause applied to them even when cross-compiling to musl. However, when building on Alpine, the host's target is in fact musl and cargo tries to statically link proc-macro creates (and build scripts).

I am not sure if your CI somehow relies on this clause - to the best of my knowledge, cross-compiling musl binaries on non-musl systems (e.g. running cargo build --target x86_64-unknown-linux-musl on a Debian machine) already uses static linking by default, and thus explicitly specifying +crt-static here should be redundant. However, if you do need to somehow pass -C target-feature=+crt-static explicitly, you should do this in the CI pipeline where it is required and not in Cargo's global config.toml (note that when cross compiling with --target and passing custom rustflags at the same time, Cargo has a useful feature where it passes these rustflags only to binaries targeting the destination architecture, and not to host-triplet targets, thus preventing breakage of this sort in that case).

Copy link
Member

@Jake-Shadle Jake-Shadle left a comment

Choose a reason for hiding this comment

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

Thanks!

@Jake-Shadle Jake-Shadle merged commit 5b025ac into EmbarkStudios:main Jan 7, 2026
11 of 12 checks passed
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