Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

Extension compiles twice when only one Ruby version is specified #133

Open
ankane opened this issue Jan 15, 2023 · 3 comments
Open

Extension compiles twice when only one Ruby version is specified #133

ankane opened this issue Jan 15, 2023 · 3 comments

Comments

@ankane
Copy link
Contributor

ankane commented Jan 15, 2023

Hi, I'm running into an odd issue when only one Ruby version is specified where the extension compiles twice. I'm able to reproduce with oxi-test.

Workflow - ankane/oxi-test@9f48d1a

name: debug
on: push
jobs:
  release:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: ruby/setup-ruby@v1
        with:
          ruby-version: 3.2
      - uses: oxidize-rb/cross-gem-action@v7
        with:
          platform: x86_64-linux
          version: latest
          ruby-versions: "3.2"

CI output - https://github.com/ankane/oxi-test/actions/runs/3920839152/jobs/6702689640

Compiling ext v0.1.0 (/home/runner/work/oxi-test/oxi-test/ext)
Compiling rb-sys-build v0.9.54
Compiling rb-sys v0.9.54

and later...

Compiling ext v0.1.0 (/home/runner/work/oxi-test/oxi-test/ext)
Compiling rb-sys-build v0.9.54
Compiling rb-sys v0.9.54

With Tokenizers Ruby, this is also causes a crash in the generated gem, which doesn't happen when 2+ versions are specified.

thread '<unnamed>' panicked at 'internal error: entered unreachable code', /usr/local/cargo/registry/src/github.com-1ecc6299db9ec823/magnus-0.4.4/src/value.rs:200:21                                            
stack backtrace:                                             
   0:     0x7f0451013690 - std::backtrace_rs::backtrace::libunwind::trace::h1d00f3fcf4cb5ac4
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f0451013690 - std::backtrace_rs::backtrace::trace_unsynchronized::h920a6ff332484ee2
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f0451013690 - std::sys_common::backtrace::_print_fmt::hd7323920c925af6d
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/sys_common/backtrace.rs:65:5
   3:     0x7f0451013690 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h3155a8c966b4beb5
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x7f045103511e - core::fmt::write::h062c617411b691df
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/fmt/mod.rs:1209:17
   5:     0x7f045100e125 - std::io::Write::write_fmt::hb61fdf1275c61e1c
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/io/mod.rs:1682:15
   6:     0x7f0451013455 - std::sys_common::backtrace::_print::hd1b4d9664ab500e0
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/sys_common/backtrace.rs:47:5
   7:     0x7f0451013455 - std::sys_common::backtrace::print::hca896ae22beb06cb
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/sys_common/backtrace.rs:34:9
   8:     0x7f0451014d0f - std::panicking::default_hook::{{closure}}::h0b5eeed5cf36ab5f
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/panicking.rs:267:22
   9:     0x7f0451014a4a - std::panicking::default_hook::h8932b573145a321b
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/panicking.rs:286:9
  10:     0x7f0451015408 - std::panicking::rust_panic_with_hook::h4b1447a24e3e94f8
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/panicking.rs:688:13
  11:     0x7f0451015161 - std::panicking::begin_panic_handler::{{closure}}::h8701da9995a3820c
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/panicking.rs:577:13
  12:     0x7f0451013b3c - std::sys_common::backtrace::__rust_end_short_backtrace::hb696c5ed02a01598
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/sys_common/backtrace.rs:137:18
  13:     0x7f0451014ec2 - rust_begin_unwind
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/std/src/panicking.rs:575:5
  14:     0x7f0450c0b123 - core::panicking::panic_fmt::h8aa706a976963c88
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/panicking.rs:65:14
  15:     0x7f0450c0b1fd - core::panicking::panic::h622b2a38bce78ff3
                               at /rustc/90743e7298aca107ddaa0c202a4d3604e29bfeb6/library/core/src/panicking.rs:115:5
  16:     0x7f0450c6996e - <magnus::r_string::RString as magnus::try_convert::TryConvert>::try_convert::h4cf22acec1b6d4f4
  17:     0x7f0450c68683 - <alloc::string::String as magnus::try_convert::TryConvert>::try_convert::h24f1eed74bf2a492
  18:     0x7f0450c2f794 - <core::panic::unwind_safe::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once::h0388255aefb12b21
  19:     0x7f0450c414f6 - tokenizers::init::anon::ha65ccae5cf3ffbfa

This probably isn't an issue for most production workflows (which will likely specify multiple versions), but it:

  1. slows down testing a single version
  2. could cause odd crashes like the one above

Edit: Sorry, meant to post in cross-gem-action if you want to transfer this there.

@ianks ianks transferred this issue from oxidize-rb/rb-sys Jan 16, 2023
@ianks
Copy link
Contributor

ianks commented Jan 16, 2023

Thanks for the report. Seems like it is compiling for 3.2.0 and 3.1.3 in the action which is wrong. Not sure if this is an issue with RCD or not though.

Shelling into the container with rb-sys-dock:

$ rb-sys-dock --platform aarch64-linux

I noticed that it's only building the 3.2 extension, which is expected:

aarch64-linux ➜ oxi-test $ export RUBY_CC_VERSION=3.2.0
aarch64-linux ➜ oxi-test $ rake native:aarch64-linux
aarch64-linux ➜ oxi-test $ ls tmp/aarch64-linux/ext/      
3.2.0

However, running rake native:aarch64-linux gem the bug appears. It seems like it's trying compile the 3.1 version for some reason. Not sure why yet....

** Invoke gem (first_time)
** Invoke pkg/oxi-test-0.1.0-aarch64-linux.gem (first_time)
** Invoke pkg (first_time, not_needed)
** Invoke pkg/oxi-test-0.1.0-aarch64-linux (first_time)
rake aborted!
Don't know how to build task 'tmp/aarch64-linux/stage/lib/oxi/test/3.1'

This does seem to be a rake-compiler bug, but I'm not entirely sure. I wonder if this can be recreated with a default C extension....

@ankane
Copy link
Contributor Author

ankane commented Jan 21, 2023

Thanks, will see if I can reproduce with C. Guessing it may have to do with this logic.

@gjtorikian
Copy link
Collaborator

👋 Sorry for lurking, but I think this is a problem with RCD.

I can't remember what the original problem I faced was, exactly, but I observed an issue where building a gem on one version of Ruby would not build on multiple platforms. I wrote a hack to workaround the exact line(s) mentioned: https://github.com/gjtorikian/commonmarker/blob/b0f5c0335746d12526bbe7794419602bfbf8d6c5/rakelib/extension.rake#L5-L31

(At this point, Commonmarker supports multiple 3.x verisons, so the hack was removed.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants