Skip to content

Commit

Permalink
feat: optimize size usage
Browse files Browse the repository at this point in the history
  • Loading branch information
rvolosatovs committed Jan 9, 2025
1 parent c6bad1f commit a67f064
Showing 1 changed file with 62 additions and 8 deletions.
70 changes: 62 additions & 8 deletions lib/rust/mkAttrs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,26 @@ let

buildHostPackage =
craneArgs:
trace' "buildHostPackage" {
inherit craneArgs;
} callHostCraneWithDeps craneArgs hostCraneLib.buildPackage;
trace' "buildHostPackage"
{
inherit craneArgs;
}
callHostCraneWithDeps
(
craneArgs
// {
nativeBuildInputs = [
final.removeReferencesTo
];

postInstall = ''
find "$out" -type f -exec remove-references-to \
-t ${hostRustToolchain} \
'{}' +
'';
}
)
hostCraneLib.buildPackage;

hostBin = buildHostPackage commonReleaseArgs;
hostDebugBin = buildHostPackage commonDebugArgs;
Expand Down Expand Up @@ -295,6 +312,7 @@ let
craneArgs,
craneLib,
pkgsCross,
rustToolchain,
target,
}:
let
Expand Down Expand Up @@ -329,6 +347,10 @@ let
${final.zig}/bin/zig cc ${optionalString pkgsCross.stdenv.buildPlatform.isDarwin ''--sysroot="$SDKROOT" -I"$SDKROOT/usr/include" -L"$SDKROOT/usr/lib" -F"$SDKROOT/System/Library/Frameworks"''} $@ -target ${target'}
'';

nativeBuildInputs = [
final.removeReferencesTo
];

targetArgs =
{
HOST_AR = "${final.stdenv.cc.targetPrefix}ar";
Expand All @@ -346,14 +368,31 @@ let
// (
if pkgsCross.stdenv.hostPlatform.isDarwin then
{
inherit
nativeBuildInputs
;

depsBuildBuild = [
crossZigCC
];
] ++ optional final.stdenv.hostPlatform.isDarwin pkgsCross.darwin.autoSignDarwinBinariesHook;

disallowedReferences = [
final.stdenv.cc
final.zig
pkgsCross.stdenv.cc

crossZigCC
];

postInstall = ''
find "$out" -type f -exec remove-references-to \
-t ${crossZigCC} \
-t ${final.stdenv.cc} \
-t ${final.zig} \
-t ${rustToolchain} \
'{}' +
'';

preBuild =
''
export HOME=$(mktemp -d)
Expand All @@ -369,20 +408,34 @@ let
else
(
{
depsBuildBuild = [
inherit
nativeBuildInputs
;

disallowedReferences = [
final.stdenv.cc
pkgsCross.stdenv.cc
] ++ optional pkgsCross.stdenv.hostPlatform.isWindows pkgsCross.windows.pthreads;

disallowedReferences = [
depsBuildBuild = [
pkgsCross.stdenv.cc
];
] ++ optional pkgsCross.stdenv.hostPlatform.isWindows pkgsCross.windows.pthreads;

postInstall = ''
find "$out" -type f -exec remove-references-to \
-t ${final.stdenv.cc} \
-t ${pkgsCross.stdenv.cc} \
-t ${rustToolchain} \
${optionalString pkgsCross.stdenv.hostPlatform.isWindows "-t ${pkgsCross.windows.pthreads}"} \
'{}' +
'';

"AR_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}ar";
"CC_${target}" = "${pkgsCross.stdenv.cc.targetPrefix}cc";
}
# Use `mold` linker for Linux targets
// optionalAttrs pkgsCross.stdenv.hostPlatform.isLinux {
nativeBuildInputs = [
nativeBuildInputs = nativeBuildInputs ++ [
final.mold
];

Expand Down Expand Up @@ -701,6 +754,7 @@ let
craneArgs
craneLib
pkgsCross
rustToolchain
target
;
};
Expand Down

0 comments on commit a67f064

Please sign in to comment.