ocaml / ocaml/dune

Dune does not correctly handle c_compiler using a shim

Open
#3,040 21 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

build c-bindings macos
Dominant language
OCaml
Stars
1.9k
Forks
500
Avg merge
15h 21m
Merged PRs (30d)
277

Description

Expected Behavior

In a macos environment, it is normal to specify the c-compiler using a shim, for example : "xcrun -sdk macosx10.14 clang". I would expect Dune to use this completely, and not try to interpret the arguments to the shim as arguments to the compiler (c_flags)

Actual Behavior

Dune interprets "-sdk macosx10.14 clang" as arguments and when processing ".c" files, it gets passed to ocamlc as "-ccopt sdk -ccopt macosx10.14 -ccopt clang". This cause the compiler to fail as ocamlc passes these options to clang (ocamlc apparently picks up the compiler specification from the environment variables, and uses the full "xcrun -sdk macosx10.14 clang" internally)

Reproduction

  • PR with a reproducing test:
  1. Set "CC=xcrun -sdk macosx10.14 clang" in lib/ocaml/std-lib/Makefile.config
  2. Compile a ocaml module having a c-stub (dune itself has fcntl_stubs.c which fails to compile on a mac with the above setting)

Specifications

  • Version of dune (output of dune --version): 2.0.0
  • Version of ocaml (output of ocamlc --version) : 4.06.1
  • Operating system (distribution and version): macos Mohave 10.14.6

Additional information

  • Link to gist with verbose output (run dune with the --verbose flag):

$ (cd _build/default/src/stdune && /usr/share/ocaml/bin/ocamlc.opt -g -I caml -ccopt -sdk -ccopt macosx10.14 -ccopt clang -ccopt -mmacosx-version-min=10.9 -ccopt -O2 -ccopt -pipe -ccopt -fno-common -ccopt -O2 -ccopt -fno-strict-aliasing -ccopt -fwrapv -ccopt -g -o fcntl_stubs.o fcntl_stubs.c)
clang: error: unknown argument: '-sdk'
clang: error: no such file or directory: 'macosx10.14'
clang: error: no such file or directory: 'clang'

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure using CC=xcrun -sdk macosx10.14 clang and the c-stub in lib/ocaml/std-lib/Makefile.config, then inspect how Dune handles that compiler setting. The change is done when compiling fcntl_stubs.c no longer forwards the shim's arguments as separate c_flags and the shown ocamlc command succeeds.

Written by the indexing model from the issue text.

Assessment

Tech stack
ocaml
Domain
build-system, compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.