OCaml 5.3 / arm64 support
This package currently fails to build on OCaml 5.3 with the following error:
#=== ERROR while compiling core_unix.v0.17.0 ==================================#
# context 2.3.0 | linux/arm64 | ocaml-variants.5.3.0+trunk | https://opam.ocaml.org#f708af850343b2bc3bfd2a069aa8c836d46c59f9
# path ~/.opam/5.3/.opam-switch/build/core_unix.v0.17.0
# command ~/.opam/opam-init/hooks/sandbox.sh build dune build -p core_unix -j 9
# exit-code 1
# env-file ~/.opam/log/core_unix-51178-8d08aa.env
# output-file ~/.opam/log/core_unix-51178-8d08aa.out
### output ###
# /home/kit_ty_kate/.opam/5.3/lib/ocaml/caml/platform.h:221:10: error: implicit declaration of function ‘atomic_load_acquire’ [-Wimplicit-function-declaration]
# [...]
# | ^~~~~~~~~~~~~~~~~~~
# /home/kit_ty_kate/.opam/5.3/lib/ocaml/caml/platform.h: In function ‘caml_plat_latch_set’:
# /home/kit_ty_kate/.opam/5.3/lib/ocaml/caml/platform.h:229:3: error: implicit declaration of function ‘atomic_store_release’; did you mean ‘atomic_store_explicit’? [-Wimplicit-function-declaration]
# 229 | atomic_store_release(&latch->value, Latch_unreleased);
# | ^~~~~~~~~~~~~~~~~~~~
# | atomic_store_explicit
I'm not sure if this is related, but I also cannot build core_unix. in OCaml 5.3, macOS ARM.
#=== ERROR while compiling core_unix.v0.17.0 ==================================#
# context 2.3.0 | macos/arm64 | ocaml.5.3.0 | https://opam.ocaml.org#f93eb7cb02fb91bfd11535b3ce693d313341dd60
# path ~/.opam/default/.opam-switch/build/core_unix.v0.17.0
# command ~/.opam/opam-init/hooks/sandbox.sh build dune build -p core_unix -j 10
# exit-code 1
# env-file ~/.opam/log/core_unix-30989-de2bef.env
# output-file ~/.opam/log/core_unix-30989-de2bef.out
### output ###
# [...]
# ./thread_id.h:12:23: note: expanded from macro 'GET_THREAD_ID'
# 12 | #define GET_THREAD_ID syscall(SYS_gettid)
# | ^
# /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:740:6: note: 'syscall' has been explicitly marked deprecated here
# 740 | int syscall(int, ...);
# | ^
# 4 warnings generated.
# (cd _build/default && /Users/tiferrei/.opam/default/bin/ocamlopt.opt -w -40 -g -I time_float_unix/time_unix/.time_unix.objs/byte -I time_float_unix/time_unix/.time_unix.objs/native -I /Users/tiferrei/.opam/default/lib/base -I /Users/tiferrei/.opam/default/lib/base/base_internalhash_types -I /Users/tiferrei/.opam/default/lib/base/md5 -I /Users/tiferrei/.opam/default/lib/base/shadow_stdlib -I /[...]
# File "time_float_unix/time_unix/time_unix.ml", line 1, characters 4-14:
# 1 | [@@@deprecated "[since 2022-04] Use [Time_float_unix] instead"]
# ^^^^^^^^^^
# Warning 53 [misplaced-attribute]: the "deprecated" attribute cannot appear in this context
In unrelated please let me know, and I'm happy to open another issue.
I am getting the same error as @tiferrei on macOS ARM Sonoma 14.7.2 and OCaml 5.3.0.
FWIW, one easy way to work around this if you just want to install with opam: edit your switch's lib/ocaml/caml/camlatomic.h to remove the #ifdef CAML_INTERNALS guard (and the corresponding #endif).
(I'm on macOS 15.2 & OCaml 5.3.0, but this hack probably works fine anywhere. I guess the bug is hidden on glibc platforms because glibc happens to define it's own atomic_load/store_<memorder> macros? idk.)
The reported issue has been fixed in v0.18~preview.130.00+55 (b0dee35) by moving #define CAML_INTERNALS before including any caml headers. Some were included inside ocaml_utils.h.
FWIW, one easy way to work around this if you just want to install with opam: edit your switch's lib/ocaml/caml/camlatomic.h to remove the #ifdef CAML_INTERNALS guard (and the corresponding #endif).
Instead of editing the switch I suggest applying this patch:
diff --git a/bigstring_unix/src/bigstring_unix_stubs.c b/bigstring_unix/src/bigstring_unix_stubs.c
index 0d4c7df..785ff10 100644
--- a/bigstring_unix/src/bigstring_unix_stubs.c
+++ b/bigstring_unix/src/bigstring_unix_stubs.c
@@ -46,6 +46,10 @@
#define bswap_64 bswap64
#endif
+#define CAML_INTERNALS
+#include <caml/io.h>
+#undef CAML_INTERNALS
+
#include "ocaml_utils.h"
#include "unix_utils.h"
#include <caml/socketaddr.h>
@@ -309,9 +313,6 @@ CAMLprim value bigstring_recvfrom_assume_fd_is_nonblocking_stub(value v_sock, va
/* I/O of bigstrings from channels */
-#define CAML_INTERNALS
-#include <caml/io.h>
-
CAMLprim value bigstring_input_stub(value v_min_len, value v_chan, value v_pos,
value v_len, value v_bstr) {
CAMLparam2(v_chan, v_bstr);
The syscall/GET_THREAD_ID is fixed by 0bb6267 in my #16.
I don't understand the misplaced attribute warning. May be related to https://github.com/ocaml/ocaml/issues/13054#issuecomment-2205839590.
@MisterDA's comment worked for me!
-
After the build failure, go in to ~/.opam/default/.opam-switch/build/core_unix.v0.17.0/bigstring_unix/src/bigstring_unix_stubs.c and do the changes shown in his comment.
-
Use the command
opam pin add core_unix "~/.opam/default/.opam-switch/build/core_unix.v0.17.0(opam pin add core_unix .if you are in the directory after your changes) to build.
This also affects amd64.
I ended up just building a unix container using Docker (the same one used for my Codespace) instead of trying to make it work on the Mac directly
Trying to pin the janestreet repo to get v0.18preview is too messy and just end up with other unexpected errors.