oxidize-rb / rb-sys

Easily build Ruby native extensions in Rust
https://oxidize-rb.github.io/rb-sys/
Apache License 2.0
219 stars 34 forks source link

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

Open sliiser opened 4 months ago

sliiser commented 4 months ago

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.