Skip to content

build: build the test objects through the rules - #7253

Merged
matz merged 1 commit into
mruby:masterfrom
takumin:test-objects-through-rules
Aug 18, 2026
Merged

build: build the test objects through the rules#7253
matz merged 1 commit into
mruby:masterfrom
takumin:test-objects-through-rules

Conversation

@takumin

@takumin takumin commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

mrbtest.o, assert.o and the gem_test.o of every gem, the objects
mrbtest is made of, are declared by hand in
mrbgems/mruby-test/mrbgem.rake: file tasks without an action, with the
generated source as their only prerequisite. Rake finds the rule for such
a task, but only when the task runs, after it has already answered
needed? from that one file. The .d the compile writes and the flags
record beside the object are read by the prerequisite procs of the rule,
and for these objects those never ran. A header the object includes
changing, or a define reaching the build by a way that leaves the
generated source alone, left the old object in mrbtest. It is the same
gap #7250 closed for mrbgems/gem_init.o.

mrbtest.c reads mrb->gc.arena_idx around every gem's tests
(mrb_gc_arena_save, mrb_gc_arena_restore). Add a field at the top of
struct mrb_state and run rake test:

$ rake test                   # built once, all green
$ sed -i 's/^  struct mrb_jmpbuf \*jmp;$/&\n  void *probe_pad;/' include/mruby.h
$ rake test                   # 185 CC, none of the 52 test objects among them
mrbtest - Embeddable Ruby Test

.rake aborted!
Command failed with status (1): [build/host/bin/mrbtest]
$ rake test                   # nothing to build, the same failure

Every other object of the build is compiled again; mrbtest.o keeps the
old offset of gc.arena_idx, and mrbtest exits after the first test.

Why

The three tasks came with the test rakefiles (2014, 7201404; 2015,
c7d0f8e). Rake's Task#execute runs enhance_with_matching_rule for a
task without an action, so the rule's action does compile the object and
its prerequisite procs do run then; but that is after invoke decided
from the written prerequisite whether to execute at all. The rule from
Compiler#define_rules has paired an object under the build directory
with the generated source beside it since 2013 (ced80d2); mrblib.o
is built by it alone, and mrbgems/gem_init.o since #7250. It reads the
.d and discards an output whose recorded flags differ (#7236).

What this does

mrbgems/mruby-test/mrbgem.rake no longer declares the three kinds of
object. The rule of the compiler pairs each with its generated source,
and its .d and flags record take effect. The compile lines do not
change: the flags record of every one of the 271 objects of a rake test
build is the same as on master.

Verified

rake -m -j16 test, CCACHE_DISABLE=1, gcc; default gembox with
enable_bintest and enable_test; the build directory built once on
master (364d6dd) before each row, and the run after each row does
nothing in both columns.

change master this PR
a field added to struct mrb_state in include/mruby.h 185 CC, none of the 52 test objects among them; mrbtest prints one dot and exits with 1, and still does after another rake test 236 CC, 51 test objects among them (assert.o includes no header); bintest OK 111, mrbtest OK 2073
the field removed again as above 236 CC, 51 test objects; bintest OK 111, mrbtest OK 2073
touch include/mruby.h 185 CC, none of the test objects 236 CC, 51 test objects
rake -m -j16 test from an empty build directory bintest OK 111, mrbtest OK 2073 bintest OK 111, mrbtest OK 2073, 0 KO, 0 crash; the flags record of every object the same as on master
rake -m -j16 test MRUBY_CONFIG=ci/gcc-clang from an empty build directory every target 0 KO, 0 crash

Environment

Details
OS Linux 7.0.0-29-generic, x86_64
Compiler gcc 13.3.0
binutils 2.47
Ruby 4.0.6
rake 13.3.1

The compile line of mrbtest.o in the default build, unchanged by this
PR (the record beside the object):

gcc -MMD -c -std=gnu99 -g -O3 -Wall -Wundef -Werror-implicit-function-declaration -Wwrite-strings -DMRBTEST_COMPILER_PRISM -DMRBGEM_MRUBY_TEST_VERSION=0.0.0 -DHAVE_MRUBY_REGEXP_GEM -DMRB_USE_SET -DHAVE_MRUBY_IO_GEM -DMRB_USE_RATIONAL -DMRB_USE_COMPLEX -DMRB_USE_BIGINT -DMRB_USE_DEBUG_HOOK -I"include" -I"build/host/include" -o "build/host/mrbgems/mruby-test/mrbtest.o" "build/host/mrbgems/mruby-test/mrbtest.c"

No C source changes and the compile lines are the same, so .text is
unaffected in every build.

Summary by CodeRabbit

  • Build Improvements
    • Streamlined test build dependency tracking by removing unnecessary generated-file dependencies.
    • Existing code-generation steps remain unchanged.

@takumin
takumin requested a review from matz as a code owner August 18, 2026 03:18
@coderabbitai

coderabbitai Bot commented Aug 18, 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: 56143600-4bb7-47a7-a0de-93484137555d

📥 Commits

Reviewing files that changed from the base of the PR and between 364d6dd and 8768443.

📒 Files selected for processing (1)
  • mrbgems/mruby-test/mrbgem.rake
💤 Files with no reviewable changes (1)
  • mrbgems/mruby-test/mrbgem.rake

Included review availability: Your plan includes up to 8 reviews per rolling hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

The change removes three Rake dependency rules for generated test artifacts in mrbgems/mruby-test/mrbgem.rake. The generation rules remain unchanged.

Changes

Build dependency rules

Layer / File(s) Summary
Remove generated artifact dependencies
mrbgems/mruby-test/mrbgem.rake
Removes dependencies from assert_lib, gem test objects, and mlib on generated test files. The generation rules remain.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to 87684

This localized build-rule change makes test objects rebuild when relevant headers or flags change, preventing stale test binaries while preserving compile behavior; no actionable merge-blocking risk remains after normal checks and review.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: building test objects through the compiler rules.
✨ 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.

`mrbtest.o`, `assert.o` and the `gem_test.o` of every gem were declared
by hand in `mrbgems/mruby-test/mrbgem.rake`: action-less `file` tasks
whose only prerequisite was the generated source. Rake does find the
rule for such a task, but only when the task runs, after `needed?` was
answered from that one file. The `.d` the compile writes and the flags
record are read by the prerequisite procs of the rule, and for these
objects they never ran. A header the object includes changing, or a
define reaching the build without a new source, left the old object in
`mrbtest`.

`mrbtest.c` reads `mrb->gc.arena_idx` around every gem's tests. Add a
field to `struct mrb_state` and run `rake test`: every other object is
compiled again, `mrbtest.o` is not, and `mrbtest` prints one dot and
exits with 1. A second `rake test` changes nothing.

Drop the three tasks so the objects are built the way `mrblib.o` and
`gem_init.o` are: by the rule of the compiler that pairs an object under
the build directory with the source beside it and reads its `.d`. The
compile lines do not change; the objects were compiled by that rule
before too, only without its prerequisites.
@takumin
takumin force-pushed the test-objects-through-rules branch from 8768443 to 8550a40 Compare August 18, 2026 03:21
@takumin takumin changed the title test: build the test objects through the rules build: build the test objects through the rules Aug 18, 2026
@matz
matz merged commit 51d3986 into mruby:master Aug 18, 2026
20 of 21 checks passed
@takumin
takumin deleted the test-objects-through-rules branch August 18, 2026 03:55
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