ppx_deriving icon indicating copy to clipboard operation
ppx_deriving copied to clipboard

ppx_deriving for OCaml cross-compiler

Open mryau opened this issue 8 years ago • 6 comments

I want to create OPAM packages for x86 -> arm cross-compiler, but there is some troubles at process. Does findlib.dynload dependency needed at target runtime for ppx_deriving? Or it will be used only on host at compiling time?

mryau avatar Apr 19 '17 12:04 mryau

Only on host at compile-time.

whitequark avatar Apr 19 '17 12:04 whitequark

Thank you, I've cross-compiled it. So, I have both as for x86 as for ARM cross-compiler versions of this package. Host code works nice but, of course when I tried to compile same test to target platform I got errors:

$ ocamlbuild -use-ocamlfind -ocamlc '-toolchain arm ocamlc' -ocamldep '-toolchain arm ocamldep' -ocamlopt '-toolchain arm ocamlopt' s.native
+ ocamlfind -toolchain arm ocamldep -package ppx_deriving.show -modules s.ml > s.ml.depends
/mnt/opam/4.02.1/arm-oe-linux-gnueabi/lib/ppx_deriving/./ppx_deriving: 1: /mnt/opam/4.02.1/arm-oe-linux-gnueabi/lib/ppx_deriving/./ppx_deriving: Syntax error: word unexpected (expecting ")")
File "s.ml", line 1:
Error: Error while running external preprocessor
Command line: /mnt/opam/4.02.1/arm-oe-linux-gnueabi/lib/ppx_deriving/./ppx_deriving /mnt/opam/4.02.1/arm-oe-linux-gnueabi/lib/ppx_deriving/./ppx_deriving_show.cma '/tmp/camlppx306608' '/tmp/camlppx250687'

Command exited with code 2.
Compilation unsuccessful after building 1 target (0 cached) in 00:00:00.

Is it possible at all to chain right sequence of host and target versions of compiler's suite to build code for target platform?

s.ml itself is here:

type point2d = float * float
[@@deriving show]
let () =
        let s = show_point2d (2.,2.) in print_string s

mryau avatar Apr 19 '17 19:04 mryau

First, you should use the -toolchain option of ocamlfind itself. Second, you will not be able to use unmodified META files. In fact you will have to modify the META file, and make every reference to OCaml code in it point to build binaries, except for ppx_deriving_runtime.cma, which should point to a host binary.

whitequark avatar Apr 19 '17 19:04 whitequark

Since META for target platform has only one executlabe defined in META: ppx = "./ppx_deriving" but there is also many *.cmxs binaries too. I simply replaced it to host version, also I replaced ppx_deriving_show.cmxs to host version and for now as after the following commands

ppx_deriving_show.cmxs itself exist in folder. and it 
ocamlfind ocamlopt -c -package ppx_deriving.show -o s.cmx s.ml
ocamlfind ocamlopt -linkpkg -package ppx_deriving.show s.cmx -o s.native

as build using

ocamlbuild -use-ocamlfind -ocamlc '-toolchain arm ocamlc' -ocamldep '-toolchain arm ocamldep' -ocamlopt '-toolchain arm ocamlopt'

successfully builds target binary. Is this means I should replace all binaries in target library folder to host version? Is a such method of building a right way or I missing something yet?

mryau avatar Apr 19 '17 20:04 mryau

First, you should use the -toolchain option of ocamlfind itself.

Sorry, let me correct that above, as I wrote a typo. You should use the -toolchain option of ocamlbuild itself. It was recently introduced and it works correctly in e.g. cases where there is a myocamlbuild.ml.

Is this means I should replace all binaries in target library folder to host version? Is a such method of building a right way or I missing something yet?

This method is ugly. But I do not know of any better one.

whitequark avatar Apr 19 '17 20:04 whitequark

Is this still an issue to be addressed? Seems as though sufficient info was provided back in 2017, and there may not be anything be done around this?

shonfeder avatar Sep 29 '21 23:09 shonfeder