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-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-06-07 18:38:24 +00:00
|
|
|
extraSrcPaths = [ gomobile ];
|
2022-05-10 16:09:29 +00:00
|
|
|
nativeBuildInputs = [ gomobile removeReferencesTo ]
|
2020-04-23 18:19:12 +00:00
|
|
|
++ optional (platform == "android") openjdk
|
2022-06-07 18:38:24 +00:00
|
|
|
++ optional (platform == "ios") 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-06-07 18:38:24 +00:00
|
|
|
ANDROID_HOME = optionalString (platform == "android") 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.
|
|
|
|
preConfigure = optionalString (platform == "ios") utils.enforceXCodeAvailable;
|
|
|
|
|
|
|
|
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-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-06-07 18:38:24 +00:00
|
|
|
${optionalString (platform == "android") "-androidapi=${platformVersion}"} \
|
|
|
|
${optionalString (platform == "ios") "-iosversion=${platformVersion}"} \
|
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.
|
|
|
|
preFixup = optionalString (platform == "ios") ''
|
|
|
|
find $out -type f -exec \
|
|
|
|
remove-references-to -t $disallowedReferences '{}' + || true
|
|
|
|
'';
|
2020-04-23 18:19:12 +00:00
|
|
|
}
|