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

Example of using with ndk + android? #129

Open
mamcx opened this issue Dec 2, 2023 · 3 comments
Open

Example of using with ndk + android? #129

mamcx opened this issue Dec 2, 2023 · 3 comments

Comments

@mamcx
Copy link

mamcx commented Dec 2, 2023

Exist a example that show how integrate android targets that need ndk and compile stuff like rustqlite?

@rvolosatovs
Copy link
Contributor

I'm successfully cross-compiling Android binaries on x86_64-linux using https://github.com/ipetkov/crane and this cross package set: https://github.com/rvolosatovs/nixify/blob/c06d74a4cebc2a149bef2e9237a9a08c135cad22/lib/rust/defaultPkgsFor.nix#L40

I'm using https://github.com/rui314/mold linker, but it should not matter, it's a pretty standard cross setup https://github.com/rvolosatovs/nixify/blob/c06d74a4cebc2a149bef2e9237a9a08c135cad22/lib/rust/mkAttrs.nix#L314-L398

@mamcx
Copy link
Author

mamcx commented Dec 5, 2023

Ok, this looks promising but is a complex nix. I tried using as in the examples:

P.D: The sample branch is here

{
  inputs.nixify.url = github:rvolosatovs/nixify;

  outputs = {nixify, ...}:
    nixify.lib.rust.mkFlake {
      src = ./.;
      name = "rust-workspace";

      build.workspace = true;
      clippy.workspace = true;
      test.workspace = true;
    };
}

and get

❯ nix build
warning: Git tree '/Users/mamcx/Proyectos/Apps' is dirty
error:
       … while updating the lock file of flake 'git+file:///Users/mamcx/Proyectos/Apps?dir=RustStore'while updating the flake input 'nixify'

       error: unsupported tarball input attribute 'lastModified'

@rvolosatovs
Copy link
Contributor

Ok, this looks promising but is a complex nix. I tried using as in the examples:

P.D: The sample branch is here

{
  inputs.nixify.url = github:rvolosatovs/nixify;

  outputs = {nixify, ...}:
    nixify.lib.rust.mkFlake {
      src = ./.;
      name = "rust-workspace";

      build.workspace = true;
      clippy.workspace = true;
      test.workspace = true;
    };
}

and get

❯ nix build
warning: Git tree '/Users/mamcx/Proyectos/Apps' is dirty
error:
       … while updating the lock file of flake 'git+file:///Users/mamcx/Proyectos/Apps?dir=RustStore'while updating the flake input 'nixify'

       error: unsupported tarball input attribute 'lastModified'

I've seen this error before with outdated Nix versions, you may want to update your Nix version (also, btw, I recommend this Nix installer: https://github.com/DeterminateSystems/nix-installer)

You don't really have to use nixify for this, but I would only be glad if you did, feel free to open an issue on that repo and we can continue the discussion there.

But in short, cross-compilation towards Android is only supported on x86_64-linux in nixpkgs (or at least it was so last time I checked)

Looking at your error message, I'm assuming you're on a Mac - you'd need to have either a remote x86_64-linux builder available and configured or you'd need to run one in a VM - there is darwin.linux-builder derivation upstream and even a nix-darwin module for that

So with an up-to-date Nix and nixify.lib.rust.mkFlake invoked in flake.nix you should be able to build your package as packages.x86_64-linux.$name-aarch64-android-linux where $name is whatever you have configured in your flake or the name in Cargo.toml if you have not

To do this manually you'd need set correct env vars to use cross C toolchain for linking and compilation from the pkgsCross like in the source I've linked to above

Again, more than happy to help you with getting this working with nixify, but let's discuss in that repo

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