include status-go params to set varsion and commit
Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
parent
02ce0782b1
commit
971db3ea2e
2
Makefile
2
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:
|
||||
|
|
|
@ -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
|
||||
'';
|
||||
|
|
|
@ -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,16 +27,20 @@ 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} \
|
||||
${concatStringsSep " " envVars} \
|
||||
gomobile bind \
|
||||
-target=${name} \
|
||||
-ldflags='${CGO_LDFLAGS}' \
|
||||
${concatStringsSep " " gomobileExtraFlags} \
|
||||
${goBuildFlags} \
|
||||
-o ${outputFileName} \
|
||||
${goPackagePath}/mobile
|
||||
|
||||
rm -rf ${NIX_GOWORKDIR}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue