Class: Beni::Tasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/beni/tasks.rb,
sig/beni/tasks.rbs

Overview

Rake task library exposing the beni:* namespace. Add to a Rakefile:

require "beni/tasks"

Beni::Tasks.new

or with declarations (a custom config cross-building to wasm32-wasip1):

Beni::Tasks.new do
build_config "build_config/mruby.rb"

target :host
target :wasi do
  toolchain "wasi-sdk"
end
end

The block is the declarative DSL from SPEC.md, run on DSL::Context: scalar settings (+version+ / build_config / vendor_dir), target declarations carrying toolchain references, and top-level toolchain definitions overriding a built-in pair. Every malformed declaration raises here — no task defined, nothing downloaded.

Defined tasks:

rake beni:build           — fetch toolchains + build libmruby.a per target
rake beni:clean           — remove mruby build trees (keeps source)
rake beni:config          — generate the upstream default build config
rake beni:vendor:setup    — download & unpack the selected toolchains
rake beni:vendor:clean    — remove unpacked toolchains (keeps tarball cache)
rake beni:vendor:clobber  — remove the vendor tree entirely

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Tasks

Returns a new instance of Tasks.



45
46
47
48
49
50
51
# File 'lib/beni/tasks.rb', line 45

def initialize(&block)
  super()
  context = DSL::Context.new
  context.instance_exec(&block) if block
  @configuration = context.configuration
  define
end

Instance Attribute Details

#configurationConfiguration (readonly)

The resolved declarations — exposed so consumers and tests can inspect what the task definitions were wired from.

Returns:



43
44
45
# File 'lib/beni/tasks.rb', line 43

def configuration
  @configuration
end

Instance Method Details

#builderBuilder

Returns:



55
56
57
58
59
60
61
# File 'lib/beni/tasks.rb', line 55

def builder
  @builder ||= Builder.new(
    vendor_dir: configuration.vendor_dir,
    build_config: configuration.build_config,
    targets: configuration.targets
  )
end

#definevoid

This method returns an undefined value.



74
75
76
77
78
79
80
81
# File 'lib/beni/tasks.rb', line 74

def define
  namespace :beni do
    define_vendor_namespace
    define_build_task
    define_clean_task
    define_config_task
  end
end

#define_build_taskvoid

This method returns an undefined value.



127
128
129
130
131
132
133
# File 'lib/beni/tasks.rb', line 127

def define_build_task
  desc "Build vendored mruby for #{configuration.targets.join(" + ")} " \
       "(produces #{builder.libmruby_paths.join(", ")})"
  task build: "vendor:setup" do
    builder.ensure_built
  end
end

#define_clean_taskvoid

This method returns an undefined value.



135
136
137
138
139
140
# File 'lib/beni/tasks.rb', line 135

def define_clean_task
  desc "Remove mruby's build trees (keeps vendored mruby source)"
  task :clean do
    builder.clean
  end
end

#define_config_taskvoid

This method returns an undefined value.



142
143
144
145
146
147
148
149
150
151
# File 'lib/beni/tasks.rb', line 142

def define_config_task
  desc "Generate mruby's upstream default build config at the `build_config` declaration's path"
  task :config do
    dest = configuration.build_config
    raise Error, "[beni] beni:config requires a `build_config` declaration naming the file to generate" unless dest

    BuildConfig.generate(dest, mruby_dir: builder.mruby_dir, version: configuration.mruby_version)
    puts "[beni] generated #{dest} — edit it to define further targets"
  end
end

#define_toolchain_tasks(toolchain) ⇒ void

This method returns an undefined value.

Parameters:



114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/beni/tasks.rb', line 114

def define_toolchain_tasks(toolchain)
  file toolchain.tarball_path do
    toolchain.fetch
  end

  namespace :setup do
    desc "Download and unpack #{toolchain.name} #{toolchain.version_label} into #{toolchain.final_dir}"
    task toolchain.task_name => toolchain.tarball_path do
      toolchain.install
    end
  end
end

#define_vendor_clean_tasksvoid

This method returns an undefined value.



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/beni/tasks.rb', line 102

def define_vendor_clean_tasks
  desc "Remove unpacked vendor toolchains (keeps cached tarballs)"
  task :clean do
    vendor_toolchains.each { |toolchain| FileUtils.rm_rf(toolchain.final_dir) }
  end

  desc "Remove #{configuration.vendor_dir} entirely (unpacked trees and cached tarballs)"
  task :clobber do
    FileUtils.rm_rf(configuration.vendor_dir)
  end
end

#define_vendor_namespacevoid

This method returns an undefined value.



83
84
85
86
87
88
89
# File 'lib/beni/tasks.rb', line 83

def define_vendor_namespace
  namespace :vendor do
    vendor_toolchains.each { |toolchain| define_toolchain_tasks(toolchain) }
    define_vendor_setup_task
    define_vendor_clean_tasks
  end
end

#define_vendor_setup_taskvoid

This method returns an undefined value.



91
92
93
94
95
96
# File 'lib/beni/tasks.rb', line 91

def define_vendor_setup_task
  desc "Fetch and unpack the selected vendor toolchains (#{vendor_toolchains.map(&:name).join(" + ")})"
  task setup: vendor_toolchains.map { |toolchain| "setup:#{toolchain.task_name}" } do
    Vendor.stage_wasi_toolchain_file(vendor_dir: configuration.vendor_dir) if wasi_sdk_selected?
  end
end

#vendor_toolchainsArray[Vendor::Toolchain]

The selected toolchains as Vendor pipeline values, each carrying its resolved version and checksum.

Returns:



65
66
67
68
69
70
71
72
# File 'lib/beni/tasks.rb', line 65

def vendor_toolchains
  @vendor_toolchains ||= configuration.toolchains.map do |selected|
    Vendor.public_send(
      Vendor::TOOLCHAIN_FACTORIES.fetch(selected.name),
      vendor_dir: configuration.vendor_dir, version: selected.version, sha256: selected.sha256
    )
  end
end

#wasi_sdk_selected?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/beni/tasks.rb', line 98

def wasi_sdk_selected?
  configuration.toolchains.any? { |toolchain| toolchain.name == "wasi-sdk" }
end