Skip to content
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

Cannot build for RubyInstaller version of Ruby #162

Closed
NuriYuri opened this issue Mar 10, 2023 · 7 comments
Closed

Cannot build for RubyInstaller version of Ruby #162

NuriYuri opened this issue Mar 10, 2023 · 7 comments

Comments

@NuriYuri
Copy link

Hello,

I've seen that rb-sys is going to be integrated with Rutie (which should probably improve Rutie a bit), regarless I have a little issue with rb-sys on my end (and also the end of all people that depends on the work of my community). I cannot build for i686-pc-windows-gnu.

This requirement comes from two factor:

  1. I have to support x86 operating system (still widespread in my community)
  2. We have to use RubyInstaller version of Ruby (mingw32/64 build using gcc, supporting all the standard ruby features & digitally signed unlike home made builds).

Here's the log I got for attempting to build (I ran the ridk enable command which works for rake-compile or building current version of rutie or any rust lib using rutie ^^):

D:\nuriy\Downloads\rb-sys>set "PATH=X:\Ruby30\bin;X:\Ruby30\msys32\mingw32\bin;X:\Ruby30\msys32\usr\bin;C:\Python311\Scripts\;C:\Python311\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\Git\cmd;C:\Program Files\nodejs\;C:\ProgramData\chocolatey\bin;X:\Ruby30\bin;C:\Users\nuriy\.cargo\bin;C:\Users\nuriy\AppData\Local\Microsoft\WindowsApps;;C:\Users\nuriy\AppData\Local\Programs\Microsoft VS Code\bin;X:\System128\roaming\npm"

D:\nuriy\Downloads\rb-sys>cargo build --target i686-pc-windows-gnu --release
   Compiling memchr v2.5.0
   Compiling proc-macro2 v1.0.50
   Compiling winapi v0.3.9
   Compiling glob v0.3.1
   Compiling quote v1.0.23
   Compiling libc v0.2.139
   Compiling syn v1.0.109
   Compiling unicode-ident v1.0.6
   Compiling bindgen v0.60.1
   Compiling minimal-lexical v0.2.1
   Compiling regex-syntax v0.6.28
   Compiling lazy_static v1.4.0
   Compiling peeking_take_while v0.1.2
   Compiling rustc-hash v1.1.0
   Compiling shlex v1.1.0
   Compiling bitflags v1.3.2
   Compiling lazycell v1.3.0
   Compiling winapi-i686-pc-windows-gnu v0.4.0
   Compiling shell-words v1.1.0
   Compiling cc v1.0.79
   Compiling clang-sys v1.4.0
   Compiling nom v7.1.3
   Compiling aho-corasick v0.7.20
   Compiling libloading v0.7.4
   Compiling regex v1.7.1
   Compiling rb-sys-env v0.1.2 (D:\nuriy\Downloads\rb-sys\crates\rb-sys-env)
   Compiling rb-sys-tests v0.9.67 (D:\nuriy\Downloads\rb-sys\crates\rb-sys-tests)
   Compiling cexpr v0.6.0
   Compiling rb-sys-build v0.9.67 (D:\nuriy\Downloads\rb-sys\crates\rb-sys-build)
   Compiling ctor v0.1.26
   Compiling rb-sys v0.9.67 (D:\nuriy\Downloads\rb-sys\crates\rb-sys)
error: failed to run custom build command for `rb-sys v0.9.67 (D:\nuriy\Downloads\rb-sys\crates\rb-sys)`

