[llvm] 3f64ba5 - [OCaml] Try to fix library dependencies (#171470)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 22 01:09:24 PST 2025
Author: Nikita Popov
Date: 2025-12-22T10:09:21+01:00
New Revision: 3f64ba5b5ba88d31df93b4a5a72081aae73ce623
URL: https://github.com/llvm/llvm-project/commit/3f64ba5b5ba88d31df93b4a5a72081aae73ce623
DIFF: https://github.com/llvm/llvm-project/commit/3f64ba5b5ba88d31df93b4a5a72081aae73ce623.diff
LOG: [OCaml] Try to fix library dependencies (#171470)
Whenever I try to change anything in the OCaml bindings, I run into
errors like this when running tests:
```
File
"/home/npopov/repos/llvm-project/build/test/Bindings/OCaml/Output/debuginfo.ml.tmp/Testsuite.ml",
line 1:
Warning 70 [missing-mli]: Cannot find interface file.
File
"/home/npopov/repos/llvm-project/build/test/Bindings/OCaml/Output/debuginfo.ml.tmp/debuginfo.ml",
line 1:
Error: The files
"/home/npopov/repos/llvm-project/build/lib/ocaml/llvm/llvm.cmi"
and
"/home/npopov/repos/llvm-project/build/lib/ocaml/llvm/llvm_debuginfo.cmi"
make inconsistent assumptions over interface "Llvm"
```
The only reliable way of getting rid of these I have found is to do an
`rm -rf build` and just rebuild everything.
The root cause of this issue is that we currently add
target-dependencies between ocaml modules, but we don't have file-level
dependencies. This means that everything gets built in the correct
order, but targets don't get rebuilt if a dependency is changed.
To fix this, add file-level dependencies to the custom command. These
are generated via a target property that stores the ocaml outputs of the
target.
Added:
Modified:
llvm/cmake/modules/AddOCaml.cmake
Removed:
################################################################################
diff --git a/llvm/cmake/modules/AddOCaml.cmake b/llvm/cmake/modules/AddOCaml.cmake
index 2d9116b08a526..9a393ae3b7474 100644
--- a/llvm/cmake/modules/AddOCaml.cmake
+++ b/llvm/cmake/modules/AddOCaml.cmake
@@ -57,9 +57,12 @@ function(add_ocaml_library name)
"-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/../.."
${ocaml_pkgs})
+ set(ocaml_dep_inputs)
foreach( ocaml_dep ${ARG_OCAMLDEP} )
get_target_property(dep_ocaml_flags "ocaml_${ocaml_dep}" OCAML_FLAGS)
list(APPEND ocaml_flags ${dep_ocaml_flags})
+ get_target_property(dep_ocaml_outputs "ocaml_${ocaml_dep}" OCAML_OUTPUTS)
+ list(APPEND ocaml_dep_inputs ${dep_ocaml_outputs})
endforeach()
if( NOT BUILD_SHARED_LIBS )
@@ -157,7 +160,7 @@ function(add_ocaml_library name)
OUTPUT ${ocaml_outputs}
COMMAND "${OCAMLFIND}" "ocamlmklib" "-ocamlcflags" "-bin-annot"
"-o" "${name}" ${ocaml_flags} ${ocaml_params}
- DEPENDS ${ocaml_inputs} ${c_outputs}
+ DEPENDS ${ocaml_inputs} ${ocaml_dep_inputs} ${c_outputs}
COMMENT "Building OCaml library ${name}"
VERBATIM)
@@ -168,7 +171,7 @@ function(add_ocaml_library name)
"-I" "${LLVM_LIBRARY_DIR}/ocaml/llvm/"
"-dump" "${bin}/${name}.odoc"
${ocaml_pkgs} ${ocaml_inputs}
- DEPENDS ${ocaml_inputs} ${ocaml_outputs}
+ DEPENDS ${ocaml_inputs} ${ocaml_dep_inputs} ${ocaml_outputs}
COMMENT "Building OCaml documentation for ${name}"
VERBATIM)
@@ -180,6 +183,8 @@ function(add_ocaml_library name)
OCAML_FLAGS "-I;${bin}")
set_target_properties("ocaml_${name}" PROPERTIES
OCAML_ODOC "${bin}/${name}.odoc")
+ set_target_properties("ocaml_${name}" PROPERTIES
+ OCAML_OUTPUTS "${ocaml_outputs}")
foreach( ocaml_dep ${ARG_OCAMLDEP} )
add_dependencies("ocaml_${name}" "ocaml_${ocaml_dep}")
More information about the llvm-commits
mailing list