Class: Beni::Builder
- Inherits:
-
Object
- Object
- Beni::Builder
- Defined in:
- lib/beni/builder.rb
Overview
Drives the vendored mruby tree’s build to produce the per-target libmruby.a archives, by running mruby’s own Rakefile — the documented build entry point (doc/guides/compile.md). With no build_config, mruby falls back to its own build_config/default.rb; an explicit config is wired in via the MRUBY_CONFIG env var, which mruby resolves as an absolute path.
Constant Summary collapse
- DEFAULT_TARGETS =
mruby’s anonymous
MRuby::Build.newnames its target “host” (lib/mruby/build.rb), so the upstream default config producesbuild/host/lib/libmruby.a. A custom build config with different target names supplies its own list viaBeni::Tasks. %w[host].freeze
Instance Attribute Summary collapse
-
#build_config ⇒ Object
readonly
Returns the value of attribute build_config.
-
#targets ⇒ Object
readonly
Returns the value of attribute targets.
-
#vendor_dir ⇒ Object
readonly
Returns the value of attribute vendor_dir.
Instance Method Summary collapse
-
#build ⇒ Object
Run mruby’s rake and raise unless every target’s
libmruby.aexists afterwards. -
#built? ⇒ Boolean
True when every target’s artifacts —
libmruby.aplus thelibmruby.flags.maksidecarbeni-sysparses for ABI alignment — are already present, letting callers skip the build without spawning a subprocess. -
#clean ⇒ Object
Remove each target’s build tree (keeps the vendored mruby source).
-
#ensure_built ⇒ Object
Idempotent build entry point for rake beni:build: skip with a note when every artifact is already present, otherwise build and report readiness.
-
#initialize(vendor_dir:, build_config: nil, targets: DEFAULT_TARGETS) ⇒ Builder
constructor
A new instance of Builder.
- #libmruby_path(target) ⇒ Object
- #libmruby_paths ⇒ Object
- #mruby_dir ⇒ Object
Constructor Details
#initialize(vendor_dir:, build_config: nil, targets: DEFAULT_TARGETS) ⇒ Builder
Returns a new instance of Builder.
22 23 24 25 26 |
# File 'lib/beni/builder.rb', line 22 def initialize(vendor_dir:, build_config: nil, targets: DEFAULT_TARGETS) @vendor_dir = vendor_dir @build_config = build_config @targets = targets end |
Instance Attribute Details
#build_config ⇒ Object (readonly)
Returns the value of attribute build_config.
20 21 22 |
# File 'lib/beni/builder.rb', line 20 def build_config @build_config end |
#targets ⇒ Object (readonly)
Returns the value of attribute targets.
20 21 22 |
# File 'lib/beni/builder.rb', line 20 def targets @targets end |
#vendor_dir ⇒ Object (readonly)
Returns the value of attribute vendor_dir.
20 21 22 |
# File 'lib/beni/builder.rb', line 20 def vendor_dir @vendor_dir end |
Instance Method Details
#build ⇒ Object
Run mruby’s rake and raise unless every target’s libmruby.a exists afterwards. Alongside the default task, each target’s libmruby.flags.mak file task is requested explicitly — mruby’s embedder interface recording the exact compile flags, which beni-sys‘s build script parses to keep bindgen’s view of the ABI aligned with the archive. (The file task is defined per target but not part of mruby’s default products.) The underlying build is make-style incremental, so re-running on a partially built tree only compiles what is missing.
74 75 76 77 78 79 80 |
# File 'lib/beni/builder.rb', line 74 def build check_build_config! cmd = [RbConfig.ruby, "-S", "rake", "default", *flags_mak_paths] puts "[beni] cd #{mruby_dir} && #{env.map { |k, v| "#{k}=#{v}" }.join(" ")} #{cmd.join(" ")}" run_mruby_rake(env, cmd) verify_artifacts! end |
#built? ⇒ Boolean
True when every target’s artifacts — libmruby.a plus the libmruby.flags.mak sidecar beni-sys parses for ABI alignment — are already present, letting callers skip the build without spawning a subprocess. An archive without its sidecar (e.g. a tree built before flags.mak joined the contract) triggers a rebuild, which is incremental and only emits the missing file.
46 47 48 |
# File 'lib/beni/builder.rb', line 46 def built? artifact_paths.all? { |path| File.exist?(path) } end |
#clean ⇒ Object
Remove each target’s build tree (keeps the vendored mruby source).
83 84 85 86 87 88 89 |
# File 'lib/beni/builder.rb', line 83 def clean targets.each do |target| dir = File.join(mruby_dir, "build", target) FileUtils.rm_rf(dir) puts "[beni] removed #{dir}" end end |
#ensure_built ⇒ Object
Idempotent build entry point for rake beni:build: skip with a note when every artifact is already present, otherwise build and report readiness. A declared config that does not exist aborts before the skip check — stale artifacts must not mask it.
54 55 56 57 58 59 60 61 62 63 |
# File 'lib/beni/builder.rb', line 54 def ensure_built check_build_config! if built? puts "[beni] libmruby.a already present for #{targets.join(" + ")} — skipping" return end build puts "[beni] libmruby.a ready for #{targets.join(" + ")}" end |
#libmruby_path(target) ⇒ Object
32 33 34 |
# File 'lib/beni/builder.rb', line 32 def libmruby_path(target) File.join(mruby_dir, "build", target, "lib", "libmruby.a") end |
#libmruby_paths ⇒ Object
36 37 38 |
# File 'lib/beni/builder.rb', line 36 def libmruby_paths targets.map { |target| libmruby_path(target) } end |
#mruby_dir ⇒ Object
28 29 30 |
# File 'lib/beni/builder.rb', line 28 def mruby_dir File.join(vendor_dir, "mruby") end |