oxidize-rb / rb-sys

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

Failed to build for release on Windows latest runner: `defines.h:43:11: fatal error: 'strings.h' file not found\n")` #415

Closed setoelkahfi closed 3 weeks ago

setoelkahfi commented 1 month ago

I have a Tauri project and got a compilation error on Windows's latest runner:

error: failed to run custom build command for `rb-sys v0.9.100`
Caused by:
  process didn't exit successfully: `D:\adesktop\src-tauri\target\release\build\rb-sys-ef992799c55b6db2\build-script-main` (exit code: 101)
  --- stdout
  cargo:rerun-if-env-changed=RUBY
  cargo:rerun-if-env-changed=RBCONFIG_CROSS_COMPILING
  cargo:rerun-if-env-changed=RBCONFIG_RUBY_PROGRAM_VERSION
  cargo:rerun-if-env-changed=RBCONFIG_platform
  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\stable_api_config.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
  cargo:rerun-if-env-changed=RBCONFIG_rubyhdrdir
  #include "ruby/re.h"
  #endif
  #ifdef HAVE_RUBY_REGEX_H
  #include "ruby/regex.h"
  #endif
  #ifdef HAVE_RUBY_RUBY_H
  #include "ruby/ruby.h"
  #endif
  #ifdef HAVE_RUBY_ST_H
  #include "ruby/st.h"
  #endif
  #ifdef HAVE_RUBY_THREAD_H
  #include "ruby/thread.h"
  #endif
  #ifdef HAVE_RUBY_THREAD_NATIVE_H
  #include "ruby/thread_native.h"
  #endif
  #ifdef HAVE_RUBY_UTIL_H
  #include "ruby/util.h"
  #endif
  #ifdef HAVE_RUBY_VERSION_H
  #include "ruby/version.h"
  #endif
  #ifdef HAVE_RUBY_VM_H
  #include "ruby/vm.h"
  #endif
  #ifdef HAVE_RUBY_WIN32_H
  #include "ruby/win32.h"
  #endif
  #ifdef HAVE_RUBY_IO_BUFFER_H
  #include "ruby/io/buffer.h"
  #endif
  struct rb_sys__Opaque__RString { struct RString dummy; };
  struct rb_sys__Opaque__RArray { struct RArray dummy; };
  warning: unknown warning option '-Wduplicated-cond' [-Wunknown-warning-option]
  warning: unknown warning option '-Wimplicit-fallthrough=0'; did you mean '-Wimplicit-fallthrough'? [-Wunknown-warning-option]
  warning: unknown warning option '-Wno-packed-bitfield-compat'; did you mean '-Wno-padded-bitfield'? [-Wunknown-warning-option]
  warning: unknown warning option '-Wsuggest-attribute=format'; did you mean '-Wproperty-attribute-mismatch'? [-Wunknown-warning-option]
  warning: unknown warning option '-Wsuggest-attribute=noreturn' [-Wunknown-warning-option]
  warning: unknown warning option '-Wduplicated-cond' [-Wunknown-warning-option]
  warning: unknown warning option '-Wimplicit-fallthrough=0'; did you mean '-Wimplicit-fallthrough'? [-Wunknown-warning-option]
  warning: unknown warning option '-Wno-packed-bitfield-compat'; did you mean '-Wno-padded-bitfield'? [-Wunknown-warning-option]
  warning: unknown warning option '-Wsuggest-attribute=format'; did you mean '-Wproperty-attribute-mismatch'? [-Wunknown-warning-option]
  warning: unknown warning option '-Wsuggest-attribute=noreturn' [-Wunknown-warning-option]
  C:/hostedtoolcache/windows/Ruby/3.2.2/x64/include/ruby-3.2.0\ruby\defines.h:43:11: fatal error: 'strings.h' file not found
  clang diag: warning: unknown warning option '-Wduplicated-cond' [-Wunknown-warning-option]
  clang diag: warning: unknown warning option '-Wimplicit-fallthrough=0'; did you mean '-Wimplicit-fallthrough'? [-Wunknown-warning-option]
  clang diag: warning: unknown warning option '-Wno-packed-bitfield-compat'; did you mean '-Wno-padded-bitfield'? [-Wunknown-warning-option]
  clang diag: warning: unknown warning option '-Wsuggest-attribute=format'; did you mean '-Wproperty-attribute-mismatch'? [-Wunknown-warning-option]
  clang diag: warning: unknown warning option '-Wsuggest-attribute=noreturn' [-Wunknown-warning-option]
  thread 'main' panicked at C:\Users\runneradmin/.cargo\registry\src\index.crates.io-6f17d22bba15001f\rb-sys-0.9.100\build/main.rs:55:6:
  generate bindings: ClangDiagnostic("C:/hostedtoolcache/windows/Ruby/3.2.2/x64/include/ruby-3.2.0\\ruby\\defines.h:43:11: fatal error: 'strings.h' file not found\n")
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
       Error failed to build app: failed to build app
