Skip to content

Commit 9da3ed3

Browse files
committed
gh-146197: Add Emscripten to CI
1 parent d357a7d commit 9da3ed3

File tree

4 files changed

+92
-0
lines changed

4 files changed

+92
-0
lines changed

.github/workflows/build.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ jobs:
371371
- name: Build and test
372372
run: python3 Apple ci iOS --fast-ci --simulator 'iPhone SE (3rd generation),OS=17.5'
373373

374+
build-emscripten:
375+
name: 'Emscripten'
376+
needs: build-context
377+
if: needs.build-context.outputs.run-emscripten == 'true'
378+
uses: ./.github/workflows/reusable-emscripten.yml
379+
374380
build-wasi:
375381
name: 'WASI'
376382
needs: build-context
@@ -650,6 +656,7 @@ jobs:
650656
- build-ubuntu
651657
- build-ubuntu-ssltests
652658
- build-ios
659+
- build-emscripten
653660
- build-wasi
654661
- test-hypothesis
655662
- build-asan
@@ -706,5 +713,6 @@ jobs:
706713
}}
707714
${{ !fromJSON(needs.build-context.outputs.run-android) && 'build-android,' || '' }}
708715
${{ !fromJSON(needs.build-context.outputs.run-ios) && 'build-ios,' || '' }}
716+
${{ !fromJSON(needs.build-context.outputs.run-emscripten) && 'build-emscripten,' || '' }}
709717
${{ !fromJSON(needs.build-context.outputs.run-wasi) && 'build-wasi,' || '' }}
710718
jobs: ${{ toJSON(needs) }}

.github/workflows/reusable-context.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ on: # yamllint disable-line rule:truthy
4141
run-ubuntu:
4242
description: Whether to run the Ubuntu tests
4343
value: ${{ jobs.compute-changes.outputs.run-ubuntu }} # bool
44+
run-emscripten:
45+
description: Whether to run the Emscripten tests
46+
value: ${{ jobs.compute-changes.outputs.run-emscripten }} # bool
4447
run-wasi:
4548
description: Whether to run the WASI tests
4649
value: ${{ jobs.compute-changes.outputs.run-wasi }} # bool
@@ -65,6 +68,7 @@ jobs:
6568
run-macos: ${{ steps.changes.outputs.run-macos }}
6669
run-tests: ${{ steps.changes.outputs.run-tests }}
6770
run-ubuntu: ${{ steps.changes.outputs.run-ubuntu }}
71+
run-emscripten: ${{ steps.changes.outputs.run-emscripten }}
6872
run-wasi: ${{ steps.changes.outputs.run-wasi }}
6973
run-windows-msi: ${{ steps.changes.outputs.run-windows-msi }}
7074
run-windows-tests: ${{ steps.changes.outputs.run-windows-tests }}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: Reusable Emscripten
2+
3+
on:
4+
workflow_call:
5+
6+
env:
7+
FORCE_COLOR: 1
8+
9+
jobs:
10+
build-emscripten-reusable:
11+
name: 'build and test'
12+
runs-on: ubuntu-24.04
13+
timeout-minutes: 60
14+
env:
15+
EMSDK_CACHE: ${{ github.workspace }}/../emsdk-cache
16+
steps:
17+
- uses: actions/checkout@v6
18+
with:
19+
persist-credentials: false
20+
- name: "Read Emscripten config"
21+
id: emscripten-config
22+
shell: python
23+
run: |
24+
import hashlib
25+
import json
26+
import os
27+
import tomllib
28+
from pathlib import Path
29+
30+
config = tomllib.loads(Path("Platforms/emscripten/config.toml").read_text())
31+
h = hashlib.sha256()
32+
h.update(json.dumps(config["libffi"], sort_keys=True).encode())
33+
h.update(json.dumps(config["mpdec"], sort_keys=True).encode())
34+
h.update(Path("Platforms/emscripten/make_libffi.sh").read_bytes())
35+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
36+
f.write(f"emscripten-version={config['emscripten-version']}\n")
37+
f.write(f"node-version={config['node-version']}\n")
38+
f.write(f"deps-hash={h.hexdigest()}\n")
39+
- name: "Install Node.js"
40+
uses: actions/setup-node@v6
41+
with:
42+
node-version: ${{ steps.emscripten-config.outputs.node-version }}
43+
- name: "Cache Emscripten SDK"
44+
uses: actions/cache@v5
45+
with:
46+
path: ${{ env.EMSDK_CACHE }}
47+
key: emsdk-${{ steps.emscripten-config.outputs.emscripten-version }}-${{ steps.emscripten-config.outputs.deps-hash }}
48+
- name: "Install Python"
49+
uses: actions/setup-python@v6
50+
with:
51+
python-version: '3.x'
52+
- name: "Runner image version"
53+
run: echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV"
54+
- name: "Install Emscripten"
55+
run: python3 Platforms/emscripten install-emscripten
56+
- name: "Configure build Python"
57+
run: python3 Platforms/emscripten configure-build-python -- --config-cache --with-pydebug
58+
- name: "Make build Python"
59+
run: python3 Platforms/emscripten make-build-python
60+
- name: "Make dependencies"
61+
run: python3 Platforms/emscripten make-dependencies
62+
- name: "Configure host Python"
63+
run: python3 Platforms/emscripten configure-host --host-runner node -- --config-cache
64+
- name: "Make host Python"
65+
run: python3 Platforms/emscripten make-host
66+
- name: "Test"
67+
run: python3 Platforms/emscripten run --test

