Skip to content

Commit bf2be79

Browse files
Merge pull request #2 from kateinoigakukun/build-libyaml
Build libyaml as a dependency
2 parents 29f6552 + 8a34613 commit bf2be79

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

Rakefile

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ class BuildPlan
8585
"#{@base_dir}/build/ext-build/#{name}"
8686
end
8787

88+
def deps_install_dir
89+
"#{@base_dir}/build/deps/#{@params[:target]}/opt"
90+
end
91+
8892
def dest_dir
8993
"#{@base_dir}/rubies/#{name}"
9094
end
@@ -93,6 +97,11 @@ class BuildPlan
9397
"#{ext_build_dir}/extinit.o"
9498
end
9599

100+
def dep_tasks
101+
return [] if @params[:profile] == "minimal"
102+
["deps:libyaml-#{@params[:target]}"]
103+
end
104+
96105
def check_deps
97106
target = @params[:target]
98107
profile = BUILD_PROFILES[@params[:profile]]
@@ -125,6 +134,7 @@ class BuildPlan
125134
args = ["--host", target, "--build", build_triple]
126135
args << "--with-static-linked-ext"
127136
args << %Q(--with-ext="#{default_exts}")
137+
args << %Q(--with-libyaml-dir="#{deps_install_dir}/libyaml/usr/local")
128138

129139
case target
130140
when "wasm32-unknown-wasi"
@@ -149,6 +159,38 @@ class BuildPlan
149159
end
150160
end
151161

162+
namespace :deps do
163+
["wasm32-unknown-wasi", "wasm32-unknown-emscripten"].each do |target|
164+
install_dir = File.join(Dir.pwd, "/build/deps/#{target}/opt")
165+
libyaml_version = "0.2.5"
166+
desc "build libyaml #{libyaml_version} for #{target}"
167+
task "libyaml-#{target}" do
168+
next if Dir.exist?("#{install_dir}/libyaml")
169+
170+
build_dir = File.join(Dir.pwd, "/build/deps/#{target}/yaml-#{libyaml_version}")
171+
mkdir_p File.dirname(build_dir)
172+
rm_rf build_dir
173+
sh "curl -L https://github.com/yaml/libyaml/releases/download/#{libyaml_version}/yaml-#{libyaml_version}.tar.gz | tar xz", chdir: File.dirname(build_dir)
174+
175+
# obtain the latest config.guess and config.sub for Emscripten and WASI triple support
176+
sh "curl -o #{build_dir}/config/config.guess 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD'"
177+
sh "curl -o #{build_dir}/config/config.sub 'https://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD'"
178+
179+
configure_args = []
180+
case target
181+
when "wasm32-unknown-wasi"
182+
configure_args.concat(%W(--host wasm32-wasi CC=#{ENV["WASI_SDK_PATH"]}/bin/clang RANLIB=#{ENV["WASI_SDK_PATH"]}/bin/llvm-ranlib LD=#{ENV["WASI_SDK_PATH"]}/bin/clang AR=#{ENV["WASI_SDK_PATH"]}/bin/llvm-ar))
183+
when "wasm32-unknown-emscripten"
184+
configure_args.concat(%W(--host wasm32-emscripten CC=emcc RANLIB=emranlib LD=emcc AR=emar))
185+
else
186+
raise "unknown target: #{target}"
187+
end
188+
sh "./configure #{configure_args.join(" ")}", chdir: build_dir
189+
sh "make install DESTDIR=#{install_dir}/libyaml", chdir: build_dir
190+
end
191+
end
192+
end
193+
152194
namespace :build do
153195

154196
base_dir = Dir.pwd
@@ -174,7 +216,7 @@ namespace :build do
174216
directory build.dest_dir
175217
directory build.build_dir
176218

177-
task "#{build.name}-configure", [:reconfigure] => [build.build_dir, source.src_dir, source.configure_file] do |t, args|
219+
task "#{build.name}-configure", [:reconfigure] => [build.build_dir, source.src_dir, source.configure_file] + build.dep_tasks do |t, args|
178220
args.with_defaults(:reconfigure => false)
179221
build.check_deps
180222

0 commit comments

Comments
 (0)