janestreet / virtual_dom

OCaml bindings for the virtual-dom library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Building on Mac OS

lostman opened this issue · comments

I managed to build virtual_dom on Mac OS using a 32-bit compiler but it wasn't easy.

First I had trouble with camlp4 which is needed by js_of_ocaml:
camlp4/camlp4#108

I've built 4.02.3+32bit with natdynlink=true and managed to compile camlp4, js_of_ocaml and all other dependencies (core_kernel, ppx_* ...).

virtual_dom wouldn't build though:

❯ opam pin add virtual_dom . -k git
...
# + /Users/lostman/.opam/4.02.3+32bit+dynlink/bin/ocamlfind ocamlopt -predicates ppx_driver -linkpkg -o ppx-driver-js_of_ocaml.ppx.driver.native -package js_of_ocaml.ppx.driver ppx_driver_runner.cmxa
# ocamlfind: Package `js_of_ocaml.ppx.driver' not found
# Command exited with code 2.

So I removed <**/*>: predicate(custom_ppx) from tags_ and changed <src/*.ml{,i}>: ppx-driver(js_of_ocaml.ppx.driver) to package(js_of_ocaml.ppx). With that virtual_dom installs fine:

=-=- Installing packages =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=  🐫
Building virtual_dom.~unknown:
  ./configure --prefix /Users/lostman/.opam/4.02.3+32bit+dynlink
  make
Installing virtual_dom.~unknown.

And I can compile and run the examples.

Is this something that can be fixed? I don't know OCaml toolchain enough to know whether dynlink is the problem or perhaps ppx_driver?

I would like to build incr_dom and I've run into similar ppx-related problems when installing its dependencies.

js_of_ocaml.ppx.driver should exists if ppx_driver is installed. What version of js_of_ocaml do you have installed?

I have js_of_ocaml 2.8.1. virtual_dom works on linux with the same version.

I had a look and it seems that js_of_ocaml.ppx.driver hasn't been released yet. You can pin it to its dev repo:

opam pin add js_of_ocaml --dev-repo

Actually it is part of js_of_ocaml 2.8.1 but ppx_driver is not listed as a depopt of js_of_ocaml in the opam repository. If you reinstall js_of_ocaml after having installed ppx_driver you should get js_of_ocaml.ppx.driver. @hhugo is going to fix the opam package

Thanks! Pinning js_of_ocaml to dev fixes the problem.

If this isn't released yet, how did virtual_dom compile on linux (Ubuntu)? It was a clean install:

opam switch 4.02.3+32bit
opam pin virtual_dom . -k git

There's another somewhat related problem I've encountered: to build hello_world and terminal examples I had to remove open Js_of_ocaml from the sources. I wrote a simple Makefile for each of them:

terminal.bc.js: terminal.byte
    js_of_ocaml +toplevel.js +weak.js +nat.js +bin_prot.js +core_kernel.js terminal.byte -o terminal.bc.js
terminal.byte: terminal.ml
    ocamlbuild -use-ocamlfind -package virtual_dom,ppx_custom_printf,core_kernel,js_of_ocaml.ppx,js_of_ocaml terminal.byte
clean:
    ocamlbuild -clean && rm -f terminal.bc.js

.PHONY: clean

If I don't remove the module open OCaml complains:

Reference to undefined global `Js_of_ocaml'

However, I have a nearly identical Makefile to build incr_dom/examples/incr_decr and that compiles even though main.ml contains open! Js_of_ocaml. Not sure what is the difference.

Any thoughts?

The fix has been merged in opam (ocaml/opam-repository#6962) so you don't need to pin js_of_ocaml anymore. I'm closing this ticket as a result.

For the first question, the prefered way to install Jane Street development packages is by adding the janestreet opam repository:

$ opam repo add janestreet-dev https://github.com/janestreet/opam-repository.git

About the open Js_of_ocaml, that is an unfortunate problem; internally we often have to wrap library that we import from github as their upstream versions are not properly namespaced. For instance we wrap toplevel modules of js_of_ocaml under the single toplevel name Js_of_ocaml to avoid name clashes.

The release process tries to take care of these details but it ignores examples, tests, ... as it is too much work to setup their compilation with ocamlbuild. Hopefully this will be fixed once we switch the build to jenga in our public packages.