Bonsai not compiling on macOS

Hello,
I wanted to use bonsai but I encountered a problem with bonsai v0.18 installation on my machine (macOS). Here is the path I followed to install bonsai :

  1. add the janestreet repository to my OPAM setup
opam switch create bonsai18 5.2.1 --no-switch
opam repo add janestreet-bleeding \
  https://github.com/janestreet/opam-repository.git --switch bonsai18
  1. install a bonsai library e.g. ‘ppx_html’
opam install ppx_html

the build stops early, deep in the dependency tree, at the compilation of the basement library:

stubs.c:95:19: error: use of undeclared identifier 'caml_state'
   95 |   return Val_long(caml_state->id);

This is not an OCaml version problem. In caml/domain_state.h, the caml_statevariable is declared only under a condition:

#if defined(HAS_FULL_THREAD_VARIABLES) || defined(IN_CAML_RUNTIME)
  CAMLextern CAMLthread_local caml_domain_state* caml_state;
  #define Caml_state_opt caml_state
#else
  CAMLextern caml_domain_state* caml_get_domain_state(void);
  #define Caml_state_opt (caml_get_domain_state())
#endif

macOS does not provide the full thread-local storage this requires — s.h in every OCaml switch on the machine says /* #undef HAS_FULL_THREAD_VARIABLES */. So the runtime exposes only the Caml_state macro, and basement’s stub reaches for a symbol the public header only declares where thread-local storage is full.

The solution is to call the Macro Caml_state. One character of difference, and the fix is to use the macro the runtime actually publishes:

mkdir -p \~/.opam-sources/basement

curl -sL https://github.com/janestreet/basement/archive/5c640c230a3989f8e505cda7aa6aca9925a23a5b.tar.gz \
 | tar xz -C ~/.opam-sources/basement --strip-components=1

sed -i '' 's/Val_long(caml_state->id)/Val_long(Caml_state->id)/' \
  \~/.opam-sources/basement/src/stubs.c

opam pin add -y -n -k path --switch bonsai18 \
  'basement.v0.18\~preview.130.106+341' ~/.opam-sources/basement
# compiles !

Worth reporting as an issue on Issues · janestreet/basement · GitHub

Looking through the rest of stubs.c this is clearly a typo.

I incorporated your patch in my 5.5-compatible version of Janestreet libraries (see Jane Street Libraries (base/core/async/etc) with 5.5 )

You may want to use this until the following bug in incremental is fixed in the Jane Street version: Recompute heap does not work in non-oxcaml compiler · Issue #20 · janestreet/incremental · GitHub

@lambda_foo I have opened an issue.

@smuenzel thank you, I will test your repo when I come back to bonsai testing (working on others project now)