diff --git a/doc/guides/amalgamation.md b/doc/guides/amalgamation.md index c42bdeecf..38ac26dcd 100644 --- a/doc/guides/amalgamation.md +++ b/doc/guides/amalgamation.md @@ -72,6 +72,7 @@ The following gems work with amalgamation: - `mruby-enum-ext`, `mruby-compar-ext` - `mruby-error`, `mruby-math`, `mruby-struct`, `mruby-bigint` - `mruby-io` (with `hal-posix-io`) +- `mruby-task` (with `hal-posix-task`) ### Excluded Gems @@ -79,10 +80,6 @@ Binary gems (`mruby-bin-*`) are automatically excluded as they contain their own `main()` function. The amalgamation produces a library, not an executable. -### Incompatible Gems - -- `mruby-task` - Requires special build configuration (`mrb->task` member) - ## Example Configuration A minimal configuration for amalgamation: @@ -130,6 +127,12 @@ Typical sizes depend on included gems: - Local includes (`.cstub` files) are automatically inlined - Generated files (`mrblib.c`, `gem_init.c`) are included +### Gem Defines + +Gems that add preprocessor defines affecting core structures (like +`MRB_USE_TASK_SCHEDULER` from mruby-task) are automatically detected +and included at the top of `mruby.h`. + ### Build Order 1. Core sources (`src/*.c`) diff --git a/lib/mruby/amalgam.rb b/lib/mruby/amalgam.rb index 4fe9a8489..125f84657 100644 --- a/lib/mruby/amalgam.rb +++ b/lib/mruby/amalgam.rb @@ -169,6 +169,26 @@ module MRuby #include PREAMBLE + + # Add build-level defines from gems (e.g., MRB_USE_TASK_SCHEDULER) + gem_defines = collect_gem_defines + unless gem_defines.empty? + f.puts "/* Gem-required defines */" + gem_defines.each do |d| + f.puts "#define #{d}" + end + f.puts + end + end + + # Collect defines added by gems that affect core headers + def collect_gem_defines + defines = [] + @build.defines.each do |d| + # Include defines that affect mrb_state or core functionality + defines << d if d =~ /^MRB_USE_|^MRB_UTF8_|^HAVE_MRUBY_/ + end + defines.uniq.sort end def write_header_postamble(f)