# Bonsai not compiling on macOS

**URL:** <https://discuss.ocaml.org/t/bonsai-not-compiling-on-macos/18517>\
**Category:** Ecosystem\
**Tags:** bonsai, opam\
**Created:** [September 8, 2026, 7:05pm UTC](https://discuss.ocaml.org/t/bonsai-not-compiling-on-macos/18517 "2026-09-08T19:05:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![frederic-lang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/frederic-lang/32/6678_2.png) [@frederic-lang](https://discuss.ocaml.org/u/frederic-lang)\
**Post date:** [September 8, 2026, 7:05pm UTC](https://discuss.ocaml.org/t/bonsai-not-compiling-on-macos/18517/1 "2026-09-08T19:05:25Z")

</div>

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

```auto
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’

```auto
opam install ppx_html

```

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

```auto
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_state`variable is declared only under a condition:

```auto
#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:

```sh
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 !

```

---

<div class="post-metadata">

**Author:** ![lambda\_foo](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/lambda_foo/32/275_2.png) [@lambda\_foo](https://discuss.ocaml.org/u/lambda_foo)\
**Post date:** [September 8, 2026, 9:46pm UTC](https://discuss.ocaml.org/t/bonsai-not-compiling-on-macos/18517/2 "2026-09-08T21:46:41Z")

</div>

Worth reporting as an issue on [Issues · janestreet/basement · GitHub](https://github.com/janestreet/basement/issues)

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

---

<div class="post-metadata">

**Author:** ![smuenzel](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/smuenzel/32/3945_2.png) [@smuenzel](https://discuss.ocaml.org/u/smuenzel)\
**Post date:** [September 9, 2026, 11:17am UTC](https://discuss.ocaml.org/t/bonsai-not-compiling-on-macos/18517/3 "2026-09-09T11:17:59Z")

</div>

I incorporated your patch in my 5.5-compatible version of Janestreet libraries (see [Jane Street Libraries (base/core/async/etc) with 5.5](https://discuss.ocaml.org/t/jane-street-libraries-base-core-async-etc-with-5-5/18469) )

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](https://github.com/janestreet/incremental/issues/20)

---

<div class="post-metadata">

**Author:** ![frederic-lang](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/frederic-lang/32/6678_2.png) [@frederic-lang](https://discuss.ocaml.org/u/frederic-lang)\
**Post date:** [September 9, 2026, 3:50pm UTC](https://discuss.ocaml.org/t/bonsai-not-compiling-on-macos/18517/4 "2026-09-09T15:50:41Z")

</div>

@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)
