From ab1e8d956c33320ffe77a3b69d1141c07106c036 Mon Sep 17 00:00:00 2001 From: hellodword <46193371+hellodword@users.noreply.github.com> Date: Thu, 16 May 2024 04:34:49 +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 | 61 ++++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 3f5edc7..5a022fb 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 ecf86ac..6bb1d75 100644 --- a/shell.nix +++ b/shell.nix @@ -1,20 +1,53 @@ -{ 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.isLinux && !stdenv.isx86_64) [ + "aarch64-unknown-linux-gnu" + ]) ++ + (lib.optionals (stdenv.isDarwin && stdenv.isx86_64) [ + "x86_64-apple-darwin" + ]) ++ + (lib.optionals (stdenv.isDarwin && !stdenv.isx86_64) [ + "aarch64-apple-darwin" + ]) + ; + }; in mkShell ({ nativeBuildInputs = [ + rustc #cargo-udeps #cargo-edit #cargo-watch - rustup - rustfmt + # rustup + # rustfmt libiconv pkg-config #cmake @@ -45,13 +78,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}";