Skip to content
File

Blob: justfile

6.0 KB
1alias b := build
2alias t := test
3alias f := format
4alias st := stream-test
5alias c := coverage
6alias w := watch
7 
8default:
9 @just --list
10 
11pwd := `pwd`
12 
13prepare:
14 @if [ "{{os()}}" = "macos" ]; then just prepare-macos; elif [ "{{os()}}" = "linux" ]; then just prepare-ubuntu; else echo "Unsupported OS: {{os()}}"; exit 1; fi
15 cargo install gen-compile-commands watchexec-cli
16 just create-external
17 just compile-commands
18 just prepare-rust
19 
20prepare-rust:
21 rustup install 1.91.0
22 rustup component add rust-analyzer --toolchain 1.91.0
23 
24prepare-ubuntu:
25 sudo apt-get install -y --no-install-recommends libc++abi1-19 libc++1-19 libc++-19-dev lld-19 bazelisk python3 lcov fd-find
26 
27prepare-macos:
28 brew install --quiet bazelisk python3 lcov fd
29 
30compile-commands:
31 rm -f compile_commands.json
32 gen-compile-commands --root {{pwd}} --compile-flags compile_flags.txt --out compile_commands.json --src-dir {{pwd}}/src
33 
34clean:
35 rm -f compile_commands.json
36 
37build *args="//...":
38 bazel build {{args}}
39 
40# example: just watch run -- serve $(pwd)/samples/helloworld/config.capnp
41run *args="-- --help":
42 bazel run //src/workerd/server:workerd -- {{args}} --watch --verbose --experimental
43 
44build-asan *args="//...":
45 just build {{args}} --config=asan
46 
47test *args="//...":
48 bazel test {{args}}
49 
50test-asan *args="//...":
51 just test {{args}} --config=asan
52 
53# e.g. just stream-test //src/cloudflare:cloudflare.capnp@eslint
54stream-test *args:
55 bazel test {{args}} --test_output=streamed --nocache_test_results --test_tag_filters= --test_size_filters=
56 
57# e.g. just node-test zlib
58node-test test_name *args:
59 just stream-test //src/workerd/api/node/tests:{{test_name}}-nodejs-test@ {{args}}
60 
61# e.g. just wpt-test urlpattern
62wpt-test test_name:
63 just stream-test //src/wpt:{{test_name}}
64 
65lldb-wpt-test test_name: build
66 cd bazel-bin/src/wpt/{{test_name}}.runfiles/workerd/src/wpt; lldb ../workerd/server/workerd -- test {{test_name}}.wd-test --experimental --directory-path=TEST_TMPDIR=/tmp
67 
68asan-wpt-test test_name:
69 bazel test //src/workerd/api/wpt:{{test_name}} --config=asan
70 
71new-wpt-test test_name:
72 mkdir -p src/wpt/$(dirname {{test_name}})
73 echo "export default {};" > src/wpt/{{test_name}}-test.ts
74 git add src/wpt/{{test_name}}-test.ts
75 
76 echo >> src/wpt/BUILD.bazel
77 echo 'wpt_test(name = "{{test_name}}", config = "{{test_name}}-test.ts", wpt_directory = "@wpt//:{{test_name}}@module")' >> src/wpt/BUILD.bazel
78 
79 ./tools/cross/format.py
80 bazel test //src/wpt:{{test_name}}@ --test_env=GEN_TEST_CONFIG=1 --test_output=streamed
81 
82# Specify the full Bazel target name for the test to be created.
83# e.g. just new-test //src/workerd/api/tests:v8-temporal-test
84new-test test_name:
85 ./tools/unix/new-test.sh {{test_name}}
86 
87format:
88 python3 tools/cross/format.py
89 
90internal-pr:
91 ./tools/unix/create-internal-pr.sh
92 
93# update dependencies with a given prefix (all by default)
94update-deps prefix="":
95 ./build/deps/update-deps.py {{prefix}}
96 
97# equivalent to `cargo update`; use `workspace` or <package> to limit update scope
98update-rust package="":
99 bazel run @rules_rust//tools/upstream_wrapper:cargo -- update --manifest-path=deps/rust/Cargo.toml {{package}}
100 
101# example: just bench mimetype
102bench path:
103 bazel run //src/workerd/tests:bench-{{path}} --config=benchmark
104 
105# example: just clippy dns
106clippy package="...":
107 bazel build //src/rust/{{package}} --config=lint
108 
109# example: just clang-tidy //src/rust/jsg:ffi
110clang-tidy target="//...":
111 bazel build {{target}} --config=clang-tidy
112 
113generate-types:
114 bazel build //types
115 cp -r bazel-bin/types/definitions/latest types/generated-snapshot/
116 cp -r bazel-bin/types/definitions/experimental types/generated-snapshot/
117 
118update-reported-node-version:
119 python3 tools/update_node_version.py src/workerd/api/node/node-version.h
120 
121update-opencode:
122 python3 tools/update_opencode_version.py
123 
124# called by rust-analyzer discoverConfig (quiet recipe with no output)
125# rust-analyzer doesn't like stderr output, redirect it to /dev/null
126@_rust-analyzer:
127 rm -rf ./rust-project.json
128 bazel run @rules_rust//tools/rust_analyzer:discover_bazel_rust_project 2>/dev/null
129 
130create-external:
131 tools/unix/create-external.sh
132 
133bench-all:
134 bazel query 'attr(tags, "[\[ ]google_benchmark[,\]]", //... + @capnp-cpp//...)' --output=label | xargs -I {} bazel run --config=benchmark {}
135 
136lint: eslint
137 
138eslint:
139 just stream-test \
140 //src/cloudflare:cloudflare@eslint \
141 //src/node:node@eslint \
142 //src/pyodide:pyodide_static@eslint \
143 //src/wpt:wpt-all@tsproject@eslint \
144 //types:types_lib@eslint
145 
146# Generate code coverage report (Linux only)
147coverage path="//...":
148 bazel coverage --config=coverage {{path}}
149 genhtml --branch-coverage --ignore-errors category --output coverage "$(bazel info output_path)/_coverage/_coverage_report.dat"
150 open coverage/index.html
151 
152profile path:
153 bazel run //src/workerd/tests:bench-{{path}} --config=benchmark --run_under="perf record -F max --call-graph lbr"
154 PERF_FILE=$(fdfind perf.data bazel-bin | grep "{{path}}" | head -1); \
155 if [ -n "$PERF_FILE" ] && [ -s "$PERF_FILE" ]; then \
156 cp $PERF_FILE perf.data; \
157 perf report --input=$PERF_FILE; \
158 else \
159 echo "No valid perf.data file found for {{path}}"; \
160 fi
161 
162# Run the @gc-stress test variants to detect GC-related bugs (premature collection,
163# missing visitForGc, etc). Debug builds only. These variants are tagged off-by-default
164# so they won't run in normal `just test` invocations.
165# e.g. just test-gc-stress //src/workerd/api/tests:all
166test-gc-stress *args="//src/...":
167 bazel test $(bazel query 'attr(tags, gc-stress, kind("_wd_test rule", {{args}}))' 2>/dev/null) --test_tag_filters=gc-stress
168 
169# Like test-gc-stress but with AddressSanitizer to detect use-after-free.
170# Leak detection is disabled to avoid masking more serious issues.
171test-gc-stress-asan *args="//src/...":
172 bazel test $(bazel query 'attr(tags, gc-stress, kind("_wd_test rule", {{args}}))' 2>/dev/null) --config=asan --test_tag_filters=gc-stress,-no-asan --test_timeout=300 --test_env=ASAN_OPTIONS=detect_leaks=0
173 
174watch *args="build":
175 watchexec -rc -w src -w build just {{args}}