Skip to content

Commit 557cd7d

Browse files
committed
musl: fix build for x86_64-unknown-linux-musl target
1 parent 347fe6d commit 557cd7d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## Unreleased
4+
### Fixed
5+
- Fix regression from `setuptools-rust` 1.1.0 which broke builds for the `x86_64-unknown-linux-musl` target. [#194](https://github.com/PyO3/setuptools-rust/pull/194)
6+
37
## 1.1.0 (2021-11-30)
48
### Added
59
- Add support for cross-compiling using [`cross`](https://github.com/rust-embedded/cross). [#185](https://github.com/PyO3/setuptools-rust/pull/185)

setuptools_rust/build.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,18 @@ def build_extension(
175175
# Tell musl targets not to statically link libc. See
176176
# https://github.com/rust-lang/rust/issues/59302 for details.
177177
if rustc_cfgs.get("target_env") == "musl":
178-
rustc_args.extend(["-C", "target-feature=-crt-static"])
178+
# This must go in the env otherwise rustc will refuse to build
179+
# the cdylib, see https://github.com/rust-lang/cargo/issues/10143
180+
MUSL_FLAGS = "-C target-feature=-crt-static"
181+
rustflags = env.get("RUSTFLAGS")
182+
if rustflags is not None:
183+
env["RUSTFLAGS"] = f"{rustflags} {MUSL_FLAGS}"
184+
else:
185+
env["RUSTFLAGS"] = MUSL_FLAGS
186+
187+
# Include this in the command-line anyway, so that when verbose
188+
# logging enabled the user will see that this flag is in use.
189+
rustc_args.extend(MUSL_FLAGS.split())
179190

180191
command = [
181192
self.cargo,

0 commit comments

Comments
 (0)