From e92f43388dc1c8fe021ffb9c38476b95ae77c95f Mon Sep 17 00:00:00 2001 From: 12101111 Date: Wed, 6 Nov 2019 17:07:21 +0800 Subject: [PATCH] fix #7563 Fix building proc-macro crates on musl host when --target is specified. --- src/cargo/core/compiler/build_context/target_info.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 3c23d2d8b75..8cbbff0b01d 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -403,7 +403,16 @@ fn env_args( // This is probably a build script or plugin and we're // compiling with --target. In this scenario there are // no rustflags we can apply. - return Ok(Vec::new()); + // However, musl host need this rustflags to compile + // plugin dynamically. + if cfg!(target_env = "musl") { + let mut rustflags = Vec::new(); + rustflags.push("-C".into()); + rustflags.push("target-feature=-crt-static".into()); + return Ok(rustflags); + } else { + return Ok(Vec::new()); + } } // First try RUSTFLAGS from the environment