From 6403e0510b00d634cfa295f36e743c1c293febf8 Mon Sep 17 00:00:00 2001 From: Watson Date: Tue, 27 Aug 2024 05:36:30 +0900 Subject: [PATCH] Use Etc.nprocessors --- ext/ilios/extconf.rb | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/ext/ilios/extconf.rb b/ext/ilios/extconf.rb index c306aa5..7598281 100644 --- a/ext/ilios/extconf.rb +++ b/ext/ilios/extconf.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require File.expand_path('../../lib/ilios/version', __dir__) +require 'etc' require 'fileutils' require 'mini_portile2' require 'mkmf' @@ -8,25 +9,6 @@ have_func('malloc_usable_size') have_func('malloc_size') -MAX_CORES = 8 - -def num_cpu_cores - cores = - begin - if RUBY_PLATFORM.include?('darwin') - Integer(`sysctl -n hw.ncpu`, 10) - else - Integer(`nproc`, 10) - end - rescue StandardError - 2 - end - - return 1 if cores <= 0 - - cores >= 7 ? MAX_CORES : cores -end - def create_compile_flags_txt cppflags = $CPPFLAGS.split include_flags = cppflags.select { |flag| flag.start_with?('-I') } @@ -60,7 +42,7 @@ def self.install def self.install_from_source unless File.exist?(LIBUV_INSTALL_PATH) - libuv_recipe = LibuvRecipe.new('libuv', Ilios::LIBUV_VERSION, make_command: "make -j #{num_cpu_cores}") + libuv_recipe = LibuvRecipe.new('libuv', Ilios::LIBUV_VERSION, make_command: "make -j #{Etc.nprocessors}") libuv_recipe.files << { url: "https://github.com/libuv/libuv/archive/v#{Ilios::LIBUV_VERSION}.tar.gz" } @@ -107,7 +89,7 @@ def self.install def self.install_from_source unless File.exist?(CASSANDRA_CPP_DRIVER_INSTALL_PATH) - cassandra_recipe = CassandraRecipe.new('cpp-driver', Ilios::CASSANDRA_CPP_DRIVER_VERSION, make_command: "make -j #{num_cpu_cores}") + cassandra_recipe = CassandraRecipe.new('cpp-driver', Ilios::CASSANDRA_CPP_DRIVER_VERSION, make_command: "make -j #{Etc.nprocessors}") cassandra_recipe.files << { url: "https://github.com/datastax/cpp-driver/archive/#{Ilios::CASSANDRA_CPP_DRIVER_VERSION}.tar.gz" }