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
6 changes: 6 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
[alias]
xtask = "run --package xtask --"
vv = "run --package xtask -- validate"

# The exported uorc code recurses structurally over archives and byte ropes;
# the default 1 MiB WebAssembly stack is too small for it. 2 KiB inputs run in
# 16 MiB, and 64 MiB leaves room for deeper inputs.
[target.wasm32-unknown-unknown]
rustflags = ["-C", "link-arg=-zstack-size=67108864"]
166 changes: 166 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Builds the uorc client from the committed LexLean-exported Rust (generated/rust)
# and publishes it: native binaries, the library source bundle, the WebAssembly
# module, a benchmark run, and the GitHub Pages site that runs the client.
name: release

on:
push:
tags: ["v*"]
workflow_dispatch:
inputs:
tag:
description: Existing tag to (re)publish, e.g. v0.1.0
required: true
type: string

permissions:
contents: read

concurrency:
group: release-${{ github.event.inputs.tag || github.ref_name }}
cancel-in-progress: false

env:
TAG: ${{ github.event.inputs.tag || github.ref_name }}
CARGO_TERM_COLOR: never

jobs:
native:
name: native / ${{ matrix.target }}
strategy:
fail-fast: false
matrix:
include:
- { runner: ubuntu-24.04, target: x86_64-unknown-linux-gnu }
- { runner: ubuntu-24.04-arm, target: aarch64-unknown-linux-gnu }
runs-on: ${{ matrix.runner }}
timeout-minutes: 45
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
ref: ${{ env.TAG }}
fetch-depth: 0
persist-credentials: false
- name: Build and test the client
run: |
set -euo pipefail
rustup show active-toolchain
cargo test --locked --release -p uorc
cargo build --locked --release -p uorc --target ${{ matrix.target }}
- name: Package
run: |
set -euo pipefail
name="uorc-${TAG}-${{ matrix.target }}"
mkdir -p "dist/$name"
cp "target/${{ matrix.target }}/release/uorc" LICENSE-APACHE LICENSE-MIT "dist/$name/"
tar -C dist -czf "dist/$name.tar.gz" "$name"
(cd dist && sha256sum "$name.tar.gz" > "$name.tar.gz.sha256")
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: native-${{ matrix.target }}
path: dist/*.tar.gz*
if-no-files-found: error
- name: Fetch the Canterbury corpus
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
set -euo pipefail
sudo apt-get install -y -qq zstd brotli >/dev/null
mkdir -p corpus/canterbury
curl -fsSL https://corpus.canterbury.ac.nz/resources/cantrbry.tar.gz | tar -xz -C corpus/canterbury
- name: Benchmark the release binary
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: node scripts/bench.mjs --uorc "target/${{ matrix.target }}/release/uorc" --corpus corpus/canterbury --steps 0 --out bench
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
if: matrix.target == 'x86_64-unknown-linux-gnu'
with:
name: bench
path: bench/
if-no-files-found: error

wasm:
name: wasm and site
needs: native
runs-on: ubuntu-24.04
timeout-minutes: 30
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
ref: ${{ env.TAG }}
fetch-depth: 0
persist-credentials: false
- name: Build the WebAssembly client
run: cargo build --locked --release -p uorc-wasm --target wasm32-unknown-unknown
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
name: bench
path: bench
- name: Assemble the site and the wasm bundle
run: |
set -euo pipefail
mkdir -p site dist
cp web/* site/
cp target/wasm32-unknown-unknown/release/uorc_wasm.wasm site/uorc.wasm
cp bench/bench.html bench/bench.json bench/bench.md site/
printf '%s\n' "$TAG" > site/version.txt
name="uorc-${TAG}-wasm"
mkdir -p "dist/$name"
cp site/uorc.wasm site/uorc.js LICENSE-APACHE LICENSE-MIT "dist/$name/"
tar -C dist -czf "dist/$name.tar.gz" "$name"
git archive --format=tar.gz --prefix="uorc-${TAG}-src/" -o "dist/uorc-${TAG}-src.tar.gz" HEAD \
Cargo.toml Cargo.lock rust-toolchain.toml crates/uorc crates/uorc-wasm generated/rust LICENSE-APACHE LICENSE-MIT
cp bench/bench.json "dist/uorc-${TAG}-bench.json"
(cd dist && sha256sum *.tar.gz *.json > SHA256SUMS-wasm-src)
- uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
with:
name: wasm-src
path: dist/*
if-no-files-found: error
- uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa
with:
path: site

publish:
name: publish release
needs: [native, wasm]
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
contents: write
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
with:
ref: ${{ env.TAG }}
fetch-depth: 0
persist-credentials: false
- uses: actions/download-artifact@d3f86a106a0bac45b974a628896c90dbdf5c8093
with:
path: assets
merge-multiple: true
- name: Create or update the GitHub release
env:
GH_TOKEN: ${{ github.token }}
run: |
set -euo pipefail
ls -la assets
{ printf 'uorc %s\n\n' "$TAG"; printf 'Client: https://%s.github.io/%s/\n\n' "${GITHUB_REPOSITORY_OWNER,,}" "${GITHUB_REPOSITORY#*/}"; cat assets/bench.md; } > notes.md
files=$(find assets -maxdepth 1 -type f \( -name '*.tar.gz' -o -name '*.sha256' -o -name 'SHA256SUMS*' -o -name '*-bench.json' \))
if gh release view "$TAG" >/dev/null 2>&1; then
gh release upload "$TAG" $files --clobber
else
gh release create "$TAG" --verify-tag --title "uorc $TAG" --notes-file notes.md $files
fi

