mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
eacecb01bc
This adds support for both UTF-8 and UTF-16. All the JSON value strings use internal representation of UTF-8. Unicode validation and translation to UTF-8 is performed only at the JSON parsing time. There's no further encoding validation at the writing time but it is assumed all the string operations maintain the validity of UTF-8 representation. Fixes #1885 Signed-off-by: Teemu Koponen <koponen@styra.com>
98 lines
2.4 KiB
Makefile
98 lines
2.4 KiB
Makefile
DOCKER := docker
|
|
|
|
WASM_BUILDER_REPOSITORY := openpolicyagent/opa-wasm-builder
|
|
WASM_BUILDER_VERSION := 1.0
|
|
WASM_BUILDER_IMAGE := $(WASM_BUILDER_REPOSITORY):$(WASM_BUILDER_VERSION)
|
|
WASM_OBJ_DIR := _obj
|
|
|
|
$(shell mkdir -p $(WASM_OBJ_DIR))
|
|
|
|
CFLAGS := \
|
|
-O3 \
|
|
-nostdinc \
|
|
-nodefaultlibs \
|
|
--target=wasm32-unknown-unknown-wasm
|
|
|
|
.PHONY: all
|
|
all: build test
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
rm -fr $(WASM_OBJ_DIR)
|
|
|
|
.PHONY: builder
|
|
builder: Dockerfile
|
|
@$(DOCKER) build -t $(WASM_BUILDER_IMAGE) -f Dockerfile .
|
|
|
|
.PHONY: build
|
|
build:
|
|
@$(DOCKER) run -it --rm -v $(CURDIR):/src $(WASM_BUILDER_IMAGE) make $(WASM_OBJ_DIR)/opa.wasm
|
|
|
|
.PHONY: test
|
|
test:
|
|
@$(DOCKER) run -it --rm -v $(CURDIR):/src $(WASM_BUILDER_IMAGE) make $(WASM_OBJ_DIR)/opa-test.wasm
|
|
@$(DOCKER) run -it --rm -e VERBOSE=$(VERBOSE) -v $(CURDIR):/src -w /src node:8 node test.js $(WASM_OBJ_DIR)/opa-test.wasm
|
|
|
|
.PHONY: hack
|
|
hack:
|
|
@$(DOCKER) run -it --rm -v $(CURDIR):/src $(WASM_BUILDER_IMAGE)
|
|
|
|
$(WASM_OBJ_DIR)/malloc.wasm: src/malloc.c
|
|
@$(CC) $(CFLAGS) -c $^ -o $@
|
|
|
|
$(WASM_OBJ_DIR)/printf.wasm: src/printf.c
|
|
@$(CC) $(CFLAGS) -c $^ -o $@
|
|
|
|
$(WASM_OBJ_DIR)/string.wasm: src/string.c
|
|
@$(CC) $(CFLAGS) -c $^ -o $@
|
|
|
|
$(WASM_OBJ_DIR)/json.wasm: src/json.c
|
|
@$(CC) $(CFLAGS) -c $^ -o $@
|
|
|
|
$(WASM_OBJ_DIR)/value.wasm: src/value.c
|
|
@$(CC) $(CFLAGS) -c $^ -o $@
|
|
|
|
$(WASM_OBJ_DIR)/context.wasm: src/context.c
|
|
@$(CC) $(CFLAGS) -c $^ -o $@
|
|
|
|
$(WASM_OBJ_DIR)/unicode.wasm: src/unicode.c
|
|
@$(CC) $(CFLAGS) -c $^ -o $@
|
|
|
|
$(WASM_OBJ_DIR)/opa.wasm: \
|
|
$(WASM_OBJ_DIR)/context.wasm \
|
|
$(WASM_OBJ_DIR)/json.wasm \
|
|
$(WASM_OBJ_DIR)/malloc.wasm \
|
|
$(WASM_OBJ_DIR)/printf.wasm \
|
|
$(WASM_OBJ_DIR)/string.wasm \
|
|
$(WASM_OBJ_DIR)/unicode.wasm \
|
|
$(WASM_OBJ_DIR)/value.wasm
|
|
@wasm-ld-8 \
|
|
--allow-undefined-file=src/undefined.symbols \
|
|
--import-memory \
|
|
--no-entry \
|
|
--export-all \
|
|
$^ \
|
|
-o $@
|
|
@wasm2wat $(WASM_OBJ_DIR)/opa.wasm > $(WASM_OBJ_DIR)/opa.wast
|
|
|
|
$(WASM_OBJ_DIR)/test.wasm: tests/test.c
|
|
@$(CC) $(CFLAGS) -I src -c $^ -o $@
|
|
|
|
$(WASM_OBJ_DIR)/opa-test.wasm: \
|
|
$(WASM_OBJ_DIR)/context.wasm \
|
|
$(WASM_OBJ_DIR)/json.wasm \
|
|
$(WASM_OBJ_DIR)/malloc.wasm \
|
|
$(WASM_OBJ_DIR)/printf.wasm \
|
|
$(WASM_OBJ_DIR)/string.wasm \
|
|
$(WASM_OBJ_DIR)/test.wasm \
|
|
$(WASM_OBJ_DIR)/unicode.wasm \
|
|
$(WASM_OBJ_DIR)/value.wasm
|
|
@cat src/undefined.symbols tests/undefined.symbols > _obj/undefined.symbols
|
|
@wasm-ld-8 \
|
|
--allow-undefined-file=_obj/undefined.symbols \
|
|
--import-memory \
|
|
--no-entry \
|
|
--export-all \
|
|
$^ \
|
|
-o $@
|