core_unix icon indicating copy to clipboard operation
core_unix copied to clipboard

opam install core_unix fails on macos/x86_64

Open gav451 opened this issue 9 months ago β€’ 5 comments

The terminal output below indicates that syscall has been explicitly deprecated:

% opam install core_unix
The following actions will be performed:
=== install 1 package
  βˆ— core_unix v0.17.0

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
⬇ retrieved core_unix.v0.17.0  (cached)
[ERROR] The compilation of core_unix.v0.17.0 failed at "dune build -p core_unix
        -j 3".

#=== ERROR while compiling core_unix.v0.17.0 ==================================#
# context     2.3.0 | macos/x86_64 | ocaml.5.3.0 | https://opam.ocaml.org#580fdfb74226d1dc1fad223ca0d05ab70a42bca1
# 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 3
# exit-code   1
# env-file    ~/.opam/log/core_unix-15106-be3e6b.env
# output-file ~/.opam/log/core_unix-15106-be3e6b.out
### output ###
# [...]
# ./thread_id.h:12:23: note: expanded from macro 'GET_THREAD_ID'
# #define GET_THREAD_ID syscall(SYS_gettid)
#                       ^
# /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/unistd.h:746:6: note: 'syscall' has been explicitly marked deprecated here
# int      syscall(int, ...);
#          ^
# 4 warnings generated.
# (cd _build/default && /Users/vermeulen/.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/vermeulen/.opam/default/lib/base -I /Users/vermeulen/.opam/default/lib/base/base_internalhash_types -I /Users/vermeulen/.opam/default/lib/base/md5 -I /Users/vermeulen/.opam/default/lib/base/shadow_stdlib[...]
# 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



<><> Error report <><><><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
β”Œβ”€ The following actions failed
β”‚ Ξ» build core_unix v0.17.0
└─
╢─ No changes have been performed

gav451 avatar Mar 15 '25 09:03 gav451

I've hit a similar issue whilst trying to build core_unix. However, what gets printed to stdout seems to only be warnings; I believe the notice about syscall() getting deprecated is a red herring.

Inspecting the output file from my run, we see the actual error in question:

In file included from bigstring_unix_stubs.c:316:
In file included from /Users/ntaylor/.opam/default/lib/ocaml/caml/io.h:28:
/Users/ntaylor/.opam/default/lib/ocaml/caml/platform.h:222:10: error: call to undeclared function 'atomic_load_acquire'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  222 |   return atomic_load_acquire(&latch->value) == Latch_released;
      |          ^
/Users/ntaylor/.opam/default/lib/ocaml/caml/platform.h:230:3: error: call to undeclared function 'atomic_store_release'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
  230 |   atomic_store_release(&latch->value, Latch_unreleased);
      |   ^
/Users/ntaylor/.opam/default/lib/ocaml/caml/platform.h:311:3: error: call to undeclared function 'atomic_store_release'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]                                                                                                                                                                311 |   atomic_store_release(&barrier->arrived, 0);                                                                                                                                             |   ^                                                                                                                                                                                 
/Users/ntaylor/.opam/default/lib/ocaml/caml/platform.h:337:11: error: call to undeclared function 'atomic_load_acquire'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]                                                                                                                                                                337 |   return (atomic_load_acquire(&barrier->futex.value) & BARRIER_SENSE_BIT)                                                                                                                 |           ^                                                                                                                                                                         4 errors generated.

dijkstracula avatar Mar 19 '25 14:03 dijkstracula

Looking at this a bit more: the header file that is failing to compile seems to be part of the OCaml runtime and is not specific to core_unix, per se. It's not obvious to me why OCaml itself should be able to compile with these missing intrinsics (perhaps platform.h is a part of the FFI and core_unix happened to be the first package I tried to install that included it?). Perhaps this issue should be forwarded to the OCaml team instead.

In particular: At an extremely brief glance, atomic_load_* and friends appears to be a macro exposed in a header file called camlatomic.h, which, up until the 5.3 release, was implemented in platform.h. It is possible that if the fix is on core_unix's side, it is to ensure that at whatever point platform.h gets picked up, camlatomic.h is also included. Though, in my opinion, it seems logical that including the latter is the responsibility of the former (and thus the responsibility of OCaml to fix.)

@gav451 : in the meantime, downgrading your OCaml verison to 5.2.0 ought to make things right for the moment:

$ opam switch create 5.2.0
$ eval $(opam env --switch=5.2.0)
$ opam install core_unix
   ...
βˆ— installed core_unix.v0.17.0
Done.
$ 

dijkstracula avatar Mar 19 '25 14:03 dijkstracula

@dijkstracula: I am an OCaml newbie, thanks for the work-around tip.

gav451 avatar Mar 19 '25 16:03 gav451

An OCaml maintainer replied thus: https://github.com/ocaml/ocaml/issues/13883#issuecomment-2737143525 - they propose that the placement of the CAML_INTERNALS directive in bigstring_unix_stubs.c is at play. (I'll admit it's not obvious to me how the particular patch they propose would affect anything, since the headers included prior to the point of definition seem to be agnostic to OCaml itself, but there you have it)

dijkstracula avatar Mar 19 '25 16:03 dijkstracula

Note that the issue is fixed on master, and there is a number of #include <caml/..> before the #define CAML_INTERNALS in the v0.17 branch

Octachron avatar Mar 19 '25 16:03 Octachron