Skip to content

Commit

Permalink
feat(rust): support compilation for Android
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Volosatovs <[email protected]>
  • Loading branch information
rvolosatovs committed Sep 8, 2023
1 parent bbdb749 commit 73cc790
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:
test-bin: file ./result/bin/rust-hello
test-oci: docker load < ./result

- package: rust-hello-aarch64-linux-android
test-bin: file ./result/bin/rust-hello
test-oci: docker load < ./result

- package: rust-hello-aarch64-unknown-linux-musl
test-bin: nix shell --inputs-from . 'nixpkgs#qemu' -c qemu-aarch64 ./result/bin/rust-hello
test-oci: docker load < ./result
Expand Down Expand Up @@ -64,6 +68,10 @@ jobs:
test-bin: nix shell --inputs-from . 'nixpkgs#qemu' -c qemu-aarch64 ./result/bin/rust-hello
test-oci: docker load < ./result

- package: rust-hello-debug-aarch64-linux-android
test-bin: file ./result/bin/rust-hello
test-oci: docker load < ./result

- package: rust-hello-debug-armv7-unknown-linux-musleabihf
test-bin: nix shell --inputs-from . 'nixpkgs#qemu' -c qemu-arm ./result/bin/rust-hello
test-oci: docker load < ./result
Expand Down Expand Up @@ -132,6 +140,9 @@ jobs:
- package: rust-complex-aarch64-apple-darwin
test-bin: file ./result/bin/foo

- package: rust-complex-aarch64-linux-android
test-bin: file ./result/bin/foo

- package: rust-complex-aarch64-unknown-linux-musl
test-bin: nix shell --inputs-from . 'nixpkgs#qemu' -c qemu-aarch64 ./result/bin/foo

Expand All @@ -154,6 +165,9 @@ jobs:
- package: rust-complex-debug-aarch64-apple-darwin
test-bin: file ./result/bin/foo

- package: rust-complex-debug-aarch64-linux-android
test-bin: file ./result/bin/foo

- package: rust-complex-debug-aarch64-unknown-linux-musl
test-bin: nix shell --inputs-from . 'nixpkgs#qemu' -c qemu-aarch64 ./result/bin/foo

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Simple, yet extensible, batteries-included Nix flake bootstrapping library for r
- `aarch64-darwin` -> `x86_64-pc-windows-gnu`

- `aarch64-linux` -> `aarch64-apple-darwin`
- `aarch64-linux` -> `aarch64-linux-android`
- `aarch64-linux` -> `aarch64-linux-musl`
- `aarch64-linux` -> `armv7-unknown-linux-musleabihf`
- `aarch64-linux` -> `wasm32-wasi`
Expand All @@ -55,6 +56,7 @@ Simple, yet extensible, batteries-included Nix flake bootstrapping library for r
- `x86_64-darwin` -> `x86_64-pc-windows-gnu`

- `x86_64-linux` -> `aarch64-apple-darwin`
- `x86_64-linux` -> `aarch64-linux-android`
- `x86_64-linux` -> `aarch64-linux-musl`
- `x86_64-linux` -> `armv7-unknown-linux-musleabihf`
- `x86_64-linux` -> `wasm32-wasi`
Expand Down
1 change: 1 addition & 0 deletions lib/rust/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ in {
];

targets.aarch64-apple-darwin = "aarch64-apple-darwin";
targets.aarch64-linux-android = "aarch64-linux-android";
targets.aarch64-unknown-linux-gnu = "aarch64-unknown-linux-gnu";
targets.aarch64-unknown-linux-musl = "aarch64-unknown-linux-musl";
targets.armv7-unknown-linux-musleabihf = "armv7-unknown-linux-musleabihf";
Expand Down
8 changes: 6 additions & 2 deletions lib/rust/defaultPkgsFor.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ with self.lib.rust.targets;
then pkgs
else if hostPlatform.isAarch64 && hostPlatform.isLinux && hostPlatform.isGnu && target == aarch64-unknown-linux-gnu
then pkgs
else if hostPlatform.isAarch64 && hostPlatform.isLinux && hostPlatform.isAndroid && target == aarch64-linux-android
then pkgs
else if hostPlatform.isAarch64 && hostPlatform.isLinux && target == aarch64-unknown-linux-musl
then
if hostPlatform.isMusl
Expand All @@ -30,12 +32,14 @@ with self.lib.rust.targets;
else pkgs.pkgsCross.musl64
else if hostPlatform.isx86_64 && hostPlatform.isWindows && target == x86_64-pc-windows-gnu
then pkgs
else if target == aarch64-apple-darwin
then pkgs.pkgsCross.aarch64-darwin
else if target == aarch64-linux-android
then pkgs.pkgsCross.aarch64-android-prebuilt
else if target == aarch64-unknown-linux-gnu
then pkgs.pkgsCross.aarch64-multiplatform
else if target == aarch64-unknown-linux-musl
then pkgs.pkgsCross.aarch64-multiplatform-musl
else if target == aarch64-apple-darwin
then pkgs.pkgsCross.aarch64-darwin
else if target == armv7-unknown-linux-musleabihf
then pkgs.pkgsCross.armv7l-hf-multiplatform
else if target == x86_64-apple-darwin
Expand Down
6 changes: 6 additions & 0 deletions lib/rust/mkAttrs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,10 @@ with self.lib.rust.targets;
// optionalAttrs final.stdenv.buildPlatform.isDarwin {
doCheck = warn "testing not currently supported when cross-compiling for `${target}` on Darwin" false;
}
else if target == aarch64-linux-android
then {
doCheck = warn "testing not currently supported when cross-compiling for `${target}`" false;
}
else if target == aarch64-unknown-linux-gnu
then
{
Expand Down Expand Up @@ -488,6 +492,7 @@ with self.lib.rust.targets;

targets' = let
default.${aarch64-apple-darwin} = true;
default.${aarch64-linux-android} = prev.stdenv.hostPlatform.isLinux;
default.${aarch64-unknown-linux-gnu} = true;
default.${aarch64-unknown-linux-musl} = true;
default.${armv7-unknown-linux-musleabihf} = true;
Expand Down Expand Up @@ -567,6 +572,7 @@ with self.lib.rust.targets;
#ociArchitecture.${x86_64-apple-darwin} = "darwin-amd64";
#ociArchitecture.${x86_64-pc-windows-gnu} = "windows-amd64";
ociArchitecture.${aarch64-apple-darwin} = "arm64";
ociArchitecture.${aarch64-linux-android} = "arm64";
ociArchitecture.${aarch64-unknown-linux-gnu} = "arm64";
ociArchitecture.${aarch64-unknown-linux-musl} = "arm64";
ociArchitecture.${armv7-unknown-linux-musleabihf} = "arm";
Expand Down

0 comments on commit 73cc790

Please sign in to comment.