ocaml-cross / opam-cross-android

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

ppx_deriving-android.4.1 creates native library (as for x86 as for x64) instead of ARM version #36

Open mryau opened 7 years ago

mryau commented 7 years ago

When I tried to build my code I got:

ssp@ssp-vb:/mnt/ssp/1$ ocamlbuild -toolchain android -use-ocamlfind router.native
+ ocamlfind -toolchain android ocamlc -c -package ZMQ -package lwt.unix -package ppx_deriving_protobuf -o router.cmo router.ml
+ ocamlfind -toolchain android ocamlopt -c -package ZMQ -package lwt.unix -package ppx_deriving_protobuf -o router.cmx router.ml
+ ocamlfind -toolchain android ocamlopt -linkpkg -package ZMQ -package lwt.unix -package ppx_deriving_protobuf lwt_zmq.cmx router.cmx -o router.native
/home/ssp/build/tmp-glibc/sysroots/i686-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/6.2.0/ld: warning: library search path "/usr/local/lib" is unsafe for cross-compilation
/home/ssp/build/tmp-glibc/sysroots/i686-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/6.2.0/ld: /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ppx_deriving/ppx_deriving_runtime.a(ppx_deriving_runtime.o): Relocations in generic ELF (EM: 3)
/home/ssp/build/tmp-glibc/sysroots/i686-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/6.2.0/ld: /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ppx_deriving/ppx_deriving_runtime.a(ppx_deriving_runtime.o): Relocations in generic ELF (EM: 3)
/home/ssp/build/tmp-glibc/sysroots/i686-linux/usr/libexec/arm-oe-linux-gnueabi/gcc/arm-oe-linux-gnueabi/6.2.0/ld: /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ppx_deriving/ppx_deriving_runtime.a(ppx_deriving_runtime.o): Relocations in generic ELF (EM: 3)
/home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ppx_deriving/ppx_deriving_runtime.a: error adding symbols: File in wrong format
collect2: error: ld returned 1 exit status
File "caml_startup", line 1:
Error: Error during linking
Command exited with code 2.
Compilation unsuccessful after building 7 targets (0 cached) in 00:00:01.

So, I've extracted content of ppx_deriving_runtime.a:

ssp@ssp-vb:/mnt/ssp/1$ ar x /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ppx_deriving/ppx_deriving_runtime.a
ssp@ssp-vb:/mnt/ssp/1$ file ppx_deriving_runtime.o 
ppx_deriving_runtime.o: ELF 32-bit LSB  relocatable, Intel 80386, version 1 (SYSV), not stripped

It's simple to fix ppx_deriving-android to create right version of library: just add "-toolchain android" to pkg/build.ml:

let ocamlbuild =
  "ocamlbuild -toolchain android -use-ocamlfind -classic-display -plugin-tag " ^ quote_parens "package(cppo_ocamlbuild)"

But package failed to build since it can't find dynlink.cmxa compiled for ARM:

