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

Fix android prebuilt ghc [Fixes #40194] #40210

Merged
merged 3 commits into from May 10, 2018

Conversation

ElvishJerricco
Copy link
Contributor

Motivation for this change

In order to build GHC to cross compile to android, we need an extra c flag, and we need a patch from master to fix hsc2hs. There is also an issue with forbidden references in dynamic exes, so for now we just don't enableShared:

RPATH of binary /nix/store/bbg892bbs7dqjqm9y1jpgwc2s5sw1xxb-aarch64-unknown-linux-android-ghc-8.4.2/lib/aarch64-unknown-linux-android-ghc-8.4.2/bin/ghc-iserv-dyn contains a forbidden reference to /tmp/nix-build-aarch64-unknown-linux-android-ghc-8.4.2.drv
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.

@ElvishJerricco ElvishJerricco requested a review from peti as a code owner May 9, 2018 08:28
@ElvishJerricco
Copy link
Contributor Author

Hm. There's a lingering issue with libiconv when trying to build the hello haskell package.

@nix { "action": "setPhase", "phase": "setupCompilerEnvironmentPhase" }
setupCompilerEnvironmentPhase
Build with /nix/store/xnyaam87fjk1nqfpj7fgyyzji5q2flh1-aarch64-unknown-linux-android-ghc-8.4.2.
@nix { "action": "setPhase", "phase": "unpackPhase" }
unpacking sources
unpacking source archive /nix/store/x3p4dk6kpx485f94d09hiqiy6cvz7i93-hello-1.0.0.2.tar.gz
source root is hello-1.0.0.2
setting SOURCE_DATE_EPOCH to timestamp 1278083122 of file hello-1.0.0.2/src/hello.hs
@nix { "action": "setPhase", "phase": "patchPhase" }
patching sources
@nix { "action": "setPhase", "phase": "compileBuildDriverPhase" }
compileBuildDriverPhase
setupCompileFlags: -package-db=/tmp/nix-build-hello-1.0.0.2-aarch64-unknown-linux-android.drv-0/package.conf.d -j4 -threaded
[1 of 1] Compiling Main             ( Setup.hs, /tmp/nix-build-hello-1.0.0.2-aarch64-unknown-linux-android.drv-0/Main.o )
Linking Setup ...
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.so when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.a when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.so when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.a when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: cannot find -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.so when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.a when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.so when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.a when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: cannot find -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.so when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.a when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.so when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.a when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: cannot find -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.so when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.a when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.so when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: skipping incompatible /nix/store/fh010pwx46whw9dwzxsawkwygwrgri5k-libiconv-1.15-aarch64-unknown-linux-android/lib/libiconv.a when searching for -liconv
/nix/store/j75dgadrff2d1fyc4fczmcgqkid2imdx-binutils-2.30/bin/ld: cannot find -liconv
collect2: error: ld returned 1 exit status
`cc' failed in phase `Linker'. (Exit code: 1)

But I think we can call this a separate issue.

@ElvishJerricco
Copy link
Contributor Author

/cc @Ericson2314 @angerman

@ElvishJerricco ElvishJerricco changed the title Fix android prebuilt ghc Fix android prebuilt ghc [Fixes #40194] May 9, 2018
@@ -79,6 +81,8 @@ stdenv.mkDerivation rec {

outputs = [ "out" "doc" ];

patches = [./8.4.2-hsc2hs-cross-build.patch];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Ericson2314 Should this be unconditional like this? It's harmless on the normal build, but will require a rebuild of GHC 8.4.2.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I agree. Simple is better.

Copy link
Member

@Ericson2314 Ericson2314 left a comment

Choose a reason for hiding this comment

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

Great work @ElvishJerricco! Thanks so much!!

@@ -22,7 +22,7 @@

, # Whether to build dynamic libs for the standard library (on the target
# platform). Static libs are always built.
enableShared ? true
enableShared ? !targetPlatform.useAndroidPrebuilt
Copy link
Member

Choose a reason for hiding this comment

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

Can you apply the head.nix changes on more other GHCs for consistency?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's already applied to 8.4. No other GHC versions will be able to build for Android. It'd be better to have a "Not android" assertion in all the other GHCs. Want me to add this?

Copy link
Member

Choose a reason for hiding this comment

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

Ah and there are fewer GHCs now too, +1.

@@ -79,6 +81,8 @@ stdenv.mkDerivation rec {

outputs = [ "out" "doc" ];

patches = [./8.4.2-hsc2hs-cross-build.patch];
Copy link
Member

Choose a reason for hiding this comment

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

Yeah I agree. Simple is better.

@@ -0,0 +1,41 @@
Submodule utils/hsc2hs 9483ad1006..738f3666c8:
Copy link
Member

Choose a reason for hiding this comment

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

This is a great patch! Can you open a phabricator review of it? Then we can fetchPatch it.

Copy link
Member

Choose a reason for hiding this comment

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

If it's already an 8.4 branch (or even master) commit we can pull the diff from cgit at haskell.org too. (You can give me hash and I'll do it if you like.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's on master but not 8.4. It's an update to a submodule, which complicates things. I tried doing fetchPatch on https://git.haskell.org/ghc.git/commitdiff_plain/..., but the change to the submodule is just shown as -rev\n+rev. Had to do git diff --submodule=diff, and I don't know of any end point that would have such a diff.

Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/haskell/hsc2hs/commit/738f3666c878ee9e79c3d5e819ef8b3460288edf.diff there is a fetchPath argument to prefix all paths in the patch so that it works.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks

@matthewbauer
Copy link
Member

Hey, just for reference, did you ever get "armv7a-android-prebuilt" to build after these changes? I am trying to figure out the cause of #42333 & not sure if it 8.4.* was ever working.

@ElvishJerricco
Copy link
Contributor Author

@matthewbauer No, I think I only ever tested this with arm64

@@ -22,7 +22,7 @@

, # Whether to build dynamic libs for the standard library (on the target
# platform). Static libs are always built.
enableShared ? true
enableShared ? !targetPlatform.useAndroidPrebuilt
Copy link
Member

Choose a reason for hiding this comment

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

Did you ever get this to build a valid .apk? I think we need shared here for the Haskell activity stuff to link. Maybe it worked for you though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe the old stuff from reflex-platform used this and successfully built APKs. I did not try it with this branch though.

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

Successfully merging this pull request may close these issues.

None yet

4 participants