Skip to content

Commit

Permalink
Fix patch
Browse files Browse the repository at this point in the history
  • Loading branch information
alan-j-hu committed Jan 25, 2025
1 parent 527feec commit ab7c7d1
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions patches/llvm/AddOCaml.cmake.patch.18
Original file line number Diff line number Diff line change
@@ -1,8 +1,23 @@
--- a/llvm/cmake/modules/AddOCaml.cmake
+++ b/llvm/cmake/modules/AddOCaml.cmake
@@ -39,11 +39,12 @@ function(add_ocaml_library name)
@@ -38,12 +38,27 @@ function(add_ocaml_library name)
set(ocaml_inputs)

set(ocaml_outputs "${bin}/${name}.cma")
+
+ # The -custom flag causes bytecode executables to fail upon creating the
+ # runtime when installing the bindings for an out-of-tree build.
+ #
+ # However, the -custom flag is necessary when running the in-tree
+ # test suite, otherwise multiple libraries will link to the same libLLVM and
+ # runtime errors of the form
+ # "CommandLine Error: Option *opt* registered more than once!" will occur.
+ if (NOT LLVM_OCAML_OUT_OF_TREE AND NOT BUILD_SHARED_LIBS)
+ set(ocaml_custom TRUE)
+ else()
+ set(ocaml_custom FALSE)
+ endif()
+
if( ARG_C )
+ # ocamlmklib outputs .a and .so
list(APPEND ocaml_outputs
Expand All @@ -16,7 +31,7 @@
endif()
endif()
if( HAVE_OCAMLOPT )
@@ -52,7 +53,12 @@ function(add_ocaml_library name)
@@ -52,7 +67,12 @@ function(add_ocaml_library name)
"${bin}/${name}${CMAKE_STATIC_LIBRARY_SUFFIX}")
endif()

Expand All @@ -30,19 +45,12 @@
"-ccopt" "-L\\$CAMLORIGIN/../.."
"-ccopt" "-Wl,-rpath,\\$CAMLORIGIN/../.."
${ocaml_pkgs})
@@ -62,12 +68,19 @@ function(add_ocaml_library name)
@@ -62,12 +82,12 @@ function(add_ocaml_library name)
list(APPEND ocaml_flags ${dep_ocaml_flags})
endforeach()

- if( NOT BUILD_SHARED_LIBS )
+ # Not passing the -custom flag is necessary for the bytecode to work when
+ # installing the bindings for an out-of-tree build.
+ #
+ # However, the -custom flag is necessary when running the in-tree
+ # test suite, otherwise multiple libraries will link to the same libLLVM and
+ # runtime errors of the form
+ # "CommandLine Error: Option *opt* registered more than once!" will occur.
+ if( NOT LLVM_OCAML_OUT_OF_TREE AND NOT BUILD_SHARED_LIBS )
+ if(ocaml_custom)
list(APPEND ocaml_flags "-custom")
endif()

Expand All @@ -52,7 +60,7 @@
else()
explicit_map_components_to_libraries(llvm_libs ${ARG_LLVM})
foreach( llvm_lib ${llvm_libs} )
@@ -201,9 +214,9 @@ function(add_ocaml_library name)
@@ -201,9 +221,9 @@ function(add_ocaml_library name)
if( NOT (ext STREQUAL ".cmo" OR
ext STREQUAL ".ml" OR
ext STREQUAL CMAKE_C_OUTPUT_EXTENSION OR
Expand Down

0 comments on commit ab7c7d1

Please sign in to comment.