Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Emscriptem WebAssembly target + examples #4486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 27 additions & 0 deletions examples/emcc-wasm/compile_to_wasm.sh
@@ -0,0 +1,27 @@
#/usr/bin/env bash
port=8000
build_dir=../../build

which emcc
ret=$?
if [ $ret -ne 0 ]; then
echo "emcc compiler could not be found.\nInstall Emscripten or source emsdk_set_env.sh file. Exiting."
exit $ret
fi

for f in hello_world fib; do
echo -n "Compiling $f.rb to $f.wasm..."
../../bin/mrbc -Btest_symbol $f.rb
emcc -D CFILE="<$f.c>" -I../../include -I. -o $f.bc stub.c
emcc -o $f.html $f.bc ../../build/emcc-wasm/lib/libmruby.bc
echo "done"
done

echo ""
echo "Launch a minimal Web server:"
echo "ruby -run -e httpd . -p $port"
echo ""
echo "and navigate to:"
for f in hello_world fib; do
echo "http://localhost:8000/$f.html"
done
7 changes: 7 additions & 0 deletions examples/emcc-wasm/fib.rb
@@ -0,0 +1,7 @@

def fib n
return n if n < 2
fib(n-2) + fib(n-1)
end

puts 1.upto(15).collect {|i| fib(i)}.join(',')
1 change: 1 addition & 0 deletions examples/emcc-wasm/hello_world.rb
@@ -0,0 +1 @@
puts "Hello World!"
13 changes: 13 additions & 0 deletions examples/emcc-wasm/stub.c
@@ -0,0 +1,13 @@
#include <mruby.h>
#include <mruby/irep.h>
#include CFILE

int
main(void)
{
mrb_state *mrb = mrb_open();
if (!mrb) { /* handle error */ }
mrb_load_irep(mrb, test_symbol);
mrb_close(mrb);
return 0;
}
37 changes: 37 additions & 0 deletions examples/targets/build_config_emcc_wasm.rb
@@ -0,0 +1,37 @@
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

# include the default GEMs
conf.gembox 'default'
end


# Define cross build settings
MRuby::CrossBuild.new('emcc-wasm') do |conf|
toolchain :gcc

conf.cc.command = 'emcc'
#conf.cc.flags << "-m32"
conf.linker.command = 'emcc'
#conf.linker.flags << "-m32"
conf.archiver.command = 'emcc'
conf.archiver.archive_options = '-o %{outfile} %{objs}'

conf.exts do |exts|
exts.object = '.o'
exts.executable = ''
exts.library = '.bc' # It's LLVM bit code
end

conf.build_mrbtest_lib_only

conf.gembox 'default'
end