diff --git a/.config/wasm-pkg/config.toml b/.config/wasm-pkg/config.toml new file mode 100644 index 0000000..ec58b31 --- /dev/null +++ b/.config/wasm-pkg/config.toml @@ -0,0 +1,3 @@ +[namespace_registries] +wasi = "wasi.dev" +componentized = "componentized.dev" diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile deleted file mode 100644 index b46b2fb..0000000 --- a/.devcontainer/Dockerfile +++ /dev/null @@ -1,7 +0,0 @@ -FROM mcr.microsoft.com/devcontainers/rust:2-1-trixie -RUN sudo apt update && sudo apt upgrade -y -RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash -RUN cargo binstall -y wasm-tools -RUN cargo binstall -y wkg -RUN cargo binstall -y wac-cli -RUN cargo binstall -y wasmtime-cli diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5c07aa3..427dd44 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,11 +1,8 @@ // For format details, see https://aka.ms/devcontainer.json. For config options, see the // README at: https://github.com/devcontainers/templates/tree/main/src/rust { - "name": "logging", - "build": { - "dockerfile": "Dockerfile" - }, - + "name": "componentized-logging", + "image": "mcr.microsoft.com/devcontainers/rust", // Use 'mounts' to make the cargo cache persistent in a Docker Volume. "mounts": [ { @@ -19,15 +16,12 @@ "type": "volume" } ], - // Features to add to the dev container. More info: https://containers.dev/features. "features": { "ghcr.io/devcontainers/features/github-cli:1": {} }, - // Use 'postCreateCommand' to run commands after the container is created. - "postCreateCommand": "cargo check", - + "postCreateCommand": "./scripts/init-devcontainer.sh", // Configure tool-specific properties. "customizations": { // Configure properties specific to VS Code. @@ -47,7 +41,6 @@ ] } } - // Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root. // "remoteUser": "root" -} +} \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 5c1266c..fc87e11 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,18 +1,22 @@ version: 2 updates: -- package-ecosystem: github-actions - directory: "/" - schedule: - interval: daily -- package-ecosystem: cargo - directory: "/" - schedule: - interval: daily -- package-ecosystem: rust-toolchain - directory: "/" - schedule: - interval: daily -- package-ecosystem: devcontainers - directory: "/" - schedule: - interval: weekly + - package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily + - package-ecosystem: cargo + directory: "/" + schedule: + interval: daily + - package-ecosystem: cargo + directory: "/tools" + schedule: + interval: daily + - package-ecosystem: rust-toolchain + directory: "/" + schedule: + interval: daily + - package-ecosystem: devcontainers + directory: "/" + schedule: + interval: weekly diff --git a/.github/workflows/bump-version.yaml b/.github/workflows/bump-version.yaml new file mode 100644 index 0000000..ba9c8ba --- /dev/null +++ b/.github/workflows/bump-version.yaml @@ -0,0 +1,203 @@ +name: Bump version + +on: + workflow_dispatch: + inputs: + version: + description: The new version of the interface package, e.g. 0.3.0 or 0.4.0-dev + required: true + type: string + default: "0.3.0-dev" # the current version, kept current by scripts/bump-version.sh + +jobs: + # bumps the version with read only access, the changes are handed to the push job as a patch so + # the third party actions used to build never run with write access + bump: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - name: Check version + # a semver version without a leading `v`, the tag adds it. Build metadata is used to tag the + # debug builds of components, e.g. 0.1.0+debug, and isn't allowed in the version itself. + run: | + identifier='(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)' + semver="^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-${identifier}(\.${identifier})*)?$" + if ! [[ "${VERSION}" =~ ${semver} ]] ; then + echo "::error::the version '${VERSION}' is not a valid semver version, e.g. 0.3.0 or 0.4.0-dev" + exit 1 + fi + if [[ "${VERSION}" == *+* ]] ; then + echo "::error::the version '${VERSION}' must not contain build metadata" + exit 1 + fi + env: + VERSION: ${{ inputs.version }} + - uses: actions/checkout@v7 + with: + persist-credentials: false + - uses: actions-rust-lang/setup-rust-toolchain@v2 + - name: Install cargo binstall + uses: cargo-bins/cargo-binstall@main + - name: Install tools + run: | + make tools + make -s tools-path >> "${GITHUB_PATH}" + - name: Bump version + # also fetches the wit dependencies for the new version, and builds and tests the components + run: scripts/bump-version.sh "${VERSION}" + env: + VERSION: ${{ inputs.version }} + - name: Collect changes + run: | + git add --all + git diff --cached --binary > bump-version.patch + - name: Upload changes + uses: actions/upload-artifact@v7 + with: + name: bump-version.patch + path: bump-version.patch + if-no-files-found: error + retention-days: 1 + + # pushes the bump to the branch the workflow was run on, using only first party actions and the gh + # cli + push: + needs: + - bump + # the bump is a new commit on the branch, a tag can't be moved forward + if: github.ref_type == 'branch' + runs-on: ubuntu-latest + # the commit is pushed with a token for the custodian GitHub App rather than the GITHUB_TOKEN, + # which can't change workflow files and doesn't trigger the CI workflow. The app must be allowed + # to bypass the branch's ruleset, the commit is pushed without the status checks it requires, + # the bump job built and tested the changes instead. + permissions: + contents: read + env: + VERSION: ${{ inputs.version }} + steps: + - name: Check custodian app credentials + run: | + if [ -z "${CLIENT_ID}" ] || [ -z "${PRIVATE_KEY}" ] ; then + echo "::error::the CUSTODIAN_CLIENT_ID and CUSTODIAN_PRIVATE_KEY secrets must be available to this repository, the private key of the custodian GitHub App is needed to create a token" + exit 1 + fi + env: + CLIENT_ID: ${{ secrets.CUSTODIAN_CLIENT_ID }} + PRIVATE_KEY: ${{ secrets.CUSTODIAN_PRIVATE_KEY }} + - name: Create custodian app token + id: app-token + uses: actions/create-github-app-token@v3 + with: + client-id: ${{ secrets.CUSTODIAN_CLIENT_ID }} + private-key: ${{ secrets.CUSTODIAN_PRIVATE_KEY }} + # only this repository, with only the permissions the bump needs + repositories: ${{ github.event.repository.name }} + permission-contents: write + # the bump changes the default version in this workflow + permission-workflows: write + # a release runs this workflow again, to bump to the next dev version + permission-actions: write + - uses: actions/checkout@v7 + with: + persist-credentials: false + - name: Download changes + uses: actions/download-artifact@v8 + with: + name: bump-version.patch + path: ${{ runner.temp }} + - name: Read current version + # the checkout is before the bump, the wit package's version is the current version + run: | + current=$( sed -n 's/^package componentized:logging@\(.*\);$/\1/p' wit/worlds.wit ) + echo "CURRENT_VERSION=${current}" >> "${GITHUB_ENV}" + - name: Commit changes + # the commit is created with the REST API, as the app's token can't push. The patch is applied + # locally only to find the changed files and their modes. + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + APP_SLUG: ${{ steps.app-token.outputs.app-slug }} + run: | + api="repos/${GITHUB_REPOSITORY}" + base=$( git rev-parse HEAD ) + git apply --index "${RUNNER_TEMP}/bump-version.patch" + + # a blob for each changed file, or a null sha for a deleted file + entries="${RUNNER_TEMP}/tree-entries.json" + echo '[]' > "${entries}" + git diff --cached --no-renames --name-status "${base}" | while IFS=$'\t' read -r status path ; do + if [ "${status}" = "D" ] ; then + entry=$( jq -n --arg path "${path}" '{path: $path, mode: "100644", type: "blob", sha: null}' ) + else + mode=$( git ls-files --stage -- "${path}" | cut -d' ' -f1 ) + sha=$( base64 < "${path}" | tr -d '\n' | jq -Rs '{encoding: "base64", content: .}' | gh api --method POST "${api}/git/blobs" --input - --jq .sha ) + entry=$( jq -n --arg path "${path}" --arg mode "${mode}" --arg sha "${sha}" '{path: $path, mode: $mode, type: "blob", sha: $sha}' ) + fi + jq --argjson entry "${entry}" '. + [$entry]' "${entries}" > "${entries}.tmp" && mv "${entries}.tmp" "${entries}" + echo "${status} ${path}" + done + tree=$( jq --arg base "$( git rev-parse "${base}^{tree}" )" '{base_tree: $base, tree: .}' "${entries}" | gh api --method POST "${api}/git/trees" --input - --jq .sha ) + + # authored, committed and signed off (DCO) by the custodian app's bot. GitHub only signs + # commits it attributes entirely to the app, so the author and committer are left for GitHub + # to fill in. The user who triggered the workflow is credited as a co-author, with their + # GitHub noreply email so their email address isn't exposed. A run started by the app after a + # release has no one else to credit. + bot="${APP_SLUG}[bot]" + bot_email="$( gh api "users/${bot}" --jq .id )+${bot}@users.noreply.github.com" + message=$( printf 'Bump version from %s to %s\n\nSigned-off-by: %s <%s>' "${CURRENT_VERSION}" "${VERSION}" "${bot}" "${bot_email}" ) + if [ "${GITHUB_ACTOR}" != "${bot}" ] ; then + name=$( gh api "users/${GITHUB_ACTOR}" --jq '.name // .login' ) + name="${name:-${GITHUB_ACTOR}}" + email="${GITHUB_ACTOR_ID}+${GITHUB_ACTOR}@users.noreply.github.com" + message=$( printf '%s\nCo-authored-by: %s <%s>' "${message}" "${name}" "${email}" ) + fi + read -r commit verified < <( jq -n \ + --arg message "${message}" \ + --arg tree "${tree}" --arg parent "${base}" \ + '{message: $message, tree: $tree, parents: [$parent]}' \ + | gh api --method POST "${api}/git/commits" --input - --jq '"\(.sha) \(.verification.verified)"' ) + echo "created commit ${commit}" + # the branch requires signed commits, fail before pushing rather than after + if [ "${verified}" != "true" ] ; then + echo "::error::the commit '${commit}' was not created, or was not signed by GitHub" + exit 1 + fi + + # a release, rather than a pre-release, is tagged, e.g. v0.1.0. Tags are immutable, check the + # tag is free before pushing the branch, so a release isn't left without its tag + tag="" + if [[ "${VERSION}" != *-* ]] ; then + tag="v${VERSION}" + if gh api "${api}/git/ref/tags/${tag}" --silent 2> /dev/null ; then + echo "::error::the tag ${tag} already exists" + exit 1 + fi + fi + + # fast forwards the branch to the commit, failing rather than losing commits pushed to the + # branch since the workflow started + if ! gh api --method PATCH "${api}/git/refs/heads/${GITHUB_REF_NAME}" -f sha="${commit}" -F force=false --silent ; then + echo "::error::failed to push ${commit} to ${GITHUB_REF_NAME}, either the branch moved since ${base} and the workflow should be run again, or the custodian app is not allowed to bypass the branch's ruleset" + exit 1 + fi + echo "pushed ${commit} to ${GITHUB_REF_NAME}" + + # a lightweight tag, pushed with the app's token so the CI workflow runs for it and drafts + # the release + if [ -n "${tag}" ] ; then + gh api --method POST "${api}/git/refs" -f ref="refs/tags/${tag}" -f sha="${commit}" --silent + echo "tagged ${commit} as ${tag}" + fi + - name: Bump to the next dev version + # after a release, the branch moves on to a pre-release of the next patch version, e.g. 0.3.0 + # is followed by 0.3.1-dev. Run with the app's token, the GITHUB_TOKEN can't start workflows. + if: ${{ !contains(inputs.version, '-') }} + env: + GH_TOKEN: ${{ steps.app-token.outputs.token }} + run: | + IFS=. read -r major minor patch <<< "${VERSION}" + next="${major}.${minor}.$(( patch + 1 ))-dev" + gh workflow run bump-version.yaml --repo "${GITHUB_REPOSITORY}" --ref "${GITHUB_REF_NAME}" -f version="${next}" + echo "started the ${GITHUB_WORKFLOW} workflow for ${next} on ${GITHUB_REF_NAME}" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 2062d7c..894d16f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,34 +17,43 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@v2 - name: Install cargo binstall uses: cargo-bins/cargo-binstall@main - - name: Install wkg - run: cargo binstall --force wkg - - name: Install wasm-tools - run: cargo binstall --force wasm-tools - - name: Install wac-cli - run: cargo binstall --force wac-cli - - name: Fetch wit + - name: Install tools + # the versions pinned in tools/Cargo.toml, on the path for later steps + run: | + make tools + make -s tools-path >> "${GITHUB_PATH}" + - name: Sync wit run: make wit - name: Check for drift in generated wit run: git diff --exit-code . - name: Build components run: make components - name: Collect components.tar - run: tar -cvf ../components.tar *.wasm* - working-directory: ./lib + run: tar -cvf ../../components.tar . + working-directory: ./target/components - name: Upload components.tar uses: actions/upload-artifact@v7 with: name: components.tar path: components.tar retention-days: 7 + - name: Test + run: make test - name: Capture WIT - working-directory: ./lib + working-directory: ./target/components run: | - for component in *.wasm ; do - echo "::group::${component} ($(du -h ${component} | cut -f1 ))" - wasm-tools component wit "${component}" - echo "::endgroup::" + dump_wit() { + echo "::group::$(basename "$1") ($(du -h "$1" | awk '{print $1}' ))" + wasm-tools component wit "$1" + echo "::endgroup::" + } + + # print interface.wasm first + if [ -f interface.wasm ] ; then + dump_wit interface.wasm + fi + for component in $(find . -name '*.wasm' -not -name '*.debug.wasm' -not -name 'interface.wasm' | sort) ; do + dump_wit "${component}" done publish: @@ -61,10 +70,10 @@ jobs: - uses: actions-rust-lang/setup-rust-toolchain@v2 - name: Install cargo binstall uses: cargo-bins/cargo-binstall@main - - name: Install wkg - run: cargo binstall --force wkg - - name: Install wasm-tools - run: cargo binstall --force wasm-tools + - name: Install tools + run: | + make tools + make -s tools-path >> "${GITHUB_PATH}" - name: Install cosign uses: sigstore/cosign-installer@v4.1.2 - name: Download components.tar @@ -72,10 +81,10 @@ jobs: with: name: components.tar - name: Extract components - run: tar -xvf components.tar -C lib + run: mkdir -p target/components && tar -xvf components.tar -C target/components - name: Get interface version id: interface_version - run: echo "VERSION=$( wasm-tools component wit lib/interface.wasm --json | jq -r "[.packages[] | select(.name | contains(\"${GITHUB_REPOSITORY/\//:}@\"))][0].name" | cut -d'@' -f2 )" >> $GITHUB_OUTPUT + run: echo "VERSION=$( wasm-tools component wit target/components/interface.wasm --json | jq -r "[.packages[] | select(.name | contains(\"${GITHUB_REPOSITORY/\//:}@\"))][0].name" | cut -d'@' -f2 )" >> $GITHUB_OUTPUT - name: Get tag version if: startsWith(github.ref, 'refs/tags/') id: tag_version @@ -91,15 +100,29 @@ jobs: if: startsWith(github.ref, 'refs/tags/') || (github.ref == 'refs/heads/main' && contains(steps.interface_version.outputs.VERSION, '-')) run: make publish env: + PUBLISH_LOG: "${{ runner.temp }}/published.txt" REPOSITORY: "ghcr.io/${{ github.repository }}" VERSION: "${{ case(github.ref == 'refs/heads/main', steps.interface_version.outputs.VERSION, steps.tag_version.outputs.VERSION) }}" + - name: Draft release notes + run: | + { + echo "## Published components" + echo + echo "| File | Size | Image |" + echo "| --- | --: | --- |" + while read -r file bytes image ; do + size=$( numfmt --to=iec-i --suffix=B --format=%.1f "${bytes}" ) + echo "| \`${file}\` | ${size} | \`${image}\` |" + done < "${RUNNER_TEMP}/published.txt" + } > "${RUNNER_TEMP}/release-notes.md" + cat "${RUNNER_TEMP}/release-notes.md" - name: Draft GitHub Release if: startsWith(github.ref, 'refs/tags/') uses: softprops/action-gh-release@v3 with: draft: true + body_path: ${{ runner.temp }}/release-notes.md files: | - lib/*.wasm components.tar fail_on_unmatched_files: true token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index b546111..f3027d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ /components.tar /target .DS_Store +/tools/Cargo.lock +# wit dependencies, fetched by `make wit` from the wkg.toml and wkg.lock files +**/wit/deps/ diff --git a/Cargo.toml b/Cargo.toml index 22732cd..2274835 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,15 @@ [workspace] resolver = "2" members = [ - "components/*", -] -exclude = [ - "components/wit", + "components/levels", + "components/to-stdout", ] [workspace.dependencies] wit-bindgen = "0.62.0" + +[profile.release] +opt-level = "s" +lto = true +codegen-units = 1 +strip = "debuginfo" diff --git a/Makefile b/Makefile index 4756e51..9e26af7 100644 --- a/Makefile +++ b/Makefile @@ -2,84 +2,30 @@ SHELL := /bin/bash export RUST_BACKTRACE ?= 1 export WASMTIME_BACKTRACE_DETAILS ?= 1 +export WKG_CONFIG_FILE := $(abspath .config/wasm-pkg/config.toml) -COMPONENTS = $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard components/*/Cargo.toml))))) +# `make` without a goal runs all, otherwise the first target of an included file would run +.DEFAULT_GOAL := all -.PHONY: all -all: components - -.PHONY: clean -clean: - cargo clean - rm -rf lib/*.wasm - rm -rf lib/*.wasm.md - -.PHONY: components -components: lib/interface.wasm $(foreach component,$(COMPONENTS),lib/$(component).wasm lib/$(component).debug.wasm) - -define BUILD_COMPONENT - -lib/$1.wasm: Cargo.toml Cargo.lock wit/deps $(shell find components/$1 -type f) - cargo build -p $1 --target wasm32-unknown-unknown --release - wasm-tools component new target/wasm32-unknown-unknown/release/$(subst -,_,$1).wasm -o lib/$1.wasm - cp components/$1/README.md lib/$1.wasm.md +# tools first, the others use the variables it defines for each tool when their rules are read +include make/tools.mk +include make/wit.mk +include make/components.mk +include make/publish.mk -lib/$1.debug.wasm: Cargo.toml Cargo.lock wit/deps $(shell find components/$1 -type f) - cargo build -p $1 --target wasm32-unknown-unknown - wasm-tools component new target/wasm32-unknown-unknown/debug/$(subst -,_,$1).wasm -o lib/$1.debug.wasm - cp components/$1/README.md lib/$1.debug.wasm.md -endef - -$(foreach component,$(COMPONENTS),$(eval $(call BUILD_COMPONENT,$(component)))) - -lib/interface.wasm: wit/deps README.md - wkg build -o lib/interface.wasm - cp README.md lib/interface.wasm.md - -.PHONY: wit -wit: wit/deps components/wit/deps - -wit/deps: wkg.toml $(shell find wit -type f -name "*.wit" -not -path "deps") - wkg wit fetch +.PHONY: all +all: tools wit components test -components/wit/deps: wit/deps components/wkg.toml $(shell find components/wit -type f -name "*.wit" -not -path "deps") - wkg wit fetch +.PHONY: clean +clean: clean-components clean-wit + @: -.PHONY: publish ## Publish each component in the lib directory -publish: $(shell find lib -maxdepth 1 -type f -name "*.wasm" | sed -e 's:^lib/:publish-:g') +.PHONY: clean-all +clean-all: clean-components clean-tools clean-wit + cargo clean -.PHONY: publish-% -publish-%: -ifndef VERSION - $(error VERSION is undefined) -endif -ifndef REPOSITORY - $(error REPOSITORY is undefined) -endif - @$(eval FILE := $(@:publish-%=%)) - @$(eval COMPONENT := $(if $(filter %.debug.wasm,$(FILE)),$(FILE:%.debug.wasm=%),$(FILE:%.wasm=%))) - @$(eval TITLE := $(if $(filter %.debug.wasm,$(FILE)),$(COMPONENT) (debug),$(COMPONENT))) - @$(eval DESCRIPTION := $(shell head -n 3 "lib/${FILE}.md" | tail -n 1)) - @$(eval REVISION := $(shell git rev-parse HEAD)$(shell git diff --quiet HEAD && echo "+dirty")) - @$(eval COMPONENT_VERSION := $(if $(filter %.debug.wasm,$(FILE)),${VERSION}+debug,${VERSION})) - @$(eval TAG := $(patsubst v%,%,$(subst +,_,$(COMPONENT_VERSION)))) - @$(eval IMAGE := $(if $(filter interface.wasm,$(FILE)),${REPOSITORY}:${TAG},${REPOSITORY}/${COMPONENT}:${TAG})) - @echo "::group::${FILE} -> ${IMAGE}" - @DIGEST=$$( \ - wkg oci push \ - --annotation "org.opencontainers.image.title=${TITLE}" \ - --annotation "org.opencontainers.image.description=${DESCRIPTION}" \ - --annotation "org.opencontainers.image.version=${COMPONENT_VERSION}" \ - --annotation "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}.git" \ - --annotation "org.opencontainers.image.revision=${REVISION}" \ - --annotation "org.opencontainers.image.licenses=Apache-2.0" \ - "${IMAGE}" \ - "lib/${FILE}" \ - 2>&1 \ - | tee /dev/stderr \ - | grep -o 'sha256:[a-f0-9]\{64\}' \ - ) ; \ - cosign sign --yes "${IMAGE}@$${DIGEST}" - @echo "::endgroup::" +.PHONY: test +test: components + cargo test --workspace diff --git a/README.md b/README.md index d6ca200..c048e2e 100644 --- a/README.md +++ b/README.md @@ -23,13 +23,16 @@ A [dev container](https://containers.dev) is available that contains the necessa Prereqs: - a rust toolchain -- [`cargo component`](https://github.com/bytecodealliance/cargo-component) -- [`wkg`](https://github.com/bytecodealliance/wasm-pkg-tools) +- [`cargo-binstall`](https://github.com/cargo-bins/cargo-binstall), optional, to download prebuilt tools instead of building them ```sh make components ``` +The build creates each component in [`components`](./components) into `target/components`, e.g. the levels component at `target/components/levels/levels.wasm`, along with `target/components/interface.wasm`, the `componentized:logging` WIT package. Each component is also built with debug info, e.g. `target/components/levels/levels.debug.wasm`. + +The cli tools the build uses, [`wasm-tools`](https://github.com/bytecodealliance/wasm-tools) and [`wkg`](https://github.com/bytecodealliance/wasm-pkg-tools), are pinned in [`tools/Cargo.toml`](./tools/Cargo.toml) and installed into `target/tools/`, e.g. `target/tools/aarch64-apple-darwin`, as needed, or ahead of time with `make tools`. Dependabot bumps the pinned versions. + ## Community ### Code of Conduct diff --git a/components/levels/src/lib.rs b/components/levels/src/lib.rs index d87078a..69f75f5 100644 --- a/components/levels/src/lib.rs +++ b/components/levels/src/lib.rs @@ -1,5 +1,3 @@ -#![no_main] - use std::collections::HashMap; use exports::wasi::logging::logging::{Guest, Level}; diff --git a/components/to-stdout/src/lib.rs b/components/to-stdout/src/lib.rs index ae58ab5..d85ea80 100644 --- a/components/to-stdout/src/lib.rs +++ b/components/to-stdout/src/lib.rs @@ -1,5 +1,3 @@ -#![no_main] - use chrono::DateTime; use exports::wasi::logging::logging::{Guest, Level}; diff --git a/components/wit/deps/wasi-cli-0.3.0/package.wit b/components/wit/deps/wasi-cli-0.3.0/package.wit deleted file mode 100644 index 7aae56c..0000000 --- a/components/wit/deps/wasi-cli-0.3.0/package.wit +++ /dev/null @@ -1,256 +0,0 @@ -package wasi:cli@0.3.0; - -@since(version = 0.3.0) -interface environment { - /// Get the POSIX-style environment variables. - /// - /// Each environment variable is provided as a pair of string variable names - /// and string value. - /// - /// Morally, these are a value import, but until value imports are available - /// in the component model, this import function should return the same - /// values each time it is called. - @since(version = 0.3.0) - get-environment: func() -> list>; - - /// Get the POSIX-style arguments to the program. - @since(version = 0.3.0) - get-arguments: func() -> list; - - /// Return a path that programs should use as their initial current working - /// directory, interpreting `.` as shorthand for this. - @since(version = 0.3.0) - get-initial-cwd: func() -> option; -} - -@since(version = 0.3.0) -interface exit { - /// Exit the current instance and any linked instances. - @since(version = 0.3.0) - exit: func(status: result); - - /// Exit the current instance and any linked instances, reporting the - /// specified status code to the host. - /// - /// The meaning of the code depends on the context, with 0 usually meaning - /// "success", and other values indicating various types of failure. - /// - /// This function does not return; the effect is analogous to a trap, but - /// without the connotation that something bad has happened. - @since(version = 0.3.0) - exit-with-code: func(status-code: u8); -} - -@since(version = 0.3.0) -interface run { - /// Run the program. - @since(version = 0.3.0) - run: async func() -> result; -} - -@since(version = 0.3.0) -interface types { - @since(version = 0.3.0) - enum error-code { - /// Input/output error - io, - /// Invalid or incomplete multibyte or wide character - illegal-byte-sequence, - /// Broken pipe - pipe, - } -} - -@since(version = 0.3.0) -interface stdin { - use types.{error-code}; - - /// Return a stream for reading from stdin. - /// - /// This function returns a stream which provides data read from stdin, - /// and a future to signal read results. - /// - /// If the stream's readable end is dropped the future will resolve to success. - /// - /// If the stream's writable end is dropped the future will either resolve to - /// success if stdin was closed by the writer or to an error-code if reading - /// failed for some other reason. - /// - /// Multiple streams may be active at the same time. The behavior of concurrent - /// reads is implementation-specific. - @since(version = 0.3.0) - read-via-stream: func() -> tuple, future>>; -} - -@since(version = 0.3.0) -interface stdout { - use types.{error-code}; - - /// Write the given stream to stdout. - /// - /// If the stream's writable end is dropped this function will either return - /// success once the entire contents of the stream have been written or an - /// error-code representing a failure. - /// - /// Otherwise if there is an error the readable end of the stream will be - /// dropped and this function will return an error-code. - @since(version = 0.3.0) - write-via-stream: func(data: stream) -> future>; -} - -@since(version = 0.3.0) -interface stderr { - use types.{error-code}; - - /// Write the given stream to stderr. - /// - /// If the stream's writable end is dropped this function will either return - /// success once the entire contents of the stream have been written or an - /// error-code representing a failure. - /// - /// Otherwise if there is an error the readable end of the stream will be - /// dropped and this function will return an error-code. - @since(version = 0.3.0) - write-via-stream: func(data: stream) -> future>; -} - -/// Terminal input. -/// -/// In the future, this may include functions for disabling echoing, -/// disabling input buffering so that keyboard events are sent through -/// immediately, querying supported features, and so on. -@since(version = 0.3.0) -interface terminal-input { - /// The input side of a terminal. - @since(version = 0.3.0) - resource terminal-input; -} - -/// Terminal output. -/// -/// In the future, this may include functions for querying the terminal -/// size, being notified of terminal size changes, querying supported -/// features, and so on. -@since(version = 0.3.0) -interface terminal-output { - /// The output side of a terminal. - @since(version = 0.3.0) - resource terminal-output; -} - -/// An interface providing an optional `terminal-input` for stdin as a -/// link-time authority. -@since(version = 0.3.0) -interface terminal-stdin { - @since(version = 0.3.0) - use terminal-input.{terminal-input}; - - /// If stdin is connected to a terminal, return a `terminal-input` handle - /// allowing further interaction with it. - @since(version = 0.3.0) - get-terminal-stdin: func() -> option; -} - -/// An interface providing an optional `terminal-output` for stdout as a -/// link-time authority. -@since(version = 0.3.0) -interface terminal-stdout { - @since(version = 0.3.0) - use terminal-output.{terminal-output}; - - /// If stdout is connected to a terminal, return a `terminal-output` handle - /// allowing further interaction with it. - @since(version = 0.3.0) - get-terminal-stdout: func() -> option; -} - -/// An interface providing an optional `terminal-output` for stderr as a -/// link-time authority. -@since(version = 0.3.0) -interface terminal-stderr { - @since(version = 0.3.0) - use terminal-output.{terminal-output}; - - /// If stderr is connected to a terminal, return a `terminal-output` handle - /// allowing further interaction with it. - @since(version = 0.3.0) - get-terminal-stderr: func() -> option; -} - -@since(version = 0.3.0) -world imports { - @since(version = 0.3.0) - import environment; - @since(version = 0.3.0) - import exit; - @since(version = 0.3.0) - import types; - @since(version = 0.3.0) - import stdin; - @since(version = 0.3.0) - import stdout; - @since(version = 0.3.0) - import stderr; - @since(version = 0.3.0) - import terminal-input; - @since(version = 0.3.0) - import terminal-output; - @since(version = 0.3.0) - import terminal-stdin; - @since(version = 0.3.0) - import terminal-stdout; - @since(version = 0.3.0) - import terminal-stderr; - import wasi:clocks/types@0.3.0; - import wasi:clocks/monotonic-clock@0.3.0; - import wasi:clocks/system-clock@0.3.0; - @unstable(feature = clocks-timezone) - import wasi:clocks/timezone@0.3.0; - import wasi:filesystem/types@0.3.0; - import wasi:filesystem/preopens@0.3.0; - import wasi:sockets/types@0.3.0; - import wasi:sockets/ip-name-lookup@0.3.0; - import wasi:random/random@0.3.0; - import wasi:random/insecure@0.3.0; - import wasi:random/insecure-seed@0.3.0; -} -@since(version = 0.3.0) -world command { - @since(version = 0.3.0) - import environment; - @since(version = 0.3.0) - import exit; - @since(version = 0.3.0) - import types; - @since(version = 0.3.0) - import stdin; - @since(version = 0.3.0) - import stdout; - @since(version = 0.3.0) - import stderr; - @since(version = 0.3.0) - import terminal-input; - @since(version = 0.3.0) - import terminal-output; - @since(version = 0.3.0) - import terminal-stdin; - @since(version = 0.3.0) - import terminal-stdout; - @since(version = 0.3.0) - import terminal-stderr; - import wasi:clocks/types@0.3.0; - import wasi:clocks/monotonic-clock@0.3.0; - import wasi:clocks/system-clock@0.3.0; - @unstable(feature = clocks-timezone) - import wasi:clocks/timezone@0.3.0; - import wasi:filesystem/types@0.3.0; - import wasi:filesystem/preopens@0.3.0; - import wasi:sockets/types@0.3.0; - import wasi:sockets/ip-name-lookup@0.3.0; - import wasi:random/random@0.3.0; - import wasi:random/insecure@0.3.0; - import wasi:random/insecure-seed@0.3.0; - - @since(version = 0.3.0) - export run; -} diff --git a/components/wit/deps/wasi-clocks-0.3.0/package.wit b/components/wit/deps/wasi-clocks-0.3.0/package.wit deleted file mode 100644 index d8b8cfe..0000000 --- a/components/wit/deps/wasi-clocks-0.3.0/package.wit +++ /dev/null @@ -1,161 +0,0 @@ -package wasi:clocks@0.3.0; - -/// This interface common types used throughout wasi:clocks. -@since(version = 0.3.0) -interface types { - /// A duration of time, in nanoseconds. - @since(version = 0.3.0) - type duration = u64; -} - -/// WASI Monotonic Clock is a clock API intended to let users measure elapsed -/// time. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -/// -/// A monotonic clock is a clock which has an unspecified initial value, and -/// successive reads of the clock will produce non-decreasing values. -@since(version = 0.3.0) -interface monotonic-clock { - use types.{duration}; - - /// A mark on a monotonic clock is a number of nanoseconds since an - /// unspecified initial value, and can only be compared to instances from - /// the same monotonic-clock. - @since(version = 0.3.0) - type mark = u64; - - /// Read the current value of the clock. - /// - /// The clock is monotonic, therefore calling this function repeatedly will - /// produce a sequence of non-decreasing values. - /// - /// For completeness, this function traps if it's not possible to represent - /// the value of the clock in a `mark`. Consequently, implementations - /// should ensure that the starting time is low enough to avoid the - /// possibility of overflow in practice. - @since(version = 0.3.0) - now: func() -> mark; - - /// Query the resolution of the clock. Returns the duration of time - /// corresponding to a clock tick. - @since(version = 0.3.0) - get-resolution: func() -> duration; - - /// Wait until the specified mark has occurred. - @since(version = 0.3.0) - wait-until: async func(when: mark); - - /// Wait for the specified duration to elapse. - @since(version = 0.3.0) - wait-for: async func(how-long: duration); -} - -/// WASI System Clock is a clock API intended to let users query the current -/// time. The clock is not necessarily monotonic as it may be reset. -/// -/// It is intended to be portable at least between Unix-family platforms and -/// Windows. -/// -/// External references may be reset, so this clock is not necessarily -/// monotonic, making it unsuitable for measuring elapsed time. -/// -/// It is intended for reporting the current date and time for humans. -@since(version = 0.3.0) -interface system-clock { - use types.{duration}; - - /// An "instant", or "exact time", is a point in time without regard to any - /// time zone: just the time since a particular external reference point, - /// often called an "epoch". - /// - /// Here, the epoch is 1970-01-01T00:00:00Z, also known as - /// [POSIX's Seconds Since the Epoch], also known as [Unix Time]. - /// - /// Note that even if the seconds field is negative, incrementing - /// nanoseconds always represents moving forwards in time. - /// For example, `{ -1 seconds, 999999999 nanoseconds }` represents the - /// instant one nanosecond before the epoch. - /// For more on various different ways to represent time, see - /// https://tc39.es/proposal-temporal/docs/timezone.html - /// - /// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 - /// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time - @since(version = 0.3.0) - record instant { - seconds: s64, - nanoseconds: u32, - } - - /// Read the current value of the clock. - /// - /// This clock is not monotonic, therefore calling this function repeatedly - /// will not necessarily produce a sequence of non-decreasing values. - /// - /// The nanoseconds field of the output is always less than 1000000000. - @since(version = 0.3.0) - now: func() -> instant; - - /// Query the resolution of the clock. Returns the smallest duration of time - /// that the implementation permits distinguishing. - @since(version = 0.3.0) - get-resolution: func() -> duration; -} - -@unstable(feature = clocks-timezone) -interface timezone { - @unstable(feature = clocks-timezone) - use system-clock.{instant}; - - /// Return the IANA identifier of the currently configured timezone. This - /// should be an identifier from the IANA Time Zone Database. - /// - /// For displaying to a user, the identifier should be converted into a - /// localized name by means of an internationalization API. - /// - /// If the implementation does not expose an actual timezone, or is unable - /// to provide mappings from times to deltas between the configured timezone - /// and UTC, or determining the current timezone fails, or the timezone does - /// not have an IANA identifier, this returns nothing. - @unstable(feature = clocks-timezone) - iana-id: func() -> option; - - /// The number of nanoseconds difference between UTC time and the local - /// time of the currently configured timezone, at the exact time of - /// `instant`. - /// - /// The magnitude of the returned value will always be less than - /// 86,400,000,000,000 which is the number of nanoseconds in a day - /// (24*60*60*1e9). - /// - /// If the implementation does not expose an actual timezone, or is unable - /// to provide mappings from times to deltas between the configured timezone - /// and UTC, or determining the current timezone fails, this returns - /// nothing. - @unstable(feature = clocks-timezone) - utc-offset: func(when: instant) -> option; - - /// Returns a string that is suitable to assist humans in debugging whether - /// any timezone is available, and if so, which. This may be the same string - /// as `iana-id`, or a formatted representation of the UTC offset such as - /// `-04:00`, or something else. - /// - /// WARNING: The returned string should not be consumed mechanically! It may - /// change across platforms, hosts, or other implementation details. Parsing - /// this string is a major platform-compatibility hazard. - @unstable(feature = clocks-timezone) - to-debug-string: func() -> string; -} - -@since(version = 0.3.0) -world imports { - @since(version = 0.3.0) - import types; - @since(version = 0.3.0) - import monotonic-clock; - @since(version = 0.3.0) - import system-clock; - @unstable(feature = clocks-timezone) - import timezone; -} diff --git a/components/wit/deps/wasi-config-0.2.0-rc.1/package.wit b/components/wit/deps/wasi-config-0.2.0-rc.1/package.wit deleted file mode 100644 index d8950ee..0000000 --- a/components/wit/deps/wasi-config-0.2.0-rc.1/package.wit +++ /dev/null @@ -1,33 +0,0 @@ -package wasi:config@0.2.0-rc.1; - -interface store { - /// An error type that encapsulates the different errors that can occur fetching configuration values. - variant error { - /// This indicates an error from an "upstream" config source. - /// As this could be almost _anything_ (such as Vault, Kubernetes ConfigMaps, KeyValue buckets, etc), - /// the error message is a string. - upstream(string), - /// This indicates an error from an I/O operation. - /// As this could be almost _anything_ (such as a file read, network connection, etc), - /// the error message is a string. - /// Depending on how this ends up being consumed, - /// we may consider moving this to use the `wasi:io/error` type instead. - /// For simplicity right now in supporting multiple implementations, it is being left as a string. - io(string), - } - - /// Gets a configuration value of type `string` associated with the `key`. - /// - /// The value is returned as an `option`. If the key is not found, - /// `Ok(none)` is returned. If an error occurs, an `Err(error)` is returned. - get: func(key: string) -> result, error>; - - /// Gets a list of configuration key-value pairs of type `string`. - /// - /// If an error occurs, an `Err(error)` is returned. - get-all: func() -> result>, error>; -} - -world imports { - import store; -} diff --git a/components/wit/deps/wasi-filesystem-0.3.0/package.wit b/components/wit/deps/wasi-filesystem-0.3.0/package.wit deleted file mode 100644 index 492d2ca..0000000 --- a/components/wit/deps/wasi-filesystem-0.3.0/package.wit +++ /dev/null @@ -1,149 +0,0 @@ -package wasi:filesystem@0.3.0; - -interface types { - use wasi:clocks/system-clock@0.3.0.{instant}; - - type filesize = u64; - - variant descriptor-type { - block-device, - character-device, - directory, - fifo, - symbolic-link, - regular-file, - socket, - other(option), - } - - flags descriptor-flags { - read, - write, - file-integrity-sync, - data-integrity-sync, - requested-write-sync, - mutate-directory, - } - - flags path-flags { - symlink-follow, - } - - flags open-flags { - create, - directory, - exclusive, - truncate, - } - - type link-count = u64; - - record descriptor-stat { - %type: descriptor-type, - link-count: link-count, - size: filesize, - data-access-timestamp: option, - data-modification-timestamp: option, - status-change-timestamp: option, - } - - variant new-timestamp { - no-change, - now, - timestamp(instant), - } - - record directory-entry { - %type: descriptor-type, - name: string, - } - - variant error-code { - access, - already, - bad-descriptor, - busy, - deadlock, - quota, - exist, - file-too-large, - illegal-byte-sequence, - in-progress, - interrupted, - invalid, - io, - is-directory, - loop, - too-many-links, - message-size, - name-too-long, - no-device, - no-entry, - no-lock, - insufficient-memory, - insufficient-space, - not-directory, - not-empty, - not-recoverable, - unsupported, - no-tty, - no-such-device, - overflow, - not-permitted, - pipe, - read-only, - invalid-seek, - text-file-busy, - cross-device, - other(option), - } - - enum advice { - normal, - sequential, - random, - will-need, - dont-need, - no-reuse, - } - - record metadata-hash-value { - lower: u64, - upper: u64, - } - - resource descriptor { - read-via-stream: func(offset: filesize) -> tuple, future>>; - write-via-stream: func(data: stream, offset: filesize) -> future>; - append-via-stream: func(data: stream) -> future>; - advise: async func(offset: filesize, length: filesize, advice: advice) -> result<_, error-code>; - sync-data: async func() -> result<_, error-code>; - get-flags: async func() -> result; - get-type: async func() -> result; - set-size: async func(size: filesize) -> result<_, error-code>; - set-times: async func(data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>; - read-directory: func() -> tuple, future>>; - sync: async func() -> result<_, error-code>; - create-directory-at: async func(path: string) -> result<_, error-code>; - stat: async func() -> result; - stat-at: async func(path-flags: path-flags, path: string) -> result; - set-times-at: async func(path-flags: path-flags, path: string, data-access-timestamp: new-timestamp, data-modification-timestamp: new-timestamp) -> result<_, error-code>; - link-at: async func(old-path-flags: path-flags, old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>; - open-at: async func(path-flags: path-flags, path: string, open-flags: open-flags, %flags: descriptor-flags) -> result; - readlink-at: async func(path: string) -> result; - remove-directory-at: async func(path: string) -> result<_, error-code>; - rename-at: async func(old-path: string, new-descriptor: borrow, new-path: string) -> result<_, error-code>; - symlink-at: async func(old-path: string, new-path: string) -> result<_, error-code>; - unlink-file-at: async func(path: string) -> result<_, error-code>; - is-same-object: async func(other: borrow) -> bool; - metadata-hash: async func() -> result; - metadata-hash-at: async func(path-flags: path-flags, path: string) -> result; - } -} - -interface preopens { - use types.{descriptor}; - - get-directories: func() -> list>; -} - diff --git a/components/wit/deps/wasi-logging-0.1.0-draft/package.wit b/components/wit/deps/wasi-logging-0.1.0-draft/package.wit deleted file mode 100644 index 164cb5b..0000000 --- a/components/wit/deps/wasi-logging-0.1.0-draft/package.wit +++ /dev/null @@ -1,36 +0,0 @@ -package wasi:logging@0.1.0-draft; - -/// WASI Logging is a logging API intended to let users emit log messages with -/// simple priority levels and context values. -interface logging { - /// A log level, describing a kind of message. - enum level { - /// Describes messages about the values of variables and the flow of - /// control within a program. - trace, - /// Describes messages likely to be of interest to someone debugging a - /// program. - debug, - /// Describes messages likely to be of interest to someone monitoring a - /// program. - info, - /// Describes messages indicating hazardous situations. - warn, - /// Describes messages indicating serious errors. - error, - /// Describes messages indicating fatal errors. - critical, - } - - /// Emit a log message. - /// - /// A log message has a `level` describing what kind of message is being - /// sent, a context, which is an uninterpreted string meant to help - /// consumers group similar messages, and a string containing the message - /// text. - log: func(level: level, context: string, message: string); -} - -world imports { - import logging; -} diff --git a/components/wit/deps/wasi-random-0.3.0/package.wit b/components/wit/deps/wasi-random-0.3.0/package.wit deleted file mode 100644 index f6cfb81..0000000 --- a/components/wit/deps/wasi-random-0.3.0/package.wit +++ /dev/null @@ -1,18 +0,0 @@ -package wasi:random@0.3.0; - -interface random { - get-random-bytes: func(max-len: u64) -> list; - - get-random-u64: func() -> u64; -} - -interface insecure { - get-insecure-random-bytes: func(max-len: u64) -> list; - - get-insecure-random-u64: func() -> u64; -} - -interface insecure-seed { - get-insecure-seed: func() -> tuple; -} - diff --git a/components/wit/deps/wasi-sockets-0.3.0/package.wit b/components/wit/deps/wasi-sockets-0.3.0/package.wit deleted file mode 100644 index da14ae8..0000000 --- a/components/wit/deps/wasi-sockets-0.3.0/package.wit +++ /dev/null @@ -1,116 +0,0 @@ -package wasi:sockets@0.3.0; - -interface types { - use wasi:clocks/types@0.3.0.{duration}; - - variant error-code { - access-denied, - not-supported, - invalid-argument, - out-of-memory, - timeout, - invalid-state, - address-not-bindable, - address-in-use, - remote-unreachable, - connection-refused, - connection-broken, - connection-reset, - connection-aborted, - datagram-too-large, - other(option), - } - - enum ip-address-family { - ipv4, - ipv6, - } - - type ipv4-address = tuple; - - type ipv6-address = tuple; - - variant ip-address { - ipv4(ipv4-address), - ipv6(ipv6-address), - } - - record ipv4-socket-address { - port: u16, - address: ipv4-address, - } - - record ipv6-socket-address { - port: u16, - flow-info: u32, - address: ipv6-address, - scope-id: u32, - } - - variant ip-socket-address { - ipv4(ipv4-socket-address), - ipv6(ipv6-socket-address), - } - - resource tcp-socket { - create: static func(address-family: ip-address-family) -> result; - bind: func(local-address: ip-socket-address) -> result<_, error-code>; - connect: async func(remote-address: ip-socket-address) -> result<_, error-code>; - listen: func() -> result, error-code>; - send: func(data: stream) -> future>; - receive: func() -> tuple, future>>; - get-local-address: func() -> result; - get-remote-address: func() -> result; - get-is-listening: func() -> bool; - get-address-family: func() -> ip-address-family; - set-listen-backlog-size: func(value: u64) -> result<_, error-code>; - get-keep-alive-enabled: func() -> result; - set-keep-alive-enabled: func(value: bool) -> result<_, error-code>; - get-keep-alive-idle-time: func() -> result; - set-keep-alive-idle-time: func(value: duration) -> result<_, error-code>; - get-keep-alive-interval: func() -> result; - set-keep-alive-interval: func(value: duration) -> result<_, error-code>; - get-keep-alive-count: func() -> result; - set-keep-alive-count: func(value: u32) -> result<_, error-code>; - get-hop-limit: func() -> result; - set-hop-limit: func(value: u8) -> result<_, error-code>; - get-receive-buffer-size: func() -> result; - set-receive-buffer-size: func(value: u64) -> result<_, error-code>; - get-send-buffer-size: func() -> result; - set-send-buffer-size: func(value: u64) -> result<_, error-code>; - } - - resource udp-socket { - create: static func(address-family: ip-address-family) -> result; - bind: func(local-address: ip-socket-address) -> result<_, error-code>; - connect: func(remote-address: ip-socket-address) -> result<_, error-code>; - disconnect: func() -> result<_, error-code>; - send: async func(data: list, remote-address: option) -> result<_, error-code>; - receive: async func() -> result, ip-socket-address>, error-code>; - get-local-address: func() -> result; - get-remote-address: func() -> result; - get-address-family: func() -> ip-address-family; - get-unicast-hop-limit: func() -> result; - set-unicast-hop-limit: func(value: u8) -> result<_, error-code>; - get-receive-buffer-size: func() -> result; - set-receive-buffer-size: func(value: u64) -> result<_, error-code>; - get-send-buffer-size: func() -> result; - set-send-buffer-size: func(value: u64) -> result<_, error-code>; - } -} - -interface ip-name-lookup { - use types.{ip-address}; - - variant error-code { - access-denied, - invalid-argument, - name-unresolvable, - temporary-resolver-failure, - permanent-resolver-failure, - other(option), - } - - resolve-addresses: async func(name: string) -> result, error-code>; -} - diff --git a/lib/.gitignore b/lib/.gitignore deleted file mode 100644 index 902f891..0000000 --- a/lib/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*.md -*.wasm diff --git a/make/components.mk b/make/components.mk new file mode 100644 index 0000000..012e5b8 --- /dev/null +++ b/make/components.mk @@ -0,0 +1,76 @@ +COMPONENTS_DIR := target/components + +COMPONENTS = $(sort $(foreach file,$(wildcard $(addprefix components/*/,wit/*.constants.wit *.properties *.wac *.wkg Cargo.toml)),$(word 2,$(subst /, ,$(file))))) + +.PHONY: clean-components +clean-components: clean-wit + rm -rf ${COMPONENTS_DIR} + +.PHONY: components +components: ${COMPONENTS_DIR}/interface.wasm $(foreach component,$(COMPONENTS),${COMPONENTS_DIR}/$(component)/$(component).wasm ${COMPONENTS_DIR}/$(component)/$(component).debug.wasm) + +define BUILD_COMPONENT + +.PHONY: components/$1 +components/$1: ${COMPONENTS_DIR}/$1/$1.wasm ${COMPONENTS_DIR}/$1/$1.debug.wasm + +ifneq ($(wildcard components/$1/wit/$1.constants.wit),) + +${COMPONENTS_DIR}/$1/$1.wasm: components/$1/wit/deps ${COMPONENTS_DIR}/$1/README.md | $(call tool,componentized-constants-cli) + $(CONSTANTS) --wit components/$1/wit -o ${COMPONENTS_DIR}/$1/$1.wasm + +${COMPONENTS_DIR}/$1/$1.debug.wasm: components/$1/wit/deps ${COMPONENTS_DIR}/$1/README.md | $(call tool,componentized-constants-cli) + $(CONSTANTS) --wit components/$1/wit -o ${COMPONENTS_DIR}/$1/$1.debug.wasm + +else ifneq ($(wildcard components/$1/$1.properties),) + +${COMPONENTS_DIR}/$1/$1.wasm: components/$1/$1.properties ${COMPONENTS_DIR}/$1/README.md | $(call tool,componentized-static-config-cli) + $(STATIC_CONFIG) -f components/$1/$1.properties -o ${COMPONENTS_DIR}/$1/$1.wasm + +${COMPONENTS_DIR}/$1/$1.debug.wasm: components/$1/$1.properties ${COMPONENTS_DIR}/$1/README.md | $(call tool,componentized-static-config-cli) + $(STATIC_CONFIG) -f components/$1/$1.properties -o ${COMPONENTS_DIR}/$1/$1.debug.wasm + +else ifneq ($(wildcard components/$1/$1.wac),) + +# the local packages the composition instantiates, e.g. `new local:latch-n2 { ... }` +WAC_DEPS_$1 := $$(shell grep -v '^\s*//' components/$1/$1.wac | grep -oE 'local:[a-z0-9-]+' | sed 's/^local://' | sort -u) + +${COMPONENTS_DIR}/$1/$1.wasm: components/$1/$1.wac $$(foreach component,$$(WAC_DEPS_$1),$${COMPONENTS_DIR}/$$(component)/$$(component).wasm) ${COMPONENTS_DIR}/$1/README.md | $(call tool,wac-cli) + $(WAC) compose $$(foreach component,$$(WAC_DEPS_$1),-d local:$$(component)=$${COMPONENTS_DIR}/$$(component)/$$(component).wasm) -o ${COMPONENTS_DIR}/$1/$1.wasm components/$1/$1.wac + +${COMPONENTS_DIR}/$1/$1.debug.wasm: components/$1/$1.wac $$(foreach component,$$(WAC_DEPS_$1),$${COMPONENTS_DIR}/$$(component)/$$(component).debug.wasm) ${COMPONENTS_DIR}/$1/README.md | $(call tool,wac-cli) + $(WAC) compose $$(foreach component,$$(WAC_DEPS_$1),-d local:$$(component)=$${COMPONENTS_DIR}/$$(component)/$$(component).debug.wasm) -o ${COMPONENTS_DIR}/$1/$1.debug.wasm components/$1/$1.wac + +else ifneq ($(wildcard components/$1/$1.wkg),) + +${COMPONENTS_DIR}/$1/$1.wasm: components/$1/$1.wkg ${COMPONENTS_DIR}/$1/README.md | $(call tool,wkg) + $(WKG) oci pull $(shell cat components/$1/$1.wkg 2> /dev/null | head -1) -o ${COMPONENTS_DIR}/$1/$1.wasm + +${COMPONENTS_DIR}/$1/$1.debug.wasm: components/$1/$1.wkg ${COMPONENTS_DIR}/$1/README.md | $(call tool,wkg) + $(WKG) oci pull $(shell cat components/$1/$1.wkg 2> /dev/null | tail -1 2> /dev/null) -o ${COMPONENTS_DIR}/$1/$1.debug.wasm + +# cargo is checked last, other strategies may have a Cargo.toml for tests of non-rust sources +else ifneq ($(wildcard components/$1/Cargo.toml),) + +${COMPONENTS_DIR}/$1/$1.wasm: Cargo.toml Cargo.lock components/wit/deps $(shell find components/$1 -type f) $(shell find crates -type f 2> /dev/null) ${COMPONENTS_DIR}/$1/README.md | $(call tool,wasm-tools) + cargo build -p $1 --target wasm32-unknown-unknown --release + $(WASM_TOOLS) component new target/wasm32-unknown-unknown/release/$(subst -,_,$1).wasm -o ${COMPONENTS_DIR}/$1/$1.wasm + +${COMPONENTS_DIR}/$1/$1.debug.wasm: Cargo.toml Cargo.lock components/wit/deps $(shell find components/$1 -type f) $(shell find crates -type f 2> /dev/null) ${COMPONENTS_DIR}/$1/README.md | $(call tool,wasm-tools) + cargo build --target wasm32-unknown-unknown -p $1 + $(WASM_TOOLS) component new target/wasm32-unknown-unknown/debug/$(subst -,_,$1).wasm -o ${COMPONENTS_DIR}/$1/$1.debug.wasm + +endif + +${COMPONENTS_DIR}/$1/README.md: components/$1/README.md + @mkdir -p ${COMPONENTS_DIR}/$1 + @cp components/$1/README.md ${COMPONENTS_DIR}/$1/README.md + +endef + +$(foreach component,$(COMPONENTS),$(eval $(call BUILD_COMPONENT,$(component)))) + +${COMPONENTS_DIR}/interface.wasm: wit/deps README.md | $(call tool,wkg) + @mkdir -p ${COMPONENTS_DIR} + $(WKG) build -o ${COMPONENTS_DIR}/interface.wasm + @cp README.md ${COMPONENTS_DIR}/README.md diff --git a/make/pinned.jq b/make/pinned.jq new file mode 100644 index 0000000..78fc559 --- /dev/null +++ b/make/pinned.jq @@ -0,0 +1,6 @@ +# generates target/tools/pinned.mk from `cargo metadata --no-deps` of tools/Cargo.toml, see make/tools.mk +.packages[0] as $tools +| ($tools.dependencies[].name | select($tools.metadata.bins[.] == null) | error("\(.) is missing from [package.metadata.bins] in tools/Cargo.toml")), + "TOOLS := \([$tools.dependencies[].name] | join(" "))", + "TOOLS_PINNED := \([$tools.dependencies[] | "\(.name)@\(.req | ltrimstr("="))"] | join(" "))", + ($tools.metadata.bins[][] | "\(ascii_upcase | gsub("-"; "_")) := $(TOOLS_BIN)/\(.)") diff --git a/make/publish.mk b/make/publish.mk new file mode 100644 index 0000000..2b3a472 --- /dev/null +++ b/make/publish.mk @@ -0,0 +1,15 @@ +# sign published components with cosign, `SIGN=false` to push without signing, e.g. to a local registry +SIGN ?= true +# append each published file and its image to this file, e.g. `gate.wasm ghcr.io/componentized/http/gate:0.1.0@sha256:...` +PUBLISH_LOG ?= + +# the files that can be published, e.g. gate.wasm, published from target/components/gate/gate.wasm +PUBLISH_FILES := interface.wasm $(foreach component,$(filter-out dep-% test-%,$(COMPONENTS)),$(component).wasm $(component).debug.wasm) + +.PHONY: publish ## Publish each component in the target/components directory +publish: $(addprefix publish-,$(PUBLISH_FILES)) + +.PHONY: $(addprefix publish-,$(PUBLISH_FILES)) +$(addprefix publish-,$(PUBLISH_FILES)): publish-%: | $(call tool,wkg) + @VERSION="$(VERSION)" REPOSITORY="$(REPOSITORY)" COMPONENTS_DIR="$(COMPONENTS_DIR)" SIGN="$(SIGN)" PUBLISH_LOG="$(PUBLISH_LOG)" \ + scripts/publish.sh $* diff --git a/make/tools.mk b/make/tools.mk new file mode 100644 index 0000000..f408f38 --- /dev/null +++ b/make/tools.mk @@ -0,0 +1,53 @@ +TOOLS_DIR := target/tools/$(shell rustc --print host-tuple) +# absolute, tools also run from other directories, e.g. `cd components && wkg fetch` +TOOLS_BIN := $(abspath $(TOOLS_DIR))/bin +# for the scripts and tests the recipes run, they look up the tools on the PATH +export PATH := $(TOOLS_BIN):$(PATH) + +# the tools pinned in tools/Cargo.toml, generated when it changes, make restarts after generating it. +# Defines TOOLS, TOOLS_PINNED with the version of each tool, e.g. `wkg@0.16.1`, and a variable for +# each binary a tool installs, e.g. `WKG := $(TOOLS_BIN)/wkg`. Recipes run the pinned tools by path, +# make 3.81 runs a simple command without a shell and looks it up on its own PATH, before the export +# above, which would find a tool already on the system. +TOOLS_MK := target/tools/pinned.mk +include $(TOOLS_MK) + +# cargo binstall downloads prebuilt binaries, without it the tools are built with cargo install +CARGO_INSTALL := $(if $(shell command -v cargo-binstall 2> /dev/null),cargo binstall --no-confirm --disable-telemetry,cargo install) + +.PHONY: clean-tools +clean-tools: + rm -rf ${TOOLS_DIR} + +# each tool is a dependency of the tools package, the binaries it installs are listed in +# [package.metadata.bins] +$(TOOLS_MK): tools/Cargo.toml make/pinned.jq + @mkdir -p $(@D) + @set -o pipefail; cargo metadata --manifest-path tools/Cargo.toml --no-deps --format-version 1 | jq -r -f make/pinned.jq > $@.tmp + @mv $@.tmp $@ + +tool_version = $(patsubst $(1)@%,%,$(filter $(1)@%,$(TOOLS_PINNED))) +# a stamp naming the version of a tool installed in $(TOOLS_DIR)/bin, e.g. `wkg@0.16.1`, the binary +# does not say which version it is. Bumping the pinned version names a stamp that does not exist yet, +# so the tool is installed again. +tool = $(TOOLS_DIR)/.installed/$(1)@$(call tool_version,$(1)) + +.PHONY: tools ## Install the cli tools pinned in tools/Cargo.toml +tools: $(foreach name,$(TOOLS),$(call tool,$(name))) + +.PHONY: tools-path ## Print the directory of the installed tools for this platform, to add to the PATH +tools-path: + @echo $(TOOLS_BIN) + +define INSTALL_TOOL + +$(call tool,$1): + $(CARGO_INSTALL) --locked --root $(TOOLS_DIR) --version $(call tool_version,$1) $1 + @mkdir -p $$(@D) + @# only the installed version has a stamp, so going back to a previous version installs it again + @rm -f $$(@D)/$1@* + @touch $$@ + +endef + +$(foreach name,$(TOOLS),$(eval $(call INSTALL_TOOL,$(name)))) diff --git a/make/wit.mk b/make/wit.mk new file mode 100644 index 0000000..ac4971c --- /dev/null +++ b/make/wit.mk @@ -0,0 +1,28 @@ +# a path relative to the root of the repository, e.g. `wit` for `components/../wit` +relpath = $(if $(filter $(CURDIR),$(abspath $(1))),.,$(patsubst $(CURDIR)/%,%,$(abspath $(1)))) + +# directories with a wkg.toml, each fetches the dependencies of its wit directory into wit/deps, +# e.g. `.` and `components` +WKG_DIRS := $(sort $(patsubst ./%,%,$(patsubst %/,%,$(dir $(shell find . -name wkg.toml -not -path './target/*' -not -path '*/deps/*'))))) + +# the wit/deps directory of a directory with a wkg.toml, e.g. `wit/deps` for `.` +wit_deps = $(patsubst ./%,%,$(1)/wit/deps) + +WIT_DEPS := $(foreach dir,$(WKG_DIRS),$(call wit_deps,$(dir))) + +.PHONY: clean-wit ## Remove the fetched wit dependencies, fetched again by `make wit` +clean-wit: + rm -rf $(WIT_DEPS) + +.PHONY: wit +wit: $(WIT_DEPS) + +define FETCH_WIT + +# a package overridden with a local path, e.g. `{ path = "../wit" }`, has its dependencies fetched first +$(call wit_deps,$1): $1/wkg.toml $1/wkg.lock $(shell find $1/wit -type f -name "*.wit" -not -path "*/deps/*") $(foreach path,$(shell sed -n 's/.*path *= *"\(.*\)".*/\1/p' $1/wkg.toml),$(call relpath,$1/$(path))/deps) | $(call tool,wkg) + $(if $(filter .,$1),,cd $1 && )$(WKG) fetch + +endef + +$(foreach dir,$(WKG_DIRS),$(eval $(call FETCH_WIT,$(dir)))) diff --git a/scripts/bump-version.sh b/scripts/bump-version.sh new file mode 100755 index 0000000..f9fac0c --- /dev/null +++ b/scripts/bump-version.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +# Bump the version of the wit interface package. +# +# scripts/bump-version.sh +# +# Updates the package declaration and every reference to the package in tracked files, then +# refreshes the generated wit dependencies. Items whose `@since` names an unreleased (prerelease) +# version move to the new version, since they were never published under the old one. Items +# released under the old version keep their `@since`. +# +# 0.1.0-dev -> 0.1.0 releases 0.1.0, `@since(version = 0.1.0-dev)` becomes 0.1.0 +# 0.1.0 -> 0.2.0-dev starts 0.2.0, `@since(version = 0.1.0)` is unchanged + +set -euo pipefail + +cd "$(dirname "$0")/.." + +PACKAGE="${PACKAGE:-componentized:$(basename $(git rev-parse --show-toplevel))}" +SEMVER='^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$' + +new="${1:-}" +if [[ ! "$new" =~ $SEMVER ]]; then + echo "usage: $0 , e.g. 0.1.0 or 0.2.0-dev" >&2 + exit 1 +fi + +old=$(sed -n "s/^package ${PACKAGE}@\(.*\);$/\1/p" wit/worlds.wit) +if [[ -z "$old" ]]; then + echo "unable to find the ${PACKAGE} package declaration in wit/worlds.wit" >&2 + exit 1 +fi + +# succeeds when version $1 is lower than version $2, a prerelease is lower than its release +version_lt() { + local a_core="${1%%-*}" b_core="${2%%-*}" + local a_pre="" b_pre="" + [[ "$1" == *-* ]] && a_pre="${1#*-}" + [[ "$2" == *-* ]] && b_pre="${2#*-}" + if [[ "$a_core" != "$b_core" ]]; then + local IFS=. + local -a a=($a_core) b=($b_core) + for i in 0 1 2; do + (( a[i] < b[i] )) && return 0 + (( a[i] > b[i] )) && return 1 + done + fi + [[ -n "$a_pre" && -z "$b_pre" ]] && return 0 + [[ -z "$a_pre" && -n "$b_pre" ]] && return 1 + [[ -n "$a_pre" && "$a_pre" < "$b_pre" ]] +} + +if ! version_lt "$old" "$new"; then + echo "the new version ${new} must be greater than the current version ${old}" >&2 + exit 1 +fi + +# the bump-version workflow offers the current version as the default for the next bump, checked +# before changing anything +workflow=.github/workflows/bump-version.yaml +workflow_default="default: \"${old}\" # the current version, kept current by scripts/bump-version.sh" +if ! grep -qF "$workflow_default" "$workflow"; then + echo "unable to find the current version as the default in ${workflow}, expected: ${workflow_default}" >&2 + exit 1 +fi + +old_re="${old//./\\.}" +# references to the package or one of its interfaces, an interface named for a keyword is escaped +# with `%`, e.g. `componentized:logging/imports@0.3.0-dev` +ref_re="${PACKAGE}(/%?[a-z0-9-]+)?" +# the fetched wit dependencies and the wkg.lock files are left to `make wit`, wkg replaces the +# dependencies and updates the locks for the new version +files=$(git grep --untracked -l -E "${ref_re}@${old_re}" -- ':(exclude,glob)**/wit/deps/**' ':(exclude,glob)**/wkg.lock' || true) +for file in $files; do + sed -i.bak -E "s#(${ref_re})@${old_re}#\1@${new}#g" "$file" + rm "$file.bak" + echo "updated ${file}" +done + +if [[ "$old" == *-* ]]; then + files=$(git grep --untracked -l -F "@since(version = ${old})" -- 'wit/*.wit' || true) + for file in $files; do + sed -i.bak "s/@since(version = ${old_re})/@since(version = ${new})/g" "$file" + rm "$file.bak" + echo "updated @since in ${file}" + done +fi + +perl -pi -e 's{^(\s+)\Q'"${workflow_default}"'\E$}{${1}'"${workflow_default/\"${old}\"/\"${new}\"}"'}' "$workflow" +echo "updated the default version in ${workflow}" + +# regenerate the wit dependencies for the new version +make wit components test + +echo "bumped ${PACKAGE} from ${old} to ${new}" diff --git a/scripts/init-devcontainer.sh b/scripts/init-devcontainer.sh new file mode 100755 index 0000000..59f0186 --- /dev/null +++ b/scripts/init-devcontainer.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# Setup script run once for new devcontainers to init the environment. + +set -euo pipefail + +curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + +cargo check + +echo "export \"PATH=$(make -s tools-path):${PATH}\"" >> ~/.bashrc +make tools diff --git a/scripts/publish.sh b/scripts/publish.sh new file mode 100755 index 0000000..669c112 --- /dev/null +++ b/scripts/publish.sh @@ -0,0 +1,106 @@ +#!/usr/bin/env bash + +# Publish a built component to an OCI registry, and sign it with cosign. +# +# VERSION= REPOSITORY= scripts/publish.sh +# +# The file is one of the files built into the components directory, components are in a directory +# of their own, the interface is not, e.g. gate.wasm from target/components/gate/gate.wasm and +# interface.wasm from target/components/interface.wasm. The interface is published to the +# repository, each component to a repository of its own under it, a debug build is tagged with a +# `_debug` suffix. +# +# interface.wasm -> ${REPOSITORY}:0.1.0 +# gate.wasm -> ${REPOSITORY}/gate:0.1.0 +# gate.debug.wasm -> ${REPOSITORY}/gate:0.1.0_debug +# +# VERSION the version to publish, a leading `v` is dropped from the tag, e.g. v0.1.0 +# REPOSITORY the repository to publish to, e.g. ghcr.io/componentized/http +# GITHUB_REPOSITORY the GitHub repository the components are built from, e.g. componentized/http +# COMPONENTS_DIR the directory the components are built into, defaults to target/components +# SIGN sign the published components with cosign, `false` to push without signing, +# e.g. to a local registry +# PUBLISH_LOG append the published file and its image to this file, e.g. +# `gate.wasm ghcr.io/componentized/http/gate:0.1.0@sha256:...` + +set -euo pipefail + +cd "$(dirname "$0")/.." + +file="${1:-}" +if [[ -z "$file" ]]; then + echo "usage: $0 , e.g. interface.wasm or gate.wasm" >&2 + exit 1 +fi +: "${VERSION:?VERSION is undefined}" +: "${REPOSITORY:?REPOSITORY is undefined}" +GITHUB_REPOSITORY="${GITHUB_REPOSITORY:-componentized/$(basename "$(git rev-parse --show-toplevel)")}" +COMPONENTS_DIR="${COMPONENTS_DIR:-target/components}" +SIGN="${SIGN:-true}" +PUBLISH_LOG="${PUBLISH_LOG:-}" + +component="${file%.wasm}" +component="${component%.debug}" +debug="" +[[ "$file" == *.debug.wasm ]] && debug=true + +if [[ "$file" == interface.wasm ]]; then + component_file="$file" + title="${GITHUB_REPOSITORY/\//:}" +else + component_file="${component}/${file}" + title="${GITHUB_REPOSITORY/\//:}-${component}" +fi +[[ -n "$debug" ]] && title="${title} (debug)" + +# the description is the line following the title in the readme +readme="${COMPONENTS_DIR}/$(dirname "$component_file")/README.md" +description=$(sed -n 3p "$readme") + +commit=$(git rev-parse HEAD) +revision="$commit" +git diff --quiet HEAD || revision="${commit}+dirty" +url="https://github.com/${GITHUB_REPOSITORY}/tree/${commit}" +[[ -f "components/${component}/README.md" ]] && url="${url}/components/${component}" + +component_version="$VERSION" +[[ -n "$debug" ]] && component_version="${VERSION}+debug" +tag="${component_version#v}" +tag="${tag//+/_}" + +if [[ "$file" == interface.wasm ]]; then + image="${REPOSITORY}:${tag}" +else + image="${REPOSITORY}/${component}:${tag}" +fi + +echo "::group::${file} -> ${image}" + +digest=$( + wkg oci push \ + --annotation "org.opencontainers.image.title=${title}" \ + --annotation "org.opencontainers.image.description=${description}" \ + --annotation "org.opencontainers.image.version=${component_version}" \ + --annotation "org.opencontainers.image.url=${url}" \ + --annotation "org.opencontainers.image.source=https://github.com/${GITHUB_REPOSITORY}.git" \ + --annotation "org.opencontainers.image.revision=${revision}" \ + --annotation "org.opencontainers.image.licenses=Apache-2.0" \ + "$image" \ + "${COMPONENTS_DIR}/${component_file}" \ + 2>&1 \ + | tee /dev/stderr \ + | grep -o 'sha256:[a-f0-9]\{64\}' +) + +if [[ -n "$PUBLISH_LOG" ]]; then + size=$(wc -c < "${COMPONENTS_DIR}/${component_file}" | tr -d ' ') + echo "${file} ${size} ${image}@${digest}" >> "$PUBLISH_LOG" +fi + +if [[ "$SIGN" == true ]]; then + cosign sign --yes "${image}@${digest}" +else + echo "Not signing ${image}@${digest}, SIGN=${SIGN}" +fi + +echo "::endgroup::" diff --git a/tools/Cargo.toml b/tools/Cargo.toml new file mode 100644 index 0000000..f5cb4f1 --- /dev/null +++ b/tools/Cargo.toml @@ -0,0 +1,26 @@ +# The versions of the cli tools the build uses, installed by `make tools` with cargo binstall. +# +# This package is never built, it lists the tools as dependencies so dependabot bumps them. Each +# tool is pinned to an exact version with `=`, the Makefile installs that version. +[package] +name = "tools" +version = "0.0.0" +edition = "2024" +license = "Apache-2.0" +publish = false + +[lib] +path = "lib.rs" + +# the binaries each tool installs, the Makefile runs each by path from a variable named after it, +# e.g. `$(WASM_TOOLS)` for `wasm-tools` +[package.metadata.bins] +wasm-tools = ["wasm-tools"] +wkg = ["wkg"] + +[dependencies] +wasm-tools = "=1.261.0" +wkg = "=0.16.1" + +# not a member of the repository's workspace +[workspace] diff --git a/tools/lib.rs b/tools/lib.rs new file mode 100644 index 0000000..d3769d7 --- /dev/null +++ b/tools/lib.rs @@ -0,0 +1 @@ +//! Never built, see `Cargo.toml`. diff --git a/wit/deps/wasi-logging-0.1.0-draft/package.wit b/wit/deps/wasi-logging-0.1.0-draft/package.wit deleted file mode 100644 index 164cb5b..0000000 --- a/wit/deps/wasi-logging-0.1.0-draft/package.wit +++ /dev/null @@ -1,36 +0,0 @@ -package wasi:logging@0.1.0-draft; - -/// WASI Logging is a logging API intended to let users emit log messages with -/// simple priority levels and context values. -interface logging { - /// A log level, describing a kind of message. - enum level { - /// Describes messages about the values of variables and the flow of - /// control within a program. - trace, - /// Describes messages likely to be of interest to someone debugging a - /// program. - debug, - /// Describes messages likely to be of interest to someone monitoring a - /// program. - info, - /// Describes messages indicating hazardous situations. - warn, - /// Describes messages indicating serious errors. - error, - /// Describes messages indicating fatal errors. - critical, - } - - /// Emit a log message. - /// - /// A log message has a `level` describing what kind of message is being - /// sent, a context, which is an uninterpreted string meant to help - /// consumers group similar messages, and a string containing the message - /// text. - log: func(level: level, context: string, message: string); -} - -world imports { - import logging; -}