diff options
author | Lassulus <github@lassul.us> | 2021-01-12 17:33:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-12 17:33:50 +0100 |
commit | ec4a1661b2e57894439d79d912e6791e2b7203d4 (patch) | |
tree | bd97f9685071cdcf79a88154b313b88048bf2122 /pkgs/build-support | |
parent | b4d5747d2e50b66e71ac626d6803592ddff55b2d (diff) | |
parent | 14205a64294c3a14c3b3121bbe05ada82afe3e72 (diff) |
Merge pull request #109050 from xaverdh/rust-writer
writers: add writeRust and deduplicate binary stripping
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/writers/default.nix | 32 | ||||
-rw-r--r-- | pkgs/build-support/writers/test.nix | 6 |
2 files changed, 33 insertions, 5 deletions
diff --git a/pkgs/build-support/writers/default.nix b/pkgs/build-support/writers/default.nix index 9c709921d210..89edbd513d50 100644 --- a/pkgs/build-support/writers/default.nix +++ b/pkgs/build-support/writers/default.nix @@ -63,7 +63,7 @@ rec { # # Examples: # 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 content) (types.str.check content); let @@ -76,6 +76,8 @@ rec { contentPath = content; }) '' ${compileScript} + ${lib.optionalString strip + "${pkgs.binutils-unwrapped}/bin/strip --strip-unneeded $out"} ${optionalString (types.path.check nameOrPath) '' mv $out tmp mkdir -p $out/$(dirname "${nameOrPath}") @@ -109,7 +111,10 @@ rec { # return 0; # } # '' - writeC = name: { libraries ? [] }: + writeC = name: { + libraries ? [], + strip ? true + }: makeBinWriter { compileScript = '' PATH=${makeBinPath [ @@ -131,8 +136,8 @@ rec { -Wall \ -x c \ "$contentPath" - strip --strip-unneeded "$out" ''; + inherit strip; } name; # writeCBin takes the same arguments as writeC but outputs a directory (like writeScriptBin) @@ -165,21 +170,38 @@ rec { writeHaskell = name: { libraries ? [], ghc ? pkgs.ghc, - ghcArgs ? [] + ghcArgs ? [], + strip ? true }: makeBinWriter { compileScript = '' cp $contentPath tmp.hs ${ghc.withPackages (_: libraries )}/bin/ghc ${lib.escapeShellArgs ghcArgs} tmp.hs mv tmp $out - ${pkgs.binutils-unwrapped}/bin/strip --strip-unneeded "$out" ''; + inherit strip; } name; # writeHaskellBin takes the same arguments as writeHaskell but outputs a directory (like writeScriptBin) writeHaskellBin = name: writeHaskell "/bin/${name}"; + writeRust = name: { + rustc ? pkgs.rustc, + rustcArgs ? [], + strip ? true + }: + makeBinWriter { + compileScript = '' + cp "$contentPath" tmp.rs + PATH=${makeBinPath [pkgs.gcc]} ${lib.getBin rustc}/bin/rustc ${lib.escapeShellArgs rustcArgs} -o "$out" tmp.rs + ''; + inherit strip; + } name; + + writeRustBin = name: + writeRust "/bin/${name}"; + # writeJS takes a name an attributeset with libraries and some JavaScript sourcecode and # returns an executable # diff --git a/pkgs/build-support/writers/test.nix b/pkgs/build-support/writers/test.nix index d284bda43d05..0febad2929a0 100644 --- a/pkgs/build-support/writers/test.nix +++ b/pkgs/build-support/writers/test.nix @@ -31,6 +31,12 @@ let test '~' = '~' && echo 'success' ''; + rust = writeRustBin "test_writers" {} '' + fn main(){ + println!("success") + } + ''; + haskell = writeHaskellBin "test_writers" { libraries = [ haskellPackages.acme-default ]; } '' import Data.Default |