Integrate status-go Nimbus build

Signed-off-by: Pedro Pombeiro <noreply@pedro.pombei.ro>
This commit is contained in:
Pedro Pombeiro 2020-01-21 08:19:49 +01:00
parent 08247391ad
commit 2dce0ba861
No known key found for this signature in database
GPG Key ID: B04C63F91EF312EF
15 changed files with 164 additions and 49 deletions

1
.env
View File

@ -21,3 +21,4 @@ PARTITIONED_TOPIC=0
CONTRACT_NODES=1 CONTRACT_NODES=1
MOBILE_UI_FOR_DESKTOP=1 MOBILE_UI_FOR_DESKTOP=1
STATUS_GO_PROTOCOL=0 STATUS_GO_PROTOCOL=0
STATUS_GO_ENABLE_NIMBUS=0

View File

@ -20,3 +20,4 @@ RPC_NETWORKS_ONLY=0
PARTITIONED_TOPIC=0 PARTITIONED_TOPIC=0
CONTRACT_NODES=1 CONTRACT_NODES=1
MOBILE_UI_FOR_DESKTOP=1 MOBILE_UI_FOR_DESKTOP=1
STATUS_GO_ENABLE_NIMBUS=0

View File

@ -40,7 +40,7 @@ export REACT_SERVER_PORT ?= 5001
# Our custom config is located in nix/nix.conf # Our custom config is located in nix/nix.conf
export NIX_CONF_DIR = $(PWD)/nix export NIX_CONF_DIR = $(PWD)/nix
# Defines which variables will be kept for Nix pure shell, use semicolon as divider # Defines which variables will be kept for Nix pure shell, use semicolon as divider
export _NIX_KEEP ?= TMPDIR,BUILD_ENV,STATUS_GO_SRC_OVERRIDE export _NIX_KEEP ?= TMPDIR,BUILD_ENV,STATUS_GO_SRC_OVERRIDE,NIMBUS_SRC_OVERRIDE
export _NIX_ROOT = /nix export _NIX_ROOT = /nix
# legacy TARGET_OS variable support # legacy TARGET_OS variable support
ifdef TARGET_OS ifdef TARGET_OS

View File

@ -62,6 +62,11 @@ or for a one-off build:
make release-android STATUS_GO_SRC_OVERRIDE=$GOPATH/src/github.com/status-im/status-go make release-android STATUS_GO_SRC_OVERRIDE=$GOPATH/src/github.com/status-im/status-go
``` ```
## Using a local Nimbus repository
If you need to use a locally checked-out Nimbus repository as a dependency of status-go, you can achieve that by defining the `NIMBUS_SRC_OVERRIDE`
environment variable, in the same way as the previous point for local status-go repositories.
## Known Issues ## Known Issues
### MacOS 10.15 "Catalina" ### MacOS 10.15 "Catalina"

View File

@ -14,6 +14,8 @@ let
inherit (lib) attrByPath hasAttrByPath optionalAttrs; inherit (lib) attrByPath hasAttrByPath optionalAttrs;
env' = env // optionalAttrs (hasAttrByPath ["status-im" "status-go" "src-override"] config) { env' = env // optionalAttrs (hasAttrByPath ["status-im" "status-go" "src-override"] config) {
STATUS_GO_SRC_OVERRIDE = config.status-im.status-go.src-override; STATUS_GO_SRC_OVERRIDE = config.status-im.status-go.src-override;
} // optionalAttrs (hasAttrByPath ["status-im" "nimbus" "src-override"] config) {
NIMBUS_SRC_OVERRIDE = config.status-im.nimbus.src-override;
}; };
inherit (config.status-im) build-type; inherit (config.status-im) build-type;
inherit (config.status-im.status-react) build-number; inherit (config.status-im.status-react) build-number;

View File

