Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 85 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,90 @@ on:
push:
branches: [master]
pull_request:
types: [opened, synchronize, reopened, labeled]
types: [opened, synchronize, reopened]

jobs:
# The wasm artifacts are a new, independent output of the same pipeline: one
# FMI 3.0 FMU per case in both export forms, plus the ahead-of-time jco
# transpile of the component one. Nothing consumes them yet -- this job exists
# so that they are known to build, and keep building, before anything depends
# on them. It touches none of the native simulation stages, so it runs in
# parallel with (and independently of) generate_results.
generate_wasm:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
container:
# OpenModelica built from master with OM_OMC_ENABLE_RUST=ON, which is what
# provides --simCodeTarget=wasm-jit. No published OpenModelica image has
# it; see tools/wasm/Dockerfile and tools/wasm/README.md.
image: ghcr.io/mtiller/omc-wasm:3998b1f8
credentials:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Mark checkout directory as safe
run: git config --global --add safe.directory "$GITHUB_WORKSPACE"
- name: Checkout Repository
uses: actions/checkout@v4
- name: Restore WASM DVC Cache
id: wasm-cache-restore
uses: actions/cache/restore@v4
with:
path: .dvc/cache
key: dvc-wasm-${{ hashFiles('.github/workflows/build.yaml', 'text/specs.py', 'text/source/_sphinxext/xogeny/templates/gen_wasm.mos', 'tools/wasm/transpile.mjs', 'ModelicaByExample/**/*.mo') }}
restore-keys: |
dvc-wasm-
- name: Point OpenModelica at the image's MSL
# The image installs the Modelica Standard Library under root's home,
# but a container job runs with HOME=/github/home, where omc would find
# no libraries at all and every case would re-download the MSL. Link the
# two before `make env`, which then adds its ModelicaByExample symlink
# alongside.
run: |
mkdir -p "$HOME/.openmodelica"
ln -sfn /root/.openmodelica/libraries "$HOME/.openmodelica/libraries"
- name: Build WASM Artifacts
run: make env wasm
- name: Summarize
run: |
python3 - <<'PY'
import json
idx = json.load(open('text/results/wasm/index.json'))
cases, pack = idx['cases'], idx['pack']
def tot(form):
return sum(c['artifacts'][form]['bytes'] for c in cases.values() if form in c['artifacts'])
print(f"{len(cases)} cases")
for form in ('dylink', 'component', 'aot'):
n = sum(1 for c in cases.values() if form in c['artifacts'])
print(f" {form:<10} {n:>3} artifacts {tot(form)/1048576:8.1f} MB laid out per case")
print(f" packed {pack['blobs']:>3} blobs {pack['bytes']/1048576:8.1f} MB distinct "
f"({tot('aot')/pack['bytes']:.1f}x), of which "
f"{pack['sharedByEveryCase']/1048576:.2f} MB is in every case")
PY
- name: Upload WASM Artifacts
uses: actions/upload-artifact@v4
with:
name: wasm-artifacts
# pack/ carries the same content as aot/ with the duplicates removed
# (257 MB -> 16 MB), so uploading both would be uploading the AOT
# output twice, once badly. The DVC cache still holds aot/.
path: |
text/results/wasm
!text/results/wasm/aot
# Nothing consumes these yet, so they are here to be looked at, not
# kept. The DVC cache is what actually makes a rebuild cheap.
retention-days: 7
- name: Save WASM DVC Cache
if: always() && steps.wasm-cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: .dvc/cache
key: ${{ steps.wasm-cache-restore.outputs.cache-primary-key }}

# Every pull request gets the complete build. Only the deploy is held back.
generate_results:
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'Full Build')
runs-on: ubuntu-latest
container:
image: ghcr.io/mtiller/book-builder-image:v0.1.6
Expand Down Expand Up @@ -85,7 +164,6 @@ jobs:
text/docs-dir
key: ${{ steps.cideps-cache-restore.outputs.cache-primary-key }}
generate_site:
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'Full Build')
runs-on: ubuntu-latest
needs: generate_results
container:
Expand Down Expand Up @@ -114,7 +192,10 @@ jobs:
name: korean-site
path: nextgen/dist
deploy_site:
if: github.event_name == 'push' || contains(github.event.pull_request.labels.*.name, 'Full Build')
# The one job a pull request must not run: it publishes to production.
# `push` here can only mean master -- that is the only branch in the
# workflow's push trigger.
if: github.event_name == 'push'
runs-on: ubuntu-latest
needs: generate_site
container:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ source/Examples/*.c
source/Examples/*.exp
**/_static/Icons/*.pdf
**/_static/img/*.pdf
text/results/wasm/
text/build-arch
build-arch
.DS_Store
.env
.claude
.worktrees

7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# N.B. - Any requires credentials are assumed to be provided by environment
# variables and should *not* be provided here.

.PHONY: specs results dirhtml ebooks api publish_server publish_web serve
.PHONY: specs results wasm dirhtml ebooks api publish_server publish_web serve

# When CI_BUILD=1, the json/dirhtml/pdfs targets skip the specs+results
# (DVC repro) dependency chain and assume text/results, text/plots, and
Expand Down Expand Up @@ -38,6 +38,9 @@ specs:
results: env specs
(cd text; make results)

wasm: specs
(cd text; make wasm_files)

dirhtml: $(SPHINX_DEPS)
(cd text; make dirhtml)

Expand All @@ -59,4 +62,4 @@ deploy_site:
clean:
git clean -fdx text
git clean -fdx api
git clean -fdx ModelicaByExample
git clean -fdx ModelicaByExample
13 changes: 12 additions & 1 deletion text/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ LATEXMKOPTS = "-xelatex"
SET_BOOK_LANG_CN = BOOK_LANG=zh_CN
SET_BOOK_LANG_KR = BOOK_LANG=kr

.PHONY: help clean distclean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf pdf text man changes linkcheck doctest gettext results uploadCIdeps
.PHONY: help clean distclean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf pdf text man changes linkcheck doctest gettext results wasm_files uploadCIdeps

# For CI we don't want to rebuild the whole dependencies each time.
# To enable the CI build do, e.g., `make CI_BUILD=1 pdf`
Expand Down Expand Up @@ -77,6 +77,17 @@ specs_cn: specs.py
# This target builds all the simulation results
results:
dvc repro dvc.yaml

# Build the browser-distributable WASM-backed FMUs for every generated case:
# both export forms plus the ahead-of-time jco transpile of the component one.
# These are a separate pipeline from dvc.yaml, in their own directory, so the
# two cannot reach each other: `make results` will not try to export wasm with
# an omc that has no wasm-jit backend, and this will not re-run the native
# simulation sweep.
wasm_files: specs
dvc repro dvc-wasm/dvc.yaml
$(PYTHON) ../tools/wasm/pack.py
$(PYTHON) ../tools/wasm/make-index.py
# (cd results; make results_files exes.tar.gz tidy)

# This builds all the JS and JSON files. Use this if your development
Expand Down
Loading
Loading