pages:
name: deploy pages
needs: wasm
runs-on: ubuntu-24.04
timeout-minutes: 10
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- id: deployment
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e
23 changes: 23 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[workspace]
resolver = "2"
members = ["crates/*", "xtask"]
# The client crates LexLean exports are dependencies, not members: they carry
# LexLean's lint table and formatting, which the workspace gates do not own.
exclude = ["generated/rust"]

[workspace.package]
version = "0.1.0"
Expand Down
6 changes: 4 additions & 2 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ model-write:
source-authority:
cargo run --locked -q -p xtask -- audit-source-authority

# Without --all: that also walks path dependencies, and the exported client
# crates under generated/rust keep LexLean's layout, bound by their provenance.
fmt:
cargo fmt --all
cargo fmt

fmt-check:
cargo fmt --all -- --check
cargo fmt -- --check

lint:
cargo clippy --locked --workspace --all-targets -- -D warnings
Expand Down
1 change: 1 addition & 0 deletions client/gen/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__/
24 changes: 24 additions & 0 deletions client/gen/axioms.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"LzDecode.alphabet": [],
"LzDecode.singleton": [],
"LzDecode.pow2": [],
"LzDecode.depthFor": [],
"LzDecode.afterLiteral": [],
"LzDecode.afterMatch": [],
"LzDecode.afterRep": [],
"LzDecode.afterShort": [],
"LzEncode.bitOf": [],
"LzEncode.log2Loop": [],
"LzEncode.slotOf": [],
"LzEncode.limitAt": [],
"LzEncode.afterLiteral": [],
"LzEncode.header": [],
"Table.double": [],
"Table.zeros": [],
"Archive.kernelPrefix": [],
"Archive.kernelSuffix": [],
"Archive.cat": [],
"Archive.uleb": [],
"Archive.number": [],
"Archive.preimage": []
}
9 changes: 9 additions & 0 deletions client/gen/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh
# Regenerates client/src/Uorc/Codec/*.lex.tex. The generators are writing aids; the .lex.tex files are the source.
set -e
cd "$(dirname "$0")"
C=../src/Uorc/Codec
python3 gen_table.py; python3 fixmul.py $C/Table.lex.tex; python3 finish.py dec $C/Table.lex.tex
python3 gen_dec.py; python3 fixmul.py $C/LzDecode.lex.tex; python3 finish.py dec $C/LzDecode.lex.tex
python3 gen_enc.py; python3 fixmul.py $C/LzEncode.lex.tex; python3 finish.py enc $C/LzEncode.lex.tex
python3 gen_archive.py; python3 fixmul.py $C/Archive.lex.tex
13 changes: 13 additions & 0 deletions client/gen/check_graph.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Runs the kernel graph by the Python mirror of the reference semantics (g.py) on archives the
# prototype encoder (ulz.py, byte-identical to the LexLean encoder) writes, and compares the output.
import os, sys, random
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
import ulz, ulzgraph, g
random.seed(7)
cases = [b'', b'a', b'abcabcabcabcabc hello hello', bytes(3000), os.urandom(2000),
bytes(random.choice(b'ab') for _ in range(3000)), open(__file__, 'rb').read()]
for data in cases:
G, entry = ulzgraph.build(ulz.compress(data))
assert g.evaluate(G, entry) == data, len(data)
print('kernel graph decodes', len(cases), 'cases;', sum(len(b.ins) for b in G.blocks), 'instructions in', len(G.blocks), 'blocks')
10 changes: 10 additions & 0 deletions client/gen/finish.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Replaces the state type tokens after fixmul.py has rewritten multiplications.
import sys
import os
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
from state import Layout
kind, path = sys.argv[1], sys.argv[2]
L = Layout('Dec', ['mem'], [], {}) if kind == 'dec' else Layout('Enc', ['mem'], [], {})
text = L.finish(open(path).read()).rstrip('\n') + '\n'
open(path, 'w').write(text)
41 changes: 41 additions & 0 deletions client/gen/fixmul.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import sys,re
def fix(s):
while True:
i=s.find(' * ')
if i<0: return s
# find enclosing '('
d=0; j=i
while j>=0:
c=s[j]
if c==')': d+=1
elif c=='(':
if d==0: break
d-=1
j-=1
# find matching ')'
d=0; k=j
while True:
c=s[k]
if c=='(': d+=1
elif c==')':
d-=1
if d==0: break
k+=1
inner=s[j+1:k]
# split top-level ' * '
d=0; parts=[]; last=0; m=0
while m<len(inner):
c=inner[m]
if c in '([{': d+=1
elif c in ')]}': d-=1
elif d==0 and inner.startswith(' * ',m): parts.append(inner[last:m]); last=m+3; m+=3; continue
m+=1
parts.append(inner[last:])
# Nat.mul recurses on its second argument, so a certificate's kernel unfolds `x * 16777216` once per unit.
# A literal goes first, where the recursion meets the symbolic side and stops.
lits=[q for q in parts if q.strip().isdigit()]; rest=[q for q in parts if not q.strip().isdigit()]
parts=lits+rest
expr=parts[0]
for p in parts[1:]: expr=f"(prim multiply {expr} {p} : Nat)"
s=s[:j]+expr+s[k+1:]
p=sys.argv[1]; t=fix(open(p).read().replace('(Nat * Dec)','PAIRTY').replace('(Dec * Bool)','DBTY').replace('(Nat * Nat)','NNTY').replace('(Enc * Bool)','EBTY').replace('(Nat * Bytes)','NBYTY')).replace('PAIRTY','(Nat * Dec)').replace('DBTY','(Dec * Bool)').replace('NNTY','(Nat * Nat)').replace('EBTY','(Enc * Bool)').replace('NBYTY','(Nat * Bytes)'); open(p,'w').write(t)
Loading
Loading