Repository navigation
Expand file tree
/
Copy pathjustfile
More file actions
198 lines (172 loc) · 10.1 KB
/
Copy pathjustfile
File metadata and controls
198 lines (172 loc) · 10.1 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
# Developer tasks. Each recipe runs the command CI runs for the same step (.github/workflows/).
# Tool versions: mise.toml.
# Where cargo puts its output, for the recipes that run the release binary.
target := env("CARGO_TARGET_DIR", "target")
# The CPU `just counters` pins to, such as `just core=2 counters FILE`. Pick a P-core on a hybrid CPU.
core := "0"
default:
@just --list
# Once per clone: the json5-tests submodule and the git hooks (commit and push).
setup:
git submodule update --init
prek install
# ci.yml `lint`.
lint:
cargo fmt --all --check
cargo clippy --workspace --all-targets --locked -- -D warnings
RUSTDOCFLAGS="-D warnings" cargo doc --workspace --no-deps --locked
cargo deny check --hide-inclusion-graph advisories bans licenses sources
prek run ruff-check ruff-format zizmor --all-files --show-diff-on-failure
uv run scripts/check-versions.py
just matrix-check
uv run conformance/run.py --check
# ci.yml `test`. nextest skips doctests, so they run on their own.
test:
cargo nextest run --workspace --locked
cargo test --workspace --doc --locked
# ci.yml `scaling`: code paths that could turn quadratic stay linear, by instruction counts
# (needs valgrind, so Linux).
scaling:
cargo build --release --manifest-path fuzz/Cargo.toml --bin diff_json5
JSONVET_DIFF_JSON5={{ absolute_path(env("CARGO_TARGET_DIR", "fuzz/target")) }}/release/diff_json5 \
cargo test --release --locked -p jsonvet-cli --test scaling -- --ignored
# ci.yml `bench`: instruction counts for `check` and `--schema` (needs valgrind and gungraun-runner,
# so Linux). ARGS go to gungraun, such as --save-baseline=base or --baseline=base.
counts *ARGS:
cargo bench --locked -p jsonvet --bench check -- {{ ARGS }}
cargo bench --locked -p jsonvet-cli --bench schema -- {{ ARGS }}
# ci.yml `differential`: jsonvet against check-json5 1.4.1 on generated files (CI samples 5,000).
differential CASES="5000" SEED="7":
cargo build --release --locked -p jsonvet-cli
uv run scripts/differential.py --cases {{ CASES }} --seed {{ SEED }} --jsonvet {{ target }}/release/jsonvet
# ci.yml `lint` and `test` on this OS. CONTRIBUTING.md lists the CI jobs it leaves out.
check: lint test
# ci.yml `msrv`: the oldest Rust the crates support (`rust-version` in Cargo.toml).
msrv:
cargo +1.88 check --workspace --lib --bins --locked
# Package the VS Code extension as editors/vscode/jsonvet-<version>.vsix. Nothing is published.
vsix:
cd editors/vscode && cp ../../LICENSE-MIT ../../LICENSE-APACHE . && pnpm install --frozen-lockfile && pnpm run build && pnpm dlx @vscode/vsce@4.1.0 package --no-dependencies --skip-license
# Re-run the conformance matrix (needs docker), then render docs/conformance.md.
matrix:
cargo build --release --locked -p jsonvet-cli
uv run conformance/run.py --jsonvet {{ target }}/release/jsonvet
uv run conformance/report.py
# Refresh the matrix's lock files after you change a parser pin, then run `just matrix`.
matrix-lock:
uv run conformance/run.py --lock
# ci.yml `lint`: the rendered page is up to date. Fails on uncommitted edits to those files.
matrix-check:
uv run conformance/report.py
git diff --exit-code docs/conformance.md docs/conformance.json README.md
# Fuzz one target for 20 minutes, as fuzz.yml does: check, diff_serde_json, diff_json5, parse, fix, format, config or config_file.
fuzz TARGET:
cd fuzz && cargo +nightly fuzz run -O {{ TARGET }} -- -max_total_time=1200 -print_final_stats=1
# Mutation testing over the crates in one go, which takes over an hour on one CI runner;
# mutants.yml splits it into 64 shards. The 8 GiB cap, as in mutants.yml, makes a mutant that
# allocates without end fail its test instead of taking the machine's memory. macOS refuses the
# cap, so the run goes on without it there.
mutants:
ulimit -v 8388608 2>/dev/null || echo "no memory cap on this system"; cargo mutants --workspace --no-shuffle
# CI cannot move a tag past workflow changes (CONTRIBUTING.md), so this runs by hand. A draft
# or pre-release stops it.
# Once the release is published: point `v3`, which `uses: ...@v3` follows, at the newest vX.Y.Z.
major:
#!/usr/bin/env bash
set -euo pipefail
git fetch --quiet --tags --force origin
# Pre-releases have a `-` in the tag.
tag=$(git tag --list 'v[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | sed '/-/d' | head -1)
if [ -z "$tag" ] || [ "$(gh release view "$tag" --json isDraft,isPrerelease -q '.isDraft or .isPrerelease')" != false ]; then
echo "$tag is not published yet: approve its release.yml run first" >&2
exit 1
fi
git push --force origin "$tag^{commit}:refs/tags/${tag%%.*}"
echo "${tag%%.*} now points at $tag"
# Time jsonvet against check-json5 1.4.1 (needs hyperfine).
bench *ARGS:
cargo build --release --locked -p jsonvet-cli
uv run scripts/bench.py --jsonvet {{ target }}/release/jsonvet {{ ARGS }}
# Write bench.py's files and 13 large inputs, one per scanner path plus three real-world files
# (doc-pretty.json is 88.5 MB), into DIR, for the profiling recipes below.
profile-files DIR=(target / "profile-files"):
uv run scripts/bench.py --files {{ DIR }}
# Release code with line tables and frame pointers, in target/profiling.
[private]
profiling-build:
RUSTFLAGS="-C force-frame-pointers=yes" cargo build --locked --profile profiling -p jsonvet-cli
# Where `jsonvet FILES` spends its time, recorded by samply at 10 kHz into target/profile.json.gz,
# with its symbols beside it, so `samply load` opens it on any machine once both files are copied
# there. Linux needs perf_event_paranoid at 1 or lower.
profile +FILES: profiling-build
@command -v samply >/dev/null || { echo "needs samply: https://github.com/mstange/samply" >&2; exit 1; }
samply record --save-only --unstable-presymbolicate --rate 10000 -o {{ target }}/profile.json.gz \
{{ target }}/profiling/jsonvet {{ FILES }}
# Hardware counters for `jsonvet FILES` on one CPU (`core`), mean of 10 runs: instructions per
# cycle, branch misses and cache misses. Linux perf only, so not in CI, where `just counts` gates.
counters +FILES: profiling-build
@command -v perf >/dev/null || { echo "needs Linux perf (linux-tools)" >&2; exit 1; }
taskset -c {{ core }} perf stat -r 10 -e '{instructions,cycles}' -e '{branches,branch-misses}' \
-e '{cache-references,cache-misses}' {{ target }}/profiling/jsonvet {{ FILES }}
# Instructions on the 13 large `just profile-files` cases in DIR, REF (a commit, branch or tag)
# against this working tree, each the mean of 3 runs on one CPU (`core`), as a Markdown table. REF
# is built in a temporary worktree into target/compare-ref. Linux perf only; on a hybrid CPU pick a
# P-core, such as `just core=2 compare main`.
compare REF DIR=(target / "profile-files"): profiling-build
#!/usr/bin/env bash
set -euo pipefail
command -v perf >/dev/null || { echo "needs Linux perf (linux-tools)" >&2; exit 1; }
tree=$(mktemp -d)
trap 'git -C "{{ justfile_directory() }}" worktree remove --force "$tree"' EXIT
git worktree add --quiet --detach "$tree" "{{ REF }}"
RUSTFLAGS="-C force-frame-pointers=yes" cargo build --quiet --locked --profile profiling -p jsonvet-cli \
--manifest-path "$tree/Cargo.toml" --target-dir "{{ target }}/compare-ref"
# Hybrid CPUs name the P-core counter cpu_core/instructions/.
event=instructions
perf list 2>/dev/null | grep -q cpu_core/instructions/ && event=cpu_core/instructions/
count() { taskset -c {{ core }} perf stat -x, -r 3 -e "$event" "$@" 2>&1 >/dev/null | cut -d, -f1 | tail -1; }
echo "| Case | {{ REF }} (M) | this tree (M) | Change |"
echo "|:--|--:|--:|--:|"
ref="{{ absolute_path(target) }}/compare-ref/profiling/jsonvet"
this="{{ absolute_path(target) }}/profiling/jsonvet"
cd "{{ DIR }}"
for case in doc-pretty.json doc-min.json rows.json strings.json strings-ascii.json numbers.json \
deep.json doc.jsonc doc.json5 rows.jsonl canada-x*.json citm_catalog-x*.json twitter-x*.json; do
[ -f "$case" ] || { echo "no $case in {{ DIR }}: run just profile-files" >&2; exit 1; }
before=$(count "$ref" "$case")
after=$(count "$this" "$case")
awk -v c="$case" -v b="$before" -v a="$after" \
'BEGIN { printf "| %s | %.0f | %.0f | %+.1f%% |\n", c, b / 1e6, a / 1e6, (a - b) / b * 100 }'
done
# How the 1,000 small files from `just profile-files` scale over more CPUs: one hyperfine run per
# CPU list in CPUS, pinned with taskset. `s[0-9]` leaves out strings.json and strings-ascii.json,
# two of the large cases.
threads DIR=(target / "profile-files") CPUS="0,0-1,0-3,0-7": profiling-build
hyperfine --shell=bash --warmup 3 -L cpus {{ CPUS }} 'taskset -c {cpus} {{ target }}/profiling/jsonvet {{ DIR }}/s[0-9]*.json'
# Build the playground as pages.yml does, then serve it at http://127.0.0.1:8000/jsonvet/. Needs the
# wasm32 target and wasm-bindgen-cli at the version in Cargo.lock; the deploy also runs wasm-opt.
# Runs the page's tests and smoke test, then builds the site (the playground with the docs pages)
# into site/ and serves it at /jsonvet/, as pages.yml does.
playground PORT="8000":
#!/usr/bin/env bash
set -euo pipefail
want=$(cargo pkgid --locked wasm-bindgen | sed 's/.*@//')
if [ "$(wasm-bindgen --version 2>/dev/null | cut -d' ' -f2)" != "$want" ]; then
echo "needs wasm-bindgen-cli $want: cargo install wasm-bindgen-cli --version $want --locked" >&2
exit 1
fi
node --test playground/*.test.mjs
pnpm --dir scripts/docs-site install --frozen-lockfile
pnpm --dir scripts/docs-site run check
pnpm --dir scripts/docs-site test
cargo build --locked -p jsonvet-wasm --target wasm32-unknown-unknown --profile wasm
wasm-bindgen --target web --no-typescript --out-dir playground/pkg \
{{ target }}/wasm32-unknown-unknown/wasm/jsonvet_wasm.wasm
node playground/smoke.mjs
pnpm --dir scripts/docs-site run build
# The pages' links are absolute under /jsonvet/, as on Pages.
root=$(mktemp -d)
trap 'rm -r "$root"' EXIT
ln -s "$PWD/site" "$root/jsonvet"
echo "http://127.0.0.1:{{ PORT }}/jsonvet/"
python3 -m http.server {{ PORT }} --bind 127.0.0.1 --directory "$root"