-
Notifications
You must be signed in to change notification settings - Fork 470
[BUG] C stubs dependencies are underspecified #13651
Copy link
Copy link
Closed
ocaml/opam-repository
#29562Description
Currently the rules that are used to build C stubs do not declare dependencies on the OCaml header files, only on their path, ie $(ocamlc -where)/caml). This means that if one switches compilers while keeping the same prefix (eg in a monorepo context), Dune will not rebuild C stubs. When using the Dune cache this is doubly bad of course.
One can reproduce the situation by running the following script in an empty directory. The script:
- installs 5.3.0,
- builds a simple C stub, and saves the verbose log in
build-5.3.0.log - installs 5.4.1 in the same prefix
- rebuilds the C stub (nothing actually gets rebuilt) and saves the verbose log in
build-5.4.1.log.
TL;DR: it is not enough to depend on the path to the headers; the rules to compile C stubs should declare dependencies on the actual headers *.h in that directory.
cc @Alizter
#!/bin/bash
set -euxo pipefail
DUNE=$(opam exec -- which dune)
build() {
rm -rf install
mkdir install
PREFIX=$(cd install && pwd)
if ! [ -d "ocaml-$1" ]; then
curl -L https://github.com/ocaml/ocaml/releases/download/$1/ocaml-$1.tar.gz | tar xz
fi
cd ocaml-$1
if ! [ -f Makefile.config ]; then
./configure --prefix=$PREFIX --disable-debugger --disable-ocamldoc --disable-ocamltest
fi
make -j
make install
cd ..
mkdir -p proj
cd proj
cat >dune-project <<EOF
(lang dune 3.21)
EOF
cat >dune <<EOF
(executable
(name main)
(foreign_stubs
(language c)
(names cstub)))
EOF
touch main.ml cstub.c
PATH="$PREFIX/bin:$PATH" $DUNE build --root . --display verbose _build/default/cstub.o > ../build-$1.log 2>&1
cd ..
}
build 5.3.0
build 5.4.1Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels