Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] nimbus-light-proxy integration #15341

Closed
wants to merge 16 commits into from
356 changes: 178 additions & 178 deletions ios/Podfile.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions nix/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

status-go = {
src-override = null;
gomobile-src-override = null;
ipfs-gateway-url = "https://ipfs.status.im/";
};
};
Expand Down
56 changes: 46 additions & 10 deletions nix/overlay.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,47 @@ self: super:

let
inherit (super) stdenv stdenvNoCC callPackage;
lib = (super.lib or { }) // (import ./lib {
inherit (super) lib;
inherit (self) config;
});

gomobileSrcOverride = "/Users/vvlasov/c/mobile";
# Warning message about using local sources
localSrcWarn = (path: "Using local gomobile sources from ${path}");
localGomobileSrc = rec {
owner = "status-im";
repo = "mobile";
rev = "unknown";
shortRev = rev;
rawVersion = "develop";
cleanVersion = rawVersion;
goPackagePath = "github.com/${owner}/${repo}";
# We use builtins.path so that we can name the resulting derivation,
# Normally the name would not be deterministic, taken from the checkout directory.
src = builtins.path rec {
path = lib.traceValFn localSrcWarn gomobileSrcOverride;
name = "${repo}-source-${shortRev}";
# Keep this filter as restrictive as possible in order
# to avoid unnecessary rebuilds and limit closure size
filter = lib.mkFilter {
root = path;
include = [ ".*" ];
exclude = [
".*/[.]git.*" ".*[.]md" ".*[.]yml" ".*/.*_test.go$"
"VERSION" "_assets/.*" "build/.*"
".*/.*LICENSE.*" ".*/CONTRIB.*" ".*/AUTHOR.*"
];
};
};
};
in {
inherit lib;
# Fix for MacOS
mkShell = super.mkShell.override { stdenv = stdenvNoCC; };

# Various utilities
utils = callPackage ./tools/utils.nix { };
lib = (super.lib or { }) // (import ./lib {
inherit (super) lib;
inherit (self) config;
});

# Project dependencies
deps = {
clojure = callPackage ./deps/clojure { };
Expand All @@ -45,11 +75,17 @@ in {
buildGoPackage = super.buildGo118Package;
buildGoModule = super.buildGo118Module;
gomobile = (super.gomobile.overrideAttrs (old: {
patches = self.fetchurl { # https://github.com/golang/mobile/pull/84
url = "https://github.com/golang/mobile/commit/f20e966e05b8f7e06bed500fa0da81cf6ebca307.patch";
sha256 = "sha256-TZ/Yhe8gMRQUZFAs9G5/cf2b9QGtTHRSObBFD5Pbh7Y=";
};
})).override {
src = "/Users/vvlasov/c/mobile";
vendorSha256 = "sha256-TZ/Yhe8gMRQUZFAs9G5/cf2b9QGtTHRSObBFD5Pbh7Y=";
# patches = self.fetchurl { # https://github.com/golang/mobile/pull/84
# url = "https://github.com/golang/mobile/commit/f20e966e05b8f7e06bed500fa0da81cf6ebca307.patch";
# sha256 = "sha256-TZ/Yhe8gMRQUZFAs9G5/cf2b9QGtTHRSObBFD5Pbh7Y=";
# };
})).override rec {
buildGoModule = args: super.buildGoModule ( args // {
src = "/Users/vvlasov/c/mobile";
vendorSha256 = "sha256-C6GD3NMolRIve1siG8wpcQav7ZWTugjce8K22EQDD7M=";
});
# FIXME: No Android SDK packages for aarch64-darwin.
withAndroidPkgs = stdenv.system != "aarch64-darwin";
androidPkgs = self.androidEnvCustom.compose;
Expand Down
3 changes: 3 additions & 0 deletions nix/scripts/shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ config=''
if [[ -n "${STATUS_GO_SRC_OVERRIDE}" ]]; then
config+="status-im.status-go.src-override=\"${STATUS_GO_SRC_OVERRIDE}\";"
fi
if [[ -n "${GOMOBILE_SRC_OVERRIDE}" ]]; then
config+="status-im.status-go.gomobile-src-override=\"${GOMOBILE_SRC_OVERRIDE}\";"
fi
config+="status-im.build-type=\"${BUILD_TYPE}\";"

if [[ -n "$config" ]]; then
Expand Down
44 changes: 43 additions & 1 deletion nix/status-go/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ let

# Source can be changed with a local override from config
source = callPackage ./source.nix { };
nimbusSource = callPackage ./nimbus_source.nix { };

