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

Please provide Android compilation example #2328

Open
bitestring opened this issue Mar 13, 2025 · 2 comments
Open

Please provide Android compilation example #2328

bitestring opened this issue Mar 13, 2025 · 2 comments

Comments

@bitestring
Copy link

bitestring commented Mar 13, 2025

Thanks for this wonderful project. I have been spending weeks in trying to build a Haskell library that exports a simple hello world function. I was able to compile it to x86_64 Linux target. But I could not figure out how to build for Android.

My flake.nix looks like this

{
  # This is a template created by `hix init`
  inputs.haskellNix.url = "github:input-output-hk/haskell.nix";
  inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";
  inputs.flake-utils.url = "github:numtide/flake-utils";
  outputs = { self, nixpkgs, flake-utils, haskellNix }:
    let
      supportedSystems = [
        "x86_64-linux"
      ];
    in
      flake-utils.lib.eachSystem supportedSystems (system:
      let
        overlays = [ haskellNix.overlay
          (final: prev: {
            hixProject =
              final.haskell-nix.hix.project {
                src = ./.;
                compiler-nix-name = "ghc984"; # Version of GHC to use
                crossPlatforms = p: [p.aarch64-android-prebuilt];
              };
          })
        ];
        pkgs = import nixpkgs { inherit system overlays; inherit (haskellNix) config; };
        flake = pkgs.hixProject.flake {};
      in flake // {
        legacyPackages = pkgs;

        packages = flake.packages // { 
          default = flake.packages."hello:exe:hello";
        };
      });

  # --- Flake Local Nix Configuration ----------------------------
  nixConfig = {
    # This sets the flake to use the IOG nix cache.
    # Nix should ask for permission before using it,
    # but remove it here if you do not want it to.
    extra-substituters = ["https://cache.iog.io"];
    extra-trusted-public-keys = ["hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="];
    allow-import-from-derivation = "true";
  };
}

But when building Android target, it gives following error

> checking ABI=64
> checking whether aarch64-unknown-linux-android-clang is gcc... yes
> checking compiler aarch64-unknown-linux-android-clang -O2 -pedantic ... no, gnupro alpha ev6 char spilling
> checking ABI=32
> checking whether aarch64-unknown-linux-android-clang is gcc... yes
> checking compiler aarch64-unknown-linux-android-clang -O2 -pedantic -fomit-frame-pointer ... no, gnupro alpha ev6 char spilling
> configure: error: could not find a working compiler, see config.log for details
For full logs, run 'nix log /nix/store/ayiwnmdck3qvhqwdvdkcrw39wm5s5jfx-gmp-aarch64-unknown-linux-android-6.3.0.drv'.
error: 1 dependencies of derivation '/nix/store/2fmvak2ai523613vdva0c9nn67ahdy4w-hello-exe-hello-aarch64-unknown-linux-android-1.0.0.2.drv' failed to build

Could you please share how to build for Android aarch64 targets? Thanks in advance.

@hamishmack
Copy link
Collaborator

inputs.nixpkgs.follows = "haskellNix/nixpkgs-unstable";

Android cross compilation seems to be broken in nixpkgs-unstable. Try:

inputs.nixpkgs.follows = "haskellNix/nixpkgs-2411";

Also make sure you nix flake update haskellNix to get #1874 (merged 2 days ago).

@bitestring
Copy link
Author

It worked. Appreciate your help. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants