This repository has been archived by the owner on Feb 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
137 lines (104 loc) · 4.12 KB
/
Makefile
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
.PHONY: clean flatbuffers generate test testdata docker-build docker-buildx
.PRECIOUS: %.wasm
SHELL := /bin/bash
GO ?= go
PYTHONWASM_BUILD = python/cpython/python.wasm
PYTHONZIP_BUILD = python/cpython/usr/local/lib/python311.zip
PYTHON ?= python3
PYTHONMAJOR ?= 3
PYTHONMINOR ?= 11
PYTHONPREFIX ?= testdata/python
PYTHONWASM ?= $(PYTHONWASM_BUILD)
PYTHONZIP ?= $(PYTHONZIP_BUILD)
VIRTUALENV ?= $(PYTHONPREFIX)/env
PYTHONHOME ?= $(VIRTUALENV)
PYTHONPATH ?= $(PYTHONZIP):$(PYTHONHOME)
ifeq ($(GITHUB_BRANCH_NAME),)
branch := $(shell git rev-parse --abbrev-ref HEAD)-
else
branch := $(GITHUB_BRANCH_NAME)-
endif
commit_timestamp := $(shell git show --no-patch --format=%ct)-
ifeq ($(GITHUB_SHA),)
commit := $(shell git rev-parse --short=8 HEAD)
else
commit := $(shell echo $(GITHUB_SHA) | cut -c1-8)
endif
container.version ?= $(if $(RELEASE_TAG),$(RELEASE_TAG),$(shell git describe --tags || echo '$(subst /,-,$(branch))$(commit_timestamp)$(commit)'))
container.image ?= ghcr.io/stealthrocket/timecraft
testdata.go.src = \
$(wildcard testdata/go/*.go) \
$(wildcard testdata/go/test/*.go)
testdata.go.wasm = $(testdata.go.src:.go=.wasm)
testdata.py.src = \
$(wildcard testdata/python/*_test.py)
format.src.fbs = \
$(wildcard format/*/*.fbs)
format.src.go = \
$(format.src.fbs:.fbs=_generated.go)
timecraft.src.go = \
$(format.src.go) \
$(wildcard *.go) \
$(wildcard */*.go) \
$(wildcard */*/*.go) \
$(wildcard */*/*/*.go)
timecraft.sdk.src.go = \
$(wildcard sdk/go/timecraft/*.go)
timecraft.sdk.src.py = \
$(wildcard sdk/python/src/timecraft/*.py)
timecraft.sdk.venv.py = \
$(VIRTUALENV)/lib/python$(PYTHONMAJOR).$(PYTHONMINOR)/site-packages/timecraft
timecraft = ./timecraft
$(timecraft): go.mod $(timecraft.src.go)
$(GO) build -o $@
clean:
rm -f $(timecraft) $(format.src.go) $(testdata.go.wasm)
lint:
golangci-lint run ./...
buf lint
fmt:
$(GO) fmt ./...
generate: flatbuffers
buf generate
flatbuffers: go.mod $(format.src.go)
$(GO) build ./format/...
test: go-test python-test wasi-testsuite
go-test: testdata
$(GO) test ./...
testdata: $(testdata.go.wasm)
%_test.wasm: %_test.go go.mod $(timecraft.sdk.src.go)
GOARCH=wasm GOOS=wasip1 $(GO) test -c -o $@ $<
%.wasm: %.go go.mod $(timecraft.sdk.src.go)
GOARCH=wasm GOOS=wasip1 $(GO) build -o $@ $<
wasi-testsuite: timecraft testdata/wasi-testsuite $(VIRTUALENV)/bin/activate
source $(VIRTUALENV)/bin/activate; pip install -r testdata/wasi-testsuite/test-runner/requirements.txt
source $(VIRTUALENV)/bin/activate; python3 testdata/wasi-testsuite/test-runner/wasi_test_runner.py \
-t testdata/wasi-testsuite/tests/assemblyscript/testsuite \
testdata/wasi-testsuite/tests/c/testsuite \
testdata/wasi-testsuite/tests/rust/testsuite \
-r testdata/adapter.py
@rm -rf testdata/wasi-testsuite/tests/rust/testsuite/fs-tests.dir/*.cleanup
python-test: $(timecraft) $(timecraft.sdk.venv.py) $(testdata.py.src) $(PYTHONWASM) $(PYTHONZIP)
@if [ -f "$(PYTHONWASM)" ] && [ -f "$(PYTHONZIP)" ]; then \
$(timecraft) run --env PYTHONPATH=$(PYTHONPATH) --env PYTHONHOME=$(PYTHONHOME) -- $(PYTHONWASM) -m unittest $(testdata.py.src); \
else \
echo "skipping Python tests (could not find $(PYTHONWASM) and $(PYTHONZIP))"; \
fi
$(PYTHONZIP_BUILD) $(PYTHONWASM_BUILD):
$(MAKE) -C python download || $(MAKE) -C python build-docker
$(timecraft.sdk.venv.py): $(VIRTUALENV)/bin/activate $(timecraft.sdk.src.py)
source $(VIRTUALENV)/bin/activate; pip install sdk/python
$(VIRTUALENV)/bin/activate:
$(PYTHON) -m venv $(VIRTUALENV)
testdata/wasi-testsuite: testdata/wasi-testsuite/.git
testdata/wasi-testsuite/.git: .gitmodules
git submodule update --init --recursive -- testdata/wasi-testsuite
# We run goimports because the flatc compiler sometimes adds an unused import of
# strconv.
%_generated.go: %.fbs
flatc --go --gen-onefile --go-namespace $(basename $(notdir $<)) --go-module-name github.com/stealthrocket/timecraft/format -o $(dir $@) $<
goimports -w $@
docker-build:
docker build -f Dockerfile -t $(container.image):$(container.version) .
docker-buildx:
docker buildx build --push --platform=linux/amd64,linux/arm64 -f Dockerfile -t $(container.image):$(container.version) .