Jakub Sokołowski 42fb40476c
nix: reafactoring of status-go builds
Changes:
- Fixed `nix/status-go/desktop` builds
- Dropped nimbus wrapper for `status-go` for now
- Split `status-go` builds into subfolders: `mobile`, `desktop`
- Fixed shells for desktop builds: `linux`,`macos`,`windows`
- Added `make status-go-*` targets for building them
- Moved source management to `nix/status-go/source.nix`
- Moved `nix/status-go/build.nix` into `nix/status-go/mobile`
- Moved `nix/desktop/cmake/qtkeychain` to `nix/pkgs/qtkeychain-src`
- Moved `nix/desktop/linux/linuxdeployqt` to `nix/pkgs`
- Moved `nix/desktop/linux/appimagekit` to `nix/pkgs`
- Dropped `nix/tools/mkShell.nix` since it did almost nothing
- Dropped `nix/desktop/cmake/snorenotify` since it's broken
- Moved setup from `nix/tools/mkShell.nix` to `nix/shells.nix`
- Simplified `nix/mobile/ios/status-go-shell.nix`
- Simplified `nix/status-go/default.nix`
- Updated the `nix/DETAILS.md` and `nix/README.md`
- Moved known issues to `nix/KNOWN_ISSUES.md`
- Improved output of `nix/scripts/build.sh`

Signed-off-by: Jakub Sokołowski <jakub@status.im>
2020-05-04 20:55:07 +02:00

92 lines
2.7 KiB
Nix

{ lib, stdenv, utils, callPackage, buildGoPackage
, go, androidPkgs, openjdk, gomobile, xcodeWrapper
# object with source attributes
, meta, source
, platform ? "android"
, architectures ? [ "arm64" "arm" "x86" ]
, goBuildFlags ? [ ]
, goBuildLdFlags ? [ ]
, outputFileName ? "status-go-${source.shortRev}-${platform}.aar" }:
let
inherit (lib)
concatStrings concatStringsSep concatMapStrings optionalString
getAttr attrValues makeBinPath optional;
removeReferences = [ go ];
removeExpr = refs: ''remove-references-to ${concatMapStrings (ref: " -t ${ref}") refs}'';
# formatted for use with -target
targetArchs = map (a: "${platform}/${a}") architectures;
in buildGoPackage {
pname = source.repo;
version = "${source.cleanVersion}-${source.shortRev}-${platform}";
inherit meta;
inherit (source) src goPackagePath;
nativeBuildInputs = [ gomobile ]
++ optional (platform == "android") openjdk
++ optional stdenv.isDarwin xcodeWrapper;
# Fixes Cgo related build failures (see https://github.com/NixOS/nixpkgs/issues/25959 )
hardeningDisable = [ "fortify" ];
# Ensure XCode is present, instead of failing at the end of the build
preConfigure = optionalString stdenv.isDarwin utils.enforceXCodeAvailable;
# Build mobile libraries
preBuild = let
NIX_GOWORKDIR = "$NIX_BUILD_TOP/go-build";
in ''
mkdir ${NIX_GOWORKDIR}
export GO111MODULE=off
export GOPATH=${gomobile.dev}:$GOPATH
export NIX_GOWORKDIR=${NIX_GOWORKDIR}
'' + optionalString (platform == "android") ''
export ANDROID_HOME=${androidPkgs}
export ANDROID_NDK_HOME=${androidPkgs}/ndk-bundle
export PATH="${makeBinPath [ openjdk ]}:$PATH"
'';
# Build the Go library using gomobile for each of the configured platforms
buildPhase = let
ldFlags = [ "-extldflags=-Wl,--allow-multiple-definition" ] ++ goBuildLdFlags;
CGO_LDFLAGS = concatStringsSep " " ldFlags;
in ''
runHook preBuild
runHook renameImports
echo -e "\nBuilding for targets: ${concatStringsSep "," targetArchs}\n"
${gomobile}/bin/gomobile bind \
-target=${concatStringsSep "," targetArchs} \
-ldflags="${CGO_LDFLAGS}" \
${optionalString (platform == "android") "-androidapi 23"} \
${optionalString (platform == "ios") "-iosversion=8.0"} \
${concatStringsSep " " goBuildFlags} \
-o ${outputFileName} \
${source.goPackagePath}/mobile
rm -rf $NIX_GOWORKDIR
runHook postBuild
'';
# replace hardcoded paths to go package in /nix/store, otherwise Nix will fail the build
fixupPhase = ''
find $out -type f -exec ${removeExpr removeReferences} '{}' + || true
'';
installPhase = ''
mkdir -p $out
mv ${outputFileName} $out/
'';
outputs = [ "out" ];
}