rustc: put the linker for the target platform first (#408710)

authored by Emily and committed by GitHub 2f9b7c6c 701aaff5

+30 -1
+30 -1
pkgs/development/compilers/rust/rustc.nix
··· 185 185 "${setHost}.cc=${ccForHost}" 186 186 "${setTarget}.cc=${ccForTarget}" 187 187 188 + # The Rust compiler build identifies platforms by Rust target 189 + # name, and later arguments override previous arguments. This 190 + # means that when platforms differ in configuration but overlap 191 + # in Rust target name (for instance, `pkgsStatic`), only one 192 + # setting will be applied for any given option. 193 + # 194 + # This is usually mostly harmless, especially as `fastCross` 195 + # means that we usually only compile `std` in such cases. 196 + # However, the build does still need to link helper tools for the 197 + # build platform in that case. This was breaking the Darwin 198 + # `pkgsStatic` build, as it was attempting to link build tools 199 + # with the target platform’s static linker, and failing to locate 200 + # an appropriate static library for `-liconv`. 201 + # 202 + # Since the static build does not link anything for the target 203 + # platform anyway, we put the target linker first so that the 204 + # build platform linker overrides it when the Rust target names 205 + # overlap, allowing the helper tools to build successfully. 206 + # 207 + # Note that Rust does not remember these settings in the built 208 + # compiler, so this does not compromise any functionality of the 209 + # resulting compiler. 210 + # 211 + # The longer‐term fix would be to get Rust to use a more nuanced 212 + # understanding of platforms, such as by explicitly constructing 213 + # and passing Rust JSON target definitions that let us 214 + # distinguish the platforms in cases like these. That would also 215 + # let us supplant various hacks around the wrappers and hooks 216 + # that we currently need. 217 + "${setTarget}.linker=${ccForTarget}" 188 218 "${setBuild}.linker=${ccForBuild}" 189 219 "${setHost}.linker=${ccForHost}" 190 - "${setTarget}.linker=${ccForTarget}" 191 220 192 221 "${setBuild}.cxx=${cxxForBuild}" 193 222 "${setHost}.cxx=${cxxForHost}"