BuildRustCrate: proc macros must be built for build's platform

When cross compiling proc macros, the proc macro needs to be built for the
build platform's architecture.

Without this change cross compiling from Darwin to Linux would simply
fail because it tries to link to a library with a file extension that
doesn't exist on the builder's platform.
This commit is contained in:
Ahmad Sattar 2024-06-06 15:30:55 +02:00 committed by Ilan Joselevich
parent 41dcd09eb0
commit fb927d5019
No known key found for this signature in database

View File

@ -49,6 +49,8 @@ let
filename =
if lib.any (x: x == "lib" || x == "rlib") dep.crateType
then "${dep.metadata}.rlib"
# Adjust lib filename for crates of type proc-macro. Proc macros are compiled/run on the build platform architecture.
else if (lib.attrByPath [ "procMacro" ] false dep) then "${dep.metadata}${stdenv.buildPlatform.extensions.library}"
else "${dep.metadata}${stdenv.hostPlatform.extensions.library}";
in
" --extern ${opts}${name}=${dep.lib}/lib/lib${extern}-${filename}"