rb-sys icon indicating copy to clipboard operation
rb-sys copied to clipboard

libclang is not sufficient. fatal error: 'stdarg.h' file not found

Open sliiser opened this issue 1 year ago • 1 comments

I'm not sure if this issue belongs here in rb-sys, in libclang-rb or oxy-test. Let me know if I should post this elsewhere.

The README suggest using the libclang gem. However, this is not sufficient and crashes if clang is not installed.

Reproducible example

# Dockerfile
FROM ruby:3.3

RUN apt-get update
# RUN apt-get install -y clang

RUN echo "source 'https://rubygems.org'" > Gemfile

# Install only libclang first to ensure it is installed before oxy-test is installed,
# otherwise getting libclang not found errors.
RUN echo "gem 'libclang'" >> Gemfile
RUN bundle install

RUN echo "gem 'oxi-test', git: 'https://github.com/oxidize-rb/oxi-test.git'" >> Gemfile
RUN bundle install

Expected result:

rb-sys and oxi-test are installed.

This actually happens if RUN apt-get install -y clang above is uncommented. But, if clang is installed explicitly, then the libclang dependency is unnecessary.

Actual result:

Installing rb_sys 0.9.91
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
...
Compiling rb-sys v0.9.85
error: failed to run custom build command for `rb-sys v0.9.85`
Caused by:
process didn't exit successfully:
`/usr/local/bundle/bundler/gems/oxi-test-402571cd5ea1/ext/target/release/build/rb-sys-dd447c18433d495f/build-script-main`
...
thread 'main' panicked at
/usr/local/bundle/bundler/gems/oxi-test-402571cd5ea1/ext/.rb-sys/stable/cargo/registry/src/index.crates.io-6f17d22bba15001f/rb-sys-0.9.85/build/main.rs:55:6:
generate bindings: ClangDiagnostic("/usr/local/include/ruby-3.3.0/ruby/ruby.h:23:10: fatal error: 'stdarg.h' file not found\n")
...

Reproducible in both my local (arm64-darwin, meaning docker running aarch64-linux) and in CI buildkit (x86_64-linux)

Potential duplicate of https://github.com/oxidize-rb/rb-sys/issues/268 but slightly different error and has reproduction steps.

sliiser avatar Apr 05 '24 12:04 sliiser

we've experienced similar issue with cross-compiler (gcc) and our solution was to copy over clang/lib/Headers/* from clang sources and adding export BINDGEN_EXTRA_CLANG_ARGS=-I/some/dir/lib/clang/20/include

droopy4096 avatar Jun 25 '25 16:06 droopy4096