From 753609275ffba780c9679e90e055057b1965e765 Mon Sep 17 00:00:00 2001 From: hellodword <46193371+hellodword@users.noreply.github.com> Date: Thu, 16 May 2024 03:07:36 +0000 Subject: [PATCH] nix: prepare targets with rust-overlay pre-install the system-images add doc of using avd without android-studio --- README.md | 12 ++++++++++++ shell.nix | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3f5edc70..5a022fb1 100644 --- a/README.md +++ b/README.md @@ -60,11 +60,23 @@ $ cargo apk run --release ## Android Emulator +With Android Studio: + - Install [Android Studio](https://developer.android.com/studio) - Open 'Device Manager' in Android Studio - Add a new device with API level `34` and ABI `arm64-v8a` (even though the app uses 30, the 30 emulator can't find the vulkan adapter, but 34 works fine) - Start up the emulator +Without Android Studio: + +```sh +# create emulator +avdmanager create avd -k 'system-images;android-34;google_apis;arm64-v8a' -n notedeck + +# start up the emulator +env ANDROID_EMULATOR_WAIT_TIME_BEFORE_KILL=999 emulator -avd notedeck +``` + while the emulator is running, run: ```bash diff --git a/shell.nix b/shell.nix index ecf86ac9..35a7eeae 100644 --- a/shell.nix +++ b/shell.nix @@ -1,20 +1,46 @@ -{ pkgs ? import { } -, android ? "https://github.com/tadfisher/android-nixpkgs/archive/refs/tags/2024-04-02.tar.gz" +{ android ? "https://github.com/tadfisher/android-nixpkgs/archive/refs/tags/2024-04-02.tar.gz" , use_android ? true , android_emulator ? false }: -with pkgs; +with import +{ + overlays = [ + (import (builtins.fetchTarball { + url = "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"; + })) + ]; + config = { + android_sdk.accept_license = use_android; + allowUnfree = use_android; + }; +}; let x11libs = lib.makeLibraryPath [ xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi libglvnd vulkan-loader vulkan-validation-layers libxkbcommon ]; + rustc = (rust-bin.fromRustupToolchainFile ./rust-toolchain).override { + targets = [ ] ++ + (lib.optionals (stdenv.isLinux && use_android) [ + "aarch64-linux-android" + ]) ++ + (lib.optionals (stdenv.isLinux && stdenv.isx86_64 && use_android && android_emulator) [ + "x86_64-linux-android" + ]) ++ + (lib.optionals (stdenv.isLinux && stdenv.isx86_64) [ + "x86_64-unknown-linux-gnu" + ]) ++ + (lib.optionals stdenv.isDarwin [ + # TODO + ]); + }; in mkShell ({ nativeBuildInputs = [ + rustc #cargo-udeps #cargo-edit #cargo-watch - rustup - rustfmt + # rustup + # rustfmt libiconv pkg-config #cmake @@ -45,13 +71,17 @@ mkShell ({ android-nixpkgs = callPackage (fetchTarball android) { }; ndk-version = "24.0.8215888"; - android-sdk = android-nixpkgs.sdk (sdkPkgs: with sdkPkgs; [ - cmdline-tools-latest - build-tools-34-0-0 - platform-tools - platforms-android-30 - ndk-24-0-8215888 - ] ++ lib.optional android_emulator [ emulator ]); + android-sdk = android-nixpkgs.sdk + (sdkPkgs: with sdkPkgs; [ + cmdline-tools-latest + build-tools-34-0-0 + platform-tools + platforms-android-30 + ndk-24-0-8215888 + ] ++ + (lib.optionals android_emulator [ emulator ]) ++ + (lib.optionals (android_emulator && stdenv.isx86_64) [ system-images-android-34-google-apis-x86-64 ]) ++ + (lib.optionals (android_emulator && !stdenv.isx86_64) [ system-images-android-34-google-apis-arm64-v8a ])); android-sdk-path = "${android-sdk.out}/share/android-sdk"; android-ndk-path = "${android-sdk-path}/ndk/${ndk-version}";