Skip to content

mruby-regexp, mruby-task: ask the build what it defines - #7171

Merged
matz merged 2 commits into
mruby:masterfrom
takumin:gem-ask-build-defines
Aug 14, 2026
Merged

mruby-regexp, mruby-task: ask the build what it defines#7171
matz merged 2 commits into
mruby:masterfrom
takumin:gem-ask-build-defines

Conversation

@takumin

@takumin takumin commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Two GEMs read a build define out of build.cc.defines, which is the C compiler's list alone. A build that sets the define through conf.defines, which puts it on every compiler, compiles under the -D and is not seen here, so the GEM configures itself for a build it is not in. One symptom is a failing test, the other is a tool that never appears.

mruby-regexp hands mrbtest the wrong test file

MRuby::Build.new('probe') do |conf|
  conf.toolchain
  conf.gembox 'full-core'
  conf.defines << 'MRB_REGEXP_UNICODE_CASE'
  conf.enable_test
end

The engine is compiled with Unicode simple case folding, and the GEM hands mrbtest test/ascii_case.rb, the file that asserts /i refuses the very patterns the engine now folds. On master:

Fail: Regexp - /i refuses what ASCII folding cannot answer (mrbgems: mruby-regexp)
  Total: 2303
     KO: 1

mruby-task drops the tool the option asks for

MRB_TASK_BUILD_DEMO is a switch a build configuration throws to get bin/mruby_task_demo. Thrown through conf.defines, the GEM takes no binary, and nothing reports that the option went nowhere.

Both ask MRuby::Build#has_define? instead

a3513b6 added that reader for this and left it without a caller. It spans build.defines and every compiler's list, and matches on the name, so a define written as FOO=1 answers under FOO.

It has to be asked from spec.build_settings: a GEM contributes its defines while the GEMs are still being set up, so the answer during that phase depends on where the caller sits in the list, and has_define? refuses there rather than give one.

build_settings resets a GEM's build commands to the build's, so mruby-task's winmm library and its pkg-config query move into the block along with the question. Left outside they would be set during setup and then dropped. mruby-regexp sets no build command in its own block, so nothing moves there.

Verified

The conf.defines config above reports Total 2302 KO 0, one test fewer than the 2303 of the same config without the option, which is the ASCII file's two tests giving way to the Unicode file's one.

MRUBY_CONFIG=ci/gcc-clang rake -m test, four builds and the bintests, KO 0. full-debug sets the option through conf.cc.defines and still gets the Unicode file:

bintest       117 bintests
bintest       2303   Skip 10
byte-string   2239   Skip 29
cxx_abi       2303   Skip 10
full-debug    2302   Skip 2

MRUBY_CONFIG=default rake -m test, Total 2085 KO 0 plus 106 bintests, on each commit of this PR.

For mruby-task, build_config/glib_hal_test.rb sets the option through conf.cc.defines and builds under -fsanitize=address,undefined: it produces bin/mruby_task_demo, and the demo runs every scenario through to All scenarios completed. The same config without the demo passes rake -m test with Total 832 KO 0, so the glib port still compiles and links from the flags this block gathers.

Not fixed here

rake test on a build that turns the demo on cannot link mrbtest: MRuby::Gem::List#linker_attrs drops a GEM that owns a binary, and the glib libraries go with it. That is on master today and is a separate matter from which list the define is read out of.

Summary by CodeRabbit

  • Bug Fixes
    • Improved build configuration so regular expression tests use the final Unicode case-folding settings.
    • Improved task-related builds by reliably detecting platform capabilities and demo requirements.
    • Preserved required Windows multimedia linking and GLib validation behavior.

The two case folding test files assert opposite things about the same
patterns, so the gem drops one of them by asking whether this build folds
Unicode. It asked `build.cc.defines`, which is the C compiler's list alone.
A build that turns the option on through `conf.defines`, which puts it on
every compiler, compiles the engine with `-DMRB_REGEXP_UNICODE_CASE` and was
handed the ASCII file, which asserts that `/i` refuses the patterns the
engine now folds:

```ruby
MRuby::Build.new('probe') do |conf|
  conf.toolchain
  conf.gembox 'full-core'
  conf.defines << 'MRB_REGEXP_UNICODE_CASE'
  conf.enable_test
end
```

`rake -m test` on that config reports `KO: 1`, on `Regexp - /i refuses what
ASCII folding cannot answer`.

`MRuby::Build#has_define?` spans both places a define can come from and
matches on the name, so one written as `FOO=1` answers under `FOO`. It has
to be asked from `build_settings`, since a gem contributes its defines while
the gems are still being set up and the answer would otherwise depend on
where this gem sits in the list. This gem sets no build command in its own
block, so the reset that comes with `build_settings` drops nothing.

### Verified

The config above now reports `Total 2302 KO 0`, one test fewer than the
2303 of the same config without the option, which is the ASCII file's two
tests giving way to the Unicode file's one.

`MRUBY_CONFIG=ci/gcc-clang rake -m test`, four builds and the bintests, KO 0.
`full-debug` sets the option through `conf.cc.defines` and still gets the
Unicode file:

    bintest       117 bintests
    bintest       2303   Skip 10
    byte-string   2239   Skip 29
    cxx_abi       2303   Skip 10
    full-debug    2302   Skip 2
`MRB_TASK_BUILD_DEMO` is a switch a build configuration throws to get
`bin/mruby_task_demo`, and the gem read it out of `spec.build.cc.defines`,
the C compiler's list alone. Thrown through `conf.defines`, which puts it on
every compiler, nothing happened and nothing said so: the tool the option
asks for simply did not appear.

`MRuby::Build#has_define?` spans both places a define can come from and
matches on the name. It has to be asked from `build_settings`, since a gem
contributes its defines while the gems are still being set up, and that
block resets the gem's build commands to the build's. The `winmm` library
and the pkg-config query move in with it: left outside they would be set
during setup and then dropped.

### Verified

On a config that carries `conf.ports :glib` and turns the option on through
`conf.defines`, the gem now takes `mruby_task_demo` as its binary and holds
the two pkg-config answers on its compiler and its linker, where before it
took no binary at all.

`build_config/glib_hal_test.rb`, which sets the option through
`conf.cc.defines` and builds under `-fsanitize=address,undefined`, produces
`bin/mruby_task_demo`, and the demo runs all of its scenarios to
`All scenarios completed.` The same config minus the demo passes
`rake -m test` with `Total 832 KO 0`, so the glib port still compiles and
links from the flags this block gathers.

`MRUBY_CONFIG=ci/gcc-clang rake -m test` and `MRUBY_CONFIG=default rake -m
test` are unaffected, KO 0, since neither carries the gem.

Not fixed here: `rake test` on a build that turns the demo on cannot link
`mrbtest`, because `MRuby::Gem::List#linker_attrs` drops a gem that owns a
binary and the glib libraries go with it. That predates this commit.
@takumin
takumin requested a review from matz as a code owner August 14, 2026 12:19
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 3adb54d0-453e-44c5-ae2a-2a30d9279f11

📥 Commits

Reviewing files that changed from the base of the PR and between f90657d and 0ffed68.

📒 Files selected for processing (2)
  • mrbgems/mruby-regexp/mrbgem.rake
  • mrbgems/mruby-task/mrbgem.rake

📝 Walkthrough

Walkthrough

The regexp and task gem build configurations now evaluate build-dependent settings inside spec.build_settings. They use build.has_define? for finalized compiler definitions while preserving existing test selection, linker, GLib validation, and demo registration behavior.

Changes

Deferred build settings

Layer / File(s) Summary
Regexp test selection
mrbgems/mruby-regexp/mrbgem.rake
Case-folding test selection now runs inside build_settings and uses build.has_define?('MRB_REGEXP_UNICODE_CASE').
Task build configuration
mrbgems/mruby-task/mrbgem.rake
Linker setup, port detection, GLib validation, demo documentation, and demo enablement now use finalized build settings.

Estimated code review effort: 2 (Simple) | ~15 minutes

Merge Risk: ⚪ Minimal · up to 0ffed

The change makes the two GEMs honor build-wide defines so their selected tests and optional tooling match the actual build configuration; the supplied checks pass, and no actionable merge-blocking risk remains.

Possibly related PRs

  • mruby/mruby#7058: Updates regexp test selection using the Unicode case define.
  • mruby/mruby#7088: Updates regexp test-file selection for split case-folding tests.
  • mruby/mruby#7159: Introduces Build#has_define? usage within spec.build_settings.

Suggested labels: build

Suggested reviewers: matz

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: both gems now query build-defined macros through the build API.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@matz
matz merged commit e3f9ba5 into mruby:master Aug 14, 2026
21 checks passed
@takumin
takumin deleted the gem-ask-build-defines branch August 14, 2026 13:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants