beni 0.25.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6a016874c88f351f3e16608a037dcf43764b1a6103a2343095a8309993ef3e6
4
- data.tar.gz: 7dee2ba6bf749ca47d21c03c7ae8e13b088967ed066cdc1af7f65d3faa51c6c0
3
+ metadata.gz: dac8da0cd927263034acac8b4d54462b4ca1a9b1821f38612c7851340e31eea5
4
+ data.tar.gz: 62feac9f7b0c27319558b34b29e54d8eee9491fc7251919ec5f7a72b404a3cff
5
5
  SHA512:
6
- metadata.gz: 003cb5fd98c9c85c2e3e50e8e491c1e013239910e0d7fd77acfa5758666814dcf28217e0bd46323e44cee26024025359ccc0675cb998c466c8d59975467f5f30
7
- data.tar.gz: 6eed22fd23baf576f241c1d05d3120fbcb368387b4fe9df59ac3932b4a5f596a5ca775c141f47cbcfcb2d87dbe04744277b5416d8c273f38b2dbdba7b1c25620
6
+ metadata.gz: 334a6d039c379ef4937e1c81d623e98bc8529f941149837009bb823d2874a372e5167be7433eb633da5ecefe20d6e26231f895758290ccefa4a1bd9e82b2de18
7
+ data.tar.gz: 78d2dd21747eb7baf024481e9061cf50e62650229fa7d3201cf6a7d0271d632449bede13634404b1e9e73f6e563707505b10c50e6e667bf285bfcdf54e63a2e9
data/CHANGELOG.md CHANGED
@@ -1,5 +1,53 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.27.0](https://github.com/elct9620/beni/compare/v0.26.0...v0.27.0) (2026-11-11)
4
+
5
+
6
+ ### Features
7
+
8
+ * **beni-sys:** link a wasm32 archive for the WASI target it was built for ([8fca530](https://github.com/elct9620/beni/commit/8fca5307a20e68bf2f484522c6c09f2c104a05eb))
9
+ * **wasi:** take the WASI target and keep mruby's own wasi toolchain ([fde5584](https://github.com/elct9620/beni/commit/fde5584ff9a6f88190e4f549c1a1e62927733796))
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * **tasks:** hand the ABI legs' wasi builds the wasi-sdk root beni:build does ([77a628d](https://github.com/elct9620/beni/commit/77a628d3699759d619944fa04ff56267912d0a00))
15
+
16
+
17
+ ### Performance Improvements
18
+
19
+ * **build:** run mruby's rake with parallel compiles ([0089cee](https://github.com/elct9620/beni/commit/0089ceeab292fc9a7b77854559f3397ad061a3ac))
20
+
21
+
22
+ ### Reverts
23
+
24
+ * run mruby's rake without parallel compiles ([dce48d5](https://github.com/elct9620/beni/commit/dce48d5615b8823f0af4075065eae208ddf74c68))
25
+
26
+ ## [0.26.0](https://github.com/elct9620/beni/compare/v0.25.0...v0.26.0) (2026-11-06)
27
+
28
+
29
+ ### ⚠ BREAKING CHANGES
30
+
31
+ * **beni:** `RString::as_bytes` is renamed `as_slice`; `ReprValue::freeze` returns `()` instead of the receiver; `RArray::join` takes an `IntoRString` separator, so `Some(sep)` becomes `sep` and `None` becomes `""`.
32
+
33
+ ### Features
34
+
35
+ * **beni:** read frames in every build, as magnus's DebugInspector does ([7a3b01d](https://github.com/elct9620/beni/commit/7a3b01d6b44ee3cf861d3282f5c2aad1097b9c77))
36
+ * **beni:** take a join separator through IntoRString and read string bytes as as_slice ([0c2f6bd](https://github.com/elct9620/beni/commit/0c2f6bd540d1782af15e0e8a906401acb450b685))
37
+
38
+
39
+ ### Bug Fixes
40
+
41
+ * **beni:** accept only an initialized Range into the Range handle ([85a3005](https://github.com/elct9620/beni/commit/85a3005107f8a0fd9a53401afdd36ddde5dc2445))
42
+ * **beni:** copy a file name out before the next name read rewrites it ([aadf0b0](https://github.com/elct9620/beni/commit/aadf0b01a3d7ae8a9d54051885fe6fd4363b854e))
43
+ * **beni:** find no frames when the inspector opens with no Ruby call running ([11b6f87](https://github.com/elct9620/beni/commit/11b6f8708b0007cc64c7faf5a3a6a26ca0113f65))
44
+ * **beni:** read a String allocated without content as no bytes ([822a9f1](https://github.com/elct9620/beni/commit/822a9f17423e1cb340cd8ed090c6e12394f037b5))
45
+ * **gemspec:** leave the cloud bootstrap and the steep patch out of the package ([c6b5a12](https://github.com/elct9620/beni/commit/c6b5a12d2d40a050831d3cdd0a5d6edc10a4836d))
46
+ * **tasks:** clean every build tree and staged toolchain, not only the declared ones ([ca0b8d6](https://github.com/elct9620/beni/commit/ca0b8d62ec86caf19d4ed9234a9eb2cc56956894))
47
+ * **tasks:** stage and read the archive from one vendor tree ([5346e9c](https://github.com/elct9620/beni/commit/5346e9cfec90405f1391a9ac2ca44a03f2c91b49))
48
+ * **vendor:** leave no partial download behind when a fetch fails ([4bf2af3](https://github.com/elct9620/beni/commit/4bf2af3cdcb85b798d23dfa1e5e50613d8e9dc39))
49
+ * **vendor:** refuse a missing platform checksum at setup and drop a tarball that fails verification ([e3ca724](https://github.com/elct9620/beni/commit/e3ca724128f172ab607e0f9b3d5ffb95f45c6c22))
50
+
3
51
  ## [0.25.0](https://github.com/elct9620/beni/compare/v0.24.0...v0.25.0) (2026-10-22)
4
52
 
5
53
 
data/README.md CHANGED
@@ -107,7 +107,7 @@ fails naming the ones it looked for, rather than handing you a crate
107
107
  whose every call aborts later. Any C API the typed wrapper does not
108
108
  cover stays reachable through the unsafe `beni::sys` escape hatch.
109
109
 
110
- ### Cross-compile for wasm32-wasip1
110
+ ### Cross-compile for WASI
111
111
 
112
112
  Declare a `wasi` target referencing the `wasi-sdk` toolchain:
113
113
 
@@ -122,25 +122,29 @@ Beni::Tasks.new do
122
122
  end
123
123
  ```
124
124
 
125
- and append the cross build to the generated config:
125
+ and append the cross build to the generated config. `target:` picks
126
+ the WASI target, `wasm32-wasip1` when omitted:
126
127
 
127
128
  ```ruby
128
129
  MRuby::CrossBuild.new("wasi") do |conf|
129
- conf.toolchain :wasi
130
+ conf.toolchain :wasi, target: "wasm32-wasip2"
130
131
  end
131
132
  ```
132
133
 
133
- `conf.toolchain :wasi` resolves to the wasi toolchain file
134
- `beni:vendor:setup` stages into the mruby tree whenever `wasi-sdk` is
135
- selected — the cross-compile settings ship with beni and update with it.
136
- After `rake beni:build`, name the staged archive and the wasi-sdk root
137
- explicitly for the cargo side (a cross-compiled cargo target never reads
138
- the vendor tree on its own):
134
+ | mruby release | `conf.toolchain :wasi` resolves to |
135
+ |---|---|
136
+ | ships its own wasi toolchain file (4.1 onward) | that file, kept as is |
137
+ | ships none | the one `beni:vendor:setup` stages, taking the same `target:` |
138
+
139
+ `rake beni:build` points either file at the vendored wasi-sdk. A
140
+ cross-compiled cargo target never reads the vendor tree, so name the
141
+ staged archive and the wasi-sdk root. Cargo must build for the target
142
+ the archive was built for:
139
143
 
140
144
  ```bash
141
145
  MRUBY_LIB_DIR=$PWD/vendor/mruby/build/wasi/lib \
142
146
  WASI_SDK_PATH=$PWD/vendor/wasi-sdk \
143
- cargo build --target wasm32-wasip1
147
+ cargo build --target wasm32-wasip2
144
148
  ```
145
149
 
146
150
  ### Prism Source
@@ -167,9 +171,9 @@ The commit is the one the release records for
167
171
  ## Toolchain
168
172
 
169
173
  beni targets plain mruby and is not bound to WebAssembly. `rust-toolchain.toml`
170
- keeps `wasm32-wasip1` only as a build-verification target for downstream wasi
171
- consumers (kobako). For that target two versions move in lockstep, in both this
172
- repo and kobako; host builds are unaffected.
174
+ keeps `wasm32-wasip1` and `wasm32-wasip2` only as build-verification targets
175
+ for downstream wasi consumers (kobako). For those targets two versions move in
176
+ lockstep, in both this repo and kobako; host builds are unaffected.
173
177
 
174
178
  | Version | Lockstep reason |
175
179
  |---|---|
@@ -180,13 +184,13 @@ repo and kobako; host builds are unaffected.
180
184
 
181
185
  After checking out the repo, run `bin/setup` to install dependencies, then
182
186
  `bundle exec rake` for the default gate (tests + RuboCop + Steep). The repo
183
- dogfoods its own gem: the Rakefile wires `Beni::Tasks` with the validation
184
- config `build_config/mruby.rb` (host + wasi targets), and a repo-local rake
185
- chain verifies the crates compile against a real archive on both the host
186
- target and wasm32-wasip1:
187
+ dogfoods its own gem: the Rakefile wires `Beni::Tasks` with the verification
188
+ config `build_config/mruby.rb`. It builds host, wasm32-wasip1 and
189
+ wasm32-wasip2 archives, and a repo-local rake chain verifies the crates
190
+ against each:
187
191
 
188
192
  ```bash
189
- bundle exec rake rust:verify # beni:build + check/test (host) + check (wasm32)
193
+ bundle exec rake rust:verify # beni:build + check/test (host) + check/link (wasm32)
190
194
  ```
191
195
 
192
196
  Behavior contracts live in `SPEC.md` — the source of truth the
@@ -30,16 +30,11 @@ module Beni
30
30
  # wrong release.
31
31
  def staged_default_config(mruby_dir, version)
32
32
  source = File.join(mruby_dir, "build_config", "default.rb")
33
- return source if staged_version(mruby_dir) == version && File.exist?(source)
33
+ return source if Vendor::Tarball.staged_version(mruby_dir) == version && File.exist?(source)
34
34
 
35
35
  raise Error,
36
36
  "[beni] mruby #{version}'s source is not staged at #{mruby_dir} — " \
37
37
  "run `rake beni:vendor:setup` first"
38
38
  end
39
-
40
- def staged_version(mruby_dir)
41
- marker = File.join(mruby_dir, Vendor::Tarball::VERSION_MARKER)
42
- File.read(marker).strip if File.exist?(marker)
43
- end
44
39
  end
45
40
  end
data/lib/beni/builder.rb CHANGED
@@ -25,6 +25,10 @@ module Beni
25
25
  # The sidecar mruby writes beside every archive it builds.
26
26
  FLAGS_MAK = "libmruby.flags.mak"
27
27
 
28
+ # Where mruby clones the gem sources a build config fetches, under
29
+ # its build directory.
30
+ CLONED_GEMS_DIR = "repos"
31
+
28
32
  attr_reader :vendor_dir, :build_config, :targets
29
33
 
30
34
  def initialize(vendor_dir:, build_config: nil, targets: DEFAULT_TARGETS)
@@ -88,10 +92,15 @@ module Beni
88
92
  verify_artifacts!
89
93
  end
90
94
 
91
- # Remove each target's build tree (keeps the vendored mruby source).
95
+ # Remove every build tree, declared or not, keeping the vendored
96
+ # mruby source and the gem sources mruby clones into +build/repos+,
97
+ # which mruby's own +clean+ keeps too.
92
98
  def clean
93
- targets.each do |target|
94
- dir = File.join(mruby_dir, "build", target)
99
+ build_dir = File.join(mruby_dir, "build")
100
+ return unless Dir.exist?(build_dir)
101
+
102
+ (Dir.children(build_dir) - [CLONED_GEMS_DIR]).each do |entry|
103
+ dir = File.join(build_dir, entry)
95
104
  FileUtils.rm_rf(dir)
96
105
  puts "[beni] removed #{dir}"
97
106
  end
@@ -121,8 +130,10 @@ module Beni
121
130
  # the consuming project lives on disk. +MRUBY_CONFIG+ is only set
122
131
  # for an explicit config — absent, mruby falls back to its own
123
132
  # +build_config/default.rb+ (lib/mruby/build.rb#mruby_config_path).
133
+ # +WASI_SDK_PATH+ is how a wasi toolchain file — beni's or the mruby
134
+ # release's own — finds wasi-sdk.
124
135
  def env
125
- env = { "BENI_VENDOR_DIR" => vendor_dir }
136
+ env = { "BENI_VENDOR_DIR" => vendor_dir, "WASI_SDK_PATH" => Vendor.wasi_sdk_root(vendor_dir:) }
126
137
  env["MRUBY_CONFIG"] = build_config if build_config
127
138
  env
128
139
  end
@@ -99,13 +99,9 @@ module Beni
99
99
  definition = @definitions[name]
100
100
  return SelectedToolchain.new(name: name, version: definition.version, sha256: definition.sha256) if definition
101
101
 
102
- version = name == "mruby" ? mruby_version : Vendor::BUILT_IN_PAIRS.fetch(name).fetch(:version)
102
+ version = (@settings[:version] if name == "mruby") || Vendor.built_in_version(name)
103
103
  SelectedToolchain.new(name: name, version: version, sha256: Vendor.built_in_sha256(name, version))
104
104
  end
105
-
106
- def mruby_version
107
- @settings[:version] || Vendor::BUILT_IN_PAIRS.fetch("mruby").fetch(:version)
108
- end
109
105
  end
110
106
  end
111
107
  end
@@ -5,7 +5,9 @@ module Beni
5
5
  # +sha256+ is concrete at resolution time — a definition's declared
6
6
  # value or the built-in checksum +Beni::Vendor+ resolves. +nil+ has
7
7
  # exactly one reachable meaning: mruby at a non-default version, where
8
- # verification falls to the TOFU sidecar path.
8
+ # verification falls to the TOFU sidecar path. A
9
+ # +Vendor::UnvendoredChecksum+ stands for a built-in pair lacking the
10
+ # build platform's checksum, which setup refuses.
9
11
  class SelectedToolchain < Data.define(:name, :version, :sha256)
10
12
  end
11
13
  end
data/lib/beni/tasks.rb CHANGED
@@ -12,7 +12,7 @@ module Beni
12
12
  #
13
13
  # Beni::Tasks.new
14
14
  #
15
- # or with declarations (a custom config cross-building to wasm32-wasip1):
15
+ # or with declarations (a custom config cross-building to a WASI target):
16
16
  #
17
17
  # Beni::Tasks.new do
18
18
  # build_config "build_config/mruby.rb"
@@ -103,7 +103,9 @@ module Beni
103
103
  def define_vendor_clean_tasks
104
104
  desc "Remove unpacked vendor toolchains (keeps cached tarballs)"
105
105
  task :clean do
106
- vendor_toolchains.each { |toolchain| FileUtils.rm_rf(toolchain.final_dir) }
106
+ Vendor::TOOLCHAIN_FACTORIES.each_key do |name|
107
+ FileUtils.rm_rf(File.join(configuration.vendor_dir, Vendor.staged_dir(name)))
108
+ end
107
109
  end
108
110
 
109
111
  desc "Remove #{configuration.vendor_dir} entirely (unpacked trees and cached tarballs)"
@@ -32,14 +32,18 @@ module Beni
32
32
  end
33
33
 
34
34
  # Fetch +url+ into +dest+ atomically via a +.part+ sidecar, retrying
35
- # transient failures with exponential backoff. Permanent failures
36
- # (4xx, DNS resolution failure on non-network condition) surface
35
+ # transient failures with exponential backoff. A 4xx surfaces
37
36
  # immediately. Raises whatever the underlying +URI#open+ raises after
38
- # the retry budget is exhausted.
37
+ # the retry budget is exhausted, leaving no +.part+ behind.
39
38
  def download
40
39
  FileUtils.mkdir_p(File.dirname(@dest))
41
40
  tmp = "#{@dest}.part"
42
- with_retry { fetch(tmp) }
41
+ begin
42
+ with_retry { fetch(tmp) }
43
+ rescue StandardError
44
+ FileUtils.rm_f(tmp)
45
+ raise
46
+ end
43
47
  File.rename(tmp, @dest)
44
48
  end
45
49
 
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Beni
4
+ # The build platform half of the vendor façade: how the host's
5
+ # +RUBY_PLATFORM+ names the platform toolchains key their tarballs by.
6
+ module Vendor
7
+ # +RUBY_PLATFORM+ spells the same architecture and operating system
8
+ # differently across hosts; toolchains key their per-platform tarballs
9
+ # by one spelling each.
10
+ ARCH_ALIASES = { "x64" => "x86_64", "amd64" => "x86_64", "aarch64" => "arm64" }.freeze
11
+ OS_ALIASES = { /darwin/ => "macos", /linux/ => "linux", /mingw|mswin/ => "windows" }.freeze
12
+
13
+ # The build platform: the architecture and operating system the Rake
14
+ # tasks run on, spelled the way toolchains key their tarballs. Derived
15
+ # from the host rather than matched against a covered set, so a host no
16
+ # toolchain vendors a tarball for still has a name to be named in.
17
+ def self.build_platform(platform = RUBY_PLATFORM)
18
+ "#{platform_arch(platform)}-#{platform_os(platform)}"
19
+ end
20
+
21
+ def self.platform_arch(platform)
22
+ arch = platform.split("-").first.to_s
23
+ ARCH_ALIASES.fetch(arch, arch)
24
+ end
25
+
26
+ def self.platform_os(platform)
27
+ OS_ALIASES.find { |pattern, _| pattern.match?(platform) }&.last ||
28
+ platform.split("-")[1].to_s
29
+ end
30
+
31
+ private_class_method :platform_arch, :platform_os
32
+
33
+ # The build platform, resolved once at load.
34
+ BUILD_PLATFORM = build_platform
35
+ end
36
+ end
@@ -18,6 +18,13 @@ module Beni
18
18
  # value short-circuits +#prepare+, a mismatch forces re-extract.
19
19
  VERSION_MARKER = ".beni-version"
20
20
 
21
+ # Version the last successful unpack into +dir+ recorded, or +nil+
22
+ # when the tree is absent or predates version stamping.
23
+ def self.staged_version(dir)
24
+ marker = File.join(dir, VERSION_MARKER)
25
+ File.read(marker).strip if File.exist?(marker)
26
+ end
27
+
21
28
  def initialize(tarball:, top_level_dir:, final_dir:, version:)
22
29
  @tarball = tarball
23
30
  @top_level_dir = top_level_dir
@@ -44,11 +51,10 @@ module Beni
44
51
 
45
52
  private
46
53
 
47
- # Version recorded by the last successful unpack, or +nil+ when the tree
48
- # is absent or predates version stamping (forcing a re-extract).
54
+ # Version recorded by the last successful unpack; +nil+ forces a
55
+ # re-extract.
49
56
  def installed_version
50
- marker = File.join(@final_dir, VERSION_MARKER)
51
- File.read(marker).strip if File.exist?(marker)
57
+ self.class.staged_version(@final_dir)
52
58
  end
53
59
 
54
60
  def extract_to_staging(staging)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "fileutils"
4
+
3
5
  module Beni
4
6
  module Vendor
5
7
  # Declarative value object describing a tarball-style vendored
@@ -21,8 +23,8 @@ module Beni
21
23
  # stamped into +final_dir+ as the idempotency key
22
24
  # that detects a bump and forces a re-extract.
23
25
  # * +base_url+ — remote URL prefix; resolved through
24
- # +Beni::Vendor.base_url_for+ so test fixtures
25
- # can override via +BENI_VENDOR_BASE_URL+.
26
+ # +Beni::Vendor.base_url_for+, which a
27
+ # +BENI_VENDOR_BASE_URL+ mirror replaces.
26
28
  # * +tarball_name+ — filename joined to both +base_url+ (download)
27
29
  # and the +.cache+ directory (cache location).
28
30
  # * +top_level_dir+ — the single top-level directory produced when
@@ -37,7 +39,8 @@ module Beni
37
39
  # * +expected_sha256+ — the toolchain's selected checksum (resolved
38
40
  # by +Beni::Vendor+ from the built-in pair or a
39
41
  # consumer override); +nil+ falls to TOFU
40
- # sidecar pinning in +Checksum#verify_or_pin+.
42
+ # sidecar pinning in +Checksum#verify_or_pin+,
43
+ # and an +UnvendoredChecksum+ refuses setup.
41
44
  class Toolchain <
42
45
  Data.define(:name, :version_label, :base_url, :tarball_name, :top_level_dir, :vendor_dir, :staged_dir,
43
46
  :expected_sha256)
@@ -52,9 +55,8 @@ module Beni
52
55
  name.tr("-", "_").to_sym
53
56
  end
54
57
 
55
- # Resolved download URL. Honours the +BENI_VENDOR_BASE_URL+ test
56
- # fixture override at call time (not at construction time), so a
57
- # test can flip the env var after the Toolchain is built.
58
+ # Resolved download URL. Reads the +BENI_VENDOR_BASE_URL+ mirror at
59
+ # call time, not at construction time.
58
60
  def url
59
61
  "#{Vendor.base_url_for(base_url)}/#{tarball_name}"
60
62
  end
@@ -73,10 +75,10 @@ module Beni
73
75
  # Download the tarball into +tarball_path+ and verify its SHA256.
74
76
  # Intended as the body of the +file tarball_path+ rake task; the
75
77
  # task's mtime-based caching avoids re-downloading on a cache hit.
76
- # A tarball failing verification deliberately stays cached: a
77
- # checksum mismatch is an abort condition, never a re-download
78
- # trigger, and the cache-hit path re-fails it the same way.
78
+ # A toolchain with no checksum for the build platform is refused
79
+ # before anything downloads.
79
80
  def fetch
81
+ expected_checksum
80
82
  puts "[beni] downloading #{name} #{version_label} from #{url}"
81
83
  downloader.download
82
84
  verify
@@ -85,9 +87,13 @@ module Beni
85
87
  # Recompute the cached tarball's SHA256 and check it against
86
88
  # +expected_sha256+ (or pin via TOFU sidecar). Idempotent — safe
87
89
  # to call from both +file+ and +setup+ task bodies when the latter
88
- # depends on the former.
90
+ # depends on the former. A tarball failing verification leaves the
91
+ # cache, so the next setup downloads it again.
89
92
  def verify
90
- Checksum.new(tarball_path, expected_sha256).verify_or_pin
93
+ Checksum.new(tarball_path, expected_checksum).verify_or_pin
94
+ rescue Error
95
+ FileUtils.rm_f(tarball_path)
96
+ raise
91
97
  end
92
98
 
93
99
  # Verify the cached tarball, then unpack it into +final_dir+ via
@@ -106,6 +112,15 @@ module Beni
106
112
 
107
113
  private
108
114
 
115
+ # The checksum verification compares against, +nil+ for a TOFU pin;
116
+ # raises for a built-in pair lacking the build platform's checksum.
117
+ def expected_checksum
118
+ checksum = expected_sha256
119
+ raise Error, checksum.message if checksum.is_a?(UnvendoredChecksum)
120
+
121
+ checksum
122
+ end
123
+
109
124
  # The network boundary — tests override this to script the
110
125
  # download without opening a connection.
111
126
  def downloader
@@ -1,17 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # beni's wasm32-wasip1 cross-compile toolchain — the wasi toolchain
4
- # file, staged into the mruby tree's +tasks/toolchains/+ by
5
- # +beni:vendor:setup+ whenever wasi-sdk is selected. A build config
6
- # activates it with +conf.toolchain :wasi+.
7
- MRuby::Toolchain.new(:wasi) do |conf, _params|
8
- # WASI_SDK_PATH overrides the wasi-sdk root; the default is the
9
- # vendor tree this mruby source is staged in (MRUBY_ROOT's parent).
10
- wasi_sdk = ENV["WASI_SDK_PATH"] || File.join(File.expand_path("..", MRUBY_ROOT), "wasi-sdk")
3
+ # beni's wasm32 WASI cross-compile toolchain — the wasi toolchain file,
4
+ # staged into the mruby tree's +tasks/toolchains/+ by
5
+ # +beni:vendor:setup+ when the tree holds none of its own. A build
6
+ # config activates it with +conf.toolchain :wasi+, or names another
7
+ # WASI target with +conf.toolchain :wasi, target: "wasm32-wasip2"+ —
8
+ # the parameter mruby's own wasi toolchain file takes.
9
+ MRuby::Toolchain.new(:wasi) do |conf, params|
10
+ # +beni:build+ points WASI_SDK_PATH at the vendored wasi-sdk.
11
+ wasi_sdk = ENV["WASI_SDK_PATH"] || "/opt/wasi-sdk"
11
12
  bin = File.join(wasi_sdk, "bin")
12
- target_flags = ["--target=wasm32-wasip1", "--sysroot=#{File.join(wasi_sdk, "share", "wasi-sysroot")}"]
13
- # setjmp/longjmp via the wasm exception-handling mechanism: all
14
- # three flags must be present at both compile and link stages.
13
+ target = params[:target] || "wasm32-wasip1"
14
+ target_flags = ["--target=#{target}", "--sysroot=#{File.join(wasi_sdk, "share", "wasi-sysroot")}"]
15
+ # setjmp/longjmp via the wasm exception-handling mechanism: these
16
+ # flags go to every compile and the link, and the link adds the
17
+ # setjmp library.
15
18
  sjlj_flags = ["-mllvm", "-wasm-enable-sjlj", "-mllvm", "-wasm-use-legacy-eh=false"]
16
19
 
17
20
  conf.toolchain :clang
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Beni
4
+ module Vendor
5
+ # The checksum a platform-keyed built-in pair lacks for the build
6
+ # platform. It stands in for the checksum until setup, which refuses
7
+ # it before anything downloads, so the tasks still load there.
8
+ class UnvendoredChecksum < Data.define(:name, :version, :platform)
9
+ def message
10
+ "[beni] #{name} #{version} vendors no tarball for build platform #{platform}; " \
11
+ "declare the toolchain with a version and sha256 for this platform"
12
+ end
13
+ end
14
+ end
15
+ end
data/lib/beni/vendor.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative "vendor/platform"
3
4
  require_relative "vendor/downloader"
4
5
  require_relative "vendor/checksum"
6
+ require_relative "vendor/unvendored_checksum"
5
7
  require_relative "vendor/tarball"
6
8
  require_relative "vendor/toolchain"
7
9
 
@@ -15,8 +17,7 @@ module Beni
15
17
  # tarball extraction in +Vendor::Tarball+, and the per-toolchain
16
18
  # pipeline composition in +Vendor::Toolchain+.
17
19
  #
18
- # Honors +BENI_VENDOR_BASE_URL+ to point downloads at a local fixture
19
- # during tests.
20
+ # Honors +BENI_VENDOR_BASE_URL+ to move every download to a mirror.
20
21
  module Vendor
21
22
  # ---- Built-in pairs ----------------------------------------------------
22
23
  # The version and checksum pair this release vendors per toolchain.
@@ -25,8 +26,8 @@ module Beni
25
26
  # digests); mruby's source archive is host-agnostic with a single
26
27
  # checksum.
27
28
  #
28
- # wasi-sdk: must be >= 26 for native wasm32-wasip1 setjmp/longjmp
29
- # support. 33's +libc.a+ supplies +__wasi_init_tp+, which Rust's
29
+ # wasi-sdk: must be >= 26 for native WASI setjmp/longjmp support.
30
+ # 33's +libc.a+ supplies +__wasi_init_tp+, which Rust's
30
31
  # wasm32-wasip1 +crt1-command.o+ references from 1.96 onward. Keep in
31
32
  # lockstep with the channel in +rust-toolchain.toml+ — in both this
32
33
  # repo and kobako.
@@ -54,35 +55,6 @@ module Beni
54
55
  # mruby source rather than serving a target, and has no built-in pair.
55
56
  SELECTED_BY_DEFINITION = %w[prism].freeze
56
57
 
57
- # +RUBY_PLATFORM+ spells the same architecture and operating system
58
- # differently across hosts; toolchains key their per-platform tarballs
59
- # by one spelling each.
60
- ARCH_ALIASES = { "x64" => "x86_64", "amd64" => "x86_64", "aarch64" => "arm64" }.freeze
61
- OS_ALIASES = { /darwin/ => "macos", /linux/ => "linux", /mingw|mswin/ => "windows" }.freeze
62
-
63
- # The build platform: the architecture and operating system the Rake
64
- # tasks run on, spelled the way toolchains key their tarballs. Derived
65
- # from the host rather than matched against a covered set, so a host no
66
- # toolchain vendors a tarball for still has a name to be named in.
67
- def self.build_platform(platform = RUBY_PLATFORM)
68
- "#{platform_arch(platform)}-#{platform_os(platform)}"
69
- end
70
-
71
- def self.platform_arch(platform)
72
- arch = platform.split("-").first.to_s
73
- ARCH_ALIASES.fetch(arch, arch)
74
- end
75
-
76
- def self.platform_os(platform)
77
- OS_ALIASES.find { |pattern, _| pattern.match?(platform) }&.last ||
78
- platform.split("-")[1].to_s
79
- end
80
-
81
- private_class_method :platform_arch, :platform_os
82
-
83
- # The build platform, resolved once at load.
84
- BUILD_PLATFORM = build_platform
85
-
86
58
  # Known toolchain names mapped to their factory methods — the name
87
59
  # domain the DSL validates against and +Beni::Tasks+ dispatches on.
88
60
  TOOLCHAIN_FACTORIES = {
@@ -91,10 +63,20 @@ module Beni
91
63
  "prism" => :prism
92
64
  }.freeze
93
65
 
66
+ # What every wasi toolchain file beni has shipped says about itself,
67
+ # and an mruby release's own does not.
68
+ WASI_TOOLCHAIN_MARK = "beni:vendor:setup"
69
+
70
+ # Where a toolchain staging somewhere other than its own name under
71
+ # the vendor tree unpacks; every other one unpacks at its name.
72
+ STAGED_DIRS = {
73
+ "prism" => File.join("mruby", "mrbgems", "mruby-compiler", "lib", "prism")
74
+ }.freeze
75
+
94
76
  module_function
95
77
 
96
78
  def wasi_sdk(vendor_dir:, version: nil, sha256: nil)
97
- version ||= BUILT_IN_PAIRS.fetch("wasi-sdk").fetch(:version)
79
+ version ||= built_in_version("wasi-sdk")
98
80
  # The release tag carries the major version only; tarballs carry the
99
81
  # full version plus the platform.
100
82
  Toolchain.new(
@@ -109,7 +91,7 @@ module Beni
109
91
  end
110
92
 
111
93
  def mruby(vendor_dir:, version: nil, sha256: nil)
112
- version ||= BUILT_IN_PAIRS.fetch("mruby").fetch(:version)
94
+ version ||= built_in_version("mruby")
113
95
  Toolchain.new(
114
96
  name: "mruby",
115
97
  version_label: version,
@@ -133,14 +115,14 @@ module Beni
133
115
  tarball_name: "#{version}.tar.gz",
134
116
  top_level_dir: "prism-#{version}",
135
117
  vendor_dir: vendor_dir,
136
- staged_dir: File.join("mruby", "mrbgems", "mruby-compiler", "lib", "prism"),
118
+ staged_dir: staged_dir("prism"),
137
119
  expected_sha256: sha256
138
120
  )
139
121
  end
140
122
 
141
123
  # When BENI_VENDOR_BASE_URL is set, all tarballs are fetched from that
142
- # base URL (test fixture). The base URL must serve files named exactly
143
- # +tarball_name+ for each toolchain.
124
+ # mirror, which serves each toolchain's tarball under its exact
125
+ # +tarball_name+.
144
126
  def base_url_for(default)
145
127
  override = ENV.fetch("BENI_VENDOR_BASE_URL", nil)
146
128
  return default if override.nil? || override.empty?
@@ -148,36 +130,52 @@ module Beni
148
130
  override.chomp("/")
149
131
  end
150
132
 
133
+ # The version +name+'s built-in pair vendors.
134
+ def built_in_version(name)
135
+ BUILT_IN_PAIRS.fetch(name).fetch(:version)
136
+ end
137
+
138
+ # Where +name+ unpacks, relative to the vendor tree.
139
+ def staged_dir(name)
140
+ STAGED_DIRS.fetch(name, name)
141
+ end
142
+
143
+ # The wasi-sdk root +beni:build+ hands a wasi toolchain file: the
144
+ # caller's +WASI_SDK_PATH+, else the one unpacked in +vendor_dir+.
145
+ def wasi_sdk_root(vendor_dir:)
146
+ ENV.fetch("WASI_SDK_PATH") { File.join(vendor_dir, staged_dir("wasi-sdk")) }
147
+ end
148
+
151
149
  # The built-in checksum for +name+ at +version+: the build platform's
152
150
  # entry when the toolchain's checksums are platform-keyed, +nil+ for
153
151
  # any version other than the vendored one — mruby's TOFU pinning path.
154
152
  # A platform-keyed pair carrying no entry for +platform+ vendors no
155
- # tarball there, and says so rather than letting another platform's
156
- # checksum stand in.
153
+ # tarball there: the lookup answers an +UnvendoredChecksum+, which
154
+ # setup refuses, rather than letting another platform's checksum
155
+ # stand in.
157
156
  def built_in_sha256(name, version, platform = BUILD_PLATFORM)
158
157
  pair = BUILT_IN_PAIRS.fetch(name)
159
- return nil unless version == pair.fetch(:version)
158
+ return nil unless version == built_in_version(name)
160
159
 
161
160
  checksum = pair.fetch(:sha256)
162
161
  return checksum unless checksum.is_a?(Hash)
163
162
 
164
- checksum.fetch(platform) do
165
- raise Error, "[beni] #{name} #{version} vendors no tarball for build platform " \
166
- "#{platform}; declare the toolchain with a version and sha256 " \
167
- "for this platform"
168
- end
163
+ checksum.fetch(platform) { UnvendoredChecksum.new(name:, version:, platform:) }
169
164
  end
170
165
 
171
- # Write the gem-shipped wasi toolchain file into the staged mruby
172
- # source, where mruby's +conf.toolchain :wasi+ resolves it from.
173
- # Idempotent and always overwriting, so a re-extracted tree or an
174
- # older beni's copy converges on this release's definition. Returns
175
- # the staged path.
166
+ # Put a wasi toolchain file in the staged mruby source, where
167
+ # mruby's +conf.toolchain :wasi+ resolves it from. One the tree
168
+ # already holds that beni did not write — an mruby release's own —
169
+ # is kept; otherwise the gem-shipped file is written, so a
170
+ # re-extracted tree or an older beni's copy converges on this
171
+ # release's definition. Returns the staged path.
176
172
  def stage_wasi_toolchain_file(vendor_dir:)
173
+ target = File.join(vendor_dir, "mruby", "tasks", "toolchains", "wasi.rake")
174
+ return target if File.exist?(target) && !File.read(target).include?(WASI_TOOLCHAIN_MARK)
175
+
177
176
  # `__dir__ || "."`: __dir__ is only nil under eval, which never
178
177
  # loads this file; the fallback satisfies steep's String? typing.
179
178
  source = File.expand_path("vendor/toolchains/wasi.rake", __dir__ || ".")
180
- target = File.join(vendor_dir, "mruby", "tasks", "toolchains", "wasi.rake")
181
179
  FileUtils.mkdir_p(File.dirname(target))
182
180
  FileUtils.cp(source, target)
183
181
  target
data/lib/beni/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Beni
4
- VERSION = "0.25.0"
4
+ VERSION = "0.27.0"
5
5
  end
@@ -3,7 +3,5 @@ module Beni
3
3
  def self?.generate: (String dest, mruby_dir: String, version: String) -> String
4
4
 
5
5
  def self?.staged_default_config: (String mruby_dir, String version) -> String
6
-
7
- def self?.staged_version: (String mruby_dir) -> String?
8
6
  end
9
7
  end
data/sig/beni/builder.rbs CHANGED
@@ -3,6 +3,7 @@ module Beni
3
3
  DEFAULT_TARGETS: Array[String]
4
4
  ARCHIVE_PATH_KEY: String
5
5
  FLAGS_MAK: String
6
+ CLONED_GEMS_DIR: String
6
7
 
7
8
  attr_reader vendor_dir: String
8
9
  attr_reader build_config: String?
@@ -32,8 +32,6 @@ module Beni
32
32
  def selected_names: () -> Array[String]
33
33
 
34
34
  def selected_toolchain: (String name) -> SelectedToolchain
35
-
36
- def mruby_version: () -> String
37
35
  end
38
36
  end
39
37
  end
@@ -2,8 +2,8 @@ module Beni
2
2
  class SelectedToolchain
3
3
  attr_reader name: String
4
4
  attr_reader version: String
5
- attr_reader sha256: String?
5
+ attr_reader sha256: (String | Vendor::UnvendoredChecksum)?
6
6
 
7
- def initialize: (name: String, version: String, sha256: String?) -> void
7
+ def initialize: (name: String, version: String, sha256: (String | Vendor::UnvendoredChecksum)?) -> void
8
8
  end
9
9
  end
@@ -0,0 +1,13 @@
1
+ module Beni
2
+ module Vendor
3
+ ARCH_ALIASES: Hash[String, String]
4
+ OS_ALIASES: Hash[Regexp, String]
5
+ BUILD_PLATFORM: String
6
+
7
+ def self.build_platform: (?String platform) -> String
8
+
9
+ def self.platform_arch: (String platform) -> String
10
+
11
+ def self.platform_os: (String platform) -> String
12
+ end
13
+ end
@@ -3,6 +3,8 @@ module Beni
3
3
  class Tarball
4
4
  VERSION_MARKER: String
5
5
 
6
+ def self.staged_version: (String dir) -> String?
7
+
6
8
  @tarball: String
7
9
  @top_level_dir: String
8
10
  @final_dir: String
@@ -8,9 +8,9 @@ module Beni
8
8
  attr_reader top_level_dir: String
9
9
  attr_reader vendor_dir: String
10
10
  attr_reader staged_dir: String
11
- attr_reader expected_sha256: String?
11
+ attr_reader expected_sha256: (String | UnvendoredChecksum)?
12
12
 
13
- def initialize: (name: String, version_label: String, base_url: String, tarball_name: String, top_level_dir: String, vendor_dir: String, ?staged_dir: String, expected_sha256: String?) -> void
13
+ def initialize: (name: String, version_label: String, base_url: String, tarball_name: String, top_level_dir: String, vendor_dir: String, ?staged_dir: String, expected_sha256: (String | UnvendoredChecksum)?) -> void
14
14
 
15
15
  def task_name: () -> Symbol
16
16
 
@@ -28,6 +28,8 @@ module Beni
28
28
 
29
29
  private
30
30
 
31
+ def expected_checksum: () -> String?
32
+
31
33
  def downloader: () -> Downloader
32
34
  end
33
35
  end
@@ -0,0 +1,13 @@
1
+ module Beni
2
+ module Vendor
3
+ class UnvendoredChecksum
4
+ attr_reader name: String
5
+ attr_reader version: String
6
+ attr_reader platform: String
7
+
8
+ def initialize: (name: String, version: String, platform: String) -> void
9
+
10
+ def message: () -> String
11
+ end
12
+ end
13
+ end
data/sig/beni/vendor.rbs CHANGED
@@ -4,27 +4,26 @@ module Beni
4
4
 
5
5
  BUILT_IN_PAIRS: Hash[String, built_in_pair]
6
6
  DEPENDENCIES: Hash[String, Array[String]]
7
- ARCH_ALIASES: Hash[String, String]
8
- OS_ALIASES: Hash[Regexp, String]
9
- BUILD_PLATFORM: String
10
7
  TOOLCHAIN_FACTORIES: Hash[String, Symbol]
8
+ WASI_TOOLCHAIN_MARK: String
9
+ STAGED_DIRS: Hash[String, String]
11
10
  SELECTED_BY_DEFINITION: Array[String]
12
11
 
13
- def self.build_platform: (?String platform) -> String
12
+ def self?.wasi_sdk: (vendor_dir: String, ?version: String?, ?sha256: (String | UnvendoredChecksum)?) -> Toolchain
14
13
 
15
- def self.platform_arch: (String platform) -> String
14
+ def self?.mruby: (vendor_dir: String, ?version: String?, ?sha256: (String | UnvendoredChecksum)?) -> Toolchain
16
15
 
17
- def self.platform_os: (String platform) -> String
16
+ def self?.prism: (vendor_dir: String, version: String, sha256: String) -> Toolchain
18
17
 
19
- def self?.wasi_sdk: (vendor_dir: String, ?version: String?, ?sha256: String?) -> Toolchain
18
+ def self?.base_url_for: (String default) -> String
20
19
 
21
- def self?.mruby: (vendor_dir: String, ?version: String?, ?sha256: String?) -> Toolchain
20
+ def self?.built_in_version: (String name) -> String
22
21
 
23
- def self?.prism: (vendor_dir: String, version: String, sha256: String) -> Toolchain
22
+ def self?.staged_dir: (String name) -> String
24
23
 
25
- def self?.base_url_for: (String default) -> String
24
+ def self?.wasi_sdk_root: (vendor_dir: String) -> String
26
25
 
27
- def self?.built_in_sha256: (String name, String version, ?String platform) -> String?
26
+ def self?.built_in_sha256: (String name, String version, ?String platform) -> (String | UnvendoredChecksum)?
28
27
 
29
28
  def self?.stage_wasi_toolchain_file: (vendor_dir: String) -> String
30
29
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: beni
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.27.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aotokitsuruya
@@ -23,8 +23,8 @@ dependencies:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '13.0'
26
- description: Vendors mruby and builds libmruby.a through a Rake task library, with
27
- generated build configs for customization. Aims to grow into a full mruby dependency
26
+ description: Vendors mruby and builds its static archive through a Rake task library,
27
+ with generated build configs for customization. Aims to grow into a full mruby dependency
28
28
  manager.
29
29
  email:
30
30
  - contact@aotoki.me
@@ -50,11 +50,12 @@ files:
50
50
  - lib/beni/vendor.rb
51
51
  - lib/beni/vendor/checksum.rb
52
52
  - lib/beni/vendor/downloader.rb
53
+ - lib/beni/vendor/platform.rb
53
54
  - lib/beni/vendor/tarball.rb
54
55
  - lib/beni/vendor/toolchain.rb
55
56
  - lib/beni/vendor/toolchains/wasi.rake
57
+ - lib/beni/vendor/unvendored_checksum.rb
56
58
  - lib/beni/version.rb
57
- - scripts/cloud_setup.sh
58
59
  - sig/beni.rbs
59
60
  - sig/beni/build_config.rbs
60
61
  - sig/beni/builder.rbs
@@ -70,9 +71,10 @@ files:
70
71
  - sig/beni/vendor.rbs
71
72
  - sig/beni/vendor/checksum.rbs
72
73
  - sig/beni/vendor/downloader.rbs
74
+ - sig/beni/vendor/platform.rbs
73
75
  - sig/beni/vendor/tarball.rbs
74
76
  - sig/beni/vendor/toolchain.rbs
75
- - sig/patches/open-uri.rbs
77
+ - sig/beni/vendor/unvendored_checksum.rbs
76
78
  homepage: https://github.com/elct9620/beni
77
79
  licenses:
78
80
  - Apache-2.0
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env bash
2
- # Cloud session bootstrap
3
- # =======================
4
- #
5
- # A cloud session starts from a fresh VM holding nothing but a clone, so
6
- # everything the task surface expects from a working checkout is rebuilt
7
- # here. A local checkout keeps its own, so the script stops unless it is
8
- # running in the cloud.
9
- set -euo pipefail
10
-
11
- [ "${CLAUDE_CODE_REMOTE:-}" = "true" ] || exit 0
12
-
13
- cd "$CLAUDE_PROJECT_DIR"
14
-
15
- # The default rake task and every hook run through bundler.
16
- bundle check >/dev/null 2>&1 || bundle install
17
-
18
- # The coverage measure reads its inventory from the vendored mruby headers,
19
- # and the session's egress serves the git protocol but not source archives —
20
- # so the source arrives by clone here, at the gem's default version.
21
- if [ ! -d vendor/mruby ]; then
22
- version="$(ruby -Ilib -rbeni/vendor -e 'print Beni::Vendor::BUILT_IN_PAIRS.fetch("mruby").fetch(:version)')"
23
- GIT_LFS_SKIP_SMUDGE=1 git -c advice.detachedHead=false clone --quiet --depth 1 \
24
- --branch "$version" https://github.com/mruby/mruby.git vendor/mruby
25
- fi
@@ -1,10 +0,0 @@
1
- # Patch: rbs' open-uri stdlib signatures only cover the module function
2
- # +URI.open+; the instance form +URI::Generic#open+ (mixed in via
3
- # +OpenURI::OpenRead+ for http/https/ftp URIs at runtime) is missing.
4
- # Declared here so +Beni::Vendor::Downloader#download+ type-checks.
5
- module URI
6
- class Generic
7
- def open: (?String mode) -> (StringIO & OpenURI::Meta)
8
- | [T] (?String mode) { (StringIO | Tempfile) -> T } -> T
9
- end
10
- end