2023-06-27 11:45:21 +00:00
|
|
|
{ callPackage, lib, buildGoPackage
|
2022-05-10 16:09:29 +00:00
|
|
|
, 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
|
2024-09-20 09:31:42 +00:00
|
|
|
inherit (lib) concatStringsSep optionalString optional splitString;
|
2022-11-08 13:17:38 +00:00
|
|
|
isIOS = platform == "ios";
|
|
|
|
isAndroid = platform == "android";
|
2023-06-27 11:45:21 +00:00
|
|
|
enforceXCodeAvailable = callPackage ./enforceXCodeAvailable.nix { };
|
2022-11-08 13:17:38 +00:00
|
|
|
|
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
|
|
|
|
2024-09-20 09:31:42 +00:00
|
|
|
ldflags = 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.
|
2023-06-27 11:45:21 +00:00
|
|
|
preConfigure = optionalString isIOS enforceXCodeAvailable;
|
2022-06-07 18:38:24 +00:00
|
|
|
|
2024-04-26 12:34:04 +00:00
|
|
|
# https://pkg.go.dev/net#hdr-Name_Resolution
|
|
|
|
# https://github.com/status-im/status-mobile/issues/19736
|
|
|
|
# https://github.com/status-im/status-mobile/issues/19581
|
|
|
|
# TODO: try removing when go is upgraded to 1.22
|
|
|
|
GODEBUG = "netdns=cgo+2";
|
|
|
|
|
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}"
|
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}" } \
|
2023-09-20 08:45:32 +00:00
|
|
|
-tags='${optionalString isIOS "nowatchdog"} gowaku_skip_migrations gowaku_no_rln' \
|
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
|
|
|
}
|