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 :
- 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
- 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 !