zw3rk / hs-android-helloworld

Hello World Android application with Haskell lib
3 stars 0 forks source link

[Q] Is prebuild cross compiler support "Android-16" #2

Open Guang1234567 opened 5 years ago

Guang1234567 commented 5 years ago

Hello @angerman

Today, i modify this project to support at least 'android-16'.

then 1) modify the toolchain-wrapper's android version from 24 to 16 2) modifybuild-liviconv script's android version from 24 to 16 and build libiconv again. 3) build libhs.a again 4) modify app/build.gradle minSdkVersion to 16 5) compile app

but got a error :

  ../../../../hs-libs/armeabi-v7a/libhs.a(RtsFlags.o):rts/RtsFlags.c:function procRtsOpts: error: undefined reference to 'atof'
  ../../../../hs-libs/armeabi-v7a/libhs.a(RtsFlags.o):rts/RtsFlags.c:function procRtsOpts: error: undefined reference to 'atof'
  ../../../../hs-libs/armeabi-v7a/libhs.a(RtsFlags.o):rts/RtsFlags.c:function procRtsOpts: error: undefined reference to 'atof'
  ../../../../hs-libs/armeabi-v7a/libhs.a(RtsFlags.o):rts/RtsFlags.c:function procRtsOpts: error: undefined reference to 'atof'
  ../../../../hs-libs/armeabi-v7a/libhs.a(RtsStartup.o):rts/RtsStartup.c:function shutdownHaskellAndSignal: error: undefined reference to 'sigemptyset'
  ../../../../hs-libs/armeabi-v7a/libhs.a(RtsStartup.o):rts/RtsStartup.c:function shutdownHaskellAndSignal: error: undefined reference to 'sigemptyset'
  ../../../../hs-libs/armeabi-v7a/libhs.a(RtsStartup.o):rts/RtsStartup.c:function shutdownHaskellAndSignal: error: undefined reference to 'sigaddset'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Itimer.o):rts/posix/Itimer.c:function exitTicker: error: undefined reference to 'signal'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function initUserSignals: error: undefined reference to 'sigemptyset'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function stg_sig_install: error: undefined reference to 'sigemptyset'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function stg_sig_install: error: undefined reference to 'sigaddset'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function stg_sig_install: error: undefined reference to 'sigaddset'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function stg_sig_install: error: undefined reference to 'sigdelset'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function sigtstp_handler: error: undefined reference to 'tcgetattr'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function sigtstp_handler: error: undefined reference to 'tcgetattr'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function sigtstp_handler: error: undefined reference to 'tcgetattr'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function sigtstp_handler: error: undefined reference to 'tcsetattr'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function sigtstp_handler: error: undefined reference to 'tcsetattr'
  ../../../../hs-libs/armeabi-v7a/libhs.a(Signals.o):rts/posix/Signals.c:function sigtstp_handler: error: undefined reference to 'tcsetattr'
  ../../../../hs-libs/armeabi-v7a/libhs.a(TTY.o):rts/posix/TTY.c:function resetTerminalSettings: error: undefined reference to 'sigaddset'
  ../../../../hs-libs/armeabi-v7a/libhs.a(TTY.o):rts/posix/TTY.c:function resetTerminalSettings: error: undefined reference to 'tcsetattr'

which min android version is supported by prebuild-ghc in http://hackage.mobilehaskell.org ?

Should i compile ghc from source to support android-16 ?

angerman commented 5 years ago

I think this Stack Overflow answer gives some good reasoning as to where this issue comes from: https://stackoverflow.com/a/38379405

Guang1234567 commented 5 years ago

@otherpeopleWantSupportAndroid16

ghc-8.6.5-20190531-armv7-linux-androideabi-ndk14-api16 base on ghc-v8.6.5-release is here.

Just for fun, dont try it on product env.

BTW, ghc's rts not link the android-16's stdlib ( comment by @angerman), so got above compile error:

../../../../hs-libs/armeabi-v7a/libhs.a(RtsFlags.o):rts/RtsFlags.c:function procRtsOpts: error: undefined reference to 'atof'

......
angerman commented 5 years ago

@Guang1234567 could you explain how you built that binary distribution?

Guang1234567 commented 5 years ago

@angerman

ENV: ndk14, mac OSX 10.1.4, llvm 5.0, ghc-8.6.5-release-sourcecode

https://github.com/Guang1234567/android-ndk14-toolchain-wrapper/blob/4d59043e1c5d8d49d94a767cfbd2db5cd4b0c5a0/android-toolchain.config#L20-L21

sysroot cannot to assign to ${ANDROID_NDK} /sysroot is important, must be depends on android-16's sysroot

ANDROID_API=16
 --sysroot ${ANDROID_NDK}/platforms/android-${ANDROID_API}/arch-${ANDROID_ARM_ARCH}"

add -fPIC to cflags in toolchainwrapper is also important.

Guang1234567 commented 5 years ago

@all

That haskell wiki

https://gitlab.haskell.org/ghc/ghc/wikis/arm64

maybe more detailed!

but remember if you want to support android api 16 at least:

1)

ANDROID_API=16
 --sysroot ${ANDROID_NDK}/platforms/android-${ANDROID_API}/arch-${ANDROID_ARM_ARCH}"

2) -fPIC

cd $PROJDIR/ghc-8.0.0.20160111
./configure \
    --target=aarch64-linux-android \
        --with-gcc=$TOOLCHAIN/bin/aarch64-linux-android-gcc \
      --with-clang=$TOOLCHAIN/bin/clang \
         --with-ld=$TOOLCHAIN/bin/aarch64-linux-android-ld \
    --with-ld.gold=$TOOLCHAIN/bin/aarch64-linux-android-ld.gold \
         --with-nm=$TOOLCHAIN/bin/aarch64-linux-android-nm \
    --with-objdump=$TOOLCHAIN/bin/aarch64-linux-android-objdump \
         --with-ar=$TOOLCHAIN/bin/aarch64-linux-android-ar \
     --with-ranlib=$TOOLCHAIN/bin/aarch64-linux-android-ranlib \
        --with-llc=$TOOLCHAIN/bin/llc \
        --with-opt=$TOOLCHAIN/bin/opt \
        --prefix=$PROJDIR \
    CONF_CC_OPTS_STAGE1="-fPIC -fPIE -pie" \
    CONF_GCC_LINKER_OPTS_STAGE1="-fPIC -fPIE -pie" \
    CONF_LD_LINKER_OPTS_STAGE1="-fPIC -fPIE -pie" \
    CONF_CC_OPTS_STAGE2="-fPIC -fPIE -pie" \
    CONF_GCC_LINKER_OPTS_STAGE2="-fPIC -fPIE -pie" \
    CONF_LD_LINKER_OPTS_STAGE2="-fPIC -fPIE -pie"