include status-go params to set varsion and commit

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-10-22 13:56:13 +02:00
parent 02ce0782b1
commit 971db3ea2e
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
6 changed files with 52 additions and 36 deletions

View File

@ -310,7 +310,7 @@ android-install: export _NIX_ATTR := targets.mobile.android.adb.shell
android-install: export TARGET_OS ?= android android-install: export TARGET_OS ?= android
android-install: export BUILD_TYPE ?= release android-install: export BUILD_TYPE ?= release
android-install: android-install:
adb install result/app.apk adb install result/app-$(BUILD_TYPE).apk
_list: SHELL := /bin/sh _list: SHELL := /bin/sh
_list: _list:

View File

@ -14,19 +14,25 @@ let
inherit buildGoPackage go xcodeWrapper utils; inherit buildGoPackage go xcodeWrapper utils;
}; };
# Remove desktop-only arguments from args
args = removeAttrs args' [ args = removeAttrs args' [
"goBuildFlags" "goBuildFlags" "goBuildLdFlags" "outputFileName" "hostSystem"
"goBuildLdFlags" ];
"outputFileName"
"hostSystem"
]; # Remove desktop-only arguments from args
buildStatusGoDesktopLib = buildStatusGo (args // { buildStatusGoDesktopLib = buildStatusGo (args // {
buildMessage = "Building desktop library"; buildMessage = "Building desktop library";
#GOOS=windows GOARCH=amd64 CGO_ENABLED=1 go build ${goBuildFlags} -buildmode=c-archive -o $out/${outputFileName} ./lib #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 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 popd >/dev/null
''; '';

View File

@ -14,7 +14,11 @@ let
targetConfig = config; targetConfig = config;
buildStatusGo = callPackage ./build-status-go.nix { inherit buildGoPackage go xcodeWrapper utils; }; 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 // { buildStatusGoMobileLib = buildStatusGo (args // {
nativeBuildInputs = [ gomobile ] ++ optional (targetConfig.name == "android") openjdk; nativeBuildInputs = [ gomobile ] ++ optional (targetConfig.name == "android") openjdk;
@ -23,17 +27,21 @@ let
buildPhase = buildPhase =
let let
NIX_GOWORKDIR = "$NIX_BUILD_TOP/go-build"; NIX_GOWORKDIR = "$NIX_BUILD_TOP/go-build";
in '' CGO_LDFLAGS = concatStringsSep " " goBuildLdFlags;
in with targetConfig; ''
mkdir ${NIX_GOWORKDIR} mkdir ${NIX_GOWORKDIR}
GOPATH=${gomobile.dev}:$GOPATH \ GOPATH=${gomobile.dev}:$GOPATH \
PATH=${makeBinPath [ gomobile.bin ]}:$PATH \ PATH=${makeBinPath [ gomobile.bin ]}:$PATH \
NIX_GOWORKDIR=${NIX_GOWORKDIR} \ NIX_GOWORKDIR=${NIX_GOWORKDIR} \
${concatStringsSep " " targetConfig.envVars} \ ${concatStringsSep " " envVars} \
gomobile bind ${goBuildFlags} -target=${targetConfig.name} ${concatStringsSep " " targetConfig.gomobileExtraFlags} \ gomobile bind \
-o ${targetConfig.outputFileName} \ -target=${name} \
${goBuildLdFlags} \ -ldflags='${CGO_LDFLAGS}' \
${goPackagePath}/mobile ${concatStringsSep " " gomobileExtraFlags} \
${goBuildFlags} \
-o ${outputFileName} \
${goPackagePath}/mobile
rm -rf ${NIX_GOWORKDIR} rm -rf ${NIX_GOWORKDIR}
''; '';

View File

@ -28,24 +28,6 @@ let
# Fixes Cgo related build failures (see https://github.com/NixOS/nixpkgs/issues/25959 ) # Fixes Cgo related build failures (see https://github.com/NixOS/nixpkgs/issues/25959 )
hardeningDisable = [ "fortify" ]; 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 # Ensure XCode is present, instead of failing at the end of the build
preConfigure = lib.optionalString isDarwin utils.enforceXCodeAvailable; preConfigure = lib.optionalString isDarwin utils.enforceXCodeAvailable;

View File

@ -3,7 +3,10 @@
androidPkgs, xcodeWrapper }: androidPkgs, xcodeWrapper }:
let 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; }; platform = callPackage ../platform.nix { inherit target-os; };
utils = callPackage ../utils.nix { inherit xcodeWrapper; }; utils = callPackage ../utils.nix { inherit xcodeWrapper; };
gomobile = callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit target-os xcodeWrapper utils buildGoPackage; }; 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; currentHostConfig = if stdenv.isDarwin then hostConfigs.darwin else hostConfigs.linux;
goBuildFlags = "-v"; goBuildFlags = "-v";
# TODO: Manage to pass "-s -w" to -ldflags. Seems to only accept a single flag # status-go params to be set at build time, important for About section and metrics
goBuildLdFlags = "-ldflags=-s"; 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; }; statusGoArgs = { inherit owner repo rev version goPackagePath src goBuildFlags goBuildLdFlags; };
status-go-packages = { status-go-packages = {

View File

@ -1,5 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
if [[ -z "${IN_NIX_SHELL}" ]]; then
echo "Remember to call 'make shell'!"
exit 1
fi
set -eof pipefail set -eof pipefail
GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel) GIT_ROOT=$(cd "${BASH_SOURCE%/*}" && git rev-parse --show-toplevel)