Files
dearblue db1578c123 Separating the build setup portion from the GEMS setup block
The issue resolved by the preceding patch was solely the C++ exception task within the mruby core.
This patch aims to resolve a similar sequencing issue that also exists in GEMS.

In practice, `mruby-compiler` is sometimes loaded via dependencies rather than being explicitly specified in the build configuration file.
In such cases, when `mruby-compiler/mrbgem.rake` is loaded, it is not yet determined whether C++ exceptions will be used. Consequently, even if it later becomes clear that `core/codegen-cxx.cxx` and `core/y.tab-cxx.cxx` are required, the system could not handle this.

To resolve this issue, we introduce the `MRuby::Gem::Specification#build_settings` method as a mechanism for lazily evaluating build setup.
However, for backward compatibility, the commands are cloned twice in `gem.setup` and `gem.setup_build`.
This is because many existing GEMS configure commands directly within the setup block.

ref. https://github.com/mruby/mruby/issues/6615
2025-09-11 22:53:06 +09:00

43 lines
1.2 KiB
Ruby

MRuby::Gem::Specification.new 'mruby-compiler' do |spec|
spec.license = 'MIT'
spec.author = 'mruby developers'
spec.summary = 'mruby compiler library'
spec.build_settings do
objs = %w[codegen y.tab].map do |name|
src = "#{dir}/core/#{name}.c"
if build.cxx_exception_enabled?
build.compile_as_cxx(src)
else
objfile(src.pathmap("#{build_dir}/core/%n"))
end
end
build.libmruby_core_objs << objs
end
end
dir = __dir__
lex_def = "#{dir}/core/lex.def"
unless Rake::Task.task_defined?(lex_def)
# Parser
file "#{dir}/core/y.tab.c" => ["#{dir}/core/parse.y", lex_def] do |t|
MRuby.targets["host"].yacc.run t.name, t.prerequisites.first
replace_line_directive(t.name)
end
# Lexical analyzer
file lex_def => "#{dir}/core/keywords" do |t|
MRuby.targets["host"].gperf.run t.name, t.prerequisites.first
replace_line_directive(t.name)
end
def replace_line_directive(path)
content = File.read(path).gsub(%r{
^\#line\s+\d+\s+"\K.*(?="$) | # #line directive
^/\*\s+Command-line:.*\s\K\S+(?=\s+\*/$) # header comment in lex.def
}x, &:relative_path)
File.write(path, content)
end
end