Skip to content

[OCaml] Build OCaml bindings using Dune #67272

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open

Conversation

alan-j-hu
Copy link
Contributor

@alan-j-hu alan-j-hu commented Sep 24, 2023

This PR still needs some cleanup. Problems of note:

  • The function llvm_diagnostic_handler_trampoline in llvm_ocaml.c needs to be marked as static or else the linker will produce an error about non-relocatable code. Even though the error message suggests adding -fPIC, adding this flag doesn't seem to fix the issue. This issue does not happen with the current CMake+OCamlfind build system.
  • I currently surround the OCaml doc generation with if(FALSE) endif(). What should I do with this?

The OCaml unit tests currently pass on my computer (if you build ocaml_all and then check-llvm-bindings-ocaml). Therefore, the PR is in a state in which I would appreciate other pairs of eyes to see if this work is on the right track, and if there is possibility that the OCaml bindings could use Dune.

@github-actions
Copy link

github-actions bot commented Sep 24, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@alan-j-hu
Copy link
Contributor Author

alan-j-hu commented Sep 25, 2023

I realized that when I nuked the build directory and tried again, I can't get the build to work again. The reason is that for each backend, there is some implicit dependency on some other libLLVMSomeTargetMCA.a, such that adding a dependency via CMake add_dependencies does not cause it to be built, but when calling llvm-config --libs <backend>, llvm-config will emit an error that libLLVMSomeTargetMCA.a does not exist.

e.g.

(cd _build/default/backends/AMDGPU && ../../discover.sh AMDGPU)
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMMCA.a
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMAMDGPUTargetMCA.a
(cd _build/default/backends/RISCV && ../../discover.sh RISCV)
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMMCA.a
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMRISCVTargetMCA.a
(cd _build/default/backends/X86 && ../../discover.sh X86)
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMMCA.a
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMX86TargetMCA.a
(cd _build/default/all_backends && ../discover.sh AArch64 AMDGPU ARM AVR BPF Hexagon Lanai LoongArch Mips MSP430 NVPTX PowerPC RISCV Sparc SystemZ VE WebAssembly X86 XCore)
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMMCA.a
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMAMDGPUTargetMCA.a
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMRISCVTargetMCA.a
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMX86TargetMCA.a
(cd _build/default/executionengine && ../discover.sh executionengine mcjit native)
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMMCA.a
llvm-config: error: missing: /home/me/llvm-project/builddune/lib/libLLVMX86TargetMCA.a

Edit: However, building a second time always succeeds. It seems that Dune just ignores the failure to generate a c_library_flags.sexp the second time.

@alan-j-hu
Copy link
Contributor Author

Fixed the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant