Streamline status-go Nix expressions

Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
Pedro Pombeiro 2019-05-06 16:52:02 +02:00
parent 69b9847c5f
commit a753be4ab9
No known key found for this signature in database
GPG Key ID: C4A24185B2AA48A1
3 changed files with 35 additions and 33 deletions

View File

@ -2,6 +2,8 @@
{ buildGoPackage, go, xcodeWrapper, pkgs, stdenv }: { buildGoPackage, go, xcodeWrapper, pkgs, stdenv }:
{ owner, repo, rev, version, goPackagePath, src, host, { owner, repo, rev, version, goPackagePath, src, host,
# desktop-only arguments
goBuildFlags, goBuildLdFlags, goBuildFlags, goBuildLdFlags,
outputFileName, outputFileName,
hostSystem } @ args': hostSystem } @ args':
@ -9,36 +11,24 @@
with stdenv; with stdenv;
let let
args = removeAttrs args' [ "goBuildFlags" "goBuildLdFlags" "outputFileName" "hostSystem" ];
buildStatusGo = pkgs.callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper; }; buildStatusGo = pkgs.callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper; };
args = removeAttrs args' [ "goBuildFlags" "goBuildLdFlags" "outputFileName" "hostSystem" ]; # Remove desktop-only arguments from args
buildStatusGoDesktopLib = buildStatusGo (args // { buildStatusGoDesktopLib = buildStatusGo (args // {
buildMessage = "Building desktop library";
#GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build ${goBuildFlags} -buildmode=c-archive -o $out/${outputFileName} ./lib
buildPhase = '' buildPhase = ''
runHook preBuild
runHook renameImports
pushd "$NIX_BUILD_TOP/go/src/${goPackagePath}" >/dev/null pushd "$NIX_BUILD_TOP/go/src/${goPackagePath}" >/dev/null
echo
echo "Building desktop library"
echo
#GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build ${goBuildFlags} -buildmode=c-archive -o $out/${outputFileName} ./lib
go build -o $out/${outputFileName} ${goBuildFlags} -buildmode=c-archive ${goBuildLdFlags} ./lib go build -o $out/${outputFileName} ${goBuildFlags} -buildmode=c-archive ${goBuildLdFlags} ./lib
popd >/dev/null popd >/dev/null
runHook postBuild
''; '';
installPhase = '' installPhase = ''
runHook preInstall
mkdir -p $out/lib/${hostSystem} $out/include mkdir -p $out/lib/${hostSystem} $out/include
mv $out/${outputFileName} $out/lib/${hostSystem} mv $out/${outputFileName} $out/lib/${hostSystem}
mv $out/libstatus.h $out/include mv $out/libstatus.h $out/include
runHook postInstall
''; '';
outputs = [ "out" ]; outputs = [ "out" ];

View File

@ -2,29 +2,25 @@
{ buildGoPackage, go, gomobile, openjdk, xcodeWrapper, pkgs, stdenv }: { buildGoPackage, go, gomobile, openjdk, xcodeWrapper, pkgs, stdenv }:
{ owner, repo, rev, version, goPackagePath, src, host, { owner, repo, rev, version, goPackagePath, src, host,
# mobile-only arguments
goBuildFlags, goBuildLdFlags, goBuildFlags, goBuildLdFlags,
config } @ args': config } @ args':
with stdenv; with stdenv;
let let
args = removeAttrs args' [ "config" "goBuildFlags" "goBuildLdFlags" ];
targetConfig = config; targetConfig = config;
buildStatusGo = pkgs.callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper; }; buildStatusGo = pkgs.callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper; };
args = removeAttrs args' [ "config" "goBuildFlags" "goBuildLdFlags" ]; # Remove mobile-only arguments from args
buildStatusGoMobileLib = buildStatusGo (args // { buildStatusGoMobileLib = buildStatusGo (args // {
nativeBuildInputs = [ gomobile ] ++ lib.optional (targetConfig.name == "android") openjdk; nativeBuildInputs = [ gomobile ] ++ lib.optional (targetConfig.name == "android") openjdk;
buildMessage = "Building mobile library for ${targetConfig.name}";
# Build mobile libraries
# TODO: Manage to pass -s -w to -ldflags. Seems to only accept a single flag
buildPhase = '' buildPhase = ''
runHook preBuild
runHook renameImports
# Build mobile libraries
# TODO: Manage to pass -s -w to -ldflags. Seems to only accept a single flag
echo
echo "Building mobile library for ${targetConfig.name}"
echo
GOPATH=${gomobile.dev}:$GOPATH \ GOPATH=${gomobile.dev}:$GOPATH \
PATH=${lib.makeBinPath [ gomobile.bin ]}:$PATH \ PATH=${lib.makeBinPath [ gomobile.bin ]}:$PATH \
${lib.concatStringsSep " " targetConfig.envVars} \ ${lib.concatStringsSep " " targetConfig.envVars} \
@ -32,17 +28,11 @@ let
-o ${targetConfig.outputFileName} \ -o ${targetConfig.outputFileName} \
${goBuildLdFlags} \ ${goBuildLdFlags} \
${goPackagePath}/mobile ${goPackagePath}/mobile
runHook postBuild
''; '';
installPhase = '' installPhase = ''
runHook preInstall
mkdir -p $out/lib mkdir -p $out/lib
mv ${targetConfig.outputFileName} $out/lib/ mv ${targetConfig.outputFileName} $out/lib/
runHook postInstall
''; '';
outputs = [ "out" ]; outputs = [ "out" ];

View File

@ -2,10 +2,10 @@
{ owner, repo, rev, version, goPackagePath, src, host, { owner, repo, rev, version, goPackagePath, src, host,
nativeBuildInputs ? [], nativeBuildInputs ? [],
buildPhase, buildPhase, buildMessage,
installPhase ? "", installPhase ? "",
postInstall ? "", postInstall ? "",
outputs, meta } @ args: outputs, meta } @ args':
with stdenv; with stdenv;
@ -13,6 +13,7 @@ let
removeReferences = [ go ]; removeReferences = [ go ];
removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}''; removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}'';
args = removeAttrs args' [ "buildMessage" ]; # Remove our arguments from args before passing them on to buildGoPackage
buildStatusGo = buildGoPackage (args // { buildStatusGo = buildGoPackage (args // {
name = "${repo}-${version}-${host}"; name = "${repo}-${version}-${host}";
@ -44,6 +45,27 @@ let
xcrun xcodebuild -version xcrun xcodebuild -version
''; '';
buildPhase = ''
runHook preBuild
runHook renameImports
echo
echo "${buildMessage}"
echo
${buildPhase}
runHook postBuild
'';
installPhase = ''
runHook preInstall
${installPhase}
runHook postInstall
'';
# remove hardcoded paths to go package in /nix/store, otherwise Nix will fail the build # remove hardcoded paths to go package in /nix/store, otherwise Nix will fail the build
preFixup = '' preFixup = ''
find $out -type f -exec ${removeExpr removeReferences} '{}' + || true find $out -type f -exec ${removeExpr removeReferences} '{}' + || true