Caused by:
  process didn't exit successfully: `D:\nuriy\Downloads\rb-sys\target\release\build\rb-sys-61e177a78593a2aa\build-script-main` (exit code: 101)
  --- stdout
  cargo:rerun-if-env-changed=RUBY
  cargo:rerun-if-env-changed=RBCONFIG_DEFFILE
  cargo:rerun-if-env-changed=RBCONFIG_ruby_version
  cargo:rerun-if-env-changed=RBCONFIG_platform
  cargo:rerun-if-env-changed=RBCONFIG_arch
  cargo:rerun-if-env-changed=RUBY_ROOT
  cargo:rerun-if-env-changed=RUBY_VERSION
  cargo:rerun-if-env-changed=RUBY
  cargo:rerun-if-changed=build\features.rs
  cargo:rerun-if-changed=build\main.rs
  cargo:rerun-if-changed=build\ruby_macros.rs
  cargo:rerun-if-changed=build\version.rs
  cargo:rerun-if-env-changed=RUBY_STATIC
  cargo:rerun-if-env-changed=RBCONFIG_ENABLE_SHARED
  cargo:rerun-if-env-changed=RBCONFIG_rubyhdrdir
  cargo:rerun-if-env-changed=RBCONFIG_rubyarchhdrdir
  cargo:rerun-if-env-changed=RBCONFIG_CPPFLAGS

  --- stderr
  Using bindgen with clang args: ["-IX:/Ruby30/include/ruby-3.0.0", "-IX:/Ruby30/include/ruby-3.0.0/i386-mingw32", "-fms-extensions", "-O3", "-fno-omit-frame-pointer", "-ggdb3", "-Wall", "-Wextra", "-Wdeprecated-declarations", "-Wduplicated-cond", "-Wimplicit-function-declaration", "-Wimplicit-int", "-Wmisleading-indentation", "-Wpointer-arith", "-Wwrite-strings", "-Wimplicit-fallthrough=0", "-Wmissing-noreturn", "-Wno-cast-function-type", "-Wno-constant-logical-operand", "-Wno-long-long", "-Wno-missing-field-initializers", "-Wno-overlength-strings", "-Wno-packed-bitfield-compat", "-Wno-parentheses-equality", "-Wno-self-assign", "-Wno-tautological-compare", "-Wno-unused-parameter", "-Wno-unused-value", "-Wsuggest-attribute=format", "-Wsuggest-attribute=noreturn", "-Wunused-variable", "-D__USE_MINGW_ANSI_STDIO=1", "-DFD_SETSIZE=2048", "-D_WIN32_WINNT=0x0600", "-D__MINGW_USE_VC2005_COMPAT", "-D_FILE_OFFSET_BITS=64"]
  thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [])"', C:\Users\nuriy\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.60.1\src/lib.rs:2172:31
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

From what I get it's trying to build with clang, which isn't the right tool because it might not be able to link with the symbol of Ruby since it was built using gcc (two different gcc version aren't even compatible between them so I don't really imagine what would happen when trying to link gcc stuff using clang).

@ianks
Copy link
Collaborator

ianks commented Mar 11, 2023

Thanks for posting the issue @NuriYuri!

libclang is only needed for generating bindings to libruby using bindgen, no it’s not actually involved in the linking process. Installing libclang will hopefully resolve this issue.

In the meantime, I should mention this in the readme so that’s more clear. LMK how it goes!

@NuriYuri
Copy link
Author

NuriYuri commented Mar 11, 2023

Ok, thanks for the info :)

I tried with:

pacman -S mingw-w64-i686-clang
SET LIBCLANG_PATH=X:\Ruby30\msys32\mingw32\bin

And got:

   Compiling rb-sys v0.9.67 (D:\nuriy\Downloads\rb-sys\crates\rb-sys)
error: failed to run custom build command for `rb-sys v0.9.67 (D:\nuriy\Downloads\rb-sys\crates\rb-sys)`

