cibuildwheel icon indicating copy to clipboard operation
cibuildwheel copied to clipboard

Using Libclang in Rust build

Open maxwellflitton opened this issue 2 years ago • 0 comments

Description

I'm building a python crate in Rust using PyO3. I have managed to get cibuildwheel working in github actions for Windows, Mac, and Linux for a range versions and supporting Arch as well:

https://github.com/surrealdb/surrealdb.py/actions/runs/5545627578

However, when I add rocksdb into the rust project as a dependency the builds work fine for Windows builds but all Linux and mac builds break with the following:

 Running `/project/target/release/build/librocksdb-sys-f79e82b834bed183/build-script-build`
    error: failed to run custom build command for `librocksdb-sys v0.11.0+8.1.1`
  
    Caused by:
      process didn't exit successfully: `/project/target/release/build/librocksdb-sys-f79e82b834bed183/build-script-build` (exit status: 101)
      --- stderr
      thread 'main' panicked at '
      A `libclang` function was called that is not supported by the loaded `libclang` instance.
  
          called function = `clang_getTranslationUnitTargetInfo`
          loaded `libclang` instance = unsupported version
  
      This crate only supports `libclang` 3.5 and later.
      The minimum `libclang` requirement for this particular function can be found here:
      https://docs.rs/clang-sys/latest/clang_sys/clang_getTranslationUnitTargetInfo/index.html
  
      Instructions for installing `libclang` can be found here:
      https://rust-lang.github.io/rust-bindgen/requirements.html
      ', /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/clang-sys-1.6.1/src/lib.rs:1735:1
      note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
    cargo rustc --lib --message-format=json-render-diagnostics --manifest-path Cargo.toml --release -v --features pyo3/extension-module --crate-type cdylib --
    error: `cargo rustc --lib --message-format=json-render-diagnostics --manifest-path Cargo.toml --release -v --features pyo3/extension-module --crate-type cdylib --` failed with code 101
    error: subprocess-exited-with-error

I've read around libclang and tried to do some hacky workaround in the setup,py with the following code:

install_llvm = subprocess.Popen("yum install -y clang", shell=True)
install_llvm.wait()


user_lib_ls = subprocess.check_output(["ls", "/usr/lib/"]).decode().strip()
print(f"user_lib_ls: {user_lib_ls}")

import glob

file_patterns = ['libclang.so', 'libclang-*.so', 'libclang.so.*', 'libclang-*.so.*']
file_paths = []

for pattern in file_patterns:
    matching_files = glob.glob(pattern)
    file_paths.extend(matching_files)

print("file_paths from python:")
for i in file_paths:
    print(i)

Whilst it's installed clang I cannot find anything and the build still fails. Plus, I acknowledge that this approach will fall apart for Mac builds but I just want to get something working and build from there. Any advice on an approach would be greatly appreciated.

The CI config attached has versions and platforms commented out just to make the iteration testing a new approach quicker. They will all be uncommented once the problem is solved.

Build log

https://github.com/surrealdb/surrealdb.py/actions/runs/5554434012

CI config

https://github.com/surrealdb/surrealdb.py/blob/build-test/.github/workflows/cross_build.yml

maxwellflitton avatar Jul 15 '23 08:07 maxwellflitton