Skip to content

Building dune static using musl triggers compilation error #12313

@maiste

Description

@maiste

While building the ocaml-dune/binary-distribution, I have encountered a regression when building the static version.

Expected Behavior

It builds without error.

Actual Behavior

> otherlibs/stdune/src/copyfile_stubs.c:91:43: error: unknown type name 'loff_t'; did you mean 'off_t'?
> otherlibs/stdune/src/copyfile_stubs.c:91:57: error: unknown type name 'loff_t'; did you mean 'off_t'?
> otherlibs/stdune/src/copyfile_stubs.c:93:8: error: unknown type name 'copy_file_range_t'
> otherlibs/stdune/src/copyfile_stubs.c:93:47: error: initialization of 'int' from 'void *' makes integer from pointer without a cast [-Wint-conversion]
> otherlibs/stdune/src/copyfile_stubs.c: In function 'dune_copy_file_range':
> otherlibs/stdune/src/copyfile_stubs.c:98:11: error: called object 'copy_file_range_fn' is not a function or function pointer
> otherlibs/stdune/src/copyfile_stubs.c:93:26: note: declared here
> otherlibs/stdune/src/copyfile_stubs.c: In function 'stdune_sendfile':
> otherlibs/stdune/src/copyfile_stubs.c:124:32: error: 'copy_file_range_t' undeclared (first use in this function); did you mean 'copy_file_range_fn'?
> otherlibs/stdune/src/copyfile_stubs.c:124:32: note: each undeclared identifier is reported only once for each function it appears in
> otherlibs/stdune/src/copyfile_stubs.c:124:50: error: expected ')' before 'dlsym'

It can be reduced to this error:

> otherlibs/stdune/src/copyfile_stubs.c:91:43: error: unknown type name 'loff_t'; did you mean 'off_t'?

Reproduction

An example of the error can be found in https://github.com/ocaml-dune/binary-distribution/actions/runs/17226133735/job/48870893140

To reproduce, just run nix build .#dune-static (or nix build .#dune-static-experimental but they have the same root).

Specifications

  • Version of dune (output of dune --version): main with commit a88ec65
  • Version of ocaml (output of ocamlc --version): 5.3.0
  • Operating system (distribution and version): Arch Linux

Problem

The regression can be traced to #12074. Before this PR it works, after it generates the errors above.

From what I found about it, it seems to be related to the fact that musl defines loff_t type as a cpp macro instead of a typedef. Two solutions I have found are:

Not having touch C for a while, I'd like to have input from more competent C people 😄

cc @nojb @rgrinberg

Metadata

Metadata

Assignees

No one assigned

    Labels

    otherlibsRelated to internal dune libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions