2022-05-10 16:09:29 +00:00
|
|
|
{ lib, utils, buildGoPackage
|
|
|
|
, androidPkgs, openjdk, gomobile, xcodeWrapper, removeReferencesTo
|
2022-06-07 18:38:24 +00:00
|
|
|
, meta
|
|
|
|
, source
|
2020-04-23 18:19:12 +00:00
|
|
|
, platform ? "android"
|
2022-06-07 18:38:24 +00:00
|
|
|
, platformVersion ? "23"
|
2022-05-10 16:09:29 +00:00
|
|
|
, targets ? [ "android/arm64" "android/arm" ]
|
|
|
|
, goBuildFlags ? [ ] # Use -v or -x for debugging.
|
2020-04-23 18:19:12 +00:00
|
|
|
, goBuildLdFlags ? [ ]
|
|
|
|
, outputFileName ? "status-go-${source.shortRev}-${platform}.aar" }:
|
|
|
|
|
|
|
|
let
|
2022-06-07 18:38:24 +00:00
|
|
|
inherit (lib) concatStringsSep optionalString optional;
|
2022-11-08 13:17:38 +00:00
|
|
|
isIOS = platform == "ios";
|
|
|
|
isAndroid = platform == "android";
|
|
|
|
|
2022-05-26 08:58:25 +00:00
|
|
|
in buildGoPackage {
|
2020-04-23 18:19:12 +00:00
|
|
|
pname = source.repo;
|
|
|
|
version = "${source.cleanVersion}-${source.shortRev}-${platform}";
|
|
|
|
|
|
|
|
inherit meta;
|
|
|
|
inherit (source) src goPackagePath;
|
|
|
|
|
2022-09-01 11:28:24 +00:00
|
|
|
# Sandbox causes Xcode issues on MacOS. Requires sandbox=relaxed.
|
|
|
|
# https://github.com/status-im/status-mobile/pull/13912
|
2022-11-08 13:17:38 +00:00
|
|
|
__noChroot = isIOS;
|
2022-09-01 11:28:24 +00:00
|
|
|
|
2022-06-07 18:38:24 +00:00
|
|
|
extraSrcPaths = [ gomobile ];
|
2022-05-10 16:09:29 +00:00
|
|
|
nativeBuildInputs = [ gomobile removeReferencesTo ]
|
2022-11-08 13:17:38 +00:00
|
|
|
++ optional isAndroid openjdk
|
|
|
|
++ optional isIOS xcodeWrapper;
|
2020-04-23 18:19:12 +00:00
|
|
|
|
2022-08-04 08:20:44 +00:00
|
|
|
ldflags = concatStringsSep " " goBuildLdFlags;
|
2020-04-23 18:19:12 +00:00
|
|
|
|
2022-11-08 13:17:38 +00:00
|
|
|
ANDROID_HOME = optionalString isAndroid androidPkgs.sdk;
|
2022-03-02 14:30:27 +00:00
|
|
|
|
2022-06-07 18:38:24 +00:00
|
|
|
# Ensure XCode is present for iOS, instead of failing at the end of the build.
|
2022-11-08 13:17:38 +00:00
|
|
|
preConfigure = optionalString isIOS utils.enforceXCodeAvailable;
|
2022-06-07 18:38:24 +00:00
|
|
|
|
|
|
|
buildPhase = ''
|
2020-04-23 18:19:12 +00:00
|
|
|
runHook preBuild
|
2022-05-10 16:09:29 +00:00
|
|
|
echo -e "\nBuilding $pname for: ${concatStringsSep "," targets}"
|
2020-04-23 18:19:12 +00:00
|
|
|
|
2022-11-08 13:17:38 +00:00
|
|
|
set -x
|
2022-06-07 18:38:24 +00:00
|
|
|
gomobile bind \
|
2020-04-23 18:19:12 +00:00
|
|
|
${concatStringsSep " " goBuildFlags} \
|
2022-06-07 18:38:24 +00:00
|
|
|
-ldflags="$ldflags" \
|
2022-05-10 16:09:29 +00:00
|
|
|
-target=${concatStringsSep "," targets} \
|
2022-11-08 13:17:38 +00:00
|
|
|
${optionalString isAndroid "-androidapi=${platformVersion}" } \
|
|
|
|
${optionalString isIOS "-iosversion=${platformVersion}" } \
|
|
|
|
-tags='${optionalString isIOS "nowatchdog"} gowaku_skip_migrations' \
|
2020-04-23 18:19:12 +00:00
|
|
|
-o ${outputFileName} \
|
|
|
|
${source.goPackagePath}/mobile
|
|
|
|
|
|
|
|
runHook postBuild
|
|
|
|
'';
|
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir -p $out
|
2022-06-07 18:38:24 +00:00
|
|
|
cp -r ${outputFileName} $out/
|
2020-04-23 18:19:12 +00:00
|
|
|
'';
|
2022-05-10 16:09:29 +00:00
|
|
|
|
|
|
|
# Drop govers from disallowedReferences.
|
|
|
|
dontRenameImports = true;
|
|
|
|
# Replace hardcoded paths to go package in /nix/store.
|
2022-11-08 13:17:38 +00:00
|
|
|
preFixup = optionalString isIOS ''
|
2022-05-10 16:09:29 +00:00
|
|
|
find $out -type f -exec \
|
|
|
|
remove-references-to -t $disallowedReferences '{}' + || true
|
|
|
|
'';
|
2020-04-23 18:19:12 +00:00
|
|
|
}
|