-
Notifications
You must be signed in to change notification settings - Fork 393
Expand file tree
/
Copy pathMakefile
More file actions
309 lines (253 loc) · 10.6 KB
/
Makefile
File metadata and controls
309 lines (253 loc) · 10.6 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
TARGET_linux_x86_64 = x86_64-unknown-linux-musl
TARGET_linux_arm64 = aarch64-unknown-linux-musl
TARGET_darwin_x86_64 = x86_64-apple-darwin
TARGET_darwin_arm64 = aarch64-apple-darwin
TARGET_windows_x86_64 = x86_64-pc-windows-gnu
TARGET_windows_arm64 = aarch64-is-not-yet-supported
RUST_VERSION = nightly
TOOLCHAIN = +$(RUST_VERSION)
BUILD_ARG = $(TOOLCHAIN) build -r
BUILD_DIR = ./target/release
BUNDLE_DIR = bundle
TS_SOURCES = $(wildcard llrt_core/src/modules/js/*.ts) $(wildcard llrt_core/src/modules/js/@llrt/test/*.ts) $(wildcard llrt_core/src/modules/js/@llrt/*.ts) $(wildcard tests/unit/*.ts)
STD_JS_FILE = $(BUNDLE_DIR)/js/@llrt/std.js
RELEASE_ARCH_NAME_x64 = x86_64
RELEASE_ARCH_NAME_arm64 = arm64
LAMBDA_PREFIX = llrt-lambda
RELEASE_TARGETS = arm64 x64
RELEASE_ZIPS = $(addprefix $(LAMBDA_PREFIX)-,$(RELEASE_TARGETS))
ifeq ($(OS),Windows_NT)
DETECTED_OS := windows
ARCH = x86_64
else
DETECTED_OS := $(shell uname | tr A-Z a-z)
ARCH = $(shell uname -m)
endif
ifeq ($(ARCH),aarch64)
ARCH = arm64
endif
ZSTD_LIB_CC_ARGS = -s -O3 -flto
ZSTD_LIB_ARGS = -j lib-nomt UNAME=Linux ZSTD_LIB_COMPRESSION=0 ZSTD_LIB_DICTBUILDER=0 AR="zig ar"
ifeq ($(DETECTED_OS),windows)
ZSTD_LIB_CC_x64 = CC="zig cc -target x86_64-windows-gnu $(ZSTD_LIB_CC_ARGS)"
else
ZSTD_LIB_CC_arm64 = CC="zig cc -target aarch64-linux-musl $(ZSTD_LIB_CC_ARGS)"
ZSTD_LIB_CC_x64 = CC="zig cc -target x86_64-linux-musl $(ZSTD_LIB_CC_ARGS)"
endif
CURRENT_TARGET ?= $(TARGET_$(DETECTED_OS)_$(ARCH))
export CC_aarch64_unknown_linux_musl = $(CURDIR)/linker/cc-aarch64-linux-musl
export CXX_aarch64_unknown_linux_musl = $(CURDIR)/linker/cxx-aarch64-linux-musl
export AR_aarch64_unknown_linux_musl = $(CURDIR)/linker/ar
export CC_x86_64_unknown_linux_musl = $(CURDIR)/linker/cc-x86_64-linux-musl
export CXX_x86_64_unknown_linux_musl = $(CURDIR)/linker/cxx-x86_64-linux-musl
export AR_x86_64_unknown_linux_musl = $(CURDIR)/linker/ar
define alias_template
release${1}: llrt-$(DETECTED_OS)-$(ARCH)${1}.zip
llrt-linux-x86_64${1}.zip: llrt-linux-x64${1}.zip
llrt-windows-x86_64${1}.zip: llrt-windows-x64${1}.zip
llrt-darwin-x86_64${1}.zip: llrt-darwin-x64${1}.zip
endef
$(eval $(call alias_template,-full-sdk))
$(eval $(call alias_template,))
$(eval $(call alias_template,-no-sdk))
define release_template
release-aws-${1}${2}: | llrt-lambda-${1}${2}.zip llrt-container-${1}${2} llrt-linux-${1}${2}.zip
llrt-lambda-${1}${2}.zip: export SDK_BUNDLE_MODE = ${3}
llrt-lambda-${1}${2}.zip: | clean-js js
cargo $$(BUILD_ARG) --target $$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1})) --features lambda
./pack target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/llrt target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/bootstrap
@rm -rf $$@
zip -j $$@ target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/bootstrap
llrt-container-${1}${2}: export SDK_BUNDLE_MODE = ${3}
llrt-container-${1}${2}: | clean-js js
cargo $$(BUILD_ARG) --target $$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1})) --features lambda,uncompressed
mv target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/llrt $$@
llrt-linux-${1}${2}.zip: export SDK_BUNDLE_MODE = ${3}
llrt-linux-${1}${2}.zip: | clean-js js
cargo $$(BUILD_ARG) --target $$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))
@rm -rf $$@
zip -j $$@ target/$$(TARGET_linux_$$(RELEASE_ARCH_NAME_${1}))/release/llrt
llrt-darwin-${1}${2}.zip: export SDK_BUNDLE_MODE = ${3}
llrt-darwin-${1}${2}.zip: | clean-js js
cargo $$(BUILD_ARG) --target $$(TARGET_darwin_$$(RELEASE_ARCH_NAME_${1}))
@rm -rf $$@
zip -j $$@ target/$$(TARGET_darwin_$$(RELEASE_ARCH_NAME_${1}))/release/llrt
# llrt-windows-arm64* is automatically generated, but not currently supported.
llrt-windows-${1}${2}.zip: export SDK_BUNDLE_MODE = ${3}
llrt-windows-${1}${2}.zip: | clean-js js
cargo $$(BUILD_ARG) --target $$(TARGET_windows_$$(RELEASE_ARCH_NAME_${1}))
zip -j $$@ target/$$(TARGET_windows_$$(RELEASE_ARCH_NAME_${1}))/release/llrt.exe
endef
$(foreach target,$(RELEASE_TARGETS),$(eval $(call release_template,$(target),-full-sdk,FULL)))
$(foreach target,$(RELEASE_TARGETS),$(eval $(call release_template,$(target),,STD)))
$(foreach target,$(RELEASE_TARGETS),$(eval $(call release_template,$(target),-no-sdk,NONE)))
build: js
cargo $(BUILD_ARG) --target $(CURRENT_TARGET)
ifeq ($(DETECTED_OS),windows)
stdlib:
rustup toolchain install $(RUST_VERSION) --target $(TARGET_windows_x86_64)
rustup target add $(TARGET_windows_x86_64)
rustup component add rust-src --toolchain $(RUST_VERSION) --target $(TARGET_windows_x86_64)
else
stdlib-x64:
rustup toolchain install $(RUST_VERSION) --target $(TARGET_linux_x86_64)
rustup target add $(TARGET_linux_x86_64)
rustup component add rust-src --toolchain $(RUST_VERSION) --target $(TARGET_linux_x86_64)
stdlib-arm64:
rustup toolchain install $(RUST_VERSION) --target $(TARGET_linux_arm64)
rustup target add $(TARGET_linux_arm64)
rustup component add rust-src --toolchain $(RUST_VERSION) --target $(TARGET_linux_arm64)
stdlib: | stdlib-x64 stdlib-arm64
endif
toolchain:
rustup toolchain install $(RUST_VERSION) --target $(CURRENT_TARGET)
rustup target add $(CURRENT_TARGET)
rustup component add rust-src --toolchain $(RUST_VERSION) --target $(CURRENT_TARGET)
clean-js:
rm -rf ./bundle
clean: clean-js
rm -rf ./target
rm -rf ./lib
js: $(STD_JS_FILE)
bundle/js/%.js: $(TS_SOURCES)
node build.mjs
fix:
npx pretty-quick
cargo fix --allow-dirty
cargo clippy --fix --allow-dirty
cargo fmt
bloat: js
cargo build --profile=flame --target $(CURRENT_TARGET)
cargo bloat --profile=flame --crates
run: export AWS_LAMBDA_FUNCTION_NAME = n/a
run: export AWS_LAMBDA_FUNCTION_MEMORY_SIZE = 1
run: export AWS_LAMBDA_FUNCTION_VERSION = 1
run: export AWS_LAMBDA_RUNTIME_API = localhost:3000
run: export _EXIT_ITERATIONS = 1
run: export JS_MINIFY = 0
run: export RUST_LOG = llrt=trace
run: export _HANDLER = index.handler
run:
cargo run -vv
run-ssr: export AWS_LAMBDA_RUNTIME_API = localhost:3000
run-ssr: export TABLE_NAME=quickjs-table
run-ssr: export AWS_REGION = us-east-1
run-ssr: export _HANDLER = index.handler
run-ssr: js
cargo build
cd example/functions && yarn build && cd build && ../../../target/debug/llrt
flame:
cargo flamegraph --profile flame -- index.mjs
run-cli: export RUST_LOG = llrt=trace
run-cli: js
cargo run
test: export JS_MINIFY = 0
test: export TEST_SUB_DIR = unit
test: export LLRT_ASYNC_HOOKS = 1
test: js
cargo run -- test -d bundle/js/__tests__/$(TEST_SUB_DIR)
init-wpt:
cd wpt && \
git sparse-checkout init --no-cone && \
git sparse-checkout set \
/README.md \
/console \
/docs \
/encoding \
/FileAPI \
/fetch \
/hr-time \
/streams \
/tools \
/url \
/WebCryptoAPI \
/webidl \
/wpt \
/xhr
update-wpt:
( cd wpt && git fetch origin master && git reset --hard FETCH_HEAD && git log -1 --oneline > ../tests/wpt/revision )
test-wpt: export JS_MINIFY = 0
test-wpt: export TEST_SUB_DIR = wpt
test-wpt: js
npx pretty-quick --pattern "tests/wpt/**/*.{js,ts,json}"
cargo run -- test -d bundle/js/__tests__/$(TEST_SUB_DIR) 2> wpt_errors.tmp
tidyup-wpt:
sed -E 's/\x1b\[[0-9;]*m//g' wpt_errors.tmp \
| sed '1,/^$$/d' \
| sed -E '/^ ?[^ ]/s|^.*__tests__/|🧪/|' \
> wpt_errors.txt
E2E_STACK_NAME := LLRTReleaseIntegTestResourcesStack
E2E_TEMPLATE := tests/e2e/IntegTestResourcesStack.template.yml
setup-e2e:
@echo "Deploying $(E2E_STACK_NAME)..."
aws cloudformation deploy \
--stack-name $(E2E_STACK_NAME) \
--template-file $(E2E_TEMPLATE) \
--capabilities CAPABILITY_IAM \
--no-fail-on-empty-changeset
@echo "Stack ready. Export env vars with:"
@echo ' eval $$(make e2e-env)'
E2E_OUTPUTS := \
AwsSmokeTestBucket:AWS_SMOKE_TEST_BUCKET \
AwsSmokeTestIdentityPoolId:AWS_SMOKE_TEST_IDENTITY_POOL_ID \
AwsSmokeTestMrapArn:AWS_SMOKE_TEST_MRAP_ARN
e2e-env:
@outputs=$$(aws cloudformation describe-stacks --stack-name $(E2E_STACK_NAME) \
--query 'Stacks[0].Outputs[].[OutputKey,OutputValue]' --output text); \
for mapping in $(E2E_OUTPUTS); do \
echo "$$outputs" | sed -n "s/^$${mapping%%:*}\t/export $${mapping##*:}=/p"; \
done; \
echo "export AWS_REGION=$$(aws cloudformation describe-stacks --stack-name $(E2E_STACK_NAME) --query 'Stacks[0].StackId' --output text | cut -d: -f4)"; \
aws configure export-credentials --format env-no-export 2>/dev/null | sed 's/^/export /'
test-e2e: export JS_MINIFY = 0
test-e2e: export TEST_TIMEOUT = 60000
test-e2e: export SDK_BUNDLE_MODE = STD
test-e2e: export TEST_SUB_DIR = e2e
test-e2e: setup-e2e js
eval $$($(MAKE) e2e-env) && cargo run -- test -d bundle/js/__tests__/$(TEST_SUB_DIR) s3
test-ci: export JS_MINIFY = 0
test-ci: export RUST_BACKTRACE = 1
test-ci: export TEST_SUB_DIR = unit
test-ci: export LLRT_ASYNC_HOOKS = 1
test-ci: clean-js | toolchain js
ifdef CARGO_FEATURES
cargo $(TOOLCHAIN) -Z build-std -Z build-std-features test --target $(CURRENT_TARGET) $(CARGO_FEATURES) -- --nocapture --show-output
cargo $(TOOLCHAIN) run -r --target $(CURRENT_TARGET) $(CARGO_FEATURES) -- test -d bundle/js/__tests__/$(TEST_SUB_DIR)
else
cargo $(TOOLCHAIN) -Z build-std -Z build-std-features test --target $(CURRENT_TARGET) --features lambda -- --nocapture --show-output
cargo $(TOOLCHAIN) run -r --target $(CURRENT_TARGET) -- test -d bundle/js/__tests__/$(TEST_SUB_DIR)
endif
libs-arm64: lib/arm64/libzstd.a lib/zstd.h lib/zstd_errors.h
libs-x64: lib/x64/libzstd.a lib/zstd.h lib/zstd_errors.h
libs: | libs-arm64 libs-x64
lib/zstd.h:
cp zstd/lib/zstd.h $@
lib/zstd_errors.h:
cp zstd/lib/zstd_errors.h $@
lib/arm64/libzstd.a:
mkdir -p $(dir $@)
rm -f zstd/lib/-.o
cd zstd/lib && make clean && make $(ZSTD_LIB_ARGS) $(ZSTD_LIB_CC_arm64)
cp zstd/lib/libzstd.a $@
lib/x64/libzstd.a:
mkdir -p $(dir $@)
rm -f zstd/lib/-.o
cd zstd/lib && make clean && make $(ZSTD_LIB_ARGS) $(ZSTD_LIB_CC_x64)
cp zstd/lib/libzstd.a $@
bench:
cargo build -r
hyperfine -N --warmup=100 "node fixtures/hello.js" "deno run fixtures/hello.js" "bun fixtures/hello.js" "$(BUILD_DIR)/llrt fixtures/hello.js" "qjs fixtures/hello.js"
deploy:
cd example/infrastructure && yarn deploy --require-approval never
check:
cargo clippy --all-targets --no-default-features --features "lambda,macro,no-sdk,uncompressed,crypto-rust,tls-ring" -- -D warnings
test-rs:
cargo test --all-targets --no-default-features --features "lambda,macro,no-sdk,uncompressed,crypto-rust,tls-ring"
check-crates:
cargo metadata --no-deps --format-version 1 --quiet | \
jq -r '.packages[] | select(.manifest_path | contains("modules/")) | .name' | \
while read crate; do \
echo "Checking crate: $$crate"; \
cargo check -p "$$crate"; \
done
.PHONY: libs check check-all check-crates libs-arm64 libs-x64 toolchain clean-js release-linux release-darwin release-windows lambda stdlib stdlib-x64 stdlib-arm64 test test-ci test-e2e setup-e2e e2e-env run js run-release build release clean flame deploy