about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-12-13T21·23+0000
committerVincent Ambo <tazjin@google.com>2019-12-13T21·23+0000
commit7f74980457df843aea542510a406f34366e8b868 (patch)
tree235c3ccdeea6edea4edd7c48bffb821f1c904343
parent859c429b2fbf21e3ea799b1068daa6f123c59a48 (diff)
feat(external): Compile Go assembly and include it in pkg archive
This was the final step required to add support for packages that make
use of Go assembly, such as golang.org/x/sys.
-rw-r--r--buildGo.nix22
1 files changed, 17 insertions, 5 deletions
diff --git a/buildGo.nix b/buildGo.nix
index b61c3904fb18..140cbf2d9d16 100644
--- a/buildGo.nix
+++ b/buildGo.nix
@@ -65,16 +65,28 @@ let
   # This outputs both the sources and compiled binary, as both are
   # needed when downstream packages depend on it.
   package = { name, srcs, deps ? [], path ? name, sfiles ? [] }:
-  let uniqueDeps = allDeps deps;
-      asmBuild = if sfiles == [] then "" else ''
-        ${go}/bin/go tool asm -trimpath $PWD -I $PWD -I ${go}/share/go/pkg/include -D GOOS_linux -D GOARCH_amd64 -gensymabis -o ./symabis ${spaceOut sfiles}
-      '';
-      asmLink = if sfiles == [] then "-complete" else "-symabis ./symabis";
+  let
+    uniqueDeps = allDeps deps;
+
+    # The build steps below need to be executed conditionally for Go
+    # assembly if the analyser detected any *.s files.
+    #
+    # This is required for several popular packages (e.g. x/sys).
+    ifAsm = do: if sfiles == [] then "" else do;
+    asmBuild = ifAsm ''
+      ${go}/bin/go tool asm -trimpath $PWD -I $PWD -I ${go}/share/go/pkg/include -D GOOS_linux -D GOARCH_amd64 -gensymabis -o ./symabis ${spaceOut sfiles}
+      ${go}/bin/go tool asm -trimpath $PWD -I $PWD -I ${go}/share/go/pkg/include -D GOOS_linux -D GOARCH_amd64 -o ./asm.o ${spaceOut sfiles}
+    '';
+    asmLink = ifAsm "-symabis ./symabis -asmhdr $out/go_asm.h";
+    asmPack = ifAsm ''
+      ${go}/bin/go tool pack r $out/${path}.a ./asm.o
+    '';
   in (runCommand "golib-${name}" {} ''
     mkdir -p $out/${path}
     ${srcList path (map (s: "${s}") srcs)}
     ${asmBuild}
     ${go}/bin/go tool compile -pack ${asmLink} -o $out/${path}.a -trimpath=$PWD -trimpath=${go} -p ${path} ${includeSources uniqueDeps} ${spaceOut srcs}
+    ${asmPack}
   '') // { goDeps = uniqueDeps; goImportPath = path; };
 
   # Build a tree of Go libraries out of an external Go source