Skip to content

Commit fa30a3e

Browse files
Merge pull request #366 from ruby/katei/package-all-files-in-dot-gem
Package all files in packaged .gem
2 parents 7ba1c32 + b71c735 commit fa30a3e

File tree

6 files changed

+58
-19
lines changed

6 files changed

+58
-19
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ jobs:
126126
${{ steps.builder-image.outputs.imageid }} /bin/sh
127127
echo 'docker exec -u me builder "$@"' > ./build-exec
128128
chmod +x ./build-exec
129-
- run: ./build-exec bundle config set --local without check
129+
# wait for docker exec to be ready
130+
timeout 10 bash -c 'until ./build-exec bundle config set --local without check; do sleep 1; done'
130131
- run: ./build-exec ./bin/setup
131132
- run: ./build-exec bundle exec rake compile
132133
- name: Pre-release configuration

Rakefile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,7 @@ NPM_PACKAGES = [
4242
gemfile: "packages/npm-packages/ruby-wasm-wasi/Gemfile",
4343
target: "wasm32-unknown-wasi"
4444
},
45-
{
46-
name: "ruby-wasm-wasi",
47-
target: "wasm32-unknown-wasi"
48-
}
45+
{ name: "ruby-wasm-wasi", target: "wasm32-unknown-wasi" }
4946
]
5047

5148
STANDALONE_PACKAGES = [

lib/ruby_wasm/packager/file_system.rb

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,20 @@ def each_gem_content_path(&block)
115115
@packager.specs.each do |spec|
116116
next unless File.exist?(spec.full_gem_path)
117117

118-
spec.files
119-
.each do |require_path|
120-
source = File.expand_path(require_path, spec.full_gem_path)
121-
next unless File.exist?(source)
122-
relative =
123-
File.join(
124-
bundle_relative_path,
125-
"gems",
126-
spec.full_name,
127-
require_path
128-
)
129-
yield relative, source
130-
end
118+
# spec.files is only valid before the gem is packaged.
119+
if spec.source.path?
120+
relative_paths = spec.files
121+
else
122+
# All files in .gem are required.
123+
relative_paths = Dir.children(spec.full_gem_path)
124+
end
125+
relative_paths.each do |require_path|
126+
source = File.expand_path(require_path, spec.full_gem_path)
127+
next unless File.exist?(source)
128+
relative =
129+
File.join(bundle_relative_path, "gems", spec.full_name, require_path)
130+
yield relative, source
131+
end
131132
end
132133
end
133134

rakelib/format.rake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace :format do
77
"Rakefile",
88
"lib/**/*.rb",
99
"ext/**/*.rb",
10+
"test/**/*.rb",
1011
"rakelib/**/*.rake",
1112
"packages/**/*.rb"
1213
]

rakelib/packaging.rake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ namespace :npm do
4141
pkg_dir = "#{Dir.pwd}/packages/npm-packages/#{pkg[:name]}"
4242

4343
namespace pkg[:name] do
44-
4544
desc "Build ruby for npm package #{pkg[:name]}"
4645
task "ruby" do
4746
build_command = npm_pkg_build_command(pkg)

test/test_build_smoke.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
require "test-unit"
2+
require "tmpdir"
3+
require "bundler"
4+
5+
class TestBuildSmoke < Test::Unit::TestCase
6+
def run_rbwasm(*args)
7+
rbwasm_path = File.expand_path("../../exe/rbwasm", __FILE__)
8+
system("bundle", "exec", rbwasm_path, *args, exception: true)
9+
end
10+
11+
def run_wasmtime(*args)
12+
IO.popen(["wasmtime", *args], &:read)
13+
end
14+
15+
def test_build_rack
16+
Dir.mktmpdir do |dir|
17+
gemfile_path = File.join(dir, "Gemfile")
18+
output_path = File.join(dir, "output.wasm")
19+
20+
File.write(gemfile_path, <<-GEMFILE)
21+
source "https://rubygems.org"
22+
gem "rack", "3.0.8"
23+
GEMFILE
24+
Bundler.with_unbundled_env do
25+
ENV["RUBY_WASM_ROOT"] = File.expand_path("../../", __FILE__)
26+
ENV["BUNDLE_GEMFILE"] = gemfile_path
27+
assert system("bundle", "install")
28+
run_rbwasm("build", "-o", output_path)
29+
assert_equal "Rack::RELEASE=3.0.8\n",
30+
run_wasmtime(
31+
output_path,
32+
"-r/bundle/setup.rb",
33+
"-rrack",
34+
"-e",
35+
"puts \"Rack::RELEASE=\#{Rack::RELEASE}\""
36+
)
37+
end
38+
end
39+
end
40+
end

0 commit comments

Comments
 (0)