diff --git a/flake.nix b/flake.nix --- a/flake.nix +++ b/flake.nix @@ -20,6 +20,7 @@ # package set pkgsForSystem = system: import nixpkgs { inherit overlays system; + config.android_sdk.accept_license = true; }; # utils.lib.eachSystem helps create a result set of expected flake outputs diff --git a/native/android/app/CMakeLists.txt b/native/android/app/CMakeLists.txt --- a/native/android/app/CMakeLists.txt +++ b/native/android/app/CMakeLists.txt @@ -15,7 +15,10 @@ set(PACKAGE_NAME "comm_jni_module") -find_package(fbjni REQUIRED CONFIG) +find_package(fbjni + NAMES fbjni fbjniLibrary + REQUIRED CONFIG +) set(BUILD_TESTING OFF) set(HAVE_SYMBOLIZE OFF) @@ -41,6 +44,9 @@ add_subdirectory(./build/third-party-ndk/glog/glog-${GLOG_VERSION}/) add_subdirectory(../../node_modules/olm ./build) +# Common Comm Cpp projects +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../../../native/cpp ${CMAKE_CURRENT_BINARY_DIR}/cpp) + include_directories( ../../node_modules/react-native/React ../../node_modules/react-native/React/Base @@ -55,9 +61,6 @@ # SQLCipher amalgamation ../../node_modules/@commapp/sqlcipher-amalgamation/src - # SQLite ORM - ../../cpp/lib/sqlite_orm - # symlinked React Native headers ../headers @@ -102,7 +105,17 @@ ../../node_modules/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModule.cpp ../../node_modules/react-native/ReactCommon/react/nativemodule/core/ReactCommon/LongLivedObject.cpp ../../node_modules/react-native/ReactCommon/react/nativemodule/core/ReactCommon/TurboModuleUtils.cpp - + + # Comm + comm-modules + comm-databasemanagers + comm-tools + comm-grpc + comm-backup + comm-blob + comm-tunnelbroker + comm-sqlite-orm + # SQLCipher ${SQLCIPHER} diff --git a/nix/android-dev-env.nix b/nix/android-dev-env.nix new file mode 100644 --- /dev/null +++ b/nix/android-dev-env.nix @@ -0,0 +1,33 @@ +{ androidenv }: + +androidenv.composeAndroidPackages { + toolsVersion = "26.1.1"; + platformToolsVersion = "33.0.1"; + buildToolsVersions = [ "31.0.0" ]; + includeEmulator = false; + emulatorVersion = "30.9.0"; + platformVersions = [ "30" ]; + includeSources = false; + includeSystemImages = false; + systemImageTypes = [ "google_apis_playstore" ]; + abiVersions = [ "armeabi-v7a" "arm64-v8a" ]; + cmakeVersions = [ "3.10.2" ]; + includeNDK = true; + ndkVersions = ["22.0.7026061"]; + useGoogleAPIs = false; + useGoogleTVAddOns = false; + includeExtras = [ + "extras;google;gcm" + ]; + + extraLicenses = [ + "android-googletv-license" + "android-sdk-preview-license" + "android-sdk-arm-dbt-license" + "android-sdk-preview-license" + "google-gdk-license" + "intel-android-extra-license" + "intel-android-sysimage-license" + "mips-android-sysimage-license" + ]; +} diff --git a/nix/dev-shell.nix b/nix/dev-shell.nix --- a/nix/dev-shell.nix +++ b/nix/dev-shell.nix @@ -1,6 +1,7 @@ { mkShell , stdenv , lib +, androidDevEnv , amqp-cpp , arcanist , boost @@ -11,11 +12,13 @@ , fbjni , folly , fmt +, glog , grpc , libiconv , libuv , nodejs-16_x , olm +, openjdk8 , openssl , pkg-config , protobuf_3_15_cmake @@ -25,6 +28,7 @@ , watchman , rustfmt , yarn +, zlib }: mkShell { @@ -68,6 +72,10 @@ olm # needed for CryptoTools sqlite # needed for sqlite_orm openssl # needed for grpc + ] ++ lib.optionals stdenv.isx86_64 [ + # aarch64-darwin tarballs are not available + androidDevEnv.androidsdk + glog # android ] ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ CoreFoundation CoreServices @@ -75,12 +83,25 @@ libiconv # identity service ]); + # Used by gradle + JAVA_HOME = openjdk8.passthru.home; + # shell commands to be ran upon entering shell shellHook = '' if [[ "$OSTYPE" == 'linux'* ]]; then export MYSQL_UNIX_PORT=''${XDG_RUNTIME_DIR:-/run/user/$UID}/mysql-socket/mysql.sock + export ANDROID_SDK_ROOT=''${ANDROID_SDK_ROOT:-$HOME/Android/Sdk} + fi + + if [ -f /etc/NIXOS ]; then + # allow for impurely downloaded android ndk tools to be used on NixOS + export LD_LIBRARY_PATH=${lib.makeLibraryPath [ stdenv.cc.cc.lib zlib ]} fi echo "Welcome to Comm dev environment! :)" + '' + lib.optionalString stdenv.isx86_64 '' + #export ANDROID_SDK_ROOT=${androidDevEnv.androidsdk}/libexec/android-sdk/ ''; +} // lib.optionalAttrs stdenv.isx86_64 { + ANDROID_SDK_ROOT = androidDevEnv.androidsdk; } diff --git a/nix/fbjni.nix b/nix/fbjni.nix --- a/nix/fbjni.nix +++ b/nix/fbjni.nix @@ -33,6 +33,7 @@ # They install the target export in the wrong directory postInstall = '' mv $out/share/cmake $out/lib/cmake + rm -r $out/share ''; meta = with lib; { diff --git a/nix/overlay.nix b/nix/overlay.nix --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -13,6 +13,8 @@ # add packages meant for just this repository amqp-cpp = prev.callPackage ./amqp-cpp.nix { }; + androidDevEnv = prev.callPackage ./android-dev-env.nix { }; + protobuf_3_15_cmake = prev.callPackage ./protobuf_3_15.nix { }; comm-grpc = final.callPackage ./comm-grpc.nix { }; @@ -40,4 +42,11 @@ }); fbjni = prev.callPackage ./fbjni.nix { }; + + # Android ecosystem expects to be to available at `$out/lib` + openjdk8 = prev.openjdk8.overrideAttrs(_: { + preFixup = '' + ln -s $out/lib/openjdk/lib/* $out/lib + ''; + }); } diff --git a/nix/tunnelbroker.nix b/nix/tunnelbroker.nix new file mode 100644 --- /dev/null +++ b/nix/tunnelbroker.nix @@ -0,0 +1,54 @@ +{ lib +, stdenv +, fetchFromGitHub +, amqp-cpp +, aws-sdk-cpp +, cmake +, folly +, fmt +, pkg-config +, libuv +, cryptopp +, protobuf_3_15_cmake +, grpc +, glog +, boost17x +}: + +stdenv.mkDerivation rec { + pname = "tunnelbroker"; + version = "0.0.1"; + + # needs access to native/cpp/CommonCpp/grpc + # so we have to capture the top-level directory + src = ../.; + + prePatch = '' + cd services/tunnelbroker + ''; + + nativeBuildInputs = [ + cmake + pkg-config + ]; + + buildInputs = [ + amqp-cpp + aws-sdk-cpp + boost17x + libuv + cryptopp + protobuf_3_15_cmake + folly + fmt + grpc + glog + ]; + + # TODO: fix aws sdk installation assumptions, make assumption that include shares same prefix as lib + cmakeFlags = [ + "-DAWSSDK_DEFAULT_ROOT_DIR=" + "-DAWSSDK_INSTALL_INCLUDEDIR=${lib.getDev aws-sdk-cpp}/include" + "-DAWSSDK_CORE_HEADER_FILE=${lib.getDev aws-sdk-cpp}/include/aws/core/Aws.h" + ]; +}