Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nix: prepare targets with rust-overlay #57

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
76 changes: 62 additions & 14 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -1,20 +1,64 @@
{ pkgs ? import <nixpkgs> { }
, 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 <nixpkgs>
{
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 ];
graphicLibs = lib.makeLibraryPath [
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXi
libglvnd
vulkan-loader
vulkan-validation-layers
libxkbcommon

wayland
];
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"
Copy link
Contributor Author

@hellodword hellodword May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jb55 could you review this on the darwin and aarch64 linux? I'm simply following the rustup target list, I guess they're in the right way but I'm not sure

      (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"
      ])

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can test on darwin, I think @kernelkind has an aarch64 linux machine.

]) ++
(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
Expand All @@ -37,21 +81,25 @@ mkShell ({

} // (
lib.optionalAttrs (!stdenv.isDarwin) {
LD_LIBRARY_PATH = "${x11libs}";
LD_LIBRARY_PATH = "${graphicLibs}";
}
) // (
lib.optionalAttrs use_android (
let
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}";
Expand Down
Loading