From c521d8348e7c2b08908119813b9f71806eff1c1a Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 11 Dec 2025 11:39:39 +0900 Subject: [PATCH] gem.rb: separate inter-gem headers from external API headers; close #6671 Headers in mrbgems are now categorized into three types: - src/*.h: gem internal only - include/*.h: inter-gem use (visible to dependent gems) - include/export/*.h: external API (exported via mruby-config --cflags) This prevents internal headers like *_hal.h from being exposed to external users while maintaining inter-gem header accessibility. Co-authored-by: Claude --- lib/mruby/gem.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/mruby/gem.rb b/lib/mruby/gem.rb index 1e9a3d919..9b3819160 100644 --- a/lib/mruby/gem.rb +++ b/lib/mruby/gem.rb @@ -68,7 +68,10 @@ module MRuby @requirements = [] @export_include_paths = [] - @export_include_paths << "#{dir}/include" if File.directory? "#{dir}/include" + # Headers in include/ are for inter-gem use only + # Headers in include/export/ are exported to external users via mruby-config + export_dir = "#{dir}/include/export" + @export_include_paths << export_dir if File.directory?(export_dir) instance_eval(&@initializer) @@ -542,6 +545,16 @@ module MRuby # as circular dependency has already detected in the caller. import_include_paths(dep_g) + # Add dependency's include/ to compiler paths (for inter-gem use) + dep_include = "#{dep_g.dir}/include" + if File.directory?(dep_include) + g.compilers.each do |compiler| + compiler.include_paths << dep_include + compiler.include_paths.uniq! + end + end + + # Propagate any explicitly set export_include_paths dep_g.export_include_paths.uniq! g.compilers.each do |compiler| compiler.include_paths += dep_g.export_include_paths