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
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ resolver = "2"
members = [
"components/*",
]
exclude = [
"components/wit",
]

[workspace.dependencies]
chrono = { git = "https://github.com/chronotope/chrono.git", branch = "0.5.x" }
Expand Down
43 changes: 28 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ SHELL := /bin/bash
export RUST_BACKTRACE ?= 1
export WASMTIME_BACKTRACE_DETAILS ?= 1

COMPONENTS = $(shell ls -1 components)
COMPONENTS = $(sort $(notdir $(patsubst %/,%,$(dir $(wildcard components/*/Cargo.toml)))))

.PHONY: all
all: components
Expand All @@ -14,20 +14,24 @@ clean:
rm -rf lib/*.wasm
rm -rf lib/*.wasm.md

.PHONY: test
test:
@echo "TODO add tests"

.PHONY: components
components: $(foreach component,$(COMPONENTS),lib/$(component).wasm $(foreach component,$(COMPONENTS),lib/$(component).debug.wasm))
components: lib/interface.wasm $(foreach component,$(COMPONENTS),lib/$(component).wasm lib/$(component).debug.wasm)

define BUILD_COMPONENT

.PHONY: components/$1
components/$1: lib/$1.wasm lib/$1.debug.wasm

lib/$1.wasm: Cargo.toml Cargo.lock wit/deps $(shell find components/$1 -type f)
lib/$1.wasm: Cargo.toml Cargo.lock components/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

lib/$1.debug.wasm: Cargo.toml Cargo.lock wit/deps $(shell find components/$1 -type f)
lib/$1.debug.wasm: Cargo.toml Cargo.lock components/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
Expand All @@ -36,15 +40,21 @@ 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
wit: wit/deps components/wit/deps

wit/deps: wkg.toml $(shell find wit -type f -name "*.wit" -not -path "deps")
wkg wit fetch
wkg fetch

components/wit/deps: wit/deps components/wkg.toml $(shell find components/wit -type f -name "*.wit" -not -path "deps")
( cd components && wkg fetch )

.PHONY: publish
publish: $(shell find lib -type f -name "*.wasm" -maxdepth 1 | sed -e 's:^lib/:publish-:g')
.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: publish-%
publish-%:
Expand All @@ -55,25 +65,28 @@ ifndef REPOSITORY
$(error REPOSITORY is undefined)
endif
@$(eval FILE := $(@:publish-%=%))
@$(eval COMPONENT := $(FILE:%.wasm=%))
@$(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 TAG := $(patsubst v%,%,$(subst +,_,$(VERSION))))
@$(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} -> ${REPOSITORY}/${COMPONENT}:${TAG}"
@echo "::group::${FILE} -> ${IMAGE}"
@DIGEST=$$( \
wkg oci push \
--annotation "org.opencontainers.image.title=${COMPONENT}" \
--annotation "org.opencontainers.image.title=${TITLE}" \
--annotation "org.opencontainers.image.description=${DESCRIPTION}" \
--annotation "org.opencontainers.image.version=${VERSION}" \
--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" \
"${REPOSITORY}/${COMPONENT}:${TAG}" \
"${IMAGE}" \
"lib/${FILE}" \
2>&1 \
| tee /dev/stderr \
| grep -o 'sha256:[a-f0-9]\{64\}' \
) ; \
cosign sign --yes "${REPOSITORY}/${COMPONENT}:${TAG}@$${DIGEST}"
cosign sign --yes "${IMAGE}@$${DIGEST}"
@echo "::endgroup::"
2 changes: 1 addition & 1 deletion components/chroot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ impl GuestDescriptor for FilesystemChrootDescriptor {
}

wit_bindgen::generate!({
path: "../../wit",
path: "../wit",
world: "filesystem",
merge_structurally_equal_types: true,
generate_all
Expand Down
2 changes: 1 addition & 1 deletion components/readonly/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ impl exports::wasi::filesystem::types::GuestDescriptor for ReadOnlyDescriptor {
}

wit_bindgen::generate!({
path: "../../wit",
path: "../wit",
world: "filesystem",
merge_structurally_equal_types: true,
generate_all
Expand Down
2 changes: 1 addition & 1 deletion components/tracing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ impl Display for types::Instant {
}

wit_bindgen::generate!({
path: "../../wit",
path: "../wit",
world: "filesystem",
merge_structurally_equal_types: true,
generate_all
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package componentized:filesystem@0.3.0-dev;

world imports {
import wasi:clocks/types@0.3.0;
import wasi:clocks/system-clock@0.3.0;
import wasi:filesystem/types@0.3.0;
import wasi:filesystem/preopens@0.3.0;
}
19 changes: 19 additions & 0 deletions components/wit/deps/wasi-clocks-0.3.0/package.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package wasi:clocks@0.3.0;

interface types {
type duration = u64;
}

interface system-clock {
use types.{duration};

record instant {
seconds: s64,
nanoseconds: u32,
}

now: func() -> instant;

get-resolution: func() -> duration;
}

Loading
Loading