feat: add dev-packages
Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
parent
451270f64b
commit
dee3421313
9
dev-packages/.rust-toolchain.toml
Normal file
9
dev-packages/.rust-toolchain.toml
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
[toolchain]
|
||||||
|
# Specify the Rust version to ensure consistency across environments
|
||||||
|
channel = "stable" # You can use "nightly" if your project requires nightly features
|
||||||
|
|
||||||
|
# Add required components
|
||||||
|
components = ["rust-src", "rust-std", "wasm32-wasi"]
|
||||||
|
|
||||||
|
# Specify the target
|
||||||
|
targets = ["wasm32-wasip1"]
|
10
dev-packages/.vscode/settings.json
vendored
Normal file
10
dev-packages/.vscode/settings.json
vendored
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"rust-analyzer.check.overrideCommand": [
|
||||||
|
"cargo",
|
||||||
|
"component",
|
||||||
|
"check",
|
||||||
|
"--workspace",
|
||||||
|
"--all-targets",
|
||||||
|
"--message-format=json"
|
||||||
|
],
|
||||||
|
}
|
254
dev-packages/Cargo.lock
generated
Normal file
254
dev-packages/Cargo.lock
generated
Normal file
@ -0,0 +1,254 @@
|
|||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "bitflags"
|
||||||
|
version = "2.6.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "cfg-if"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dev-packages"
|
||||||
|
version = "0.1.0"
|
||||||
|
dependencies = [
|
||||||
|
"dirs",
|
||||||
|
"minijinja",
|
||||||
|
"wit-bindgen-rt",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs"
|
||||||
|
version = "5.0.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "44c45a9d03d6676652bcb5e724c7e988de1acad23a711b5217ab9cbecbec2225"
|
||||||
|
dependencies = [
|
||||||
|
"dirs-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "dirs-sys"
|
||||||
|
version = "0.4.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "520f05a5cbd335fae5a99ff7a6ab8627577660ee5cfd6a94a6a929b52ff0321c"
|
||||||
|
dependencies = [
|
||||||
|
"libc",
|
||||||
|
"option-ext",
|
||||||
|
"redox_users",
|
||||||
|
"windows-sys",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "getrandom"
|
||||||
|
version = "0.2.15"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7"
|
||||||
|
dependencies = [
|
||||||
|
"cfg-if",
|
||||||
|
"libc",
|
||||||
|
"wasi",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libc"
|
||||||
|
version = "0.2.167"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "09d6582e104315a817dff97f75133544b2e094ee22447d2acf4a74e189ba06fc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "libredox"
|
||||||
|
version = "0.1.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c0ff37bd590ca25063e35af745c343cb7a0271906fb7b37e4813e8f79f00268d"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
"libc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "minijinja"
|
||||||
|
version = "2.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2c37e1b517d1dcd0e51dc36c4567b9d5a29262b3ec8da6cb5d35e27a8fb529b5"
|
||||||
|
dependencies = [
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "option-ext"
|
||||||
|
version = "0.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "proc-macro2"
|
||||||
|
version = "1.0.92"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
||||||
|
dependencies = [
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "quote"
|
||||||
|
version = "1.0.37"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "redox_users"
|
||||||
|
version = "0.4.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ba009ff324d1fc1b900bd1fdb31564febe58a8ccc8a6fdbb93b543d33b13ca43"
|
||||||
|
dependencies = [
|
||||||
|
"getrandom",
|
||||||
|
"libredox",
|
||||||
|
"thiserror",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde"
|
||||||
|
version = "1.0.217"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70"
|
||||||
|
dependencies = [
|
||||||
|
"serde_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "serde_derive"
|
||||||
|
version = "1.0.217"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "syn"
|
||||||
|
version = "2.0.90"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "919d3b74a5dd0ccd15aeb8f93e7006bd9e14c295087c9896a110f490752bcf31"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"unicode-ident",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "1.0.69"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "1.0.69"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "unicode-ident"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wasi"
|
||||||
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-sys"
|
||||||
|
version = "0.48.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
|
||||||
|
dependencies = [
|
||||||
|
"windows-targets",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows-targets"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
|
||||||
|
dependencies = [
|
||||||
|
"windows_aarch64_gnullvm",
|
||||||
|
"windows_aarch64_msvc",
|
||||||
|
"windows_i686_gnu",
|
||||||
|
"windows_i686_msvc",
|
||||||
|
"windows_x86_64_gnu",
|
||||||
|
"windows_x86_64_gnullvm",
|
||||||
|
"windows_x86_64_msvc",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_aarch64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_i686_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnu"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_gnullvm"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "windows_x86_64_msvc"
|
||||||
|
version = "0.48.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "wit-bindgen-rt"
|
||||||
|
version = "0.36.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7947d0131c7c9da3f01dfde0ab8bd4c4cf3c5bd49b6dba0ae640f1fa752572ea"
|
||||||
|
dependencies = [
|
||||||
|
"bitflags",
|
||||||
|
]
|
27
dev-packages/Cargo.toml
Normal file
27
dev-packages/Cargo.toml
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
[package]
|
||||||
|
name = "dev-packages"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2021"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
dirs = "5.0.1"
|
||||||
|
minijinja = "2.5.0"
|
||||||
|
wit-bindgen-rt = { version = "0.36.0", features = ["bitflags"] }
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1
|
||||||
|
opt-level = "s"
|
||||||
|
debug = false
|
||||||
|
strip = true
|
||||||
|
lto = true
|
||||||
|
|
||||||
|
[package.metadata.component]
|
||||||
|
package = "component:dev-packages"
|
||||||
|
|
||||||
|
[package.metadata.component.target.dependencies]
|
||||||
|
"component:churn-tasks" = { path = "../churn-tasks/wit" }
|
||||||
|
|
||||||
|
[package.metadata.component.dependencies]
|
84
dev-packages/files/config.alloy
Normal file
84
dev-packages/files/config.alloy
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
// Sample config for Alloy.
|
||||||
|
//
|
||||||
|
// For a full configuration reference, see https://grafana.com/docs/dev-packages
|
||||||
|
logging {
|
||||||
|
level = "warn"
|
||||||
|
}
|
||||||
|
|
||||||
|
prometheus.exporter.unix "default" {
|
||||||
|
include_exporter_metrics = true
|
||||||
|
disable_collectors = ["mdadm"]
|
||||||
|
}
|
||||||
|
|
||||||
|
prometheus.scrape "default" {
|
||||||
|
targets = array.concat(
|
||||||
|
prometheus.exporter.unix.default.targets,
|
||||||
|
[{
|
||||||
|
// Self-collect metrics
|
||||||
|
job = "dev-packages",
|
||||||
|
__address__ = "127.0.0.1:12345",
|
||||||
|
group = "infrastructure",
|
||||||
|
}],
|
||||||
|
)
|
||||||
|
|
||||||
|
forward_to = [
|
||||||
|
// TODO: components to forward metrics to (like prometheus.remote_write or
|
||||||
|
// prometheus.relabel).
|
||||||
|
prometheus.remote_write.default.receiver,
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
prometheus.remote_write "default" {
|
||||||
|
external_labels = {
|
||||||
|
"node" = "{{ node_name }}",
|
||||||
|
}
|
||||||
|
|
||||||
|
endpoint {
|
||||||
|
url = "https://prometheus.i.kjuulh.io/api/v1/write"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
local.file_match "local_files" {
|
||||||
|
path_targets = [{"__path__" = "/var/log/*.log"}]
|
||||||
|
sync_period = "5s"
|
||||||
|
}
|
||||||
|
|
||||||
|
loki.source.file "log_scrape" {
|
||||||
|
targets = local.file_match.local_files.targets
|
||||||
|
forward_to = [loki.process.filter_logs.receiver]
|
||||||
|
tail_from_end = true
|
||||||
|
}
|
||||||
|
|
||||||
|
loki.source.journal "default" {
|
||||||
|
forward_to = [loki.process.filter_logs.receiver]
|
||||||
|
}
|
||||||
|
|
||||||
|
discovery.docker "linux" {
|
||||||
|
host = "unix:///var/run/docker.sock"
|
||||||
|
}
|
||||||
|
|
||||||
|
loki.source.docker "default" {
|
||||||
|
host = "unix:///var/run/docker.sock"
|
||||||
|
targets = discovery.docker.linux.targets
|
||||||
|
labels = {"app" = "docker"}
|
||||||
|
forward_to = [loki.write.grafana_loki.receiver]
|
||||||
|
}
|
||||||
|
|
||||||
|
loki.process "filter_logs" {
|
||||||
|
stage.drop {
|
||||||
|
source = ""
|
||||||
|
expression = ".*Connection closed by authenticating user root"
|
||||||
|
drop_counter_reason = "noisy"
|
||||||
|
}
|
||||||
|
forward_to = [loki.write.grafana_loki.receiver]
|
||||||
|
}
|
||||||
|
|
||||||
|
loki.write "grafana_loki" {
|
||||||
|
external_labels = {
|
||||||
|
"node" = "{{ node_name }}",
|
||||||
|
}
|
||||||
|
|
||||||
|
endpoint {
|
||||||
|
url = "https://loki.i.kjuulh.io/loki/api/v1/push"
|
||||||
|
}
|
||||||
|
}
|
396
dev-packages/src/bindings.rs
Normal file
396
dev-packages/src/bindings.rs
Normal file
@ -0,0 +1,396 @@
|
|||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod component {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod churn_tasks {
|
||||||
|
#[allow(dead_code, clippy::all)]
|
||||||
|
pub mod process {
|
||||||
|
#[used]
|
||||||
|
#[doc(hidden)]
|
||||||
|
static __FORCE_SECTION_REF: fn() = super::super::super::__link_custom_section_describing_imports;
|
||||||
|
use super::super::super::_rt;
|
||||||
|
#[derive(Debug)]
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct Process {
|
||||||
|
handle: _rt::Resource<Process>,
|
||||||
|
}
|
||||||
|
impl Process {
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub unsafe fn from_handle(handle: u32) -> Self {
|
||||||
|
Self {
|
||||||
|
handle: _rt::Resource::from_handle(handle),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn take_handle(&self) -> u32 {
|
||||||
|
_rt::Resource::take_handle(&self.handle)
|
||||||
|
}
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn handle(&self) -> u32 {
|
||||||
|
_rt::Resource::handle(&self.handle)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
unsafe impl _rt::WasmResource for Process {
|
||||||
|
#[inline]
|
||||||
|
unsafe fn drop(_handle: u32) {
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
unreachable!();
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
{
|
||||||
|
#[link(
|
||||||
|
wasm_import_module = "component:churn-tasks/process@0.1.0"
|
||||||
|
)]
|
||||||
|
extern "C" {
|
||||||
|
#[link_name = "[resource-drop]process"]
|
||||||
|
fn drop(_: u32);
|
||||||
|
}
|
||||||
|
drop(_handle);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Process {
|
||||||
|
#[allow(unused_unsafe, clippy::all)]
|
||||||
|
pub fn new() -> Self {
|
||||||
|
unsafe {
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
#[link(
|
||||||
|
wasm_import_module = "component:churn-tasks/process@0.1.0"
|
||||||
|
)]
|
||||||
|
extern "C" {
|
||||||
|
#[link_name = "[constructor]process"]
|
||||||
|
fn wit_import() -> i32;
|
||||||
|
}
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
fn wit_import() -> i32 {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
let ret = wit_import();
|
||||||
|
Process::from_handle(ret as u32)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Process {
|
||||||
|
#[allow(unused_unsafe, clippy::all)]
|
||||||
|
pub fn run_process(&self, inputs: &[_rt::String]) -> _rt::String {
|
||||||
|
unsafe {
|
||||||
|
#[repr(align(4))]
|
||||||
|
struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
|
||||||
|
let mut ret_area = RetArea(
|
||||||
|
[::core::mem::MaybeUninit::uninit(); 8],
|
||||||
|
);
|
||||||
|
let vec1 = inputs;
|
||||||
|
let len1 = vec1.len();
|
||||||
|
let layout1 = _rt::alloc::Layout::from_size_align_unchecked(
|
||||||
|
vec1.len() * 8,
|
||||||
|
4,
|
||||||
|
);
|
||||||
|
let result1 = if layout1.size() != 0 {
|
||||||
|
let ptr = _rt::alloc::alloc(layout1).cast::<u8>();
|
||||||
|
if ptr.is_null() {
|
||||||
|
_rt::alloc::handle_alloc_error(layout1);
|
||||||
|
}
|
||||||
|
ptr
|
||||||
|
} else {
|
||||||
|
::core::ptr::null_mut()
|
||||||
|
};
|
||||||
|
for (i, e) in vec1.into_iter().enumerate() {
|
||||||
|
let base = result1.add(i * 8);
|
||||||
|
{
|
||||||
|
let vec0 = e;
|
||||||
|
let ptr0 = vec0.as_ptr().cast::<u8>();
|
||||||
|
let len0 = vec0.len();
|
||||||
|
*base.add(4).cast::<usize>() = len0;
|
||||||
|
*base.add(0).cast::<*mut u8>() = ptr0.cast_mut();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let ptr2 = ret_area.0.as_mut_ptr().cast::<u8>();
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
#[link(
|
||||||
|
wasm_import_module = "component:churn-tasks/process@0.1.0"
|
||||||
|
)]
|
||||||
|
extern "C" {
|
||||||
|
#[link_name = "[method]process.run-process"]
|
||||||
|
fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8);
|
||||||
|
}
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8) {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
wit_import((self).handle() as i32, result1, len1, ptr2);
|
||||||
|
let l3 = *ptr2.add(0).cast::<*mut u8>();
|
||||||
|
let l4 = *ptr2.add(4).cast::<usize>();
|
||||||
|
let len5 = l4;
|
||||||
|
let bytes5 = _rt::Vec::from_raw_parts(l3.cast(), len5, len5);
|
||||||
|
if layout1.size() != 0 {
|
||||||
|
_rt::alloc::dealloc(result1.cast(), layout1);
|
||||||
|
}
|
||||||
|
_rt::string_lift(bytes5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl Process {
|
||||||
|
#[allow(unused_unsafe, clippy::all)]
|
||||||
|
pub fn get_variable(&self, key: &str) -> _rt::String {
|
||||||
|
unsafe {
|
||||||
|
#[repr(align(4))]
|
||||||
|
struct RetArea([::core::mem::MaybeUninit<u8>; 8]);
|
||||||
|
let mut ret_area = RetArea(
|
||||||
|
[::core::mem::MaybeUninit::uninit(); 8],
|
||||||
|
);
|
||||||
|
let vec0 = key;
|
||||||
|
let ptr0 = vec0.as_ptr().cast::<u8>();
|
||||||
|
let len0 = vec0.len();
|
||||||
|
let ptr1 = ret_area.0.as_mut_ptr().cast::<u8>();
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
#[link(
|
||||||
|
wasm_import_module = "component:churn-tasks/process@0.1.0"
|
||||||
|
)]
|
||||||
|
extern "C" {
|
||||||
|
#[link_name = "[method]process.get-variable"]
|
||||||
|
fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8);
|
||||||
|
}
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
fn wit_import(_: i32, _: *mut u8, _: usize, _: *mut u8) {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
wit_import((self).handle() as i32, ptr0.cast_mut(), len0, ptr1);
|
||||||
|
let l2 = *ptr1.add(0).cast::<*mut u8>();
|
||||||
|
let l3 = *ptr1.add(4).cast::<usize>();
|
||||||
|
let len4 = l3;
|
||||||
|
let bytes4 = _rt::Vec::from_raw_parts(l2.cast(), len4, len4);
|
||||||
|
_rt::string_lift(bytes4)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod exports {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod component {
|
||||||
|
#[allow(dead_code)]
|
||||||
|
pub mod churn_tasks {
|
||||||
|
#[allow(dead_code, clippy::all)]
|
||||||
|
pub mod task {
|
||||||
|
#[used]
|
||||||
|
#[doc(hidden)]
|
||||||
|
static __FORCE_SECTION_REF: fn() = super::super::super::super::__link_custom_section_describing_imports;
|
||||||
|
use super::super::super::super::_rt;
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub unsafe fn _export_id_cabi<T: Guest>() -> *mut u8 {
|
||||||
|
#[cfg(target_arch = "wasm32")] _rt::run_ctors_once();
|
||||||
|
let result0 = T::id();
|
||||||
|
let ptr1 = _RET_AREA.0.as_mut_ptr().cast::<u8>();
|
||||||
|
let vec2 = (result0.into_bytes()).into_boxed_slice();
|
||||||
|
let ptr2 = vec2.as_ptr().cast::<u8>();
|
||||||
|
let len2 = vec2.len();
|
||||||
|
::core::mem::forget(vec2);
|
||||||
|
*ptr1.add(4).cast::<usize>() = len2;
|
||||||
|
*ptr1.add(0).cast::<*mut u8>() = ptr2.cast_mut();
|
||||||
|
ptr1
|
||||||
|
}
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub unsafe fn __post_return_id<T: Guest>(arg0: *mut u8) {
|
||||||
|
let l0 = *arg0.add(0).cast::<*mut u8>();
|
||||||
|
let l1 = *arg0.add(4).cast::<usize>();
|
||||||
|
_rt::cabi_dealloc(l0, l1, 1);
|
||||||
|
}
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub unsafe fn _export_should_run_cabi<T: Guest>() -> i32 {
|
||||||
|
#[cfg(target_arch = "wasm32")] _rt::run_ctors_once();
|
||||||
|
let result0 = T::should_run();
|
||||||
|
match result0 {
|
||||||
|
true => 1,
|
||||||
|
false => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[doc(hidden)]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub unsafe fn _export_execute_cabi<T: Guest>() {
|
||||||
|
#[cfg(target_arch = "wasm32")] _rt::run_ctors_once();
|
||||||
|
T::execute();
|
||||||
|
}
|
||||||
|
pub trait Guest {
|
||||||
|
fn id() -> _rt::String;
|
||||||
|
fn should_run() -> bool;
|
||||||
|
fn execute();
|
||||||
|
}
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __export_component_churn_tasks_task_0_1_0_cabi {
|
||||||
|
($ty:ident with_types_in $($path_to_types:tt)*) => {
|
||||||
|
const _ : () = { #[export_name =
|
||||||
|
"component:churn-tasks/task@0.1.0#id"] unsafe extern "C" fn
|
||||||
|
export_id() -> * mut u8 { $($path_to_types)*::
|
||||||
|
_export_id_cabi::<$ty > () } #[export_name =
|
||||||
|
"cabi_post_component:churn-tasks/task@0.1.0#id"] unsafe extern
|
||||||
|
"C" fn _post_return_id(arg0 : * mut u8,) { $($path_to_types)*::
|
||||||
|
__post_return_id::<$ty > (arg0) } #[export_name =
|
||||||
|
"component:churn-tasks/task@0.1.0#should-run"] unsafe extern "C"
|
||||||
|
fn export_should_run() -> i32 { $($path_to_types)*::
|
||||||
|
_export_should_run_cabi::<$ty > () } #[export_name =
|
||||||
|
"component:churn-tasks/task@0.1.0#execute"] unsafe extern "C" fn
|
||||||
|
export_execute() { $($path_to_types)*::
|
||||||
|
_export_execute_cabi::<$ty > () } };
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub(crate) use __export_component_churn_tasks_task_0_1_0_cabi;
|
||||||
|
#[repr(align(4))]
|
||||||
|
struct _RetArea([::core::mem::MaybeUninit<u8>; 8]);
|
||||||
|
static mut _RET_AREA: _RetArea = _RetArea(
|
||||||
|
[::core::mem::MaybeUninit::uninit(); 8],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mod _rt {
|
||||||
|
use core::fmt;
|
||||||
|
use core::marker;
|
||||||
|
use core::sync::atomic::{AtomicU32, Ordering::Relaxed};
|
||||||
|
/// A type which represents a component model resource, either imported or
|
||||||
|
/// exported into this component.
|
||||||
|
///
|
||||||
|
/// This is a low-level wrapper which handles the lifetime of the resource
|
||||||
|
/// (namely this has a destructor). The `T` provided defines the component model
|
||||||
|
/// intrinsics that this wrapper uses.
|
||||||
|
///
|
||||||
|
/// One of the chief purposes of this type is to provide `Deref` implementations
|
||||||
|
/// to access the underlying data when it is owned.
|
||||||
|
///
|
||||||
|
/// This type is primarily used in generated code for exported and imported
|
||||||
|
/// resources.
|
||||||
|
#[repr(transparent)]
|
||||||
|
pub struct Resource<T: WasmResource> {
|
||||||
|
handle: AtomicU32,
|
||||||
|
_marker: marker::PhantomData<T>,
|
||||||
|
}
|
||||||
|
/// A trait which all wasm resources implement, namely providing the ability to
|
||||||
|
/// drop a resource.
|
||||||
|
///
|
||||||
|
/// This generally is implemented by generated code, not user-facing code.
|
||||||
|
#[allow(clippy::missing_safety_doc)]
|
||||||
|
pub unsafe trait WasmResource {
|
||||||
|
/// Invokes the `[resource-drop]...` intrinsic.
|
||||||
|
unsafe fn drop(handle: u32);
|
||||||
|
}
|
||||||
|
impl<T: WasmResource> Resource<T> {
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub unsafe fn from_handle(handle: u32) -> Self {
|
||||||
|
debug_assert!(handle != u32::MAX);
|
||||||
|
Self {
|
||||||
|
handle: AtomicU32::new(handle),
|
||||||
|
_marker: marker::PhantomData,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// Takes ownership of the handle owned by `resource`.
|
||||||
|
///
|
||||||
|
/// Note that this ideally would be `into_handle` taking `Resource<T>` by
|
||||||
|
/// ownership. The code generator does not enable that in all situations,
|
||||||
|
/// unfortunately, so this is provided instead.
|
||||||
|
///
|
||||||
|
/// Also note that `take_handle` is in theory only ever called on values
|
||||||
|
/// owned by a generated function. For example a generated function might
|
||||||
|
/// take `Resource<T>` as an argument but then call `take_handle` on a
|
||||||
|
/// reference to that argument. In that sense the dynamic nature of
|
||||||
|
/// `take_handle` should only be exposed internally to generated code, not
|
||||||
|
/// to user code.
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn take_handle(resource: &Resource<T>) -> u32 {
|
||||||
|
resource.handle.swap(u32::MAX, Relaxed)
|
||||||
|
}
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn handle(resource: &Resource<T>) -> u32 {
|
||||||
|
resource.handle.load(Relaxed)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T: WasmResource> fmt::Debug for Resource<T> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
f.debug_struct("Resource").field("handle", &self.handle).finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<T: WasmResource> Drop for Resource<T> {
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
match self.handle.load(Relaxed) {
|
||||||
|
u32::MAX => {}
|
||||||
|
other => T::drop(other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub use alloc_crate::string::String;
|
||||||
|
pub use alloc_crate::alloc;
|
||||||
|
pub use alloc_crate::vec::Vec;
|
||||||
|
pub unsafe fn string_lift(bytes: Vec<u8>) -> String {
|
||||||
|
if cfg!(debug_assertions) {
|
||||||
|
String::from_utf8(bytes).unwrap()
|
||||||
|
} else {
|
||||||
|
String::from_utf8_unchecked(bytes)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
pub fn run_ctors_once() {
|
||||||
|
wit_bindgen_rt::run_ctors_once();
|
||||||
|
}
|
||||||
|
pub unsafe fn cabi_dealloc(ptr: *mut u8, size: usize, align: usize) {
|
||||||
|
if size == 0 {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let layout = alloc::Layout::from_size_align_unchecked(size, align);
|
||||||
|
alloc::dealloc(ptr, layout);
|
||||||
|
}
|
||||||
|
extern crate alloc as alloc_crate;
|
||||||
|
}
|
||||||
|
/// Generates `#[no_mangle]` functions to export the specified type as the
|
||||||
|
/// root implementation of all generated traits.
|
||||||
|
///
|
||||||
|
/// For more information see the documentation of `wit_bindgen::generate!`.
|
||||||
|
///
|
||||||
|
/// ```rust
|
||||||
|
/// # macro_rules! export{ ($($t:tt)*) => (); }
|
||||||
|
/// # trait Guest {}
|
||||||
|
/// struct MyType;
|
||||||
|
///
|
||||||
|
/// impl Guest for MyType {
|
||||||
|
/// // ...
|
||||||
|
/// }
|
||||||
|
///
|
||||||
|
/// export!(MyType);
|
||||||
|
/// ```
|
||||||
|
#[allow(unused_macros)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
macro_rules! __export_dev_packages_impl {
|
||||||
|
($ty:ident) => {
|
||||||
|
self::export!($ty with_types_in self);
|
||||||
|
};
|
||||||
|
($ty:ident with_types_in $($path_to_types_root:tt)*) => {
|
||||||
|
$($path_to_types_root)*::
|
||||||
|
exports::component::churn_tasks::task::__export_component_churn_tasks_task_0_1_0_cabi!($ty
|
||||||
|
with_types_in $($path_to_types_root)*:: exports::component::churn_tasks::task);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#[doc(inline)]
|
||||||
|
pub(crate) use __export_dev_packages_impl as export;
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
#[link_section = "component-type:wit-bindgen:0.35.0:component:dev-packages:dev-packages:encoded world"]
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub static __WIT_BINDGEN_COMPONENT_TYPE: [u8; 460] = *b"\
|
||||||
|
\0asm\x0d\0\x01\0\0\x19\x16wit-component-encoding\x04\0\x07\xc9\x02\x01A\x02\x01\
|
||||||
|
A\x04\x01B\x0a\x04\0\x07process\x03\x01\x01i\0\x01@\0\0\x01\x04\0\x14[constructo\
|
||||||
|
r]process\x01\x02\x01h\0\x01ps\x01@\x02\x04self\x03\x06inputs\x04\0s\x04\0\x1b[m\
|
||||||
|
ethod]process.run-process\x01\x05\x01@\x02\x04self\x03\x03keys\0s\x04\0\x1c[meth\
|
||||||
|
od]process.get-variable\x01\x06\x03\0#component:churn-tasks/process@0.1.0\x05\0\x01\
|
||||||
|
B\x06\x01@\0\0s\x04\0\x02id\x01\0\x01@\0\0\x7f\x04\0\x0ashould-run\x01\x01\x01@\0\
|
||||||
|
\x01\0\x04\0\x07execute\x01\x02\x04\0\x20component:churn-tasks/task@0.1.0\x05\x01\
|
||||||
|
\x04\0#component:dev-packages/dev-packages\x04\0\x0b\x12\x01\0\x0cdev-packages\x03\
|
||||||
|
\0\0\0G\x09producers\x01\x0cprocessed-by\x02\x0dwit-component\x070.220.0\x10wit-\
|
||||||
|
bindgen-rust\x060.35.0";
|
||||||
|
#[inline(never)]
|
||||||
|
#[doc(hidden)]
|
||||||
|
pub fn __link_custom_section_describing_imports() {
|
||||||
|
wit_bindgen_rt::maybe_link_cabi_realloc();
|
||||||
|
}
|
21
dev-packages/src/lib.rs
Normal file
21
dev-packages/src/lib.rs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
use bindings::exports::component::churn_tasks::task::Guest;
|
||||||
|
|
||||||
|
#[allow(warnings)]
|
||||||
|
mod bindings;
|
||||||
|
|
||||||
|
struct Component;
|
||||||
|
|
||||||
|
impl Guest for Component {
|
||||||
|
fn id() -> String {
|
||||||
|
"clank/dev-packages".into()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_run() -> bool {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
fn execute() {
|
||||||
|
println!("running dev-packages installation");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bindings::export!(Component with_types_in bindings);
|
7
dev-packages/wit/world.wit
Normal file
7
dev-packages/wit/world.wit
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package component:dev-packages;
|
||||||
|
|
||||||
|
/// An example world for the component to target.
|
||||||
|
world dev-packages {
|
||||||
|
import component:churn-tasks/process@0.1.0;
|
||||||
|
export component:churn-tasks/task@0.1.0;
|
||||||
|
}
|
25
upload.sh
25
upload.sh
@ -9,8 +9,23 @@ export AWS_ACCESS_KEY_ID=$(op read op://personal/minio.front.kjuulh.io/username)
|
|||||||
export AWS_SECRET_ACCESS_KEY=$(op read op://personal/minio.front.kjuulh.io/password)
|
export AWS_SECRET_ACCESS_KEY=$(op read op://personal/minio.front.kjuulh.io/password)
|
||||||
export AWS_REGION=eu-west-1
|
export AWS_REGION=eu-west-1
|
||||||
|
|
||||||
echo "processing: alloy"
|
if [[ $# -eq 0 ]]; then
|
||||||
echo "building rust project"
|
print "Usage: $0 [arguments...]"
|
||||||
(cd alloy && cargo component build --release)
|
print "Please provide at least one argument"
|
||||||
echo "upload"
|
exit 1
|
||||||
aws s3 cp alloy/target/wasm32-wasip1/release/alloy.wasm s3://churn-registry/alloy/0.1.0/alloy.wasm --endpoint-url https://api-minio.front.kjuulh.io
|
fi
|
||||||
|
|
||||||
|
for arg in $@; do
|
||||||
|
echo "building and uploading: $arg"
|
||||||
|
|
||||||
|
lowercase_arg=${arg//-/_}
|
||||||
|
|
||||||
|
echo "processing: $arg"
|
||||||
|
|
||||||
|
echo "building rust project"
|
||||||
|
(cd $arg && cargo component build --release)
|
||||||
|
|
||||||
|
echo "upload"
|
||||||
|
aws s3 cp $arg/target/wasm32-wasip1/release/$lowercase_arg.wasm s3://churn-registry/$lowercase_arg/0.1.0/$lowercase_arg.wasm --endpoint-url https://api-minio.front.kjuulh.io
|
||||||
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user