Skip to content

Commit

Permalink
Merge pull request #2 from kateinoigakukun/build-libyaml
Browse files Browse the repository at this point in the history
Build libyaml as a dependency
  • Loading branch information
kateinoigakukun authored Mar 25, 2022
2 parents 29f6552 + 8a34613 commit bf2be79
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ class BuildPlan
"#{@base_dir}/build/ext-build/#{name}"
end

def deps_install_dir
"#{@base_dir}/build/deps/#{@params[:target]}/opt"
end

def dest_dir
"#{@base_dir}/rubies/#{name}"
end
Expand All @@ -93,6 +97,11 @@ class BuildPlan
"#{ext_build_dir}/extinit.o"
end

def dep_tasks
return [] if @params[:profile] == "minimal"
["deps:libyaml-#{@params[:target]}"]
end

def check_deps
target = @params[:target]
profile = BUILD_PROFILES[@params[:profile]]
Expand Down Expand Up @@ -125,6 +134,7 @@ class BuildPlan
args = ["--host", target, "--build", build_triple]
args << "--with-static-linked-ext"
args << %Q(--with-ext="#{default_exts}")
args << %Q(--with-libyaml-dir="#{deps_install_dir}/libyaml/usr/local")

case target
when "wasm32-unknown-wasi"
Expand All @@ -149,6 +159,38 @@ class BuildPlan
end
end

namespace :deps do
["wasm32-unknown-wasi", "wasm32-unknown-emscripten"].each do |target|
install_dir = File.join(Dir.pwd, "/build/deps/#{target}/opt")
libyaml_version = "0.2.5"
desc "build libyaml #{libyaml_version} for #{target}"
task "libyaml-#{target}" do
next if Dir.exist?("#{install_dir}/libyaml")

build_dir = File.join(Dir.pwd, "/build/deps/#{target}/yaml-#{libyaml_version}")
mkdir_p File.dirname(build_dir)
rm_rf build_dir
sh "curl -L https://github.com/yaml/libyaml/releases/download/#{libyaml_version}/yaml-#{libyaml_version}.tar.gz | tar xz", chdir: File.dirname(build_dir)

# obtain the latest config.guess and config.sub for Emscripten and WASI triple support
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'"
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'"

configure_args = []
case target
when "wasm32-unknown-wasi"
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))
when "wasm32-unknown-emscripten"
configure_args.concat(%W(--host wasm32-emscripten CC=emcc RANLIB=emranlib LD=emcc AR=emar))
else
raise "unknown target: #{target}"
end
sh "./configure #{configure_args.join(" ")}", chdir: build_dir
sh "make install DESTDIR=#{install_dir}/libyaml", chdir: build_dir
end
end
end

namespace :build do

base_dir = Dir.pwd
Expand All @@ -174,7 +216,7 @@ namespace :build do
directory build.dest_dir
directory build.build_dir

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

Expand Down

0 comments on commit bf2be79

Please sign in to comment.