OCaml 4.07.1 fails to build with Apple XCode 12

I just got updated to XCode 12 and found that OCaml 4.07.1 - which I planned to use for a delivery of the Coq platform - doesn’t build any more. It ends with:

# Fatal error: exception Invalid_argument("Sys.getcwd not implemented")

Any ideas what I could do about this?

Something similar seems to be reported in opam here.

Could you maybe try to compile from the tarball to see if it’s an opam problem or something that changed in the dev tools.

What does uname -s output on your machine ?

uname -s just outputs Darwin.

That seems ok. How did you compile opam via brew ? What does Sys.os_type report in that compiler ?

A ./configure and make world.opt in a git clone at tag 4.07.1 ends with the same error.

I get opam via Macports. Until the update to XCode 12 it did work as expected.

Btw.: Compiling OCaml 4.11.1 does work with XCode 12.

How can I test this if the Compiler does not build?

Ah so it rather seems a configure problem, what’s does config.log say ? Given the other report I had the impression that configure was not run, that is that none of the tests here where succeeding (which is in fact impossible).

I meant in the compiler that built opam but forget about that. It’s unlikely to be the problem.

I wonder where the config.log file is - I can’t find anything after running ./configure. The console output of ./configure does not mention HAS_GETCWD.

Apparently the old version of the configure script (used before 4.08) does not output a config.log, so that’s expected. You could show us the contents of config/Makefile though, it should give us info. Also, if you could paste the output from running the configure script, that would help.

Here is the console output of configure:

ocaml$ ./configure
Configuring OCaml version 4.07.1
Configuring for host x86_64-apple-darwin19.6.0 ...
Configuring for target x86_64-apple-darwin19.6.0 ...
Using compiler gcc.
Compiler family and version: clang-12-0.
The C compiler is ISO C99 compliant.
Checking the sizes of integers and pointers...
Wow! A 64 bit architecture!
This is a little-endian architecture.
Doubles can be word-aligned.
64-bit integers can be word-aligned.
ranlib found
#! appears to work in shell scripts.
Signals have the System V semantics.
expm1(), log1p(), hypot(), copysign() found.
issetugid() found.
clock_gettime functions not found.  Instrumented runtime can't be built.
socklen_t is defined in <sys/socket.h>
stdint.h found.
unistd.h found.
off_t is defined in <sys/types.h>
dirent.h found.
sys/select.h found.
stat() supports nanosecond precision.
sys/shm.h found.
No replay debugger (missing system calls)
System stack overflow can be detected.
POSIX threads library supported.
Options for linking with POSIX threads: -lpthread
Bytecode threads library not supported (missing system calls)
X11 works
Options for compiling for X11: -I/opt/local/include
Options for linking with X11: -L/opt/local/lib -lX11
[WARNING] BFD library not found, 'objinfo' will be unable to display info  on .cmxs files.
Assembler supports CFI

** Configuration summary **

Directories where OCaml will be installed:
        binaries.................. /usr/local/bin
        standard library.......... /usr/local/lib/ocaml
        manual pages.............. /usr/local/man (with extension .1)
Configuration for the bytecode compiler:
        C compiler used........... gcc
        options for compiling.....  -O2 -fno-strict-aliasing -fwrapv
        options for linking.......     -lpthread
        shared libraries not supported
Configuration for the native-code compiler:
        hardware architecture..... amd64
        OS variant................ macosx
        C compiler used........... gcc
        options for compiling.....  -O2 -fno-strict-aliasing -fwrapv
        options for linking.......  
        assembler ................ clang -arch x86_64 -Wno-trigraphs -c
        preprocessed assembler ... clang -arch x86_64 -Wno-trigraphs -c
        assembler supports CFI ... yes
        with frame pointers....... no
        naked pointers forbidden.. no
        spacetime profiling....... no
        reserved bits in header... no
        C plugins................. no
        compile with -fPIC........ no
        native dynlink ........... true
        profiling with gprof ..... supported
        using flambda middle-end . no
        force safe strings ............. no
        (-safe-string is the default per-file option)
        flat float arrays ........ yes
        afl-fuzz always enabled .. no
Source-level replay debugger: not supported
Debug runtime will be compiled and installed
Additional libraries supported:
        unix str dynlink bigarray raw_spacetime_lib systhreads graph
Configuration for the "graph" library:
        options for compiling .... -I/opt/local/include
        options for linking ...... -L/opt/local/lib -lX11

** OCaml configuration completed successfully **

I grepped the complete folder for HAS_GETCWD, but I see defines only in ocaml/config/s-nt.h and ocaml/config/s-templ.h, so this looks bogus. What is the header file which is supposed to be generates by configure?

Ah, byterun/caml/s.h. It reads:

#define OCAML_OS_TYPE "Unix"
#define OCAML_STDLIB_DIR "/usr/local/lib/ocaml"
#define HAS_C99_FLOAT_OPS
#define HAS_STDINT_H
#define HAS_UNISTD
#define HAS_OFF_T
#define HAS_DIRENT
#define HAS_SYS_SHM_H

So the C compiler is probably not detected correctly: it says in the report that gcc is the C compiler in use, but it’s likely not working correctly. Can you try compiling a few small examples with gcc to see what happens ?
For example, the code used to detect getcwd:

int main() {
  return 0; }

With XCode a gcc is defined, but it is not gcc, but XCode. See the configure output:

Using compiler gcc.
Compiler family and version: clang-12-0.

I am currently testing what is going wrong with the configure tests.

Hmm, obvious thing - XCode 12 turned declaration warnings into errors:

test.c:2:3: error: implicit declaration of function 'getcwd' is invalid in C99
1 error generated.

If you can’t use a more recent version of OCaml (configuration detection is much more robust starting from 4.08), you can try using ./configure -cc "gcc -Wno-implicit-function-declaration". I don’t think the maintainers will be interested in fixing the old configure scripts and make releases with those fixes, but if it feels important to you feel free too make a bug report (at least more people will be aware of the issue).

1 Like

@vlaviron @dbuenzli : I exceeded my “first day message limit” yesterday, so I couldn’t answer any more. Just wanted to let you know that the fix suggested by @vlaviron works - I just patched the opam package (it is a bit tricky to get the patched repo in during switch creation, but it works - just had to read the docs).

What way forward would you suggest? Should I make a PR for the modified opam package or report an issue at OCaml?

Besides this issue and an issue in remake I didn’t have other issues with XCode 12 btw.

1 Like