Skip to content

Commit dd33366

Browse files
committed
fw: fix building with JS support
Signed-off-by: Liam McLoughlin <hexxeh@hexxeh.net>
1 parent be2d951 commit dd33366

File tree

9 files changed

+54
-18
lines changed

9 files changed

+54
-18
lines changed

.github/workflows/build.yml

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ on:
88

99
env:
1010
ARM_GNU_TOOLCHAIN_VERSION: 14.2.rel1
11+
EM_VERSION: 4.0.1
12+
EM_CACHE_FOLDER: 'emsdk-cache'
1113

1214
jobs:
1315
build:
@@ -22,6 +24,13 @@ jobs:
2224
fetch-depth: 0
2325
submodules: true
2426

27+
- name: Setup emsdk cache
28+
id: cache-emsdk
29+
uses: actions/cache@v2
30+
with:
31+
path: ${{env.EM_CACHE_FOLDER}}
32+
key: emsdk-${{env.EM_VERSION}}-${{ runner.os }}
33+
2534
- uses: actions/setup-python@v5
2635
with:
2736
python-version: "3.13"
@@ -40,8 +49,13 @@ jobs:
4049
sudo tar xf arm-gnu-toolchain-${ARM_GNU_TOOLCHAIN_VERSION}-x86_64-arm-none-eabi.tar.xz -C /opt
4150
echo "/opt/arm-gnu-toolchain-${ARM_GNU_TOOLCHAIN_VERSION}-x86_64-arm-none-eabi/bin" >> $GITHUB_PATH
4251
52+
- uses: mymindstorm/setup-emsdk@v14
53+
with:
54+
version: ${{env.EM_VERSION}}
55+
actions-cache-folder: ${{env.EM_CACHE_FOLDER}}
56+
4357
- name: Configure
44-
run: ./waf configure --board ${{ matrix.board }} --nojs
58+
run: ./waf configure --board ${{ matrix.board }}
4559

4660
- name: Build FW
4761
run: ./waf build
@@ -63,7 +77,7 @@ jobs:
6377
6478
- name: Configure (QEMU)
6579
if: ${{ matrix.board != 'asterix_vla_dvb1' }}
66-
run: ./waf clean configure --board ${{ matrix.board }} --nojs --qemu
80+
run: ./waf clean configure --board ${{ matrix.board }} --qemu
6781

6882
- name: Build FW (QEMU)
6983
if: ${{ matrix.board != 'asterix_vla_dvb1' }}

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,17 @@ may work right now.
6363
python_libs/pulse2 \
6464
python_libs/pebble-loghash
6565
```
66+
- Install emscripten
67+
- If you're on Mac and using [Homebrew](https://brew.sh), you can run `brew install emscripten`.
68+
- If you're on Linux, follow the instructions [here](https://github.com/emscripten-core/emsdk) and install version 4.0.1.
69+
- You can skip this if you wish by configuring with `--nojs` but beware the built-in clock for several devices requires JS and will render a blank screen when disabled.
6670

6771
## Building
6872

6973
First, configure the project like this:
7074

7175
```shell
72-
./waf configure --board <board> --nojs
76+
./waf configure --board <board>
7377
```
7478

7579
Note: If you wish to debug, you're likely to want `--nowatchdog --nostop --nosleep` also.
@@ -140,7 +144,7 @@ If you're using an Apple Silicon Mac, you might find it easier to build QEMU fro
140144
The steps here are similar that of real hardware:
141145

142146
```shell
143-
./waf configure --board=snowy_bb2 --nojs --qemu
147+
./waf configure --board=snowy_bb2 --qemu
144148
./waf build
145149
./waf qemu_image_spi
146150
./waf qemu

src/fw/applib/rockyjs/api/rocky_api_graphics_color.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ static bool prv_parse_hex(const char *color_value, GColor8 *parsed_color) {
314314
return true;
315315
}
316316
}
317+
/* FALLTHROUGH */
317318
case 5: { // #RGBA
318319
if (prv_parse_hex_comps(color_value + 1, 1, &r, &g, &b, &a)) {
319320
*parsed_color = GColorFromRGBA(r * (255/15), g * (255/15), b * (255/15), a * (255/15));
@@ -323,12 +324,14 @@ static bool prv_parse_hex(const char *color_value, GColor8 *parsed_color) {
323324
return true;
324325
}
325326
}
327+
/* FALLTHROUGH */
326328
case 7: { // #RRGGBB
327329
if (prv_parse_hex_comps(color_value + 1, 2, &r, &g, &b, NULL)) {
328330
*parsed_color = GColorFromRGB(r, g, b);
329331
return true;
330332
}
331333
}
334+
/* FALLTHROUGH */
332335
case 9: { // #RRGGBBAA
333336
if (prv_parse_hex_comps(color_value + 1, 2, &r, &g, &b, &a)) {
334337
*parsed_color = GColorFromRGBA(r, g, b, a);

src/fw/vendor/jerryscript/js_tooling/_js_tooling.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ function createSnapshot(js, options) {
144144
logDuration(timeJerryInit);
145145

146146
var collectedErrors = [];
147-
var errorHandlerPtr = jerry['Runtime'].addFunction(function(msgPtr) {
147+
var errorHandlerPtr = addFunction(function(msgPtr) {
148148
var msg = jerry['Pointer_stringify'](msgPtr).trim();
149149
if (msg !== 'Error:') {
150150
collectedErrors.push(msg);
151151
}
152152
return true;
153-
});
153+
}, "ip");
154154
jerry_port_set_errormsg_handler(errorHandlerPtr);
155155

156156
var timeJerry = captureDuration('jerry_parse_and_save_snapshot');
@@ -165,7 +165,7 @@ function createSnapshot(js, options) {
165165
return error(collectedErrors.join('. '));
166166
}
167167
logDuration(timeJerry);
168-
jerry['Runtime'].removeFunction(errorHandlerPtr);
168+
removeFunction(errorHandlerPtr);
169169

170170
var timeJerryCleanup = captureDuration('jerry_cleanup');
171171
jerry['_jerry_cleanup']();

src/fw/vendor/jerryscript/js_tooling/js_tooling_port.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
#include <stdlib.h>
88
#include <string.h>
99

10-
jerry_context_t jerry_global_context;
11-
jmem_heap_t jerry_global_heap __attribute__((__aligned__(JMEM_ALIGNMENT)));
12-
jerry_hash_table_t jerry_global_hash_table;
10+
extern jerry_context_t jerry_global_context;
11+
extern jmem_heap_t jerry_global_heap __attribute__((__aligned__(JMEM_ALIGNMENT)));
12+
extern jerry_hash_table_t jerry_global_hash_table;
1313

1414
size_t jerry_parse_and_save_snapshot_from_zt_utf8_string(
1515
const jerry_char_t *zt_utf8_source_p,
@@ -68,3 +68,7 @@ void jerry_port_console(const char *format, ...) {
6868
prv_log(format, args);
6969
va_end(args);
7070
}
71+
72+
void jerry_port_fatal (jerry_fatal_code_t code, void *lr) {
73+
exit(code);
74+
}

src/fw/vendor/jerryscript/js_tooling/transform_js.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ def replace_ensured(s, old, new):
1818

1919
# source = replace_ensured(source, "func = eval('_' + ident); // explicit lookup",
2020
# "// func = eval('_' + ident); // explicit lookup")
21-
source = replace_ensured(source, "process['on']('uncaughtException',",
22-
"process['on']('uncaughtException-ignore',")
21+
# source = replace_ensured(source, "process.on('uncaughtException',",
22+
# "process.on('uncaughtException-ignore',")
2323

2424
source = "(function(){\n%s\n})(this);" % source
2525

src/fw/vendor/jerryscript/wscript

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ def jerry_build_js_compiler(bld):
8585
transform_js_file = bld.path.make_node('js_tooling/transform_js.py').abspath()
8686
env.append_value('CFLAGS', ['--js-transform', transform_js_file])
8787

88-
# tell Emscripten to create a single file
89-
env.append_value('CFLAGS', ['--memory-init-file', '0'])
90-
9188
# Uncomment this line to get verbose output for emscripten
9289
# env.append_value('CFLAGS', ['-v'])
9390

@@ -97,15 +94,28 @@ def jerry_build_js_compiler(bld):
9794
"_jerry_parse_and_save_snapshot_from_zt_utf8_string",
9895
"_legacy_defective_checksum_memory",
9996
"_rocky_fill_header",
100-
"_jerry_port_set_errormsg_handler")
97+
"_jerry_port_set_errormsg_handler",
98+
"_malloc",
99+
"_memset")
101100
env.append_value('CFLAGS', ['-s', 'EXPORTED_FUNCTIONS=[{}]'.format(
102101
', '.join(('"' + f + '"' for f in exported_functions)))])
103102

103+
exported_runtime_methods = ( "getValue",
104+
"setValue",
105+
"ccall",
106+
"addFunction",
107+
"removeFunction")
108+
env.append_value('CFLAGS', ['-s', 'EXPORTED_RUNTIME_METHODS=[{}]'.format(
109+
', '.join(('"' + f + '"' for f in exported_runtime_methods)))])
110+
104111
# so we can call jerry_port_set_errormsg_handler() with a JS function pointer
105112
env.append_value('CFLAGS', ['-s', 'RESERVED_FUNCTION_POINTERS=1'])
106113

107114
env.append_value('CFLAGS', ['-s', 'ERROR_ON_UNDEFINED_SYMBOLS=0'])
108115

116+
env.append_value('CFLAGS', ['-s', 'ALLOW_TABLE_GROWTH'])
117+
env.append_value('CFLAGS', ['-s', 'WASM_ASYNC_COMPILATION=0'])
118+
109119
sources = bld.path.ant_glob('jerry-core/**/*.c')
110120
sources += bld.path.ant_glob('js_tooling/*.c')
111121
sources += fw_path.ant_glob('util/legacy_checksum.c')
@@ -211,6 +221,7 @@ def build(bld):
211221
'-Wno-error=unused-parameter',
212222
'-Wno-error=unused-variable',
213223
'-Wno-error=unused-function',
224+
'-Wno-error=implicit-fallthrough',
214225
'-Wno-pedantic']
215226

216227
if bld.variant == 'test':

tools/resources/resource_map/resource_generator_js.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def generate_object(task, definition):
4848
bytecode.abspath(),
4949
memory_usage_output.abspath()]
5050

51-
proc = Popen(cmd, stdout=PIPE, stderr=PIPE)
51+
proc = Popen(cmd, stdout=PIPE, stderr=PIPE, encoding='utf-8')
5252
out, err = proc.communicate()
5353

5454
if proc.returncode != 0:

waftools/c_inject_include_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def process_include_files(self):
3232
for include_file in to_list(self.inject_include_files):
3333
if isinstance(include_file, Nod3):
3434
node = include_file
35-
elif isinstance(include_file, basestring):
35+
elif isinstance(include_file, str):
3636
node = self.path.find_node(include_file)
3737
if not node:
3838
self.bld.fatal('%s does not exist.' % include_file)

0 commit comments

Comments
 (0)