Skip to content
This repository was archived by the owner on Aug 5, 2022. It is now read-only.

Commit 326b8dd

Browse files
Jimmy Huanggrgustaf
authored andcommitted
[build] Fix building of snapshot in zjs-0.2 branch (#698)
Back-ported patch from master that fixes building with SNAPSHOT=on and make the default build to use the snapshot feature. Also fixed a bug in snapshot tool that incorrectly passes the length of script which results in failing to build certain JS samples. Signed-off-by: Jimmy Huang <jimmy.huang@intel.com>
1 parent eafdfe9 commit 326b8dd

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

Makefile

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ BOARD ?= arduino_101
33
# Dump memory information: on = print allocs, full = print allocs + dump pools
44
TRACE ?= off
55
# Generate and run snapshot as byte code instead of running JS directly
6-
SNAPSHOT ?= off
6+
SNAPSHOT ?= on
77

88
ifndef ZJS_BASE
99
$(error ZJS_BASE not defined. You need to source zjs-env.sh)
@@ -15,27 +15,35 @@ VARIANT ?= release
1515
# JerryScript options
1616
JERRY_BASE ?= $(ZJS_BASE)/deps/jerryscript
1717
EXT_JERRY_FLAGS ?= -DENABLE_ALL_IN_ONE=ON
18+
ifneq ($(DEV), ashell)
1819
ifeq ($(SNAPSHOT), on)
1920
EXT_JERRY_FLAGS += -DFEATURE_JS_PARSER=OFF
2021
endif
22+
endif
2123
ifeq ($(BOARD), arduino_101)
2224
EXT_JERRY_FLAGS += -DENABLE_LTO=ON
2325
endif
2426

2527
# if no config file passed use the ashell default
2628
ifeq ($(DEV), ashell)
2729
CONFIG ?= fragments/zjs.conf.dev
30+
SNAPSHOT = off
2831
endif
2932

3033
# Print callback statistics during runtime
3134
CB_STATS ?= off
3235
# Print floats (uses -u _printf_float flag). This is a workaround on the A101
3336
# otherwise floats will not print correctly. It does use ~11k extra ROM though
3437
PRINT_FLOAT ?= off
38+
3539
# Make target (linux or zephyr)
3640
# MAKECMDGOALS is a Make variable that is set to the target your building for.
3741
TARGET = $(MAKECMDGOALS)
3842

43+
ifeq ($(TARGET), linux)
44+
SNAPSHOT = off
45+
endif
46+
3947
# If target is one of these, ensure ZEPHYR_BASE is set
4048
ZEPHYR_TARGETS = zephyr arc debug
4149
ifeq ($(TARGET), $(filter $(ZEPHYR_TARGETS),$(TARGET)))
@@ -119,7 +127,7 @@ else
119127
@cat fragments/prj.conf.base >> prj.conf
120128
endif
121129
ifeq ($(BOARD), arduino_101)
122-
cat fragments/prj.conf.arduino_101 >> prj.conf
130+
@cat fragments/prj.conf.arduino_101 >> prj.conf
123131
ifeq ($(ZJS_PARTITION), 256)
124132
@cat fragments/prj.conf.partition_256 >> prj.conf
125133
endif
@@ -151,6 +159,7 @@ clean:
151159
@rm -f prj.conf.tmp
152160
@rm -f prj.mdef
153161
@rm -f zjs.conf.tmp
162+
@rm -f .snapshot.last_build
154163

155164
.PHONY: pristine
156165
pristine:
@@ -180,20 +189,35 @@ ifeq ($(SNAPSHOT), on)
180189
make -f Makefile.snapshot; \
181190
fi
182191
@echo Creating snapshot bytecode from JS application...
183-
@outdir/snapshot/snapshot $(JS) src/zjs_snapshot_gen.c
192+
@outdir/snapshot/snapshot /tmp/zjs.js src/zjs_snapshot_gen.c
193+
# SNAPSHOT=on, check if rebuilding JerryScript is needed
194+
ifeq ("$(wildcard .snapshot.last_build)", "")
195+
@rm -rf $(JERRY_BASE)/build/$(BOARD)/
196+
@rm -f outdir/$(BOARD)/libjerry-core.a
197+
endif
198+
echo "" > .snapshot.last_build
184199
else
185200
@echo Creating C string from JS application...
186201
ifeq ($(TARGET), linux)
187202
@./scripts/convert.sh $(JS) src/zjs_script_gen.c
188203
else
189204
@./scripts/convert.sh /tmp/zjs.js src/zjs_script_gen.c
190205
endif
206+
# SNAPSHOT=off, check if rebuilding JerryScript is needed
207+
ifneq ("$(wildcard .snapshot.last_build)", "")
208+
@rm -rf $(JERRY_BASE)/build/$(BOARD)/
209+
@rm -f outdir/$(BOARD)/libjerry-core.a
210+
endif
211+
@rm -f .snapshot.last_build
191212
endif
192213

193214
# Run QEMU target
194215
.PHONY: qemu
195216
qemu: zephyr
196-
make -f Makefile.zephyr MEM_STATS=$(MEM_STATS) CB_STATS=$(CB_STATS) SNAPSHOT=$(SNAPSHOT) qemu
217+
make -f Makefile.zephyr qemu \
218+
MEM_STATS=$(MEM_STATS) \
219+
CB_STATS=$(CB_STATS) \
220+
SNAPSHOT=$(SNAPSHOT)
197221

198222
# Builds ARC binary
199223
.PHONY: arc
@@ -250,4 +274,5 @@ help:
250274
@echo "Build options:"
251275
@echo " BOARD= Specify a Zephyr board to build for"
252276
@echo " JS= Specify a JS script to compile into the binary"
277+
@echo " SNAPSHOT= Specify off to turn off snapshotting"
253278
@echo

Makefile.snapshot

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ JERRY_BASE ?= $(ZJS_BASE)/deps/jerryscript
66

77
JERRY_FLAGS ?= --snapshot-save=on
88

9-
BUILD_DIR = $(ZJS_BASE)/outdir/snapshot/$(VARIANT)
9+
BUILD_DIR = $(ZJS_BASE)/outdir/snapshot/
1010

1111
UNAME := $(shell uname)
1212
ifeq ($(UNAME),Darwin)
@@ -20,11 +20,12 @@ all: snapshot
2020

2121
.PHONY: setup
2222
setup:
23-
@if [ ! -d $(ZJS_BASE)/outdir/snapshot/$(VARIANT) ]; then \
24-
mkdir -p $(ZJS_BASE)/outdir/snapshot/$(VARIANT); \
23+
@if [ ! -d $(ZJS_BASE)/outdir/snapshot/ ]; then \
24+
mkdir -p $(ZJS_BASE)/outdir/snapshot/; \
2525
fi
2626

2727
CORE_SRC += src/snapshot.c \
28+
src/zjs_common.c \
2829
src/zjs_script.c
2930

3031
CORE_OBJ = $(CORE_SRC:%.c=%.o)
@@ -62,7 +63,6 @@ SNAPSHOT_FLAGS += -fno-asynchronous-unwind-tables \
6263
-Wpointer-sign
6364

6465
ifeq ($(VARIANT), debug)
65-
SNAPSHOT_DEFINES += -DDEBUG_BUILD
6666
SNAPSHOT_FLAGS += -g
6767
DEBUG=1
6868
else

src/snapshot.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int main(int argc, char *argv[])
6363
}
6464

6565
size_t size = jerry_parse_and_save_snapshot((jerry_char_t *)script,
66-
strlen(script),
66+
len,
6767
true,
6868
false,
6969
snapshot_buf,

0 commit comments

Comments
 (0)