Caused by:
  process didn't exit successfully: `D:\nuriy\Downloads\rb-sys\target\release\build\rb-sys-61e177a78593a2aa\build-script-main` (exit code: 101)
  --- stdout
  cargo:rerun-if-env-changed=RUBY
  cargo:rerun-if-env-changed=RBCONFIG_DEFFILE
  cargo:rerun-if-env-changed=RBCONFIG_ruby_version
  cargo:rerun-if-env-changed=RBCONFIG_platform
  cargo:rerun-if-env-changed=RBCONFIG_arch
  cargo:rerun-if-env-changed=RUBY_ROOT
  cargo:rerun-if-env-changed=RUBY_VERSION
  cargo:rerun-if-env-changed=RUBY
  cargo:rerun-if-changed=build\features.rs
  cargo:rerun-if-changed=build\main.rs
  cargo:rerun-if-changed=build\ruby_macros.rs
  cargo:rerun-if-changed=build\version.rs
  cargo:rerun-if-env-changed=RUBY_STATIC
  cargo:rerun-if-env-changed=RBCONFIG_ENABLE_SHARED
  cargo:rerun-if-env-changed=RBCONFIG_rubyhdrdir
  cargo:rerun-if-env-changed=RBCONFIG_rubyarchhdrdir
  cargo:rerun-if-env-changed=RBCONFIG_CPPFLAGS

  --- stderr
  Using bindgen with clang args: ["-IX:/Ruby30/include/ruby-3.0.0", "-IX:/Ruby30/include/ruby-3.0.0/i386-mingw32", "-fms-extensions", "-O3", "-fno-omit-frame-pointer", "-ggdb3", "-Wall", "-Wextra", "-Wdeprecated-declarations", "-Wduplicated-cond", "-Wimplicit-function-declaration", "-Wimplicit-int", "-Wmisleading-indentation", "-Wpointer-arith", "-Wwrite-strings", "-Wimplicit-fallthrough=0", "-Wmissing-noreturn", "-Wno-cast-function-type", "-Wno-constant-logical-operand", "-Wno-long-long", "-Wno-missing-field-initializers", "-Wno-overlength-strings", "-Wno-packed-bitfield-compat", "-Wno-parentheses-equality", "-Wno-self-assign", "-Wno-tautological-compare", "-Wno-unused-parameter", "-Wno-unused-value", "-Wsuggest-attribute=format", "-Wsuggest-attribute=noreturn", "-Wunused-variable", "-D__USE_MINGW_ANSI_STDIO=1", "-DFD_SETSIZE=2048", "-D_WIN32_WINNT=0x0600", "-D__MINGW_USE_VC2005_COMPAT", "-D_FILE_OFFSET_BITS=64"]
  thread 'main' panicked at 'Unable to find libclang: "couldn't find any valid shared libraries matching: ['clang.dll', 'libclang.dll'], set the `LIBCLANG_PATH` environment variable to a path where one of these files can be found (invalid: [(X:\\Ruby30\\msys32\\mingw32\\bin\\libclang.dll: invalid DLL (32-bit))])"', C:\Users\nuriy\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.60.1\src/lib.rs:2172:31
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Also tried (just in case)

pacman -S mingw-w64-x86_64-clang
SET LIBCLANG_PATH=X:\Ruby30\msys32\mingw64\bin

And got:

   Compiling rb-sys v0.9.67 (D:\nuriy\Downloads\rb-sys\crates\rb-sys)
error: failed to run custom build command for `rb-sys v0.9.67 (D:\nuriy\Downloads\rb-sys\crates\rb-sys)`

Caused by:
  process didn't exit successfully: `D:\nuriy\Downloads\rb-sys\target\release\build\rb-sys-61e177a78593a2aa\build-script-main` (exit code: 101)
  --- stdout
  cargo:rerun-if-env-changed=RUBY
  cargo:rerun-if-env-changed=RBCONFIG_DEFFILE
  cargo:rerun-if-env-changed=RBCONFIG_ruby_version
  cargo:rerun-if-env-changed=RBCONFIG_platform
  cargo:rerun-if-env-changed=RBCONFIG_arch
  cargo:rerun-if-env-changed=RUBY_ROOT
  cargo:rerun-if-env-changed=RUBY_VERSION
  cargo:rerun-if-env-changed=RUBY
  cargo:rerun-if-changed=build\features.rs
  cargo:rerun-if-changed=build\main.rs
  cargo:rerun-if-changed=build\ruby_macros.rs
  cargo:rerun-if-changed=build\version.rs
  cargo:rerun-if-env-changed=RUBY_STATIC
  cargo:rerun-if-env-changed=RBCONFIG_ENABLE_SHARED
  cargo:rerun-if-env-changed=RBCONFIG_rubyhdrdir
  cargo:rerun-if-env-changed=RBCONFIG_rubyarchhdrdir
  cargo:rerun-if-env-changed=RBCONFIG_CPPFLAGS

  --- stderr
  Using bindgen with clang args: ["-IX:/Ruby30/include/ruby-3.0.0", "-IX:/Ruby30/include/ruby-3.0.0/i386-mingw32", "-fms-extensions", "-O3", "-fno-omit-frame-pointer", "-ggdb3", "-Wall", "-Wextra", "-Wdeprecated-declarations", "-Wduplicated-cond", "-Wimplicit-function-declaration", "-Wimplicit-int", "-Wmisleading-indentation", "-Wpointer-arith", "-Wwrite-strings", "-Wimplicit-fallthrough=0", "-Wmissing-noreturn", "-Wno-cast-function-type", "-Wno-constant-logical-operand", "-Wno-long-long", "-Wno-missing-field-initializers", "-Wno-overlength-strings", "-Wno-packed-bitfield-compat", "-Wno-parentheses-equality", "-Wno-self-assign", "-Wno-tautological-compare", "-Wno-unused-parameter", "-Wno-unused-value", "-Wsuggest-attribute=format", "-Wsuggest-attribute=noreturn", "-Wunused-variable", "-D__USE_MINGW_ANSI_STDIO=1", "-DFD_SETSIZE=2048", "-D_WIN32_WINNT=0x0600", "-D__MINGW_USE_VC2005_COMPAT", "-D_FILE_OFFSET_BITS=64"]
  thread 'main' panicked at 'Unable to find libclang: "the `libclang` shared library at X:\\Ruby30\\msys32\\mingw64\\bin\\libclang.dll could not be opened: LoadLibraryExW failed"', C:\Users\nuriy\.cargo\registry\src\github.com-1ecc6299db9ec823\bindgen-0.60.1\src/lib.rs:2172:31
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Note: I did remove the other package before installing the other one.

