writers: deduplicate binary stripping logic

This commit is contained in:
Dominik Xaver Hörl 2021-01-11 22:13:51 +01:00
parent db132fe8db
commit e4dae65515

View File

@ -63,7 +63,7 @@ rec {
# #
# Examples: # Examples:
# writeSimpleC = makeBinWriter { compileScript = name: "gcc -o $out $contentPath"; } # writeSimpleC = makeBinWriter { compileScript = name: "gcc -o $out $contentPath"; }
makeBinWriter = { compileScript }: nameOrPath: content: makeBinWriter = { compileScript, strip ? true }: nameOrPath: content:
assert lib.or (types.path.check nameOrPath) (builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null); assert lib.or (types.path.check nameOrPath) (builtins.match "([0-9A-Za-z._])[0-9A-Za-z._-]*" nameOrPath != null);
assert lib.or (types.path.check content) (types.str.check content); assert lib.or (types.path.check content) (types.str.check content);
let let
@ -76,6 +76,8 @@ rec {
contentPath = content; contentPath = content;
}) '' }) ''
${compileScript} ${compileScript}
${ lib.optionalString strip
"${pkgs.binutils-unwrapped}/bin/strip --strip-unneeded $out" }
${optionalString (types.path.check nameOrPath) '' ${optionalString (types.path.check nameOrPath) ''
mv $out tmp mv $out tmp
mkdir -p $out/$(dirname "${nameOrPath}") mkdir -p $out/$(dirname "${nameOrPath}")
@ -131,7 +133,6 @@ rec {
-Wall \ -Wall \
-x c \ -x c \
"$contentPath" "$contentPath"
strip --strip-unneeded "$out"
''; '';
} name; } name;
@ -172,7 +173,6 @@ rec {
cp $contentPath tmp.hs cp $contentPath tmp.hs
${ghc.withPackages (_: libraries )}/bin/ghc ${lib.escapeShellArgs ghcArgs} tmp.hs ${ghc.withPackages (_: libraries )}/bin/ghc ${lib.escapeShellArgs ghcArgs} tmp.hs
mv tmp $out mv tmp $out
${pkgs.binutils-unwrapped}/bin/strip --strip-unneeded "$out"
''; '';
} name; } name;