ocaml-cross / opam-cross-android

An OCaml cross-toolchain for Android and several useful libraries
105 stars 15 forks source link

problem with lwt-android when porting to yocto/bitbake #32

Closed mryau closed 7 years ago

mryau commented 7 years ago

Hello, I'm trying to port your crosscompiler toolchain to yocto/bitbake based ARM distro. I have slightly modified conf-android's opam file:

build: [
  ["sh" "-c" "echo \"arch: \\\"${ARCH}\\\"\" >>conf-android.config"]
  ["sh" "-c" "echo \"subarch: \\\"${SUBARCH}\\\"\" >>conf-android.config"]
  ["sh" "-c" "echo \"system: \\\"${SYSTEM}\\\"\" >>conf-android.config"]
  ["sh" "-c" "echo \"level: \\\"${LEVEL-24}\\\"\" >>conf-android.config"]
  ["sh" "-c" "echo \"triple: \\\"${TRIPLE}\\\"\" >>conf-android.config"]
  ["sh" "-c" "echo \"toolchain: \\\"/usr/bin/\\\"\" >>conf-android.config"]
  ["sh" "-c" "echo \"toolpref: \\\"/usr/bin/${TRIPLE}-\\\"\" >>conf-android.config"]
  ["sh" "-c" "echo \"cflags: \\\"--sysroot /home/dmitry/svn/wolverine/build/tmp-glibc/sysroots/wolverine_v1 -L/home/dmitry/svn/wolverine/build/tmp-glibc/sysroots/wolverine_v1/usr/lib -L/home/dmitry/svn/wolverine/build/tmp-glibc/sysroots/wolverine_v1/lib\\\"\" >>conf-android.config"]
  ["sh" "-c" "echo \"ldflags: \\\"--sysroot /home/dmitry/svn/wolverine/build/tmp-glibc/sysroots/wolverine_v1 -L/home/dmitry/svn/wolverine/build/tmp-glibc/sysroots/wolverine_v1/usr/lib -L/home/dmitry/svn/wolverine/build/tmp-glibc/sysroots/wolverine_v1/lib\\\"\" >>conf-android.config"]

pin it and successfully built ocaml-android for ARM:

ARCH=arm SUBARCH=armv7 SYSTEM=linux_eabi \
  CCARCH=arm TOOLCHAIN=arm-oe-linux-gnueabi \
  TRIPLE=arm-oe-linux-gnueabi LEVEL=24 \
  STLVER=4.9 STLARCH=armeabi \
  opam install conf-android
opam install ocaml-android
opam install re-android

Simple tests such as helloworld.ml and test_pcre.ml were crosscompiled nicely an work well on target machine. But when I tryed to install lwt-android I got:

[ERROR] The compilation of lwt-android failed at "env OCAMLFIND_TOOLCHAIN=android ocaml setup.ml
        -configure --prefix /home/guest/.opam/4.04.0+32bit --disable-libev --disable-react
        --disable-ssl --enable-unix --enable-preemptive --enable-android-target".
Processing  1/1: [lwt-android: ocamlfind android]
#=== ERROR while installing lwt-android.2.6.0 =================================#
# opam-version 1.2.2
# os           linux
# command      env OCAMLFIND_TOOLCHAIN=android ocaml setup.ml -configure --prefix /home/guest/.opam/4.04.0+32bit --disable-libev --disable-react --disable-ssl --enable-unix --enable-preemptive --enable-android-target
# path         /home/guest/.opam/4.04.0+32bit/build/lwt-android.2.6.0
# compiler     4.04.0+32bit
# exit-code    1
...
# Missing C libraries: pthread
### stderr ###
# E: Failure("Command 'ocaml utils/discover.ml -ext-obj .o -exec-name a.out -use-libev false -os-type Unix -use-glib false -ccomp-type cc -use-pthread true -use-unix true -android-target true -libev_default true' terminated with error code 1")

I've tried to setup CC,LD,CPP,CFLAGS, LDFLAGS and PTHREAD_CFLAGS with PTHREAD_LIBS environment variables by hand but nothing changed. Of course, I can cross compile test for pthread from setup.ml by hands without any errors.

I suppose, after I install conf-android, I should see file conf-android.config somewhere in .opam as it written due build stage, but there is no such file. Isn't it root of my problems?

whitequark commented 7 years ago

Should be picked up by opam automatically from the build dir, try OPAM_VERBOSE?

mryau commented 7 years ago

Here is output from opam install lwt-android --verbose --debug:

...
00:00.027  STATE                   Loaded /home/guest/.opam/state.cache in 0.024s
00:00.085  STATE                   ROOT      : /home/guest/.opam
00:00.085  STATE                   SWITCH    : 4.04.0+32bit
00:00.085  STATE                   COMPILER  : 4.04.0+32bit
...
00:00.085  STATE                   REPOS     : { android, default }
00:00.085  STATE                   PACKAGES  : 6774 packages
00:00.085  STATE                   INSTALLED : { base-bigarray.base, base-threads.base, base-unix.base, conf-android.1, conf-m4.1, ocaml-android.4.04.0, ocaml-android32.4.04.0, ocamlbuild.dev, ocamlfind.1.7.2, re-android.1.7.1, result.1.2, result-android.1.2, topkg.0.9.0 }
00:00.085  STATE                   ROOTS     : { base-bigarray.base, base-threads.base, base-unix.base, conf-android.1, ocaml-android.4.04.0, ocamlbuild.dev, re-android.1.7.1, topkg.0.9.0 }
00:00.085  STATE                   REINSTALL : {}
...
00:00.167  FILE(export)            Wrote ~/.opam/4.04.0+32bit/backup/state-20170424033011.export in 0.000s
00:00.211  CLIENT                  INSTALL lwt-android
00:00.753  CLIENT                  Orphans: full {}, versions {}
00:00.820  SOLVER                  resolve request=install:(lwt-android) remove:() upgrade:()
...
=-=- Processing actions -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
00:03.764  PARALLEL                Iterate over 1 task(s) with 4 process(es)
00:03.764  PARALLEL                Starting job 72462484 (worker 1/4): ∗  lwt-android.2.6.0
00:03.764  ACTION                  extract_package: lwt-android.2.6.0 from /home/guest/.opam/packages.dev/lwt-android.2.6.0/2.6.0.tar.gz
00:03.764  SYSTEM                  rmdir /home/guest/.opam/4.04.0+32bit/build/lwt-android.2.6.0
00:03.770  SYSTEM                  mkdir /tmp/opam-13739-42bb52
00:03.783  SYSTEM                  [log-13739-9b8556] (in 0.000s) tar xfz /home/guest/.opam/packages.dev/lwt-android.2.6.0/2.6.0.tar.gz -C /tmp/opam-13739-42bb52
00:03.794  SYSTEM                  [log-13739-5f1023] (in 0.004s) mv /tmp/opam-13739-42bb52/lwt-2.6.0 /home/guest/.opam/4.04.0+32bit/build/lwt-android.2.6.0
00:03.794  SYSTEM                  rmdir /tmp/opam-13739-42bb52
00:03.797  PARALLEL                Next task in job 72462484: env OCAMLFIND_TOOLCHAIN=android ocaml setup.ml -configure --prefix /home/guest/.opam/4.04.0+32bit --disable-libev --disable-react --disable-ssl --enable-unix --enable-preemptive --enable-android-target
[lwt-android: env ocaml] Command started
Processing  1/1: [lwt-android: env ocaml]
+ env "OCAMLFIND_TOOLCHAIN=android" "ocaml" "setup.ml" "-configure" "--prefix" "/home/guest/.opam/4.04.0+32bit" "--disable-libev" "--disable-react" "--disable-ssl" "--enable-unix" "--enable-preemptive" "--enable-android-target" (CWD=/home/guest/.opam/4.04.0+32bit/build/lwt-android.2.6.0)
- not checking for pkg-config
- not checking for libev
- testing for pthread: ........................... unavailable
- not checking for glib
-
- Some required C libraries were not found. If a C library <lib> is installed in a
- non-standard location, set <LIB>_CFLAGS and <LIB>_LIBS accordingly. You may also
- try 'ocaml setup.ml -configure --disable-<lib>' to avoid compiling support for
- it. For example, in the case of libev missing:
-     export LIBEV_CFLAGS=-I/opt/local/include
-     export LIBEV_LIBS='-L/opt/local/lib -lev'
-     (* or: *)  ocaml setup.ml -configure --disable-libev
-
- Missing C libraries: pthread
- E: Failure("Command 'ocaml utils/discover.ml -ext-obj .o -exec-name a.out -use-libev false -os-type Unix -use-glib false -ccomp-type cc -use-pthread true -use-unix true -android-target true -libev_default true' terminated with error code 1")
00:05.114  PARALLEL                Collected task for job 72462484 (ret:1)
[ERROR] The compilation of lwt-android failed at "env OCAMLFIND_TOOLCHAIN=android ocaml setup.ml
        -configure --prefix /home/guest/.opam/4.04.0+32bit --disable-libev --disable-react
        --disable-ssl --enable-unix --enable-preemptive --enable-android-target".
00:05.114  ACTION                  Removing lwt-android.2.6.0 (false)
00:05.115  PARALLEL                Next task in job 72462484: ocamlfind -toolchain android remove lwt

00:00.085  STATE                   State switch-lock loaded in 0.084s
00:00.085  SYSTEM                  locking /home/guest/.opam/4.04.0+32bit/lock
00:00.085  STATE                   LOAD-STATE(install)
...

And the setup.data of lwt-android contains:

ocamlfind="/home/guest/.opam/4.04.0+32bit/bin/ocamlfind"
ocamlc="/home/guest/.opam/4.04.0+32bit/bin/ocamlc.opt"
ocamlopt="/home/guest/.opam/4.04.0+32bit/bin/ocamlopt.opt"
ocamlbuild="/home/guest/.opam/4.04.0+32bit/bin/ocamlbuild"
pkg_name="lwt"
pkg_version="2.6.0"
os_type="Unix"
system="linux_elf"
architecture="i386"
ccomp_type="cc"
ocaml_version="4.04.0"
standard_library_default="/home/guest/.opam/4.04.0+32bit/lib/ocaml"
standard_library="/home/guest/.opam/4.04.0+32bit/lib/ocaml"
standard_runtime="/home/guest/.opam/4.04.0+32bit/bin/ocamlrun"
bytecomp_c_compiler="gcc -m32 -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -fPIC"
native_c_compiler="gcc -m32 -std=gnu99 -O2 -fno-strict-aliasing -fwrapv -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT"
...
pkg_bytes="/home/guest/.opam/4.04.0+32bit/android-sysroot/lib/bytes"
pkg_result="/home/guest/.opam/4.04.0+32bit/android-sysroot/lib/result"
pkg_unix="/home/guest/.opam/4.04.0+32bit/android-sysroot/lib/ocaml"
pkg_bigarray="/home/guest/.opam/4.04.0+32bit/android-sysroot/lib/ocaml"
pkg_compiler_libs_common="/home/guest/.opam/4.04.0+32bit/android-sysroot/lib/ocaml/compiler-libs"
pkg_threads="/home/guest/.opam/4.04.0+32bit/android-sysroot/lib/ocaml"
ocamldoc="/home/guest/.opam/4.04.0+32bit/bin/ocamldoc"

It seems lwt's setup.ml ignores as ocaml-android's default toolchain settings for C compiler as environment variables. In case I setup libffi-sys-android, it uses bitbake's toolchain, and it reacts if I override default settings by export new CC, LD, CFLAGS and LDFLAGS values too.

Is there way to say lwt's setup.ml what toolchain it should use?

mryau commented 7 years ago

As additional information: