buildGo: remove some additional references to srcs

This commit is contained in:
Luke Granger-Brown 2020-10-18 14:23:22 +00:00
parent 38b2bb3516
commit 6c007869b6

View file

@ -21,7 +21,7 @@ let
replaceStrings replaceStrings
toString; toString;
inherit (pkgs) lib go runCommand fetchFromGitHub protobuf symlinkJoin; inherit (pkgs) lib go runCommand fetchFromGitHub protobuf symlinkJoin removeReferencesTo;
# Helpers for low-level Go compiler invocations # Helpers for low-level Go compiler invocations
spaceOut = lib.concatStringsSep " "; spaceOut = lib.concatStringsSep " ";
@ -42,6 +42,8 @@ let
pathToName = p: replaceStrings ["/"] ["_"] (toString p); pathToName = p: replaceStrings ["/"] ["_"] (toString p);
removeRefs = refs: "${removeReferencesTo}/bin/remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") ([ go ] ++ refs)}";
# Add an `overrideGo` attribute to a function result that works # Add an `overrideGo` attribute to a function result that works
# similar to `overrideAttrs`, but is used specifically for the # similar to `overrideAttrs`, but is used specifically for the
# arguments passed to Go builders. # arguments passed to Go builders.
@ -55,10 +57,11 @@ let
program = { name, srcs, deps ? [], x_defs ? {} }: program = { name, srcs, deps ? [], x_defs ? {} }:
let uniqueDeps = allDeps (map (d: d.gopkg) deps); let uniqueDeps = allDeps (map (d: d.gopkg) deps);
in runCommand name {} '' in runCommand name {} ''
${go}/bin/go tool compile -o ${name}.a -trimpath=$PWD -trimpath=${go} ${includeSources uniqueDeps} ${spaceOut srcs} ${go}/bin/go tool compile -o ${name}.a -trimpath="$PWD;${go}" ${includeSources uniqueDeps} ${spaceOut srcs}
mkdir -p $out/bin mkdir -p $out/bin
export GOROOT_FINAL=go export GOROOT_FINAL=go
${go}/bin/go tool link -o $out/bin/${name} -buildid nix ${xFlags x_defs} ${includeLibs uniqueDeps} ${name}.a ${go}/bin/go tool link -o $out/bin/${name} -buildid nix ${xFlags x_defs} ${includeLibs uniqueDeps} ${name}.a
${removeRefs srcs} $out/bin/${name}
''; '';
# Build a Go library assembled out of the specified files. # Build a Go library assembled out of the specified files.
@ -87,8 +90,9 @@ let
mkdir -p $out/${path} mkdir -p $out/${path}
${srcList path (map (s: "${s}") srcs)} ${srcList path (map (s: "${s}") srcs)}
${asmBuild} ${asmBuild}
${go}/bin/go tool compile -pack ${asmLink} -o $out/${path}.a -trimpath=$PWD -trimpath=${go} -p ${path} ${includeSources uniqueDeps} ${spaceOut srcs} ${go}/bin/go tool compile -pack ${asmLink} -o $out/${path}.a -trimpath="$PWD;${go}" -p ${path} ${includeSources uniqueDeps} ${spaceOut srcs}
${asmPack} ${asmPack}
${removeRefs srcs} $out/${path}.a
'') // { '') // {
inherit gopkg; inherit gopkg;
goDeps = uniqueDeps; goDeps = uniqueDeps;