Build Android status-go mobile library on macOS
Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
parent
7b309d4875
commit
fe80c7841e
|
@ -3,22 +3,65 @@
|
||||||
with stdenv;
|
with stdenv;
|
||||||
|
|
||||||
let
|
let
|
||||||
gomobile = pkgs.callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit composeXcodeWrapper xcodewrapperArgs; };
|
gomobile = pkgs.callPackage ./gomobile { inherit (androidPkgs) platform-tools; inherit composeXcodeWrapper xcodewrapperArgs; };
|
||||||
version = lib.fileContents ../../STATUS_GO_VERSION; # TODO: Simplify this path search with lib.locateDominatingFile
|
version = lib.fileContents ../../STATUS_GO_VERSION; # TODO: Simplify this path search with lib.locateDominatingFile
|
||||||
owner = lib.fileContents ../../STATUS_GO_OWNER;
|
owner = lib.fileContents ../../STATUS_GO_OWNER;
|
||||||
repo = "status-go";
|
repo = "status-go";
|
||||||
goPackagePath = "github.com/${owner}/${repo}";
|
goPackagePath = "github.com/${owner}/${repo}";
|
||||||
rev = version;
|
rev = version;
|
||||||
sha256 = lib.fileContents ../../STATUS_GO_SHA256;
|
sha256 = lib.fileContents ../../STATUS_GO_SHA256;
|
||||||
mobileTarget = if isDarwin then "ios" else "android";
|
mobileConfigs = {
|
||||||
mobileOutputFileName = if isDarwin then "Statusgo.framework" else "status-go-${version}.aar";
|
android = {
|
||||||
desktopOutputFileName = "libstatus.a";
|
name = "android";
|
||||||
destopSystem = hostPlatform.system;
|
outputFileName = "status-go-${version}.aar";
|
||||||
removeReferences = [ go ];
|
envVars = ''
|
||||||
removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}'';
|
ANDROID_HOME=${androidPkgs.androidsdk}/libexec/android-sdk \
|
||||||
goBuildFlags = "-v";
|
ANDROID_NDK_HOME="${androidPkgs.ndk-bundle}/libexec/android-sdk/ndk-bundle" \
|
||||||
goBuildLdFlags = "-ldflags=-s";
|
'';
|
||||||
xcodeWrapper = composeXcodeWrapper xcodewrapperArgs;
|
gomobileExtraFlags = "";
|
||||||
|
};
|
||||||
|
ios = {
|
||||||
|
name = "ios";
|
||||||
|
outputFileName = "Statusgo.framework";
|
||||||
|
envVars = "";
|
||||||
|
gomobileExtraFlags = "-iosversion=8.0";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
hostConfigs = {
|
||||||
|
darwin = {
|
||||||
|
mobileTargets = [ mobileConfigs.android mobileConfigs.ios ];
|
||||||
|
desktopOutputFileName = "libstatus.a";
|
||||||
|
};
|
||||||
|
linux = {
|
||||||
|
mobileTargets = [ mobileConfigs.android ];
|
||||||
|
desktopOutputFileName = "libstatus.a";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
currentHostConfig = if isDarwin then hostConfigs.darwin else hostConfigs.linux;
|
||||||
|
currentHostMobileTargets = currentHostConfig.mobileTargets;
|
||||||
|
mobileBuildScript = lib.concatMapStrings (target: ''
|
||||||
|
echo
|
||||||
|
echo "Building mobile library for ${target.name}"
|
||||||
|
echo
|
||||||
|
GOPATH=${gomobile.dev}:$GOPATH \
|
||||||
|
PATH=${lib.makeBinPath [ gomobile.bin openjdk ]}:$PATH \
|
||||||
|
${target.envVars} \
|
||||||
|
gomobile bind ${goBuildFlags} -target=${target.name} ${target.gomobileExtraFlags} \
|
||||||
|
-o ${target.outputFileName} \
|
||||||
|
${goBuildLdFlags} \
|
||||||
|
${goPackagePath}/mobile
|
||||||
|
'') currentHostMobileTargets;
|
||||||
|
mobileInstallScript = lib.concatMapStrings (target: ''
|
||||||
|
mkdir -p $out/lib/${target.name}
|
||||||
|
mv ${target.outputFileName} $out/lib/${target.name}/
|
||||||
|
'') currentHostMobileTargets;
|
||||||
|
desktopOutputFileName = currentHostConfig.desktopOutputFileName;
|
||||||
|
desktopSystem = hostPlatform.system;
|
||||||
|
removeReferences = [ go ];
|
||||||
|
removeExpr = refs: ''remove-references-to ${lib.concatMapStrings (ref: " -t ${ref}") refs}'';
|
||||||
|
goBuildFlags = "-v";
|
||||||
|
goBuildLdFlags = "-ldflags=-s";
|
||||||
|
xcodeWrapper = composeXcodeWrapper xcodewrapperArgs;
|
||||||
|
|
||||||
in buildGoPackage rec {
|
in buildGoPackage rec {
|
||||||
inherit goPackagePath version rev;
|
inherit goPackagePath version rev;
|
||||||
|
@ -80,17 +123,7 @@ in buildGoPackage rec {
|
||||||
|
|
||||||
# Build mobile libraries
|
# Build mobile libraries
|
||||||
# TODO: Manage to pass -s -w to -ldflags. Seems to only accept a single flag
|
# TODO: Manage to pass -s -w to -ldflags. Seems to only accept a single flag
|
||||||
echo
|
${mobileBuildScript}
|
||||||
echo "Building mobile library"
|
|
||||||
echo
|
|
||||||
ANDROID_HOME=${androidPkgs.androidsdk}/libexec/android-sdk \
|
|
||||||
ANDROID_NDK_HOME="${androidPkgs.ndk-bundle}/libexec/android-sdk/ndk-bundle" \
|
|
||||||
GOPATH=${gomobile.dev}:$GOPATH \
|
|
||||||
PATH=${lib.makeBinPath [ gomobile.bin openjdk ]}:$PATH \
|
|
||||||
gomobile bind ${goBuildFlags} -target=${mobileTarget} -iosversion=8.0 \
|
|
||||||
-o ${mobileOutputFileName} \
|
|
||||||
${goBuildLdFlags} \
|
|
||||||
${goPackagePath}/mobile
|
|
||||||
|
|
||||||
runHook postBuild
|
runHook postBuild
|
||||||
'';
|
'';
|
||||||
|
@ -98,12 +131,11 @@ in buildGoPackage rec {
|
||||||
postInstall = ''
|
postInstall = ''
|
||||||
mkdir -p $bin
|
mkdir -p $bin
|
||||||
cp -r "$NIX_BUILD_TOP/go/bin/" $bin
|
cp -r "$NIX_BUILD_TOP/go/bin/" $bin
|
||||||
|
|
||||||
|
${mobileInstallScript}
|
||||||
|
|
||||||
mkdir -p $out/lib/${mobileTarget}
|
mkdir -p $out/lib/${desktopSystem} $out/include
|
||||||
mv ${mobileOutputFileName} $out/lib/${mobileTarget}/
|
mv $out/${desktopOutputFileName} $out/lib/${desktopSystem}
|
||||||
|
|
||||||
mkdir -p $out/lib/${destopSystem} $out/include
|
|
||||||
mv $out/${desktopOutputFileName} $out/lib/${destopSystem}
|
|
||||||
mv $out/libstatus.h $out/include
|
mv $out/libstatus.h $out/include
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue