File tree Expand file tree Collapse file tree 4 files changed +58
-29
lines changed Expand file tree Collapse file tree 4 files changed +58
-29
lines changed Original file line number Diff line number Diff line change @@ -19,15 +19,25 @@ namespace :mruby do
19
19
host_agent . clean_all
20
20
host_agent . mruby_download
21
21
end
22
- host_agent . mruby_config
23
- if !host_agent . mruby_build_dir . exist?
22
+
23
+ config_changed = host_agent . config_changed
24
+ if config_changed
25
+ host_agent . mruby_config
26
+ end
27
+
28
+ if !host_agent . mruby_build_dir . exist? || config_changed
24
29
host_agent . mruby_build
25
30
end
26
31
end
27
32
28
33
task :init_wasm => [ :"mruby:init" ] do
29
- wasm_agent . mruby_config
30
- if !wasm_agent . mruby_build_dir . exist?
34
+
35
+ config_changed = wasm_agent . config_changed
36
+ if config_changed
37
+ wasm_agent . mruby_config
38
+ end
39
+
40
+ if !wasm_agent . mruby_build_dir . exist? || config_changed
31
41
wasm_agent . mruby_build
32
42
end
33
43
end
@@ -48,6 +58,11 @@ task :build => [:"mruby:init"] do
48
58
host_agent . build
49
59
end
50
60
61
+ desc "run wasm program"
62
+ task :"run:wasm" => [ :"mruby:init_wasm" ] do
63
+ wasm_agent . run
64
+ end
65
+
51
66
desc "build wasm program"
52
67
task :"build:wasm" => [ :"mruby:init_wasm" ] do
53
68
wasm_agent . build
Original file line number Diff line number Diff line change 1
1
MRuby ::Build . new do |conf |
2
2
toolchain :gcc
3
+ conf . gem :mgem => 'mruby-os'
3
4
conf . gembox 'default'
4
5
end
5
6
Original file line number Diff line number Diff line change 2
2
require_relative "./utils"
3
3
4
4
class BaseAgent
5
+
5
6
include Utils
6
7
7
8
attr_accessor :platform
8
9
attr_reader :mruby_dir , :cache_dir , :build_dir , :mruby_build_dir
9
10
attr_reader :mruby , :mrbc
11
+ attr_reader :custom_build_config_file , :copied_custom_build_config_file
10
12
def initialize ( app_name :, debug : false )
11
13
@app_name = app_name
12
14
@@ -102,6 +104,11 @@ def mruby_config
102
104
shell_cp @custom_build_config_file , @copied_custom_build_config_file
103
105
end
104
106
107
+ def config_changed
108
+ file_content_change? @custom_build_config_file , @copied_custom_build_config_file
109
+ end
110
+
111
+
105
112
def clean_dir ( dir_path )
106
113
shell_rm dir_path
107
114
end
@@ -150,12 +157,10 @@ def build_to_c_code
150
157
end
151
158
end
152
159
153
- def wrap_code
154
-
155
- end
156
160
157
161
def run
158
- pack_code ( @cache_dir )
162
+ shell_clean @cache_dir
163
+ pack_code @cache_dir
159
164
shell "#{ @mruby } #{ @cache_dir } /main.rb"
160
165
end
161
166
Original file line number Diff line number Diff line change @@ -18,34 +18,42 @@ def build
18
18
shell_clean @build_dir
19
19
@host_agent . pack_code ( @build_dir )
20
20
@host_agent . build_to_c_code
21
- build_code
21
+ build_code @build_dir
22
22
build_clean
23
23
end
24
24
25
- def web_template
26
- File . open ( "#{ @build_dir } /main.c " , "w" ) do |f |
25
+ def generate_web_template ( dir_path )
26
+ File . open ( "#{ dir_path } /index.html " , "w" ) do |f |
27
27
template = <<-CODE
28
- #include <mruby.h>
29
- #include <mruby/irep.h>
30
- extern const uint8_t #{ @code_wrapper_name } [];
31
-
32
- int
33
- main(void)
34
- {
35
- mrb_state *mrb = mrb_open();
36
- if (!mrb) { /* handle error */ }
37
- mrb_load_irep(mrb, #{ @code_wrapper_name } );
38
- mrb_close(mrb);
39
- return 0;
40
- }
41
-
28
+ <!DOCTYPE html>
29
+ <html lang="en">
30
+ <head>
31
+ <meta charset="UTF-8">
32
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
33
+ <title>Document</title>
34
+ </head>
35
+ <body>
36
+ <h1>Hello World</h1>
37
+ <script src="./app.js"></script>
38
+ </body>
39
+ </html>
42
40
CODE
43
41
44
- f . puts template
45
- end
42
+ f . puts template
43
+ end
44
+ end
45
+
46
+ def serve ( dir_path )
47
+ system ( "ruby -run -e httpd #{ dir_path } " )
48
+ end
49
+
50
+ def run
51
+ build
52
+ serve @build_dir
46
53
end
47
54
48
- def build_code
49
- shell "emcc -s WASM=1 -Os -I #{ @mruby_include_dir } #{ @build_dir } /*.c #{ @mruby_lib_dir } /libmruby.a -lm -o #{ @build_dir } /#{ @app_name } .js --closure 1"
55
+ def build_code ( dir_path )
56
+ shell "emcc -s WASM=1 -Os -I #{ @mruby_include_dir } #{ dir_path } /*.c #{ @mruby_lib_dir } /libmruby.a -lm -o #{ dir_path } /#{ @app_name } .js --closure 1"
57
+ generate_web_template ( dir_path )
50
58
end
51
59
end
You can’t perform that action at this time.
0 commit comments