From 971db3ea2e95c17f654ffb9c8c4c3bc41243ccc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Tue, 22 Oct 2019 13:56:13 +0200 Subject: [PATCH] include status-go params to set varsion and commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- Makefile | 2 +- nix/status-go/build-desktop-status-go.nix | 20 +++++++++++++------- nix/status-go/build-mobile-status-go.nix | 22 +++++++++++++++------- nix/status-go/build-status-go.nix | 18 ------------------ nix/status-go/default.nix | 21 ++++++++++++++++++--- scripts/update-status-go.sh | 5 +++++ 6 files changed, 52 insertions(+), 36 deletions(-) diff --git a/Makefile b/Makefile index 3f53a510b8..eee0124159 100644 --- a/Makefile +++ b/Makefile @@ -310,7 +310,7 @@ android-install: export _NIX_ATTR := targets.mobile.android.adb.shell android-install: export TARGET_OS ?= android android-install: export BUILD_TYPE ?= release android-install: - adb install result/app.apk + adb install result/app-$(BUILD_TYPE).apk _list: SHELL := /bin/sh _list: diff --git a/nix/status-go/build-desktop-status-go.nix b/nix/status-go/build-desktop-status-go.nix index bb629e6db5..3029996942 100644 --- a/nix/status-go/build-desktop-status-go.nix +++ b/nix/status-go/build-desktop-status-go.nix @@ -14,19 +14,25 @@ let inherit buildGoPackage go xcodeWrapper utils; }; + # Remove desktop-only arguments from args args = removeAttrs args' [ - "goBuildFlags" - "goBuildLdFlags" - "outputFileName" - "hostSystem" - ]; # Remove desktop-only arguments from args + "goBuildFlags" "goBuildLdFlags" "outputFileName" "hostSystem" + ]; + 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 = + let + CGO_LDFLAGS = stdenv.lib.concatStringsSep " " goBuildLdFlags; + in '' pushd "$NIX_BUILD_TOP/go/src/${goPackagePath}" >/dev/null - go build -o $out/${outputFileName} ${goBuildFlags} -buildmode=c-archive ${goBuildLdFlags} ./lib + go build -o $out/${outputFileName} \ + ${goBuildFlags} \ + -buildmode=c-archive \ + -ldflags='${CGO_LDFLAGS}' \ + ./lib popd >/dev/null ''; diff --git a/nix/status-go/build-mobile-status-go.nix b/nix/status-go/build-mobile-status-go.nix index 7339cd509a..c7009fa551 100644 --- a/nix/status-go/build-mobile-status-go.nix +++ b/nix/status-go/build-mobile-status-go.nix @@ -14,7 +14,11 @@ let targetConfig = config; buildStatusGo = callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper utils; }; - args = removeAttrs args' [ "config" "goBuildFlags" "goBuildLdFlags" ]; # Remove mobile-only arguments from args + # Remove mobile-only arguments from args + args = removeAttrs args' [ + "config" "goBuildFlags" "goBuildLdFlags" + ]; + buildStatusGoMobileLib = buildStatusGo (args // { nativeBuildInputs = [ gomobile ] ++ optional (targetConfig.name == "android") openjdk; @@ -23,17 +27,21 @@ let buildPhase = let NIX_GOWORKDIR = "$NIX_BUILD_TOP/go-build"; - in '' + CGO_LDFLAGS = concatStringsSep " " goBuildLdFlags; + in with targetConfig; '' mkdir ${NIX_GOWORKDIR} GOPATH=${gomobile.dev}:$GOPATH \ PATH=${makeBinPath [ gomobile.bin ]}:$PATH \ NIX_GOWORKDIR=${NIX_GOWORKDIR} \ - ${concatStringsSep " " targetConfig.envVars} \ - gomobile bind ${goBuildFlags} -target=${targetConfig.name} ${concatStringsSep " " targetConfig.gomobileExtraFlags} \ - -o ${targetConfig.outputFileName} \ - ${goBuildLdFlags} \ - ${goPackagePath}/mobile + ${concatStringsSep " " envVars} \ + gomobile bind \ + -target=${name} \ + -ldflags='${CGO_LDFLAGS}' \ + ${concatStringsSep " " gomobileExtraFlags} \ + ${goBuildFlags} \ + -o ${outputFileName} \ + ${goPackagePath}/mobile rm -rf ${NIX_GOWORKDIR} ''; diff --git a/nix/status-go/build-status-go.nix b/nix/status-go/build-status-go.nix index 29ba0b618b..51a76dd1f3 100644 --- a/nix/status-go/build-status-go.nix +++ b/nix/status-go/build-status-go.nix @@ -28,24 +28,6 @@ let # Fixes Cgo related build failures (see https://github.com/NixOS/nixpkgs/issues/25959 ) hardeningDisable = [ "fortify" ]; - # gomobile doesn't seem to be able to pass -ldflags with multiple values correctly to go build, so we just patch files here - patchPhase = '' - date=$(date -u '+%Y-%m-%d.%H:%M:%S') - - substituteInPlace cmd/statusd/main.go --replace \ - "buildStamp = \"N/A\"" \ - "buildStamp = \"$date\"" - substituteInPlace params/version.go --replace \ - "var Version string" \ - "var Version string = \"${version}\"" - substituteInPlace params/version.go --replace \ - "var GitCommit string" \ - "var GitCommit string = \"${rev}\"" - substituteInPlace vendor/github.com/ethereum/go-ethereum/metrics/metrics.go --replace \ - "var EnabledStr = \"false\"" \ - "var EnabledStr = \"true\"" - ''; - # Ensure XCode is present, instead of failing at the end of the build preConfigure = lib.optionalString isDarwin utils.enforceXCodeAvailable; diff --git a/nix/status-go/default.nix b/nix/status-go/default.nix index 47bb96ba4d..cf0d91a1c6 100644 --- a/nix/status-go/default.nix +++ b/nix/status-go/default.nix @@ -3,7 +3,10 @@ androidPkgs, xcodeWrapper }: let - inherit (stdenv.lib) catAttrs concatStrings fileContents importJSON makeBinPath optional optionalString strings; + inherit (stdenv.lib) + catAttrs concatStrings fileContents importJSON makeBinPath + optional optionalString removePrefix strings attrValues mapAttrs; + platform = callPackage ../platform.nix { inherit target-os; }; utils = callPackage ../utils.nix { inherit xcodeWrapper; }; gomobile = callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit target-os xcodeWrapper utils buildGoPackage; }; @@ -53,8 +56,20 @@ let currentHostConfig = if stdenv.isDarwin then hostConfigs.darwin else hostConfigs.linux; goBuildFlags = "-v"; - # TODO: Manage to pass "-s -w" to -ldflags. Seems to only accept a single flag - goBuildLdFlags = "-ldflags=-s"; + # status-go params to be set at build time, important for About section and metrics + goBuildParams = { + Version = removePrefix "v" version; # Geth forces a 'v' prefix + GitCommit = rev; + }; + # These are necessary for status-go to show correct version + paramsLdFlags = attrValues (mapAttrs (name: value: + "-X github.com/status-im/status-go/params.${name}=${value}" + ) goBuildParams); + + goBuildLdFlags = paramsLdFlags ++ [ + "-s" # -s disabled symbol table + "-w" # -w disables DWARF debugging information + ]; statusGoArgs = { inherit owner repo rev version goPackagePath src goBuildFlags goBuildLdFlags; }; status-go-packages = { diff --git a/scripts/update-status-go.sh b/scripts/update-status-go.sh index 1bf2596c26..2bcf2c7c6d 100755 --- a/scripts/update-status-go.sh +++ b/scripts/update-status-go.sh @@ -1,5 +1,10 @@ #!/usr/bin/env bash +if [[ -z "${IN_NIX_SHELL}" ]]; then + echo "Remember to call 'make shell'!" + exit 1 +fi + set -eof pipefail GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)