Guess toolchain when `MRuby::Build#toolchain` argument is omitted
MODIFY
build_config/default.rb
build_config/default.rb
MRuby::Build.new do |conf|
# load specific toolchain settings
-
- # Gets set by the VS command prompts.
- if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
- toolchain :visualcpp
- else
- toolchain :gcc
- end
+ conf.toolchain
# Use mrbgems
# conf.gem 'examples/mrbgems/ruby_extension_example'

MODIFY
build_config/host-cxx.rb
build_config/host-cxx.rb
MRuby::Build.new do |conf|
- toolchain :gcc
+ conf.toolchain
# include the default GEMs
conf.gembox 'default'

MODIFY
build_config/host-debug.rb
build_config/host-debug.rb
MRuby::Build.new('host') do |conf|
# load specific toolchain settings
-
- # Gets set by the VS command prompts.
- if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
- toolchain :visualcpp
- else
- toolchain :gcc
- end
+ conf.toolchain
conf.enable_debug
@@ -20,7 +14,7 @@ MRuby::Build.new('host') do |conf|
conf.gem :core => "mruby-bin-debugger"
# test
- enable_test
+ conf.enable_test
# bintest
- enable_bintest
+ conf.enable_bintest
end

MODIFY
build_config/no-float.rb
build_config/no-float.rb
# Define cross build settings
MRuby::CrossBuild.new('no-float') do |conf|
- toolchain :gcc
+ conf.toolchain
# include the GEM box
conf.compilers.each do |c|

MODIFY
build_config/travis.rb
build_config/travis.rb
MRuby::Build.new('full-debug') do |conf|
- toolchain :gcc
+ conf.toolchain
conf.enable_debug
# include all core GEMs
@@ -10,7 +10,7 @@ MRuby::Build.new('full-debug') do |conf|
end
MRuby::Build.new do |conf|
- toolchain :gcc
+ conf.toolchain
# include all core GEMs
conf.gembox 'full-core'
@@ -22,7 +22,7 @@ MRuby::Build.new do |conf|
end
MRuby::Build.new('cxx_abi') do |conf|
- toolchain :gcc
+ conf.toolchain
conf.gembox 'full-core'
conf.cc.flags += %w(-fpermissive)
@@ -31,7 +31,7 @@ MRuby::Build.new('cxx_abi') do |conf|
end
conf.enable_test
- enable_cxx_abi
+ conf.enable_cxx_abi
- build_mrbc_exec
+ conf.build_mrbc_exec
end

MODIFY
lib/mruby/build.rb
lib/mruby/build.rb
@@ -22,6 +22,18 @@ module MRuby
class Toolchain
class << self
attr_accessor :toolchains
+
+ def guess
+ if cc = ENV["CC"] || ENV["CXX"]
+ return "clang" if cc.include?("clang")
+ else
+ return "clang" if RUBY_PLATFORM =~ /darwin|(?:free|open)bsd/
+ return "gcc" if RUBY_PLATFORM.include?("cygwin")
+ return "visualcpp" if ENV.include?("VisualStudioVersion")
+ return "visualcpp" if ENV.include?("VSINSTALLDIR")
+ end
+ "gcc"
+ end
end
def initialize(name, &block)
@@ -221,7 +233,7 @@ EOS
@enable_bintest
end
- def toolchain(name, params={})
+ def toolchain(name=Toolchain.guess, params={})
name = name.to_s
tc = Toolchain.toolchains[name] || begin
path = "#{MRUBY_ROOT}/tasks/toolchains/#{name}.rake"

Guess toolchain when `MRuby::Build#toolchain` argument is omitted