diff --git a/build_config/emscripten-cxx.rb b/build_config/emscripten-cxx.rb new file mode 100644 index 0000000000..3f2d14f9b3 --- /dev/null +++ b/build_config/emscripten-cxx.rb @@ -0,0 +1,12 @@ +# Make sure to add these compile options: +# build/emscripten-cxx/host-bin/mruby-config --cxxflags +# +# Make sure to add these link options: +# build/emscripten-cxx/host-bin/mruby-config --ldflags --libs +MRuby::CrossBuild.new('emscripten-cxx') do |conf| + conf.toolchain :emscripten + + conf.gembox 'default' + + conf.enable_cxx_abi +end diff --git a/build_config/emscripten.rb b/build_config/emscripten.rb new file mode 100644 index 0000000000..4933179257 --- /dev/null +++ b/build_config/emscripten.rb @@ -0,0 +1,10 @@ +# Make sure to add these compile options: +# build/emscripten/host-bin/mruby-config --cflags +# +# Make sure to add these link options: +# build/emscripten/host-bin/mruby-config --ldflags --libs +MRuby::CrossBuild.new('emscripten') do |conf| + conf.toolchain :emscripten + + conf.gembox 'default' +end diff --git a/mrbgems/mruby-cmath/src/cmath.c b/mrbgems/mruby-cmath/src/cmath.c index b0b8d5f180..43b5ba8ff4 100644 --- a/mrbgems/mruby-cmath/src/cmath.c +++ b/mrbgems/mruby-cmath/src/cmath.c @@ -92,7 +92,9 @@ CXDIVc(mrb_complex a, mrb_complex b) #else -#if defined(__cplusplus) && (defined(__APPLE__) || (defined(__clang__) && (defined(__FreeBSD__) || defined(__OpenBSD__)))) +#if defined(__cplusplus) && \ + (defined(__APPLE__) || defined(__EMSCRIPTEN__) || \ + (defined(__clang__) && (defined(__FreeBSD__) || defined(__OpenBSD__)))) #ifdef MRB_USE_FLOAT32 typedef std::complex mrb_complex; diff --git a/tasks/toolchains/emscripten.rake b/tasks/toolchains/emscripten.rake new file mode 100644 index 0000000000..6a9c05dff6 --- /dev/null +++ b/tasks/toolchains/emscripten.rake @@ -0,0 +1,36 @@ +MRuby::Toolchain.new(:emscripten) do |conf| + toolchain :clang + + # See: + # - https://emscripten.org/docs/tools_reference/emcc.html + # - https://emscripten.org/docs/tools_reference/settings_reference.html + # - https://github.com/emscripten-core/emscripten/blob/main/src/settings.js + compile_and_link_flags = [ + ] + compile_flags = [ + *compile_and_link_flags, + '-Wno-unused-but-set-variable', + ] + link_flags = [ + *compile_and_link_flags, + ] + + conf.cc do |cc| + cc.command = 'emcc' + cc.flags.concat(compile_flags) unless ENV['CFLAGS'] + end + + conf.cxx do |cxx| + cxx.command = 'em++' + cxx.flags.concat(compile_flags) unless ENV['CXXFLAGS'] || ENV['CFLAGS'] + end + + conf.linker do |linker| + linker.command = 'emcc' + linker.flags.concat(link_flags) unless ENV['LDFLAGS'] + end + + conf.archiver do |archiver| + archiver.command = 'emar' + end +end