Class: Lilac::CLI::PackageBuild

Inherits:
Object
  • Object
show all
Defined in:
lib/lilac/cli/package_build.rb

Overview

Compile one or more pure-Ruby package source files (mrblib-style: Handler class definitions plus Lilac::Directives::Scanner.register("ClassName") calls) into a single .mrb bytecode file that can be loaded into a running lilac-compiled VM via vm.loadBytecode(bytes).

Wire-level: this is a thin wrapper around BytecodeBuilder (which owns mrbc backend discovery + the wasm-driven mrbc fallback). The difference from build is that package .mrb files have a user-specified output path (no content-hash filename) and are never wrapped with Lilac.start / framework boot — they're library-style code that registers directives / defines classes at load time and then yields control back.

Multiple inputs are concatenated in the order given, separated by newlines, before compiling. This mirrors how mruby builds gems from their mrblib/*.rb set (alphabetical concat → single irep).

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(inputs:, output:, mrbc_path: nil) ⇒ PackageBuild

Returns a new instance of PackageBuild.

Raises:



30
31
32
33
34
35
36
# File 'lib/lilac/cli/package_build.rb', line 30

def initialize(inputs:, output:, mrbc_path: nil)
  raise Error, 'package-build: at least one input file required' if inputs.empty?

  @inputs = inputs
  @output = output
  @mrbc_path = mrbc_path
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



38
39
40
# File 'lib/lilac/cli/package_build.rb', line 38

def inputs
  @inputs
end

#outputObject (readonly)

Returns the value of attribute output.



38
39
40
# File 'lib/lilac/cli/package_build.rb', line 38

def output
  @output
end

Instance Method Details

#runObject

Compile + write. Returns the absolute output path.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/lilac/cli/package_build.rb', line 41

def run
  source = aggregate_sources
  builder = BytecodeBuilder.new(mrbc_path: @mrbc_path)
  bytecode = builder.compile_to_bytes(source, source_label: source_label)

  FileUtils.mkdir_p(File.dirname(@output))
  File.binwrite(@output, bytecode)
  File.expand_path(@output)
rescue BytecodeBuilder::Error => e
  raise Error, e.message
end