sp@ssp-vb:/mnt/ssp/4.04/ppx_deriving-android.4.1$ make
cp pkg/META.in pkg/META
ocaml pkg/build.ml native=true native-dynlink=true
ocamlfind ocamlopt -package unix -package ocamlbuild -linkpkg -package cppo_ocamlbuild myocamlbuild.ml /home/ssp/.opam/4.04.0+32bit/lib/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
cppo -V OCAML:4.04.0 -o src/ppx_deriving_main.ml src/ppx_deriving_main.cppo.ml
ocamlfind -toolchain android ocamldep -package compiler-libs.common -package ppx_tools.metaquot -package findlib.dynload -predicates ppx_driver -package dynlink -package result -modules src/ppx_deriving_main.ml > src/ppx_deriving_main.ml.depends
ocamlfind -toolchain android ocamldep -package compiler-libs.common -package ppx_tools.metaquot -package dynlink -package result -modules src/ppx_deriving.mli > src/ppx_deriving.mli.depends
ocamlfind -toolchain android ocamlc -c -g -bin-annot -safe-string -package compiler-libs.common -package ppx_tools.metaquot -package dynlink -package result -w @5@8@10@11@12@14@23@24@26@29@40 -I src -o src/ppx_deriving.cmi src/ppx_deriving.mli
+ ocamlfind -toolchain android ocamlc -c -g -bin-annot -safe-string -package compiler-libs.common -package ppx_tools.metaquot -package dynlink -package result -w @5@8@10@11@12@14@23@24@26@29@40 -I src -o src/ppx_deriving.cmi src/ppx_deriving.mli
findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml, /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml/compiler-libs
ocamlfind -toolchain android ocamlc -c -g -bin-annot -safe-string -package compiler-libs.common -package ppx_tools.metaquot -package findlib.dynload -predicates ppx_driver -package dynlink -package result -w @5@8@10@11@12@14@23@24@26@29@40 -I src -o src/ppx_deriving_main.cmo src/ppx_deriving_main.ml
+ ocamlfind -toolchain android ocamlc -c -g -bin-annot -safe-string -package compiler-libs.common -package ppx_tools.metaquot -package findlib.dynload -predicates ppx_driver -package dynlink -package result -w @5@8@10@11@12@14@23@24@26@29@40 -I src -o src/ppx_deriving_main.cmo src/ppx_deriving_main.ml
findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml, /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml/compiler-libs
cppo -V OCAML:4.04.0 -o src/ppx_deriving.ml src/ppx_deriving.cppo.ml
ocamlfind -toolchain android ocamldep -package compiler-libs.common -package ppx_tools.metaquot -package dynlink -package result -modules src/ppx_deriving.ml > src/ppx_deriving.ml.depends
ocamlfind -toolchain android ocamlopt -c -g -bin-annot -safe-string -package compiler-libs.common -package ppx_tools.metaquot -package dynlink -package result -w @5@8@10@11@12@14@23@24@26@29@40 -I src -o src/ppx_deriving.cmx src/ppx_deriving.ml
+ ocamlfind -toolchain android ocamlopt -c -g -bin-annot -safe-string -package compiler-libs.common -package ppx_tools.metaquot -package dynlink -package result -w @5@8@10@11@12@14@23@24@26@29@40 -I src -o src/ppx_deriving.cmx src/ppx_deriving.ml
findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml, /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml/compiler-libs
File "src/ppx_deriving.cppo.ml", line 463, characters 17-34:
Warning 3: deprecated: String.capitalize
Use String.capitalize_ascii instead.
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Ast_helper, and its interface was not compiled with -opaque
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Ast_mapper, and its interface was not compiled with -opaque
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Location, and its interface was not compiled with -opaque
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Longident, and its interface was not compiled with -opaque
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Pprintast, and its interface was not compiled with -opaque
ocamlfind -toolchain android ocamlopt -c -g -bin-annot -safe-string -package compiler-libs.common -package ppx_tools.metaquot -package findlib.dynload -predicates ppx_driver -package dynlink -package result -w @5@8@10@11@12@14@23@24@26@29@40 -I src -o src/ppx_deriving_main.cmx src/ppx_deriving_main.ml
+ ocamlfind -toolchain android ocamlopt -c -g -bin-annot -safe-string -package compiler-libs.common -package ppx_tools.metaquot -package findlib.dynload -predicates ppx_driver -package dynlink -package result -w @5@8@10@11@12@14@23@24@26@29@40 -I src -o src/ppx_deriving_main.cmx src/ppx_deriving_main.ml
findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml, /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml/compiler-libs
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Ast_helper, and its interface was not compiled with -opaque
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Ast_mapper, and its interface was not compiled with -opaque
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Dynlink, and its interface was not compiled with -opaque
File "_none_", line 1:
Warning 58: no cmx file was found in path for module Location, and its interface was not compiled with -opaque
ocamlfind -toolchain android ocamlopt -linkpkg -g -linkall -package compiler-libs.common -package ppx_tools.metaquot -package findlib.dynload -predicates ppx_driver -package dynlink -package result -I src src/ppx_deriving.cmx src/ppx_deriving_main.cmx -o src/ppx_deriving_main.native
+ ocamlfind -toolchain android ocamlopt -linkpkg -g -linkall -package compiler-libs.common -package ppx_tools.metaquot -package findlib.dynload -predicates ppx_driver -package dynlink -package result -I src src/ppx_deriving.cmx src/ppx_deriving_main.cmx -o src/ppx_deriving_main.native
findlib: [WARNING] Interface topdirs.cmi occurs in several directories: /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml, /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml/compiler-libs
File "/tmp/findlib_initlc51201.ml", line 1:
Error: Cannot find file /home/ssp/.opam/4.04.0+32bit/android-sysroot/lib/ocaml/dynlink.cmxa
Command exited with code 2.
make: *** [build] Error 10
whitequark commented 7 years ago

Well yeah, the ppx_deriving_runtime library should be the only one compiled. A switch can be added to pkg/build.ml to that extent.