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

Android Cross compilation #35451

Merged
merged 2 commits into from
Feb 27, 2018
Merged

Conversation

Ericson2314
Copy link
Member

Motivation for this change

I need to make sure GHC still works, but hydra is currently down.

Will be used by http://github.com/reflex-frp/reflex-platform

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

CC @bgamari @ElvishJerricco

@Ericson2314 Ericson2314 added the 6.topic: cross-compilation Building packages on a different platform than they will be used on label Feb 24, 2018
@GrahamcOfBorg GrahamcOfBorg added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux labels Feb 24, 2018
@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Partial log (click to expand)

/nix/store/csms6c387h6d0fydplyg8hmhgfqngj75-glibc-iconv-2.26-131
/nix/store/nrkvd447jbjv9k9vil17vc09vb19jv5m-ncurses-6.0-20171125

@GrahamcOfBorg
Copy link

Success on x86_64-darwin (full log)

Partial log (click to expand)

/nix/store/5hymrhfv7zm20ackp3i3di2n7amnlvva-libiconv-osx-10.11.6
/nix/store/a67rhbgwb41j11j6mgww3y0gq4pg0lmp-ncurses-6.0-20171125

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Partial log (click to expand)

/nix/store/zxr2dbnrjfxlajc5r85y4rkfyzlpa779-glibc-iconv-2.26-131
/nix/store/069g827lh3hrhp4vkcq3rsh5jh65pm3l-ncurses-6.0-20171125

Copy link
Member

@shlevy shlevy left a comment

Choose a reason for hiding this comment

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

Minor nits, but looks good!

config = "aarch64-unknown-linux-android";
arch = "aarch64";
platform = platforms.aarch64-multiplatform;
useAndroidPrebuilt = true;
Copy link
Member

Choose a reason for hiding this comment

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

Would be good to document somewhere what this means.

Copy link
Member Author

Choose a reason for hiding this comment

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

Any idea where? The lib.system infra today currently doesn't offer for such ad-hoc top-level ones. And let's do the same for your isiPhoneSimulator too :D.

Copy link
Member

Choose a reason for hiding this comment

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

At the very least in the cross-compiling manual?