# Params to be set at build time, important for About section and metrics
goBuildParams = {
Expand All @@ -31,14 +32,55 @@ let
"-w" # -w disables DWARF debugging information
];
in rec {
inherit nimbusSource;

mobile = callPackage ./mobile {
inherit meta source goBuildLdFlags;
inherit meta source nimbusSource nimCompiler goBuildLdFlags;
};

library = callPackage ./library {
inherit meta source;
};

nimCompiler = callPackage ./mobile/buildNim.nix {
srcRaw = nimbusSource;
};

liblcproxy-android-arm = callPackage ./mobile/buildNimbus.nix {
srcRaw = nimbusSource;
nimCompiler = nimCompiler;
platform = "android";
arch = "arm";
};

liblcproxy-android-arm64 = callPackage ./mobile/buildNimbus.nix {
srcRaw = nimbusSource;
nimCompiler = nimCompiler;
platform = "android";
arch = "arm64";
};

liblcproxy-android-x86 = callPackage ./mobile/buildNimbus.nix {
srcRaw = nimbusSource;
nimCompiler = nimCompiler;
platform = "android";
arch = "x86";
};

liblcproxy-ios-x86 = callPackage ./mobile/buildNimbus.nix {
srcRaw = nimbusSource;
nimCompiler = nimCompiler;
platform = "ios";
arch = "x86";
};

liblcproxy-ios-arm64 = callPackage ./mobile/buildNimbus.nix {
srcRaw = nimbusSource;
nimCompiler = nimCompiler;
platform = "ios";
arch = "arm64";
};

shell = mkShell {
inputsFrom = [ mobile.android mobile.ios ];
};
Expand Down
16 changes: 12 additions & 4 deletions nix/status-go/mobile/build.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
, androidPkgs, openjdk, gomobile, xcodeWrapper, removeReferencesTo
, meta
, source
, buildNimbusLc
, platform ? "android"
, platformVersion ? "23"
, targets ? [ "android/arm64" "android/arm" ]
Expand All @@ -13,7 +14,14 @@ let
inherit (lib) concatStringsSep optionalString optional;
isIOS = platform == "ios";
isAndroid = platform == "android";
lc = buildNimbusLc {inherit platform targets;};
cgoCflags = "-I" + (builtins.elemAt lc 0);

lcDirs = (builtins.concatStringsSep " " (builtins.map (s: "-L" + s) lc));

goBuildLdFlagsModified =
goBuildLdFlags ++ [("-extldflags \"-lverifproxy " + lcDirs + "\"")];
ldflags = concatStringsSep " " goBuildLdFlagsModified;
in buildGoPackage {
pname = source.repo;
version = "${source.cleanVersion}-${source.shortRev}-${platform}";
Expand All @@ -30,8 +38,6 @@ in buildGoPackage {
++ optional isAndroid openjdk
++ optional isIOS xcodeWrapper;

ldflags = concatStringsSep " " goBuildLdFlags;

ANDROID_HOME = optionalString isAndroid androidPkgs.sdk;

# Ensure XCode is present for iOS, instead of failing at the end of the build.
Expand All @@ -40,11 +46,13 @@ in buildGoPackage {
buildPhase = ''
runHook preBuild
echo -e "\nBuilding $pname for: ${concatStringsSep "," targets}"

echo -e "\n LC dirs: ${lcDirs}"
echo -e "\n ldflags: ${ldflags}"
set -x
export CGO_CFLAGS=\"${cgoCflags}\"
gomobile bind \
${concatStringsSep " " goBuildFlags} \
-ldflags="$ldflags" \
-ldflags ''\'${ldflags}''\' \
-target=${concatStringsSep "," targets} \
${optionalString isAndroid "-androidapi=${platformVersion}" } \
${optionalString isIOS "-iosversion=${platformVersion}" } \
Expand Down
67 changes: 67 additions & 0 deletions nix/status-go/mobile/buildNim.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{ pkgs, stdenv, lib, fetchFromGitHub
# Dependencies
, xcodeWrapper
, srcRaw
, writeScript
, writeTextFile
, androidPkgs
, git
, platform ? "android"
, arch ? "386"
, api ? "29" }:

let
osId = builtins.elemAt (builtins.split "\-" stdenv.hostPlatform.system) 2;
osArch = builtins.elemAt (builtins.split "\-" stdenv.hostPlatform.system) 0;

nimHostOs = if osId == "darwin" then "Darwin"
else if osId == "linux" then "Linux"
else "Windows_NT";

createNimbleLink = writeTextFile {
name = "createNimbleLink.sh";
text = ''
mkdir -p vendor/.nimble/pkgs

curdir=`pwd`
for dir in vendor/*/;
do
baseDirName=`basename ''${dir}`
dirName=vendor/.nimble/pkgs/$baseDirName-\#head
echo $dirName
mkdir -p $dirName

packageDir="''${curdir}/vendor/''${baseDirName}"
if [ -d "''${packageDir}/src" ]; then
packageDir="''${packageDir}/src"
fi
echo "''${packageDir}" > ''${dirName}/''${baseDirName}.nimble-link
echo "''${packageDir}" >> ''${dirName}/''${baseDirName}.nimble-link
done
'';
executable = true;
};

in stdenv.mkDerivation rec {
pname = "nimCompiler";
name = "nimCompiler";
src = srcRaw.src;
#version = lib.strings.substring 0 7 src.rev;
buildInputs = with pkgs; [ wget git clang which tcl curl];

phases = [ "unpackPhase" "buildPhase" "installPhase" ];


buildPhase = ''
${createNimbleLink}
export HOME=$PWD
unset SSL_CERT_FILE
make V=3 CC=clang build-nim
'';

installPhase = ''
mkdir -p $out
cp -r vendor/nimbus-build-system/vendor/Nim/* $out/
'';
}

Loading