-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
69 lines (58 loc) · 1.92 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true
# Prepare Build environment
PROJECT_ROOT = File.dirname(File.expand_path(__FILE__))
MRUBY_WASM_CONFIG = "#{PROJECT_ROOT}/mruby_wasm_config.rb"
EMSCRIPTEN_PATH = [
ENV['EMSCRIPTEN'], # CI Environment
"#{ENV['EMSDK']}/upstream/emscripten"
].compact.find { |path| path != '' }
EMSCRIPTEN_TOOLS = "#{EMSCRIPTEN_PATH}/tools"
SOURCES = FileList['src/**/*.cpp'].exclude('**/glue.*')
BINARY_CODES = SOURCES.ext('bc')
LIBMRUBY_WASM_PATH = "#{PROJECT_ROOT}/mruby/build/wasm/lib/libmruby.bc"
OBJECTS = %w[libmruby glue] + BINARY_CODES
MINIFY = ENV['MINIFY'] && ENV['MINIFY'] != ''
ENV['MRUBY_CONFIG'] = MRUBY_WASM_CONFIG
# Helper
def create(format = :wasm)
sources = [LIBMRUBY_WASM_PATH] + BINARY_CODES
optimize = MINIFY ? '-Oz' : ''
sh "emcc #{sources.join(' ')} " \
'--post-js src/glue.js --post-js src/mruby.js ' \
'--shell-file template/playground.html' \
"#{optimize} -o mruby.#{format}"
end
# Load mruby tasks
begin
namespace :mruby do
load './mruby/Rakefile'
end
rescue LoadError
sh 'git submodule init'
sh 'git submodule update --init --recursive'
retry
end
# Build tasks
task default: :html
task 'libmruby' => 'mruby:all'
task 'glue' do
sh "python #{EMSCRIPTEN_TOOLS}/webidl_binder.py mruby.idl src/glue"
end
rule '.bc' => SOURCES do |task|
sh "emcc -I mruby/include -I include -c #{task.source} -o #{task.name}"
end
%i[wasm html js].each do |format|
task "mruby.#{format}" => OBJECTS do
create(format)
end
desc "Compile sources to #{format} WebAssembly"
task format => "mruby.#{format}"
end
namespace :clean do
task(:binary) { FileUtils.rm_rf(BINARY_CODES) }
task(:glue) { FileUtils.rm_rf(['src/glue.cpp', 'src/glue.js']) }
task(:idl) { FileUtils.rm_rf(['WebIDLGrammar.pkl', 'parser.out']) }
task(:dist) { FileUtils.rm_rf(['mruby.wasm', 'mruby.html', 'mruby.js']) }
end
desc 'Clean compiled files'
task clean: %i[clean:binary clean:glue clean:idl clean:dist]