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
64 changes: 64 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Checks

on:
push:
branches: [bootstrap]
pull_request:
branches: [bootstrap]

permissions:
contents: read

concurrency:
group: checks-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
checks:
runs-on: ubuntu-24.04
timeout-minutes: 20
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- run: rustup toolchain install 1.97.1 --profile minimal --component clippy,rustfmt --target wasm32v1-none
- run: cargo fmt --all -- --check
- run: cargo clippy --locked --workspace --all-targets -- -D warnings
- run: cargo test --locked --workspace
- run: cargo build --locked --workspace --release
- name: Install SHA-verified WASI SDK
env:
URL: https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-33/wasi-sdk-33.0-x86_64-linux.tar.gz
SHA256: 0ba8b5bfaeb2adf3f29bab5841d76cf5318ab8e1642ea195f88baba1abd47bce
run: |
curl --fail --location --output "$RUNNER_TEMP/wasi-sdk.tar.gz" "$URL"
echo "$SHA256 $RUNNER_TEMP/wasi-sdk.tar.gz" | sha256sum --check
tar -xzf "$RUNNER_TEMP/wasi-sdk.tar.gz" -C "$RUNNER_TEMP"
- run: cargo run --locked --release -p krad-utils -- build "$RUNNER_TEMP/dist" "$RUNNER_TEMP/wasi-sdk-33.0-x86_64-linux/bin/clang++" --json
- name: Verify committed artifacts
run: |
for artifact in dist/*.wasm; do
cmp "$artifact" "$RUNNER_TEMP/dist/${artifact#dist/}"
done
node - <<'NODE'
const fs = require("node:fs");
const cases = [
["krad-add.wasm", "krad_add", [20, 22], 42],
["krad-clang.wasm", "krad_clang_abi", [], 1],
["krad-libs.wasm", "krad_errno", [0, 4], 38],
["krad-musl.wasm", "krad_memcmp", [0, 0, 0], 0],
["krad-utils.wasm", "krad_wasm_version", [], 1],
];
(async () => {
for (const [file, name, args, expected] of cases) {
const bytes = fs.readFileSync(`dist/${file}`);
const module = await WebAssembly.compile(bytes);
if (WebAssembly.Module.imports(module).length) throw new Error(`${file} has imports`);
const instance = await WebAssembly.instantiate(module);
if (instance.exports[name](...args) !== expected) throw new Error(`${file} failed`);
}
})().catch((error) => { console.error(error); process.exit(1); });
NODE
rejected="$(printf '\143\150\145\145\162\160')"
if grep -R -a -i --exclude-dir=.git --exclude-dir=target "$rejected" .; then exit 1; fi
if find . -path './.git' -prune -o -path './target' -prune -o -iname "*$rejected*" -print | grep -q .; then exit 1; fi
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build/
dist/
node_modules/
/target/
.*.krad-backup
.*.krad-lock
.*.krad-staging
66 changes: 66 additions & 0 deletions Cargo.lock

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

22 changes: 22 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[workspace]
members = [
"packages/krad-clang",
"packages/krad-libs",
"packages/krad-musl",
"packages/krad-utils",
]
resolver = "3"

[workspace.package]
edition = "2024"
license = "MIT"
publish = false
rust-version = "1.97"
version = "0.1.0"

[profile.release]
codegen-units = 1
lto = true
opt-level = "s"
panic = "abort"
strip = "symbols"
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Keys

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# krad

Krad is a four-crate Rust workspace for producing small, standard WebAssembly
modules without a JavaScript runtime:

- `krad-clang` drives an explicit LLVM/Clang WebAssembly compiler and also
exposes its own tiny Wasm ABI marker.
- `krad-musl` provides allocator-free memory and string primitives.
- `krad-libs` provides Linux/FreeBSD errno, page, and copy helpers.
- `krad-utils` provides the build CLI and a small Wasm utility ABI.

Build every Rust crate plus the real C++ fixture with a Clang that supports the
WebAssembly target. The compiler path is explicit; the Krad CLI never downloads
or extracts a toolchain:

```sh
cargo run -p krad-utils -- build dist /path/to/wasi-sdk/bin/clang++
```

The command creates five raw, import-free modules:

```text
dist/krad-add.wasm
dist/krad-clang.wasm
dist/krad-libs.wasm
dist/krad-musl.wasm
dist/krad-utils.wasm
```

`krad-add.wasm` is compiled from `examples/add.cpp` with the standard
`wasm32-unknown-unknown` target, `-nostdlib`, and an explicit `krad_add` export.
The checked-in artifact was built with the SHA-verified official WASI SDK 33
archive and Clang 22.1.0. The other four modules are Rust `wasm32v1-none`
release builds. The CLI uses Bytecode Alliance's pinned `wasmparser` to reject
invalid modules, imports, and missing function exports before replacing an
artifact directory as one set. Existing output is replaced only when it carries
Krad's `.krad-artifacts` ownership marker; concurrent builds serialize on a
sibling lock file.

```sh
cargo fmt --all -- --check
cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
node -e "WebAssembly.instantiate(require('node:fs').readFileSync('dist/krad-add.wasm')).then(({instance})=>{if(instance.exports.krad_add(20,22)!==42)process.exit(1)})"
```

Krad is not a complete libc, sysroot, browser-hosted compiler, Linux/BSD
distribution, or native-ISA translator. It makes no performance or size claim
without a comparable benchmark.

Krad is MIT-licensed; see `LICENSE`.
1 change: 1 addition & 0 deletions dist/.krad-artifacts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
krad-artifacts-v1
Binary file added dist/krad-add.wasm
Binary file not shown.
Binary file added dist/krad-clang.wasm
Binary file not shown.
Binary file added dist/krad-libs.wasm
Binary file not shown.
Binary file added dist/krad-musl.wasm
Binary file not shown.
Binary file added dist/krad-utils.wasm
Binary file not shown.
3 changes: 3 additions & 0 deletions examples/add.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
extern "C" int krad_add(int left, int right) {
return left + right;
}
14 changes: 14 additions & 0 deletions packages/krad-clang/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "krad-clang"
version.workspace = true
edition.workspace = true
license.workspace = true
publish.workspace = true
rust-version.workspace = true

[lib]
crate-type = ["cdylib", "rlib"]
path = "src/lib.rs"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
wasmparser = { version = "=0.252.0", default-features = false, features = ["std", "validate"] }
Loading