Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions lib/mruby/build/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,18 @@ def run(outfile, infile, _defines=[], _include_paths=[], _flags=[])
File.write(flags_file(outfile), flags_record(opts, flags))
end

def define_rules(build_dir, source_dir='', out_ext=build.exts.object)
# Define the rules that build the outputs under +build_dir+ from the
# sources under +source_dir+, and from the generated sources that sit
# beside the outputs.
#
# The rules compile with this compiler, or with the one the block returns
# when a block is given. The block is called when a rule is resolved, not
# here, so a compiler it derives from this one sees everything the build
# adds after the rules are defined: a gem's mrbgem.rake body runs before
# the gem's version define, the include paths of the gems it depends on
# and the presym include path reach the gem's compilers.
def define_rules(build_dir, source_dir='', out_ext=build.exts.object, &compiler_of)
compiler_of ||= proc { self }
gemrake = File.join(source_dir, "mrbgem.rake")
rakedep = File.exist?(gemrake) ? [ gemrake ] : []

Expand All @@ -138,9 +149,9 @@ def define_rules(build_dir, source_dir='', out_ext=build.exts.object)
source_of = proc { |file| file.sub(generated_file_matcher, "#{dir}/\\1#{ext}") }
rule generated_file_matcher => [
source_of,
proc { |file| get_dependencies(file, source_of.call(file)) + rakedep }
proc { |file| compiler_of.call.get_dependencies(file, source_of.call(file)) + rakedep }
] do |t|
run t.name, t.prerequisites.first
compiler_of.call.run t.name, t.prerequisites.first
end
end
end
Expand All @@ -152,8 +163,11 @@ def setup_debug(conf)
nil
end

private
protected

# The prerequisites of an output besides its source: the config file and
# the headers the last compile of it read. Protected, not private, so the
# rules one compiler defines can ask the compiler they run.
#
# === Example of +.d+ file
#
Expand Down Expand Up @@ -221,6 +235,8 @@ def get_dependencies(file, source)
deps.concat(header_deps)
end

private

#
# === Example of +.flags+ file
#
Expand Down
30 changes: 18 additions & 12 deletions mrbgems/mruby-compiler/mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,25 @@ MRuby::Gem::Specification.new('mruby-compiler') do |spec|
# Route Prism's allocator to libc there too: the C++ core exports mrb_malloc
# with C++ linkage, which the C-compiled Prism objects could not resolve, and
# Prism's parse memory is transient and freed through the same libc path.
# The clone happens inside the file task (not here) so cc.flags is already
# fully populated with the build's generated-header include flags.
Dir.glob("#{prism_dir}/src/**/*.c").map do |src|
obj = objfile(src.pathmap("#{build_dir}/lib/%n"))
objs << obj
file obj => [src] do |f|
prism_cc = cc
if build.cxx_abi_enabled?
prism_cc = cc.clone
prism_cc.flags = cc.flags.flatten - [cc.cxx_compile_flag].flatten
prism_cc.defines = cc.defines + %w(MRC_ALLOC_LIBC)
# The compiler is derived when a rule is first resolved (not here) so cc is
# already fully populated with the build's generated-header include flags.
#
# The objects go through the rules like every other object of the gem, so
# that a change to a Prism header or to the compile flags rebuilds them.
prism_src_dir = "#{prism_dir}/src"
prism_obj_dir = "#{build_dir}/lib"
prism_cc = nil
cc.define_rules(prism_obj_dir, prism_src_dir) do
prism_cc ||= if build.cxx_abi_enabled?
cc.clone.tap do |c|
c.flags = cc.flags.flatten - [cc.cxx_compile_flag].flatten
c.defines = cc.defines + %w(MRC_ALLOC_LIBC)
end
prism_cc.run f.name, f.prerequisites.first
else
cc
end
end
Dir.glob("#{prism_src_dir}/**/*.c").each do |src|
objs << objfile(src.relative_path_from(prism_src_dir).pathmap("#{prism_obj_dir}/%X"))
end
end
Loading