Error: Command failed with exit code 1: npm run release build

Here's my workflow file:

name: 'Deploy Desktop'

on:
  push:
    branches:
      - release/adesktop

# This workflow will trigger on each push to the `release` branch to create or update a GitHub release, build your app, and upload the artifacts to the release.
defaults:
  run:
    working-directory: frontend/adesktop
jobs:
  publish-tauri:
    permissions:
      contents: write
    strategy:
      fail-fast: false
      matrix:
        include:
          - platform: 'macos-latest' # for Arm based macs (M1 and above).
            args: '--target aarch64-apple-darwin'
          - platform: 'macos-latest' # for Intel based macs.
            args: '--target x86_64-apple-darwin'
          - platform: 'ubuntu-20.04' # for Tauri v1 you could replace this with ubuntu-20.04.
            args: ''
          - platform: 'windows-latest'
            args: ''

    runs-on: ${{ matrix.platform }}
    steps:
      - uses: actions/checkout@v4
      - name: Setup Node
        uses: actions/setup-node@v4
        with:
          node-version: 20.14.0
      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2.2
      - name: Install Rust stable
        uses: dtolnay/rust-toolchain@stable
        with:
          toolchain: 1.77.0
          # Those targets are only used on macos runners so it's in an `if` to slightly speed up windows and linux builds.
          targets: ${{ matrix.platform == 'macos-latest' && 'aarch64-apple-darwin,x86_64-apple-darwin' || '' }}

      - name: Install Ubuntu dependencies
        if: matrix.platform == 'ubuntu-20.04' # This must match the platform value defined above.
        run: |
          sudo apt-get update
          sudo apt-get install -y libwebkit2gtk-4.0-dev libappindicator3-dev librsvg2-dev patchelf libasound2-dev libudev-dev
        # webkitgtk 4.0 is for Tauri v1 - webkitgtk 4.1 is for Tauri v2.
        # You can remove the one that doesn't apply to your app to speed up the workflow a bit.

      - name: Install frontend dependencies
        run: npm install # change this to npm, pnpm or bun depending on which one you use.

      - uses: tauri-apps/tauri-action@v0
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tauriScript: npm run release
          projectPath: frontend/adesktop
          tagName: app-v__VERSION__ # the action automatically replaces \_\_VERSION\_\_ with the app version.
          releaseName: 'App v__VERSION__'
          releaseBody: 'See the assets to download this version and install.'
          releaseDraft: true
          prerelease: false
          args: ${{ matrix.args }}

Initially, I thought it was because of a mismatch in the Ruby version, which used version 3.0.0 by setup-ruby action. Now it's the correct ruby, but it still has the same errors. Any clue?

ianks commented 1 month ago

So you have a link to the build? It looks like it's having issues finding the correct header files for some reason, which should be configured

setoelkahfi commented 1 month ago

@ianks, it's a private repo. But I can share the workflow file sometime today. I posted the question on SO as well with a more detailed description.

setoelkahfi commented 1 month ago

@ianks updated to include my workflow file. Now I remember, I haven't tried adding some dependency like for the Ubuntu one.

setoelkahfi commented 3 weeks ago

I didn't solve this; instead, I removed magnus from my crate dependency since I don't use it. I used it on a Ruby gem with a Rust extension.