-
Notifications
You must be signed in to change notification settings - Fork 11
196 lines (169 loc) · 6.59 KB
/
std.yml
File metadata and controls
196 lines (169 loc) · 6.59 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
name: Std
on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
BINARYEN_VERSION: "121"
jobs:
# Clippy each stdpkg on wasm32. Anchors the matrix so downstream jobs reuse it.
lint:
name: Lint (${{ matrix.package }})
runs-on: ubuntu-latest
strategy: &package-matrix
fail-fast: false
matrix:
package: [json, re, math, test]
steps:
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
components: clippy
# Stable prefix avoids the nightly job's cache. Keyed per package so each shard owns its slot.
- name: Cache Cargo
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
std/${{ matrix.package }}/target
key: cargo-stable-${{ runner.os }}-${{ matrix.package }}-${{ hashFiles(format('std/{0}/Cargo.toml', matrix.package)) }}
restore-keys: cargo-stable-${{ runner.os }}-${{ matrix.package }}-
# Lint only the cdylib; --all-targets clashes with its panic handler.
- name: Clippy src/
if: matrix.package != 'test'
working-directory: std/${{ matrix.package }}
run: cargo clippy --release --target wasm32-unknown-unknown -- -D warnings
# Build, optimize, and test each package; uploads the wasm artifact for the deploy step.
wasm:
name: WASM (${{ matrix.package }})
needs: lint
runs-on: ubuntu-latest
strategy: *package-matrix
env:
WASM: std/${{ matrix.package }}/target/wasm32-unknown-unknown/release/${{ matrix.package }}.wasm
steps:
- uses: actions/checkout@v6
# build-std needs nightly plus rust-src.
- uses: dtolnay/rust-toolchain@nightly
with:
targets: wasm32-unknown-unknown
components: rust-src
- uses: denoland/setup-deno@v2
with:
deno-version: v2.x
# Nightly prefix avoids the lint job's cache.
- name: Cache Cargo
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
std/${{ matrix.package }}/target
key: cargo-nightly-${{ runner.os }}-${{ matrix.package }}-${{ hashFiles(format('std/{0}/Cargo.toml', matrix.package)) }}
restore-keys: cargo-nightly-${{ runner.os }}-${{ matrix.package }}-
- name: Cache Deno modules
uses: actions/cache@v5
with:
path: ~/.cache/deno
key: deno-${{ runner.os }}-${{ hashFiles('std/**/deno.json', 'std/**/deno.lock') }}
restore-keys: deno-${{ runner.os }}-
- name: Cache Playwright browsers
uses: actions/cache@v5
with:
path: ~/.cache/ms-playwright
key: playwright-${{ runner.os }}-chromium
- name: Install Chromium
run: deno run -A npm:playwright install --with-deps chromium
# apt ships an old binaryen, so fetch the upstream release.
- name: Install wasm-opt
if: matrix.package != 'test'
run: |
curl -sSL "https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz" \
| tar -xz --strip-components=2 -C /usr/local/bin "binaryen-version_${BINARYEN_VERSION}/bin/wasm-opt"
wasm-opt --version
# `test` is pure Edge Python (src/entry.py): no crate to compile, so skip the wasm build/optimize/upload and let the corpus run below.
- name: Build
if: matrix.package != 'test'
working-directory: std/${{ matrix.package }}
run: |
RUSTFLAGS="-Z location-detail=none -Z fmt-debug=none -Z unstable-options -C panic=immediate-abort" \
cargo +nightly build \
--target wasm32-unknown-unknown \
--lib --release \
-Z build-std=std,panic_abort
- name: Size (unoptimized)
if: matrix.package != 'test'
run: ls -lh "$WASM"
# Two passes: -Oz with traps-never-happen, then reflatten for a fresh CFG.
- name: Optimize
if: matrix.package != 'test'
run: |
wasm-opt -Oz --converge \
--generate-global-effects \
--strip-debug --strip-producers \
--enable-bulk-memory-opt \
--enable-nontrapping-float-to-int \
--enable-sign-ext \
-tnh \
-o /tmp/wasm_stage1.wasm "$WASM"
wasm-opt --flatten --rereloop -Oz -Oz \
--enable-bulk-memory-opt \
--enable-nontrapping-float-to-int \
--enable-sign-ext \
-o "$WASM" /tmp/wasm_stage1.wasm
rm /tmp/wasm_stage1.wasm
- name: Size (optimized)
if: matrix.package != 'test'
run: ls -lh "$WASM"
# STDPKG narrows Deno's test discovery to this package's corpus. The driver routes .py packages to src/entry.py, native ones to the built wasm.
- name: Test
working-directory: std
env:
STDPKG: ${{ matrix.package }}
run: deno test --allow-all tests/
# Stage the deployable under its canonical CDN name: native -> <pkg>.wasm, pure-Python (src/entry.py) -> <pkg>.py.
- name: Stage artifact
run: |
mkdir -p _dist
if [ -f "std/${{ matrix.package }}/src/entry.py" ]; then
cp "std/${{ matrix.package }}/src/entry.py" "_dist/${{ matrix.package }}.py"
else
cp "$WASM" "_dist/${{ matrix.package }}.wasm"
fi
- uses: actions/upload-artifact@v6
with:
name: dist-${{ matrix.package }}
path: _dist/
retention-days: 1
# Publish every per-package artifact (.wasm + .py) to Cloudflare Pages on pushes to main only.
deploy:
name: Deploy
needs: wasm
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
permissions:
contents: read
steps:
# Pull every per-package artifact uploaded by the matrix above.
- name: Download artifacts
uses: actions/download-artifact@v8
with:
pattern: dist-*
path: _site/
merge-multiple: true
# Pages serves each package at std.edgepython.com/* (e.g. json.wasm, test.py).
- name: Deploy
uses: cloudflare/wrangler-action@v4
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: pages deploy _site --project-name=edge-python-std --branch=main