diff --git a/nix/androidsdk.nix b/nix/androidsdk.nix new file mode 100644 index 00000000..1820abb2 --- /dev/null +++ b/nix/androidsdk.nix @@ -0,0 +1,30 @@ +{ stdenv, androidenv }: + +# The "android-sdk-license" license is accepted +# by setting android_sdk.accept_license = true. +androidenv.composeAndroidPackages { + toolsVersion = "26.1.1"; + platformToolsVersion = "31.0.3"; + buildToolsVersions = [ "31.0.0" ]; + platformVersions = [ "30" ]; + cmakeVersions = [ "3.18.1" ]; + ndkVersion = "22.1.7171670"; + includeNDK = true; + includeExtras = [ + "extras;android;m2repository" + "extras;google;m2repository" + ]; +} +# This derivation simply symlinks some stuff to get +# shorter paths as libexec/android-sdk is quite the mouthful. +# With this you can just do `androidPkgs.sdk` and `androidPkgs.ndk`. +#stdenv.mkDerivation { +# name = "${compose.androidsdk.name}-mod"; +# phases = [ "symlinkPhase" ]; +# outputs = [ "out" "sdk" "ndk" ]; +# symlinkPhase = '' +# ln -s ${compose.androidsdk} $out +# ln -s ${compose.androidsdk}/libexec/android-sdk $sdk +# ln -s ${compose.androidsdk}/libexec/android-sdk/ndk-bundle $ndk +# ''; +#} diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 00000000..35fb95d6 --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,5 @@ +{ pkgs ? import ../../nixpkgs { + config.android_sdk.accept_license = true; +} }: + +pkgs.callPackage ./mobile.nix { } diff --git a/nix/mobile.nix b/nix/mobile.nix new file mode 100644 index 00000000..76fc0865 --- /dev/null +++ b/nix/mobile.nix @@ -0,0 +1,50 @@ +{ lib, pkgs, callPackage, buildGoModule }: + +let + androidPkgs = pkgs.androidenv.composeAndroidPackages { + includeNDK = true; + ndkVersion = "22.1.7171670"; + }; + androidSdk = androidPkgs.androidsdk; + gomobile = pkgs.gomobile.override { inherit androidPkgs; }; +in buildGoModule { + pname = "go-waku"; + version = "devel"; + vendorSha256 = "sha256-+W5PnVmD4oPh3a8Ik9Xn3inCI8shqEsdlkG/d6PQntk="; + GIT_COMMIT = "TODO"; + doCheck = false; + + src = ./..; + + extraSrcPaths = [ gomobile ]; + nativeBuildInputs = [ gomobile pkgs.openjdk8 ]; + + # We can't symlink gomobile src in vendor created by buildGoModule. + proxyVendor = true; + + ANDROID_HOME = "${androidSdk}/libexec/android-sdk"; + ANDROID_NDK_ROOT = "${androidSdk}/libexec/android-sdk/ndk-bundle"; + ANDROID_NDK_HOME = "${androidSdk}/libexec/android-sdk/ndk-bundle"; + #GOMOBILE = pkgs.gomobile; + #GOHOSTARCH = "amd64"; + #GO111MODULE = "off"; + + buildPhase = '' + gomobile bind -x \ + -target=android/arm64 \ + -androidapi=23 \ + -ldflags="-s -w" \ + -o ./build/lib/Gowaku.xcframework \ + ./mobile + ''; + + #buildPhase = '' + # echo $ANDROID_HOME + # gomobile bind -x \ + # -target=ios \ + # -iosversion=8.0 \ + # -ldflags="-s -w" \ + # -o ./build/lib/Gowaku.xcframework \ + # ./mobile + #''; +}