@ -55,6 +55,9 @@ config=''
if [ -n "${STATUS_GO_SRC_OVERRIDE}" ]; then if [ -n "${STATUS_GO_SRC_OVERRIDE}" ]; then
config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";" config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";"
fi fi
if [ -n "${NIMBUS_SRC_OVERRIDE}" ]; then
config+="status-im.nimbus.src-override=\"${NIMBUS_SRC_OVERRIDE}\";"
fi
config+="status-im.build-type=\"${BUILD_TYPE}\";" config+="status-im.build-type=\"${BUILD_TYPE}\";"
if [ -n "$config" ]; then if [ -n "$config" ]; then

View File

@ -1,5 +1,5 @@
{ stdenv, utils, callPackage, { stdenv, utils, callPackage,
buildGoPackage, go, gomobile, openjdk, xcodeWrapper }: buildGoPackage, go, gomobile, androidPkgs, openjdk, unzip, zip, xcodeWrapper }:
{ owner, repo, rev, cleanVersion, goPackagePath, src, host, { owner, repo, rev, cleanVersion, goPackagePath, src, host,
@ -8,7 +8,7 @@
targetConfig } @ args': targetConfig } @ args':
let let
inherit (stdenv.lib) concatStringsSep makeBinPath optional; inherit (stdenv.lib) concatStringsSep makeBinPath optional optionals;
buildStatusGo = callPackage ./build-status-go.nix { buildStatusGo = callPackage ./build-status-go.nix {
inherit buildGoPackage go xcodeWrapper utils; inherit buildGoPackage go xcodeWrapper utils;
@ -19,44 +19,83 @@ let
"targetConfig" "goBuildFlags" "goBuildLdFlags" "targetConfig" "goBuildFlags" "goBuildLdFlags"
]; ];
buildStatusGoMobileLib = buildStatusGo (args // { buildStatusGoMobileLib =
nativeBuildInputs = [ gomobile ] ++ optional (targetConfig.name == "android") openjdk; let
inherit (stdenv.lib) concatStrings mapAttrsToList optionalString;
in buildStatusGo (args // {
nativeBuildInputs = [ gomobile unzip zip ] ++ optional (targetConfig.name == "android") openjdk;
buildMessage = "Building mobile library for ${targetConfig.name}"; buildMessage = "Building mobile library for ${targetConfig.name}";
# Build mobile libraries # Build mobile libraries
buildPhase = buildPhase =
let let
NIX_GOWORKDIR = "$NIX_BUILD_TOP/go-build"; NIX_GOWORKDIR = "$NIX_BUILD_TOP/go-build";
CGO_LDFLAGS = concatStringsSep " " goBuildLdFlags; CGO_LDFLAGS = concatStringsSep " " (goBuildLdFlags ++ [ "-extldflags=-Wl,--allow-multiple-definition" ]);
in with targetConfig; '' nimbusBridgeVendorDir = "$NIX_BUILD_TOP/go/src/${goPackagePath}/vendor/${goPackagePath}/eth-node/bridge/nimbus";
mkdir ${NIX_GOWORKDIR} in ''
mkdir ${NIX_GOWORKDIR}
export GO111MODULE=off export GO111MODULE=off
export GOPATH=${gomobile.dev}:$GOPATH export GOPATH=${gomobile.dev}:$GOPATH
export PATH=${makeBinPath [ gomobile.bin ]}:$PATH export PATH=${makeBinPath [ gomobile.bin ]}:$PATH
export NIX_GOWORKDIR=${NIX_GOWORKDIR} export NIX_GOWORKDIR=${NIX_GOWORKDIR}
export ${concatStringsSep " " envVars} export ${concatStringsSep " " targetConfig.envVars}
gomobile bind \
-target=${name} \
-ldflags='${CGO_LDFLAGS}' \
${concatStringsSep " " gomobileExtraFlags} \
${goBuildFlags} \
-o ${outputFileName} \
${goPackagePath}/mobile
rm -rf ${NIX_GOWORKDIR} # Build the Go library using gomobile for each of the configured platforms
''; ${concatStrings (mapAttrsToList (_: platformConfig: ''
installPhase = '' ${optionalString platformConfig.linkNimbus ''
mkdir -p $out/lib # Copy the Nimbus API artifacts to the expected vendor location
mv ${targetConfig.outputFileName} $out/lib/ cp ${platformConfig.nimbus}/{include/*,lib/libnimbus.a} ${nimbusBridgeVendorDir}
''; chmod +w ${nimbusBridgeVendorDir}/libnimbus.{a,h}
''}
outputs = [ "out" ]; echo
echo "Building for target ${platformConfig.gomobileTarget}"
gomobile bind \
-target=${platformConfig.gomobileTarget} \
-ldflags="${CGO_LDFLAGS}" \
${concatStringsSep " " targetConfig.gomobileExtraFlags} \
${goBuildFlags} \
-o ${platformConfig.outputFileName} \
${goPackagePath}/mobile
meta = { ${optionalString platformConfig.linkNimbus ''
platforms = with stdenv.lib.platforms; linux ++ darwin; rm ${nimbusBridgeVendorDir}/libnimbus.{a,h}
}; ''}
}); '') targetConfig.platforms)
}
if [ "${targetConfig.name}" = 'android' ]; then
# Merge the platform-specific .aar files into a single one
local mergeDir='.aar'
mkdir $mergeDir
${concatStrings (mapAttrsToList (_: platformConfig: ''
unzip -d $mergeDir -q -n -u ${platformConfig.outputFileName}
rm ${platformConfig.outputFileName}
'') targetConfig.platforms)}
pushd $mergeDir > /dev/null
zip -r -o ../${targetConfig.outputFileName} *
popd > /dev/null
rm -rf $mergeDir
unzip -l ${targetConfig.outputFileName}
fi
# TODO: Merge iOS packages when linking with libnimbus.a
rm -rf ${NIX_GOWORKDIR}
'';
installPhase = ''
mkdir -p $out/lib
mv ${targetConfig.outputFileName} $out/lib/
'';
outputs = [ "out" ];
meta = {
platforms = with stdenv.lib.platforms; linux ++ darwin;
};
});
in buildStatusGoMobileLib in buildStatusGoMobileLib

View File

@ -2,6 +2,7 @@
{ owner, repo, rev, cleanVersion, goPackagePath, src, host, { owner, repo, rev, cleanVersion, goPackagePath, src, host,
nativeBuildInputs ? [], nativeBuildInputs ? [],
buildInputs ? [],
buildPhase, buildMessage, buildPhase, buildMessage,
installPhase ? "", installPhase ? "",
postInstall ? "", postInstall ? "",
@ -24,6 +25,7 @@ let
nativeBuildInputs = nativeBuildInputs =
nativeBuildInputs ++ nativeBuildInputs ++
lib.optional isDarwin xcodeWrapper; lib.optional isDarwin xcodeWrapper;
inherit buildInputs;
# 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" ];

View File

@ -3,14 +3,17 @@
let let
inherit (stdenv.lib) inherit (stdenv.lib)
catAttrs concatStrings fileContents importJSON makeBinPath catAttrs concatStrings concatStringsSep fileContents importJSON makeBinPath
optional optionalString strings attrValues mapAttrs attrByPath optional optionalString strings attrValues mapAttrs attrByPath
traceValFn; traceValFn;
envFlags = callPackage ../tools/envParser.nix { };
enableNimbus = (attrByPath ["STATUS_GO_ENABLE_NIMBUS"] "0" envFlags) != "0";
utils = callPackage ./utils.nix { inherit xcodeWrapper; }; utils = callPackage ./utils.nix { inherit xcodeWrapper; };
gomobile = callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit xcodeWrapper utils buildGoPackage; }; gomobile = callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit xcodeWrapper utils buildGoPackage; };
nimbus = if enableNimbus then callPackage ./nimbus { } else { wrappers-android = { }; };
buildStatusGoDesktopLib = callPackage ./build-desktop-status-go.nix { inherit buildGoPackage go xcodeWrapper utils; }; buildStatusGoDesktopLib = callPackage ./build-desktop-status-go.nix { inherit buildGoPackage go xcodeWrapper utils; };
buildStatusGoMobileLib = callPackage ./build-mobile-status-go.nix { inherit buildGoPackage go gomobile xcodeWrapper utils; }; buildStatusGoMobileLib = callPackage ./build-mobile-status-go.nix { inherit buildGoPackage go gomobile xcodeWrapper utils androidPkgs; };
srcData = srcData =
# If config.status-im.status-go.src-override is defined, instruct Nix to use that path to build status-go # If config.status-im.status-go.src-override is defined, instruct Nix to use that path to build status-go
if (attrByPath ["status-im" "status-go" "src-override"] "" config) != "" then rec { if (attrByPath ["status-im" "status-go" "src-override"] "" config) != "" then rec {
@ -51,21 +54,43 @@ let
}; };
mobileConfigs = { mobileConfigs = {
android = { android = rec {
name = "android"; name = "android";
outputFileName = "status-go-${srcData.shortRev}.aar";
envVars = [ envVars = [
"ANDROID_HOME=${androidPkgs.androidsdk}/libexec/android-sdk" "ANDROID_HOME=${androidPkgs.androidsdk}/libexec/android-sdk"
"ANDROID_NDK_HOME=${androidPkgs.ndk-bundle}/libexec/android-sdk/ndk-bundle" "ANDROID_NDK_HOME=${androidPkgs.ndk-bundle}/libexec/android-sdk/ndk-bundle"
"PATH=${makeBinPath [ openjdk ]}:$PATH" "PATH=${makeBinPath [ openjdk ]}:$PATH"
]; ];
gomobileExtraFlags = [ "-androidapi 18" ]; gomobileExtraFlags = [ "-androidapi 23" ];
outputFileName = "status-go-${srcData.shortRev}.aar";
platforms = {
arm64 = {
linkNimbus = enableNimbus;
nimbus = assert enableNimbus; nimbus.wrappers-android.arm64;
gomobileTarget = "${name}/arm64";
outputFileName = "status-go-${srcData.shortRev}-arm64.aar";
};
x86 = {
linkNimbus = enableNimbus;
nimbus = assert enableNimbus; nimbus.wrappers-android.x86;
gomobileTarget = "${name}/386";
outputFileName = "status-go-${srcData.shortRev}-386.aar";
};
};
}; };
ios = { ios = rec {
name = "ios"; name = "ios";
outputFileName = "Statusgo.framework";
envVars = []; envVars = [];
gomobileExtraFlags = [ "-iosversion=8.0" ]; gomobileExtraFlags = [ "-iosversion=8.0" ];
outputFileName = "Statusgo.framework";
platforms = {
ios = {
linkNimbus = enableNimbus;
nimbus = assert false; null; # TODO: Currently we don't support Nimbus on iOS
gomobileTarget = name;
inherit outputFileName;
};
};
}; };
}; };
hostConfigs = { hostConfigs = {
@ -80,7 +105,7 @@ let
}; };
currentHostConfig = if stdenv.isDarwin then hostConfigs.darwin else hostConfigs.linux; currentHostConfig = if stdenv.isDarwin then hostConfigs.darwin else hostConfigs.linux;
goBuildFlags = "-v"; goBuildFlags = concatStringsSep " " [ "-v" (optionalString enableNimbus "-tags='nimbus'") ];
# status-go params to be set at build time, important for About section and metrics # status-go params to be set at build time, important for About section and metrics
goBuildParams = { goBuildParams = {
GitCommit = srcData.rev; GitCommit = srcData.rev;

View File

@ -0,0 +1,33 @@
{ config, stdenv, callPackage, fetchFromGitHub, mkFilter }:
let
inherit (stdenv.lib) attrByPath strings traceValFn;
repo = "nimbus";
localPath = attrByPath ["status-im" "nimbus" "src-override"] "" config;
localSrc = builtins.path rec { # We use builtins.path so that we can name the resulting derivation, otherwise the name would be taken from the checkout directory, which is outside of our control
path = traceValFn (path: "Using local ${repo} sources from ${path}\n") localPath;
name = "${repo}-source-local";
filter =
# Keep this filter as restrictive as possible in order to avoid unnecessary rebuilds and limit closure size
mkFilter {
dirRootsToInclude = [ "nix" "wrappers" "vendor" ];
dirsToExclude = [ ".git" ".svn" "CVS" ".hg" ".vscode" ".dependabot" ".github" "examples" "docs" ];
filesToInclude = [ "Makefile" "nim.cfg" "nimbus.nimble" "default.nix" ];
root = path;
};
};
src = if localPath != "" then localSrc
else fetchFromGitHub rec {
inherit repo;
name = "${repo}-source-${strings.substring 0 7 rev}";
rev = "501455b0cd2e74c451bc1743e2f1070a3fee1343";
owner = "status-im";
sha256 = "0nxh3hh8fib3hlmvs5d67h6cq3kyap94pa9w7ixsfa5285ila17h";
fetchSubmodules = true;
};
nimbusDeriv = import "${src}/nix/default.nix";
in nimbusDeriv

View File

@ -11,6 +11,9 @@ config+="status-im.build-type=\"${BUILD_TYPE}\";"
if [ -n "${STATUS_GO_SRC_OVERRIDE}" ]; then if [ -n "${STATUS_GO_SRC_OVERRIDE}" ]; then
config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";" config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";"
fi fi
if [ -n "${NIMBUS_SRC_OVERRIDE}" ]; then
config+="status-im.nimbus.src-override=\"${NIMBUS_SRC_OVERRIDE}\";"
fi
config+="status-im.status-react.build-number=\"${BUILD_NUMBER}\";" config+="status-im.status-react.build-number=\"${BUILD_NUMBER}\";"
config+="status-im.status-react.keystore-file=\"${STORE_FILE}\";" config+="status-im.status-react.keystore-file=\"${STORE_FILE}\";"
nixOpts=( nixOpts=(

View File

@ -286,7 +286,7 @@
- mailserver disconnected: we try to reconnect - mailserver disconnected: we try to reconnect
- mailserver connected: we mark the mailserver as trusted peer" - mailserver connected: we mark the mailserver as trusted peer"
[{:keys [db] :as cofx} previous-summary] [{:keys [db] :as cofx} previous-summary]
(when (:multiaccount db) (when (and (not config/nimbus-enabled?) (:multiaccount db))
(if (:mailserver/current-id db) (if (:mailserver/current-id db)
(let [{:keys [peers-summary peers-count]} db (let [{:keys [peers-summary peers-count]} db
{:keys [address sym-key-id] :as mailserver} (fetch-current db) {:keys [address sym-key-id] :as mailserver} (fetch-current db)
@ -303,8 +303,8 @@
(mark-trusted-peer cofx) (mark-trusted-peer cofx)
mailserver-removed? mailserver-removed?
(connect-to-mailserver cofx))) (connect-to-mailserver cofx)))
;; if there is no current mailserver defined, ;; if there is no current mailserver defined,
;; we set it first ;; we set it first
(set-current-mailserver cofx)))) (set-current-mailserver cofx))))
(defn adjust-request-for-transit-time (defn adjust-request-for-transit-time

View File

@ -320,7 +320,7 @@
:disconnected? :disconnected?
:<- [:peers-count] :<- [:peers-count]
(fn [peers-count] (fn [peers-count]
(zero? peers-count))) (and (not config/nimbus-enabled?) (zero? peers-count))))
(re-frame/reg-sub (re-frame/reg-sub
:offline? :offline?

View File

@ -42,7 +42,7 @@
(fetch-node-info-fx) (fetch-node-info-fx)
(pairing/init) (pairing/init)
(publisher/start-fx) (publisher/start-fx)
(mailserver/initialize-mailserver))) (when-not config/nimbus-enabled? (mailserver/initialize-mailserver))))
(fx/defn stop-whisper (fx/defn stop-whisper
"Stops whisper protocol" "Stops whisper protocol"

View File

@ -50,3 +50,4 @@
(def pow-target (js/parseFloat (get-config :POW_TARGET "0.002"))) (def pow-target (js/parseFloat (get-config :POW_TARGET "0.002")))
(def pow-time (js/parseInt (get-config :POW_TIME "1"))) (def pow-time (js/parseInt (get-config :POW_TIME "1")))
(def max-installations 2) (def max-installations 2)
(def nimbus-enabled? (get-config :STATUS_GO_ENABLE_NIMBUS false))