@@ -1,5 +1,6 @@
{ fetchurl, stdenv, lib
, buildPlatform, hostPlatform
, androidMinimal ? stdenv.hostPlatform.useAndroidPrebuilt
Copy link
Member

Choose a reason for hiding this comment

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

Nothing android specific about it, maybe give it a better name?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah these two hacky (in that they do a bunch of mutually-unrelated random things) androidMinimal options were cargo-cults on my part. I've just been lacking the time to go back and empirically derive what's actually needed. Kinda want a "mea culpa style" name for that reason to acknowledge the tech debt, but I'm open to suggestions.

Copy link
Member

Choose a reason for hiding this comment

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

lightweight or minimal? Or if it makes more sense then maybe expose each change individually?

Copy link
Member

@dtzWill dtzWill left a comment

Choose a reason for hiding this comment

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

Visual review, haven't tried yet. Awesome to see this, thanks!

Shouldn't there be an RFC about this first?

configureFlags =
lib.optional stdenv.isFreeBSD "--with-pic";
configureFlags = lib.optional stdenv.isFreeBSD "--with-pic"
++ lib.optionals androidMinimal [ "--enable-static" "--without-cxx" ];
Copy link
Member

Choose a reason for hiding this comment

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

I don't think --without-cxx is a valid configure flag for libiconv, please remove if it isn't.

#"--without-debug"
#"--without-termlib"
#"--without-ticlib"
"--without-cxx"
Copy link
Member

Choose a reason for hiding this comment

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

Probably want to remove all these commented-out lines, and de-duplicate what remains.

Just curious, why "--without-cxx"?

Copy link
Member Author

@Ericson2314 Ericson2314 Feb 26, 2018

Choose a reason for hiding this comment

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

literally cargo culting some prior GHC on android work a year ago as per my comment above #35451 (comment), haha. I was too busy hacking up the first draft of everything we've merged since to look into this.

libc = targetAndroidndkPkgs.libraries;
extraBuildCommands = lib.optionalString (targetPlatform.config == "arm-unknown-linux-androideabi") ''
sed -E \
-i $out/bin/${targetPlatform.config}-cc \
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't hurt anything, but no reason to specify "-i" repeatedly. But keep it if you like it aesthetically.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh I meant it to be -e repeatedly.

@dtzWill
Copy link
Member

dtzWill commented Feb 26, 2018

Also, does this work for you?

Trying to build coreutils:

$ nix build -f pkgs/top-level/release-cross.nix android64.coreutils
builder for '/nix/store/sgf8y6flk0md2yjrl701hhkp7labjszk-attr-2.4.47-aarch64-unknown-linux-android.drv' failed with exit code 77; last 10 log lines:
  fixing libtool script ./ltmain.sh
  configure flags: --disable-static --prefix=/nix/store/kfnhn1197c1qbha8fswl0dbk6nywpaa1-attr-2.4.47-aarch64-unknown-linux-android --bindir=/nix/store/4n7nkr8nrlv31n5d2jixsn6g2b00w47c-attr-2.4.47-aarch64-unknown-linux-android-bin/bin --sbindir=/nix/store/4n7nkr8nrlv31n5d2jixsn6g2b00w47c-attr-2.4.47-aarch64-unknown-linux-android-bin/sbin --includedir=/nix/store/88jqmlbagsiv3rmnjij85ac6yrkhg2kh-attr-2.4.47-aarch64-unknown-linux-android-dev/include --oldincludedir=/nix/store/88jqmlbagsiv3rmnjij85ac6yrkhg2kh-attr-2.4.47-aarch64-unknown-linux-android-dev/include --mandir=/nix/store/01mv8bnl4dw6yjlpjakpk4izzj71xs0b-attr-2.4.47-aarch64-unknown-linux-android-man/share/man --infodir=/nix/store/4n7nkr8nrlv31n5d2jixsn6g2b00w47c-attr-2.4.47-aarch64-unknown-linux-android-bin/share/info --docdir=/nix/store/bkpzzf59ihzapycyshqj8czyk02v9lk4-attr-2.4.47-aarch64-unknown-linux-android-doc/share/doc/ --libdir=/nix/store/kfnhn1197c1qbha8fswl0dbk6nywpaa1-attr-2.4.47-aarch64-unknown-linux-android/lib --libexecdir=/nix/store/kfnhn1197c1qbha8fswl0dbk6nywpaa1-attr-2.4.47-aarch64-unknown-linux-android/libexec --localedir=/nix/store/kfnhn1197c1qbha8fswl0dbk6nywpaa1-attr-2.4.47-aarch64-unknown-linux-android/share/locale MAKE=make MSGFMT=msgfmt MSGMERGE=msgmerge XGETTEXT=xgettext ECHO=echo SED=sed AWK=gawk --build=x86_64-unknown-linux-gnu --host=aarch64-unknown-linux-android
  checking build system type... x86_64-unknown-linux-gnu
  checking host system type... aarch64-unknown-linux-android
  checking how to print strings... printf
  checking for aarch64-unknown-linux-android-gcc... aarch64-unknown-linux-android-gcc
  checking whether the C compiler works... no
  configure: error: in `/build/attr-2.4.47':
  configure: error: C compiler cannot create executables
  See `config.log' for more details
cannot build derivation '/nix/store/pfr8dwlb6n7cxpm19xvn7ajsrl8vnw3d-coreutils-8.29-aarch64-unknown-linux-android.drv': 1 dependencies couldn't be built

Similar for ncurses, and such.

#"--without-debug"
#"--without-termlib"
#"--without-ticlib"
"--without-cxx"
Copy link
Contributor

Choose a reason for hiding this comment

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

Are these comments and duplicated --without-cxx important or can we clean this up?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's only important insofar that it functions as a TODO.

@Ericson2314 Ericson2314 added the 2.status: work-in-progress This PR isn't done label Feb 26, 2018
@Ericson2314 Ericson2314 changed the title Andriod Cross compilation Android Cross compilation Feb 27, 2018
@Ericson2314
Copy link
Member Author

@dtzWill Fixed a thing so it actually builds

Expose as an option for the cross stdenv.
@Ericson2314
Copy link
Member Author

Fixed and minimized the flags. @shlevy I'm going to document in a follow-up PR; It's possible I'll want to tweak how such ad-hoc attributes are used for a bit too, so the lib/systems/examples.nix example is probably a better stable interface for practical users anyways.

@Ericson2314 Ericson2314 merged commit d31fb80 into NixOS:master Feb 27, 2018
@Ericson2314 Ericson2314 deleted the android-cross branch February 27, 2018 23:21
@Ericson2314 Ericson2314 restored the android-cross branch February 27, 2018 23:34
@Ericson2314 Ericson2314 deleted the android-cross branch February 27, 2018 23:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.status: work-in-progress This PR isn't done 6.topic: cross-compilation Building packages on a different platform than they will be used on 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin 10.rebuild-linux: 0 This PR does not cause any packages to rebuild on Linux
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants