From 4437c665b038fe29ddd468dc0efad924cd2e5726 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 27 Nov 2023 15:35:59 +0000 Subject: [PATCH] build: Parallelize `make` build by default --- lib/ruby_wasm/build.rb | 10 +++++++++- lib/ruby_wasm/build/product/baseruby.rb | 5 ++++- lib/ruby_wasm/build/product/crossruby.rb | 1 + sig/ruby_wasm/build.rbs | 3 +++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/ruby_wasm/build.rb b/lib/ruby_wasm/build.rb index 5a29a622fe..01dfd748a9 100644 --- a/lib/ruby_wasm/build.rb +++ b/lib/ruby_wasm/build.rb @@ -5,9 +5,17 @@ module RubyWasm # Build executor to run the actual build commands. class BuildExecutor - def initialize(verbose: false) + attr_reader :process_count + + def initialize(verbose: false, process_count: nil) @verbose = verbose @github_actions_markup = ENV["ENABLE_GITHUB_ACTIONS_MARKUP"] != nil + __skip__ = begin + require "etc" + @process_count = process_count || Etc.nprocessors + rescue LoadError + @process_count = process_count || 1 + end end def system(*args, chdir: nil, env: nil) diff --git a/lib/ruby_wasm/build/product/baseruby.rb b/lib/ruby_wasm/build/product/baseruby.rb index 9ba6bc51fa..065d86dbc7 100644 --- a/lib/ruby_wasm/build/product/baseruby.rb +++ b/lib/ruby_wasm/build/product/baseruby.rb @@ -28,7 +28,10 @@ def build(executor) "--prefix=#{install_dir}", "--disable-install-doc", chdir: product_build_dir - executor.system "make", "install", chdir: product_build_dir + executor.system "make", + "-j#{executor.process_count}", + "install", + chdir: product_build_dir end end end diff --git a/lib/ruby_wasm/build/product/crossruby.rb b/lib/ruby_wasm/build/product/crossruby.rb index 9bccbbf783..988c071372 100644 --- a/lib/ruby_wasm/build/product/crossruby.rb +++ b/lib/ruby_wasm/build/product/crossruby.rb @@ -33,6 +33,7 @@ def build(executor, crossruby) executor.mkdir_p objdir do_extconf executor, crossruby executor.system "make", + "-j#{executor.process_count}", "-C", "#{objdir}", *make_args(crossruby), diff --git a/sig/ruby_wasm/build.rbs b/sig/ruby_wasm/build.rbs index 396d533135..9a9838f672 100644 --- a/sig/ruby_wasm/build.rbs +++ b/sig/ruby_wasm/build.rbs @@ -224,8 +224,11 @@ module RubyWasm class BuildExecutor @verbose: bool @github_actions_markup: bool + @process_count: Integer @start_times: Hash[[Class, String], Time] + attr_reader process_count: Integer + def initialize: (?verbose: bool) -> void def system: (*_ToS args, ?chdir: String?, ?env: Hash[String, String]?) -> void def rm_rf: (FileUtils::pathlist list) -> void