1#![cfg(not(target_arch = "wasm32"))]
2#![allow(clippy::all)]
4#![allow(missing_docs)]
5#![allow(unused_macros)]
6
7macro_rules! declare_world {
8 (
9 mod $mod_name:ident,
10 path = $path_literal:literal,
11 world = $world_literal:literal
12 $(, legacy = { $($legacy:item)* } )?
13 ) => {
14 pub mod $mod_name {
15 mod bindings {
16 wasmtime::component::bindgen!({
17 path: $path_literal,
18 world: $world_literal,
19 });
20 }
21
22 #[allow(unused_imports)]
23 pub use bindings::*;
24
25 $(
26 $($legacy)*
27 )?
28 }
29 };
30}
31
32#[cfg(feature = "describe-v1")]
33declare_world!(
34 mod component_describe_v1,
35 path = "wit/greentic/component@1.0.0",
36 world = "greentic:component/component@1.0.0",
37 legacy = {
38 pub const PACKAGE_ID: &str = "greentic:component@1.0.0";
40 }
41);
42
43#[cfg(feature = "component-v1")]
44declare_world!(
45 mod component_v1,
46 path = "wit/greentic/component-v1@0.1.0",
47 world = "greentic:component-v1/component-host@0.1.0",
48 legacy = {
49 pub const PACKAGE_ID: &str = "greentic:component-v1@0.1.0";
51 }
52);
53
54#[cfg(feature = "component-v0-5")]
55declare_world!(
56 mod component_v0_5,
57 path = "wit/greentic/component@0.5.0",
58 world = "greentic:component/component@0.5.0",
59 legacy = {
60 use anyhow::Result as AnyResult;
61 use wasmtime::component::{Component as WasmtimeComponent, Linker};
62 use wasmtime::StoreContextMut;
63
64 pub use bindings::greentic::component::control::Host as ControlHost;
65
66 pub fn add_control_to_linker<T>(
68 linker: &mut Linker<T>,
69 get_host: impl Fn(&mut T) -> &mut (dyn ControlHost + Send + Sync + 'static)
70 + Send
71 + Sync
72 + Copy
73 + 'static,
74 ) -> wasmtime::Result<()>
75 where
76 T: Send + 'static,
77 {
78 let mut inst = linker.instance("greentic:component/control@0.5.0")?;
79
80 inst.func_wrap(
81 "should-cancel",
82 move |mut caller: StoreContextMut<'_, T>, (): ()| {
83 let host = get_host(caller.data_mut());
84 let result = host.should_cancel();
85 Ok((result,))
86 },
87 )?;
88
89 inst.func_wrap(
90 "yield-now",
91 move |mut caller: StoreContextMut<'_, T>, (): ()| {
92 let host = get_host(caller.data_mut());
93 host.yield_now();
94 Ok(())
95 },
96 )?;
97
98 Ok(())
99 }
100
101 pub struct Component;
103
104 impl Component {
105 pub fn instantiate(
107 engine: &wasmtime::Engine,
108 component_wasm: &[u8],
109 ) -> AnyResult<WasmtimeComponent> {
110 Ok(WasmtimeComponent::from_binary(engine, component_wasm)?)
111 }
112 }
113
114 pub const PACKAGE_ID: &str = "greentic:component@0.5.0";
116 }
117);
118
119#[cfg(feature = "component-v0-5")]
120declare_world!(
121 mod component_configurable_v0_5,
122 path = "wit/greentic/component@0.5.0",
123 world = "greentic:component/component-configurable@0.5.0",
124 legacy = {
125 use anyhow::Result as AnyResult;
126 use wasmtime::component::{Component as WasmtimeComponent, Linker};
127 use wasmtime::StoreContextMut;
128
129 pub use bindings::greentic::component::control::Host as ControlHost;
130
131 pub fn add_control_to_linker<T>(
133 linker: &mut Linker<T>,
134 get_host: impl Fn(&mut T) -> &mut (dyn ControlHost + Send + Sync + 'static)
135 + Send
136 + Sync
137 + Copy
138 + 'static,
139 ) -> wasmtime::Result<()>
140 where
141 T: Send + 'static,
142 {
143 let mut inst = linker.instance("greentic:component/control@0.5.0")?;
144
145 inst.func_wrap(
146 "should-cancel",
147 move |mut caller: StoreContextMut<'_, T>, (): ()| {
148 let host = get_host(caller.data_mut());
149 let result = host.should_cancel();
150 Ok((result,))
151 },
152 )?;
153
154 inst.func_wrap(
155 "yield-now",
156 move |mut caller: StoreContextMut<'_, T>, (): ()| {
157 let host = get_host(caller.data_mut());
158 host.yield_now();
159 Ok(())
160 },
161 )?;
162
163 Ok(())
164 }
165
166 pub struct Component;
168
169 impl Component {
170 pub fn instantiate(
172 engine: &wasmtime::Engine,
173 component_wasm: &[u8],
174 ) -> AnyResult<WasmtimeComponent> {
175 Ok(WasmtimeComponent::from_binary(engine, component_wasm)?)
176 }
177 }
178
179 pub const PACKAGE_ID: &str = "greentic:component@0.5.0";
181 }
182);
183
184#[cfg(feature = "common-types-v0-1")]
185declare_world!(
186 mod common_types_v0_1,
187 path = "wit/greentic/common-types@0.1.0",
188 world = "greentic:common-types/common@0.1.0",
189 legacy = {
190 pub const PACKAGE_ID: &str = "greentic:common-types@0.1.0";
192 }
193);
194
195#[cfg(feature = "component-v0-4")]
196declare_world!(
197 mod component_v0_4,
198 path = "wit/greentic/component@0.4.0",
199 world = "greentic:component/component@0.4.0",
200 legacy = {
201 use anyhow::Result as AnyResult;
202 use wasmtime::component::{Component as WasmtimeComponent, Linker};
203 use wasmtime::StoreContextMut;
204
205 pub use bindings::greentic::component::control::Host as ControlHost;
206
207 pub fn add_control_to_linker<T>(
209 linker: &mut Linker<T>,
210 get_host: impl Fn(&mut T) -> &mut (dyn ControlHost + Send + Sync + 'static)
211 + Send
212 + Sync
213 + Copy
214 + 'static,
215 ) -> wasmtime::Result<()>
216 where
217 T: Send + 'static,
218 {
219 let mut inst = linker.instance("greentic:component/control@0.4.0")?;
220
221 inst.func_wrap(
222 "should-cancel",
223 move |mut caller: StoreContextMut<'_, T>, (): ()| {
224 let host = get_host(caller.data_mut());
225 let result = host.should_cancel();
226 Ok((result,))
227 },
228 )?;
229
230 inst.func_wrap(
231 "yield-now",
232 move |mut caller: StoreContextMut<'_, T>, (): ()| {
233 let host = get_host(caller.data_mut());
234 host.yield_now();
235 Ok(())
236 },
237 )?;
238
239 Ok(())
240 }
241
242 pub struct Component;
244
245 impl Component {
246 pub fn instantiate(
248 engine: &wasmtime::Engine,
249 component_wasm: &[u8],
250 ) -> AnyResult<WasmtimeComponent> {
251 Ok(WasmtimeComponent::from_binary(engine, component_wasm)?)
252 }
253 }
254
255 pub const PACKAGE_ID: &str = "greentic:component@0.4.0";
257 }
258);
259
260#[cfg(feature = "pack-export-v0-4")]
261declare_world!(
262 mod pack_export_v0_4,
263 path = "wit/greentic/pack-export@0.4.0",
264 world = "greentic:pack-export/pack-exports@0.4.0",
265 legacy = {
266 pub const PACKAGE_ID: &str = "greentic:pack-export@0.4.0";
268 }
269);
270
271#[cfg(feature = "pack-export-v1")]
272declare_world!(
273 mod pack_export_v1,
274 path = "wit/greentic/pack-export-v1@0.1.0",
275 world = "greentic:pack-export-v1/pack-host@0.1.0",
276 legacy = {
277 pub const PACKAGE_ID: &str = "greentic:pack-export-v1@0.1.0";
279 }
280);
281
282#[cfg(feature = "types-core-v0-4")]
283declare_world!(
284 mod types_core_v0_4,
285 path = "wit/greentic/types-core@0.4.0",
286 world = "greentic:types-core/core@0.4.0",
287 legacy = {
288 pub const PACKAGE_ID: &str = "greentic:types-core@0.4.0";
290 }
291);
292
293#[cfg(feature = "runner-host-v1")]
294declare_world!(
295 mod runner_host_v1,
296 path = "wit/greentic/host@1.0.0",
297 world = "greentic:host/runner-host@1.0.0",
298 legacy = {
299 use std::vec::Vec;
300 use wasmtime::component::Linker;
301 use wasmtime::{Result, StoreContextMut};
302
303 pub use bindings::greentic::host::{http_v1, kv_v1};
304
305 pub trait RunnerHost {
307 fn http_request(
308 &mut self,
309 method: String,
310 url: String,
311 headers: Vec<String>,
312 body: Option<Vec<u8>>,
313 ) -> Result<Result<Vec<u8>, String>>;
314
315 fn kv_get(&mut self, ns: String, key: String) -> Result<Option<String>>;
316
317 fn kv_put(&mut self, ns: String, key: String, val: String) -> Result<()>;
318 }
319
320 pub fn add_to_linker<T>(
322 linker: &mut Linker<T>,
323 get_host: impl Fn(&mut T) -> &mut (dyn RunnerHost + Send + Sync + 'static)
324 + Send
325 + Sync
326 + Copy
327 + 'static,
328 ) -> Result<()>
329 where
330 T: Send + 'static,
331 {
332 let mut http = linker.instance("greentic:host/http-v1@1.0.0")?;
333 http.func_wrap(
334 "request",
335 move |mut caller: StoreContextMut<'_, T>,
336 (method, url, headers, body): (String, String, Vec<String>, Option<Vec<u8>>)| {
337 let host = get_host(caller.data_mut());
338 host.http_request(method, url, headers, body)
339 .map(|res| (res,))
340 },
341 )?;
342
343 let mut kv = linker.instance("greentic:host/kv-v1@1.0.0")?;
344 kv.func_wrap(
345 "get",
346 move |mut caller: StoreContextMut<'_, T>, (ns, key): (String, String)| {
347 let host = get_host(caller.data_mut());
348 host.kv_get(ns, key).map(|res| (res,))
349 },
350 )?;
351 kv.func_wrap(
352 "put",
353 move |mut caller: StoreContextMut<'_, T>, (ns, key, val): (String, String, String)| {
354 let host = get_host(caller.data_mut());
355 host.kv_put(ns, key, val)
356 },
357 )?;
358
359 Ok(())
360 }
361
362 pub const PACKAGE_ID: &str = "greentic:host@1.0.0";
364 }
365);
366
367#[cfg(feature = "pack-export-v0-2")]
368declare_world!(
369 mod pack_export_v0_2,
370 path = "wit/greentic/pack-export@0.2.0",
371 world = "greentic:pack-export/pack-exports@0.2.0",
372 legacy = {
373 pub const PACKAGE_ID: &str = "greentic:pack-export@0.2.0";
375 }
376);
377
378#[cfg(feature = "types-core-v0-2")]
379declare_world!(
380 mod types_core_v0_2,
381 path = "wit/greentic/types-core@0.2.0",
382 world = "greentic:types-core/core@0.2.0",
383 legacy = {
384 pub const PACKAGE_ID: &str = "greentic:types-core@0.2.0";
386 }
387);
388
389#[cfg(feature = "oauth-broker-v1")]
390declare_world!(
391 mod oauth_broker_v1,
392 path = "wit/greentic/oauth-broker@1.0.0",
393 world = "greentic:oauth-broker/broker@1.0.0",
394 legacy = {
395 pub const PACKAGE_ID: &str = "greentic:oauth-broker@1.0.0";
397 }
398);
399
400#[cfg(feature = "oauth-broker-v1")]
401declare_world!(
402 mod oauth_broker_client_v1,
403 path = "wit/greentic/oauth-broker@1.0.0",
404 world = "greentic:oauth-broker/broker-client@1.0.0",
405 legacy = {
406 pub const PACKAGE_ID: &str = "greentic:oauth-broker@1.0.0";
408 }
409);
410
411#[cfg(feature = "component-lifecycle-v1")]
412declare_world!(
413 mod component_lifecycle_v1,
414 path = "wit/greentic/lifecycle@1.0.0",
415 world = "greentic:lifecycle/component-lifecycle@1.0.0",
416 legacy = {
417 pub const PACKAGE_ID: &str = "greentic:lifecycle@1.0.0";
419 }
420);
421
422#[cfg(feature = "events-v1")]
423declare_world!(
424 mod events_v1,
425 path = "wit/greentic/events@1.0.0",
426 world = "greentic:events/events@1.0.0",
427 legacy = {
428 pub const PACKAGE_ID: &str = "greentic:events@1.0.0";
430 }
431);
432
433#[cfg(feature = "events-broker-v1")]
434declare_world!(
435 mod events_broker_v1,
436 path = "wit/greentic/events@1.0.0",
437 world = "greentic:events/broker@1.0.0",
438 legacy = {
439 pub const PACKAGE_ID: &str = "greentic:events@1.0.0";
441 }
442);
443
444#[cfg(feature = "events-source-v1")]
445declare_world!(
446 mod events_source_v1,
447 path = "wit/greentic/events@1.0.0",
448 world = "greentic:events/source@1.0.0",
449 legacy = {
450 pub const PACKAGE_ID: &str = "greentic:events@1.0.0";
452 }
453);
454
455#[cfg(feature = "events-sink-v1")]
456declare_world!(
457 mod events_sink_v1,
458 path = "wit/greentic/events@1.0.0",
459 world = "greentic:events/sink@1.0.0",
460 legacy = {
461 pub const PACKAGE_ID: &str = "greentic:events@1.0.0";
463 }
464);
465
466#[cfg(feature = "secrets-store-v1")]
467declare_world!(
468 mod secrets_store_v1,
469 path = "wit/greentic/secrets-store@1.0.0",
470 world = "greentic:secrets-store/store@1.0.0",
471 legacy = {
472 pub const PACKAGE_ID: &str = "greentic:secrets-store@1.0.0";
474 }
475);
476
477#[cfg(feature = "secrets-provider-v0-1")]
478declare_world!(
479 mod secrets_provider_v0_1,
480 path = "wit/greentic/secrets-provider@0.1.0",
481 world = "greentic:secrets-provider/provider@0.1.0",
482 legacy = {
483 pub const PACKAGE_ID: &str = "greentic:secrets-provider@0.1.0";
485 }
486);
487
488#[cfg(feature = "provider-core-v1")]
489declare_world!(
490 mod provider_schema_core_v1,
491 path = "wit/greentic/provider/schema-core@1.0.0",
492 world = "greentic:provider-schema-core/schema-core@1.0.0",
493 legacy = {
494 pub const PACKAGE_ID: &str = "greentic:provider-schema-core@1.0.0";
496 }
497);
498
499#[cfg(feature = "secrets-generators-v0-1")]
500declare_world!(
501 mod secrets_generators_v0_1,
502 path = "wit/greentic/secrets-generators@0.1.0",
503 world = "greentic:secrets-generators/generators@0.1.0",
504 legacy = {
505 pub const PACKAGE_ID: &str = "greentic:secrets-generators@0.1.0";
507 }
508);
509
510#[cfg(feature = "secrets-audit-exporter-v0-1")]
511declare_world!(
512 mod secrets_audit_exporter_v0_1,
513 path = "wit/greentic/secrets-audit-exporter@0.1.0",
514 world = "greentic:secrets-audit-exporter/audit-exporter@0.1.0",
515 legacy = {
516 pub const PACKAGE_ID: &str = "greentic:secrets-audit-exporter@0.1.0";
518 }
519);
520
521#[cfg(feature = "secrets-policy-validator-v0-1")]
522declare_world!(
523 mod secrets_policy_validator_v0_1,
524 path = "wit/greentic/secrets-policy-validator@0.1.0",
525 world = "greentic:secrets-policy-validator/policy-validator@0.1.0",
526 legacy = {
527 pub const PACKAGE_ID: &str = "greentic:secrets-policy-validator@0.1.0";
529 }
530);
531
532#[cfg(feature = "provider-common")]
533declare_world!(
534 mod provider_common,
535 path = "wit/provider-common/world.wit",
536 world = "provider:common/common@0.0.2"
537);
538
539#[cfg(feature = "state-store-v1")]
540declare_world!(
541 mod state_store_v1,
542 path = "wit/greentic/state-store@1.0.0",
543 world = "greentic:state/store@1.0.0",
544 legacy = {
545 pub const PACKAGE_ID: &str = "greentic:state@1.0.0";
546 }
547);
548
549#[cfg(feature = "messaging-session-v1")]
550declare_world!(
551 mod messaging_session_v1,
552 path = "wit/greentic/messaging-session@1.0.0",
553 world = "greentic:messaging/session@1.0.0",
554 legacy = {
555 pub const PACKAGE_ID: &str = "greentic:messaging@1.0.0";
556 }
557);
558
559#[cfg(feature = "events-bridge-v1")]
560declare_world!(
561 mod events_bridge_message_to_event_v1,
562 path = "wit/greentic/events-bridge@1.0.0",
563 world = "greentic:events-bridge/message-to-event-bridge@1.0.0",
564 legacy = {
565 pub const PACKAGE_ID: &str = "greentic:events-bridge@1.0.0";
566 }
567);
568
569#[cfg(feature = "events-bridge-v1")]
570declare_world!(
571 mod events_bridge_event_to_message_v1,
572 path = "wit/greentic/events-bridge@1.0.0",
573 world = "greentic:events-bridge/event-to-message-bridge@1.0.0",
574 legacy = {
575 pub const PACKAGE_ID: &str = "greentic:events-bridge@1.0.0";
576 }
577);
578
579#[cfg(feature = "http-client-v1")]
580declare_world!(
581 mod http_client_v1,
582 path = "wit/greentic/http-client@1.0.0",
583 world = "greentic:http/client@1.0.0",
584 legacy = {
585 pub const PACKAGE_ID: &str = "greentic:http@1.0.0";
586 }
587);
588
589#[cfg(feature = "http-client-v1-1")]
590declare_world!(
591 mod http_client_v1_1,
592 path = "wit/greentic/http-client@1.1.0",
593 world = "greentic:http/client@1.1.0",
594 legacy = {
595 pub const PACKAGE_ID: &str = "greentic:http@1.1.0";
596 }
597);
598
599#[cfg(feature = "telemetry-logger-v1")]
600declare_world!(
601 mod telemetry_logger_v1,
602 path = "wit/greentic/telemetry-logger@1.0.0",
603 world = "greentic:telemetry/logger@1.0.0",
604 legacy = {
605 pub const PACKAGE_ID: &str = "greentic:telemetry@1.0.0";
606 }
607);
608
609#[cfg(feature = "source-v1")]
610declare_world!(
611 mod source_v1,
612 path = "wit/greentic/source@1.0.0",
613 world = "greentic:source/source-sync@1.0.0",
614 legacy = {
615 pub const PACKAGE_ID: &str = "greentic:source@1.0.0";
616 }
617);
618
619#[cfg(feature = "build-v1")]
620declare_world!(
621 mod build_v1,
622 path = "wit/greentic/build@1.0.0",
623 world = "greentic:build/builder@1.0.0",
624 legacy = {
625 pub const PACKAGE_ID: &str = "greentic:build@1.0.0";
626 }
627);
628
629#[cfg(feature = "scan-v1")]
630declare_world!(
631 mod scan_v1,
632 path = "wit/greentic/scan@1.0.0",
633 world = "greentic:scan/scanner@1.0.0",
634 legacy = {
635 pub const PACKAGE_ID: &str = "greentic:scan@1.0.0";
636 }
637);
638
639#[cfg(feature = "signing-v1")]
640declare_world!(
641 mod signing_v1,
642 path = "wit/greentic/signing@1.0.0",
643 world = "greentic:signing/signer@1.0.0",
644 legacy = {
645 pub const PACKAGE_ID: &str = "greentic:signing@1.0.0";
646 }
647);
648
649#[cfg(feature = "attestation-v1")]
650declare_world!(
651 mod attestation_v1,
652 path = "wit/greentic/attestation@1.0.0",
653 world = "greentic:attestation/attester@1.0.0",
654 legacy = {
655 pub const PACKAGE_ID: &str = "greentic:attestation@1.0.0";
656 }
657);
658
659#[cfg(feature = "policy-v1")]
660declare_world!(
661 mod policy_v1,
662 path = "wit/greentic/policy@1.0.0",
663 world = "greentic:policy/policy-evaluator@1.0.0",
664 legacy = {
665 pub const PACKAGE_ID: &str = "greentic:policy@1.0.0";
666 }
667);
668
669#[cfg(feature = "metadata-v1")]
670declare_world!(
671 mod metadata_v1,
672 path = "wit/greentic/metadata@1.0.0",
673 world = "greentic:metadata/metadata-store@1.0.0",
674 legacy = {
675 pub const PACKAGE_ID: &str = "greentic:metadata@1.0.0";
676 }
677);
678
679#[cfg(feature = "distribution-v1")]
680declare_world!(
681 mod distribution_v1,
682 path = "wit/greentic/distribution@1.0.0",
683 world = "greentic:distribution/distribution@1.0.0",
684 legacy = {
685 pub const PACKAGE_ID: &str = "greentic:distribution@1.0.0";
686 }
687);
688
689#[cfg(feature = "distributor-api")]
690declare_world!(
691 mod distributor_api_v1,
692 path = "wit/greentic/distributor@1.0.0",
693 world = "greentic:distributor-api/distributor-api@1.0.0",
694 legacy = {
695 pub const PACKAGE_ID: &str = "greentic:distributor-api@1.0.0";
696 }
697);
698
699#[cfg(feature = "oci-v1")]
700declare_world!(
701 mod oci_v1,
702 path = "wit/greentic/oci@1.0.0",
703 world = "greentic:oci/oci-distribution@1.0.0",
704 legacy = {
705 pub const PACKAGE_ID: &str = "greentic:oci@1.0.0";
706 }
707);
708
709#[cfg(feature = "repo-ui-actions-v1")]
710declare_world!(
711 mod repo_ui_actions_repo_ui_worker_v1,
712 path = "wit/greentic/repo-ui-actions@1.0.0",
713 world = "greentic:repo-ui-actions/repo-ui-worker@1.0.0",
714 legacy = {
715 pub const PACKAGE_ID: &str = "greentic:repo-ui-actions@1.0.0";
716 }
717);
718
719#[cfg(feature = "gui-fragment")]
720declare_world!(
721 mod gui_fragment_v1,
722 path = "wit/greentic/gui@1.0.0",
723 world = "greentic:gui/gui-fragment@1.0.0",
724 legacy = {
725 pub const PACKAGE_ID: &str = "greentic:gui@1.0.0";
726 }
727);
728
729#[cfg(feature = "worker-api")]
730declare_world!(
731 mod worker_v1,
732 path = "wit/greentic/worker@1.0.0",
733 world = "greentic:worker/worker@1.0.0",
734 legacy = {
735 pub const PACKAGE_ID: &str = "greentic:worker@1.0.0";
736 }
737);
738
739#[cfg(feature = "wasix-mcp-24-11-05")]
740declare_world!(
741 mod wasix_mcp_24_11_05,
742 path = "wit/wasix-mcp@24.11.05.wit",
743 world = "mcp-router",
744 legacy = {
745 pub const PACKAGE_ID: &str = "wasix:mcp@24.11.5";
747 }
748);
749
750#[cfg(feature = "wasix-mcp-25-03-26")]
751declare_world!(
752 mod wasix_mcp_25_03_26,
753 path = "wit/wasix-mcp@25.03.26.wit",
754 world = "mcp-router",
755 legacy = {
756 pub const PACKAGE_ID: &str = "wasix:mcp@25.3.26";
758 }
759);
760
761#[cfg(feature = "wasix-mcp-25-06-18")]
762declare_world!(
763 mod wasix_mcp_25_06_18,
764 path = "wit/wasix-mcp@25.06.18.wit",
765 world = "mcp-router",
766 legacy = {
767 pub const PACKAGE_ID: &str = "wasix:mcp@25.6.18";
769 }
770);