@NuriYuri
Copy link
Author

Hi, I tried to build several crates depending on bindgen (such as libsqlite3-sys or rust-sdl2) and they all succeed.

The only one that fails is rb-sys, for some reason inside bindgen it's getting confused about target_pointer_width and it assumes that the value is 64 instead of 32...

I tried to check what's wrong with rb-sys but so far no clues putting aside it doesn't have a build.rs file next to its Cargo.toml file.

@matsadler
Copy link
Contributor

Bindgen can be used from the command line as well as a library, I have a script here: https://gist.github.com/matsadler/2c563f170e07fd802872086f6f45d65b that is roughly equivalent to what rb-sys does (at least as far as invoking bindgen).

Maybe giving that a try would help track down if it's a bindgen + Ruby problem or an rb-sys problem?

@ianks
Copy link
Collaborator

ianks commented Mar 16, 2023

@goyox86 said he could boot up his i686 box to take a look as well

@NuriYuri
Copy link
Author

Bindgen can be used from the command line as well as a library, I have a script here: https://gist.github.com/matsadler/2c563f170e07fd802872086f6f45d65b that is roughly equivalent to what rb-sys does (at least as far as invoking bindgen).

Maybe giving that a try would help track down if it's a bindgen + Ruby problem or an rb-sys problem?

Thanks for your reply. I installed bindgen this way:

cargo install bindgen-cli --target i686-pc-windows-gnu

The sh scripts printed this:

clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/missing.h:123:20: warning: redeclaration of 'tgamma' should not add 'dllimport' attribute [-Wdll-attribute-on-redeclaration]
clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/internal/core/rbasic.h:46:1: warning: unknown attribute 'align' ignored [-Wunknown-attributes]
clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/internal/fl_type.h:285:1: warning: unknown attribute 'noalias' ignored [-Wunknown-attributes]
clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/internal/fl_type.h:310:1: warning: unknown attribute 'noalias' ignored [-Wunknown-attributes]
clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/internal/fl_type.h:335:1: warning: unknown attribute 'noalias' ignored [-Wunknown-attributes]
clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/internal/symbol.h:77:1: warning: unknown attribute 'noalias' ignored [-Wunknown-attributes]
clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/internal/intern/select/win32.h:58:1: warning: unknown attribute 'noalias' ignored [-Wunknown-attributes]
clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/memory_view.h:127:1: warning: unknown attribute 'noalias' ignored [-Wunknown-attributes]
clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/memory_view.h:129:1: warning: unknown attribute 'noalias' ignored [-Wunknown-attributes]
clang diag: X:/Ruby30/include/ruby-3.0.0/ruby/random.h:83:1: warning: unknown attribute 'noalias' ignored [-Wunknown-attributes]

And generated the following file: https://gist.github.com/NuriYuri/54e933215d1a7b8e517273be54f03363

I'm not sure what to do with that but I guess it's a little progress ^^

@NuriYuri
Copy link
Author

NuriYuri commented Apr 9, 2023

I could solve the build issue after digging around. It looks like the build script are not good at handling different target than the one you got from installing Rust. I did install mingw-w64-i686-rust and it fixed the issue (using: pacman -S mingw-w64-i686-rust)

I guess for every different build tool chain you need the specific rust install for it.

@NuriYuri NuriYuri closed this as completed Apr 9, 2023
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

No branches or pull requests

3 participants