diff options
| -rw-r--r-- | doc/guides/compile.md | 18 | ||||
| -rw-r--r-- | tasks/mruby_build.rake | 14 | ||||
| -rw-r--r-- | tasks/mruby_build_commands.rake | 2 | ||||
| -rw-r--r-- | tasks/mruby_build_gem.rake | 2 | ||||
| -rw-r--r-- | tasks/toolchains/gcc.rake | 2 | ||||
| -rw-r--r-- | tasks/toolchains/visualcpp.rake | 2 |
6 files changed, 33 insertions, 7 deletions
diff --git a/doc/guides/compile.md b/doc/guides/compile.md index d07b4f65f..9ca61c6fd 100644 --- a/doc/guides/compile.md +++ b/doc/guides/compile.md @@ -242,9 +242,19 @@ conf.enable_bintest ### C++ ABI mruby can use C++ exception to raise exception internally. -It is called C++ ABI mode. By using C++ exception it can release C++ stack object correctly. -Whenever you mix C++ code C++ ABI mode would be enabled automatically. + +There are two levels of C++ exception handling. The one is +C++ exception enabled (but still C files are compiled by C +compiler), and the other is C++ ABI mode where all files are +compiled by C++ compiler. + +When you mix C++ code, C++ exception would be enabled automatically. +If you need to enable C++ exception explicitly add the following: +```ruby +conf.enable_cxx_exception +``` + If you need to enable C++ ABI mode explicitly add the following: ```ruby conf.enable_cxx_abi @@ -252,8 +262,10 @@ conf.enable_cxx_abi #### C++ exception disabling. + If you need to force C++ exception disable -(For example using a compiler option to disable C++ exception) +(For example using a compiler option to disable C++ exception), +but still want to use C++ ABI mode, add following: ```ruby conf.disable_cxx_exception diff --git a/tasks/mruby_build.rake b/tasks/mruby_build.rake index bd911493d..46459cf6c 100644 --- a/tasks/mruby_build.rake +++ b/tasks/mruby_build.rake @@ -113,13 +113,23 @@ module MRuby @cxx_exception_disabled = true end + def enable_cxx_exception + @cxx_exception_disabled = false + compilers.each { |c| + c.defines += %w(MRB_ENABLE_CXX_EXCEPTION) + c.flags << c.cxx_exception_flag + } + end + def cxx_abi_enabled? @cxx_abi_enabled end def enable_cxx_abi - return if @cxx_exception_disabled or @cxx_abi_enabled - compilers.each { |c| c.defines += %w(MRB_ENABLE_CXX_EXCEPTION) } + return if @cxx_abi_enabled + unless @cxx_exception_disabled + enable_cxx_exception + end compilers.each { |c| c.flags << c.cxx_compile_flag } linker.command = cxx.command if toolchains.find { |v| v == 'gcc' } @cxx_abi_enabled = true diff --git a/tasks/mruby_build_commands.rake b/tasks/mruby_build_commands.rake index d688077ff..694b4a24c 100644 --- a/tasks/mruby_build_commands.rake +++ b/tasks/mruby_build_commands.rake @@ -41,7 +41,7 @@ module MRuby class Command::Compiler < Command attr_accessor :flags, :include_paths, :defines, :source_exts attr_accessor :compile_options, :option_define, :option_include_path, :out_ext - attr_accessor :cxx_compile_flag + attr_accessor :cxx_compile_flag, :cxx_exception_flag def initialize(build, source_exts=[]) super(build) diff --git a/tasks/mruby_build_gem.rake b/tasks/mruby_build_gem.rake index 9a802097f..b48df6510 100644 --- a/tasks/mruby_build_gem.rake +++ b/tasks/mruby_build_gem.rake @@ -38,7 +38,7 @@ module MRuby cxx_srcs = ['src', 'test', 'tools'].map do |subdir| Dir.glob("#{Gem.current.dir}/#{subdir}/*.{cpp,cxx,cc}") end.flatten - enable_cxx_abi unless cxx_srcs.empty? + enable_cxx_exception unless cxx_srcs.empty? Gem.current end diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index 59ae015ac..f370c0abf 100644 --- a/tasks/toolchains/gcc.rake +++ b/tasks/toolchains/gcc.rake @@ -7,6 +7,7 @@ MRuby::Toolchain.new(:gcc) do |conf, _params| cc.option_define = '-D%s' cc.compile_options = '%{flags} -MMD -o %{outfile} -c %{infile}' cc.cxx_compile_flag = '-x c++ -std=c++03' + cc.cxx_exception_flag = '-fexceptions' end [conf.cxx].each do |cxx| @@ -17,6 +18,7 @@ MRuby::Toolchain.new(:gcc) do |conf, _params| cxx.option_define = '-D%s' cxx.compile_options = '%{flags} -MMD -o %{outfile} -c %{infile}' cxx.cxx_compile_flag = '-x c++ -std=c++03' + cxx.cxx_exception_flag = '-fexceptions' end conf.linker do |linker| diff --git a/tasks/toolchains/visualcpp.rake b/tasks/toolchains/visualcpp.rake index 5f5bab9c2..5bc24a73a 100644 --- a/tasks/toolchains/visualcpp.rake +++ b/tasks/toolchains/visualcpp.rake @@ -8,6 +8,7 @@ MRuby::Toolchain.new(:visualcpp) do |conf, _params| cc.option_define = '/D%s' cc.compile_options = "%{flags} /Fo%{outfile} %{infile}" cc.cxx_compile_flag = '/TP' + cc.cxx_exception_flag = '/EHs' end conf.cxx do |cxx| @@ -18,6 +19,7 @@ MRuby::Toolchain.new(:visualcpp) do |conf, _params| cxx.option_define = '/D%s' cxx.compile_options = "%{flags} /Fo%{outfile} %{infile}" cxx.cxx_compile_flag = '/TP' + cxx.cxx_exception_flag = '/EHs' end conf.linker do |linker| |