Tools/build/compute-changes.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
ANDROID_DIRS = frozenset({"Android"})
5151
IOS_DIRS = frozenset({"Apple", "iOS"})
5252
MACOS_DIRS = frozenset({"Mac"})
53+
EMSCRIPTEN_DIRS = frozenset({Path("Platforms", "emscripten")})
5354
WASI_DIRS = frozenset({Path("Platforms", "WASI")})
5455

5556
LIBRARY_FUZZER_PATHS = frozenset({
@@ -107,6 +108,7 @@ class Outputs:
107108
run_ci_fuzz: bool = False
108109
run_ci_fuzz_stdlib: bool = False
109110
run_docs: bool = False
111+
run_emscripten: bool = False
110112
run_ios: bool = False
111113
run_macos: bool = False
112114
run_tests: bool = False
@@ -126,6 +128,7 @@ def compute_changes() -> None:
126128
# Otherwise, just run the tests
127129
outputs = Outputs(
128130
run_android=True,
131+
run_emscripten=True,
129132
run_ios=True,
130133
run_macos=True,
131134
run_tests=True,
@@ -196,6 +199,8 @@ def get_file_platform(file: Path) -> str | None:
196199
return "ios"
197200
if first_part in ANDROID_DIRS:
198201
return "android"
202+
if len(file.parts) >= 2 and Path(*file.parts[:2]) in EMSCRIPTEN_DIRS:
203+
return "emscripten"
199204
if len(file.parts) >= 2 and Path(*file.parts[:2]) in WASI_DIRS:
200205
return "wasi"
201206
return None
@@ -244,6 +249,10 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
244249
run_tests = True
245250
platforms_changed.add("macos")
246251
continue
252+
if file.name == "reusable-emscripten.yml":
253+
run_tests = True
254+
platforms_changed.add("emscripten")
255+
continue
247256
if file.name == "reusable-wasi.yml":
248257
run_tests = True
249258
platforms_changed.add("wasi")
@@ -284,18 +293,21 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
284293
if run_tests:
285294
if not has_platform_specific_change or not platforms_changed:
286295
run_android = True
296+
run_emscripten = True
287297
run_ios = True
288298
run_macos = True
289299
run_ubuntu = True
290300
run_wasi = True
291301
else:
292302
run_android = "android" in platforms_changed
303+
run_emscripten = "emscripten" in platforms_changed
293304
run_ios = "ios" in platforms_changed
294305
run_macos = "macos" in platforms_changed
295306
run_ubuntu = False
296307
run_wasi = "wasi" in platforms_changed
297308
else:
298309
run_android = False
310+
run_emscripten = False
299311
run_ios = False
300312
run_macos = False
301313
run_ubuntu = False
@@ -306,6 +318,7 @@ def process_changed_files(changed_files: Set[Path]) -> Outputs:
306318
run_ci_fuzz=run_ci_fuzz,
307319
run_ci_fuzz_stdlib=run_ci_fuzz_stdlib,
308320
run_docs=run_docs,
321+
run_emscripten=run_emscripten,
309322
run_ios=run_ios,
310323
run_macos=run_macos,
311324
run_tests=run_tests,

0 commit comments

Comments
 (0)