Skip to main content

greentic_interfaces/
wit_all.rs

1#![cfg(not(target_arch = "wasm32"))]
2//! Unified Wasmtime bindings for every WIT world shipped with this crate.
3#![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 generated {
16                wasmtime::component::bindgen!({
17                    path: $path_literal,
18                    world: $world_literal,
19                });
20            }
21
22            #[allow(unused_imports)]
23            pub use generated::*;
24
25            $(
26                $($legacy)*
27            )?
28        }
29    };
30}
31
32#[cfg(feature = "describe-v1")]
33declare_world!(
34    mod component_describe_v1,
35    path = "bundled-wit/greentic-component-1.0.0",
36    world = "greentic:component/component@1.0.0",
37    legacy = {
38        /// Canonical package identifier.
39        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 = "bundled-wit/greentic-component-v1-0.1.0",
47    world = "greentic:component-v1/component-host@0.1.0",
48    legacy = {
49        /// Canonical package identifier.
50        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 = "bundled-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 generated::greentic::component::control::Host as ControlHost;
65
66        /// Registers the Greentic control interface with the provided linker.
67        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        /// Back-compat shim for instantiating the component.
102        pub struct Component;
103
104        impl Component {
105            /// Loads the component from raw bytes, mirroring the old helper.
106            pub fn instantiate(
107                engine: &wasmtime::Engine,
108                component_wasm: &[u8],
109            ) -> AnyResult<WasmtimeComponent> {
110                WasmtimeComponent::from_binary(engine, component_wasm)
111                    .map_err(|err| anyhow::anyhow!("{err}"))
112            }
113        }
114
115        /// Canonical package identifier.
116        pub const PACKAGE_ID: &str = "greentic:component@0.5.0";
117    }
118);
119
120#[cfg(feature = "component-v0-6")]
121declare_world!(
122    mod component_v0_6,
123    path = "bundled-wit/greentic-component-0.6.0",
124    world = "greentic:component/component@0.6.0",
125    legacy = {
126        /// Canonical package identifier.
127        pub const PACKAGE_ID: &str = "greentic:component@0.6.0";
128    }
129);
130
131#[cfg(feature = "component-v0-5")]
132declare_world!(
133    mod component_configurable_v0_5,
134    path = "bundled-wit/greentic-component-0.5.0",
135    world = "greentic:component/component-configurable@0.5.0",
136    legacy = {
137        use anyhow::Result as AnyResult;
138        use wasmtime::component::{Component as WasmtimeComponent, Linker};
139        use wasmtime::StoreContextMut;
140
141        pub use generated::greentic::component::control::Host as ControlHost;
142
143        /// Registers the Greentic control interface with the provided linker.
144        pub fn add_control_to_linker<T>(
145            linker: &mut Linker<T>,
146            get_host: impl Fn(&mut T) -> &mut (dyn ControlHost + Send + Sync + 'static)
147                + Send
148                + Sync
149                + Copy
150                + 'static,
151        ) -> wasmtime::Result<()>
152        where
153            T: Send + 'static,
154        {
155            let mut inst = linker.instance("greentic:component/control@0.5.0")?;
156
157            inst.func_wrap(
158                "should-cancel",
159                move |mut caller: StoreContextMut<'_, T>, (): ()| {
160                    let host = get_host(caller.data_mut());
161                    let result = host.should_cancel();
162                    Ok((result,))
163                },
164            )?;
165
166            inst.func_wrap(
167                "yield-now",
168                move |mut caller: StoreContextMut<'_, T>, (): ()| {
169                    let host = get_host(caller.data_mut());
170                    host.yield_now();
171                    Ok(())
172                },
173            )?;
174
175            Ok(())
176        }
177
178        /// Back-compat shim for instantiating the component.
179        pub struct Component;
180
181        impl Component {
182            /// Loads the component from raw bytes, mirroring the old helper.
183            pub fn instantiate(
184                engine: &wasmtime::Engine,
185                component_wasm: &[u8],
186            ) -> AnyResult<WasmtimeComponent> {
187                WasmtimeComponent::from_binary(engine, component_wasm)
188                    .map_err(|err| anyhow::anyhow!("{err}"))
189            }
190        }
191
192        /// Canonical package identifier.
193        pub const PACKAGE_ID: &str = "greentic:component@0.5.0";
194    }
195);
196
197#[cfg(feature = "common-types-v0-1")]
198declare_world!(
199    mod common_types_v0_1,
200    path = "bundled-wit/greentic-common-types-0.1.0",
201    world = "greentic:common-types/common@0.1.0",
202    legacy = {
203        /// Canonical package identifier.
204        pub const PACKAGE_ID: &str = "greentic:common-types@0.1.0";
205    }
206);
207
208#[cfg(feature = "component-v0-4")]
209declare_world!(
210    mod component_v0_4,
211    path = "bundled-wit/greentic-component-0.4.0",
212    world = "greentic:component/component@0.4.0",
213    legacy = {
214        use anyhow::Result as AnyResult;
215        use wasmtime::component::{Component as WasmtimeComponent, Linker};
216        use wasmtime::StoreContextMut;
217
218        pub use generated::greentic::component::control::Host as ControlHost;
219
220        /// Registers the Greentic control interface with the provided linker.
221        pub fn add_control_to_linker<T>(
222            linker: &mut Linker<T>,
223            get_host: impl Fn(&mut T) -> &mut (dyn ControlHost + Send + Sync + 'static)
224                + Send
225                + Sync
226                + Copy
227                + 'static,
228        ) -> wasmtime::Result<()>
229        where
230            T: Send + 'static,
231        {
232            let mut inst = linker.instance("greentic:component/control@0.4.0")?;
233
234            inst.func_wrap(
235                "should-cancel",
236                move |mut caller: StoreContextMut<'_, T>, (): ()| {
237                    let host = get_host(caller.data_mut());
238                    let result = host.should_cancel();
239                    Ok((result,))
240                },
241            )?;
242
243            inst.func_wrap(
244                "yield-now",
245                move |mut caller: StoreContextMut<'_, T>, (): ()| {
246                    let host = get_host(caller.data_mut());
247                    host.yield_now();
248                    Ok(())
249                },
250            )?;
251
252            Ok(())
253        }
254
255        /// Back-compat shim for instantiating the component.
256        pub struct Component;
257
258        impl Component {
259            /// Loads the component from raw bytes, mirroring the old helper.
260            pub fn instantiate(
261                engine: &wasmtime::Engine,
262                component_wasm: &[u8],
263            ) -> AnyResult<WasmtimeComponent> {
264                WasmtimeComponent::from_binary(engine, component_wasm)
265                    .map_err(|err| anyhow::anyhow!("{err}"))
266            }
267        }
268
269        /// Canonical package identifier.
270        pub const PACKAGE_ID: &str = "greentic:component@0.4.0";
271    }
272);
273
274#[cfg(feature = "pack-export-v0-4")]
275declare_world!(
276    mod pack_export_v0_4,
277    path = "bundled-wit/greentic-pack-export-0.4.0",
278    world = "greentic:pack-export/pack-exports@0.4.0",
279    legacy = {
280        /// Canonical package identifier.
281        pub const PACKAGE_ID: &str = "greentic:pack-export@0.4.0";
282    }
283);
284
285#[cfg(feature = "pack-export-v1")]
286declare_world!(
287    mod pack_export_v1,
288    path = "bundled-wit/greentic-pack-export-v1-0.1.0",
289    world = "greentic:pack-export-v1/pack-host@0.1.0",
290    legacy = {
291        /// Canonical package identifier.
292        pub const PACKAGE_ID: &str = "greentic:pack-export-v1@0.1.0";
293    }
294);
295
296#[cfg(feature = "pack-validate-v0-1")]
297declare_world!(
298    mod pack_validate_v0_1,
299    path = "bundled-wit/greentic-pack-validate-0.1.0",
300    world = "greentic:pack-validate/pack-validator@0.1.0",
301    legacy = {
302        /// Canonical package identifier.
303        pub const PACKAGE_ID: &str = "greentic:pack-validate@0.1.0";
304    }
305);
306
307#[cfg(feature = "provision-v0-1")]
308declare_world!(
309    mod provision_v0_1,
310    path = "bundled-wit/greentic-provision-0.1.0",
311    world = "greentic:provision/provision-runner@0.1.0",
312    legacy = {
313        /// Canonical package identifier.
314        pub const PACKAGE_ID: &str = "greentic:provision@0.1.0";
315    }
316);
317
318#[cfg(feature = "types-core-v0-4")]
319declare_world!(
320    mod types_core_v0_4,
321    path = "bundled-wit/greentic-types-core-0.4.0",
322    world = "greentic:types-core/core@0.4.0",
323    legacy = {
324        /// Canonical package identifier.
325        pub const PACKAGE_ID: &str = "greentic:types-core@0.4.0";
326    }
327);
328
329#[cfg(feature = "runner-host-v1")]
330declare_world!(
331    mod runner_host_v1,
332    path = "bundled-wit/greentic-host-1.0.0",
333    world = "greentic:host/runner-host@1.0.0",
334    legacy = {
335        use std::vec::Vec;
336        use wasmtime::component::Linker;
337        use wasmtime::{Result, StoreContextMut};
338
339        pub use generated::greentic::host::{http_v1, kv_v1};
340
341        /// Minimal trait hosts implement to satisfy the runner-host imports.
342        pub trait RunnerHost {
343            fn http_request(
344                &mut self,
345                method: String,
346                url: String,
347                headers: Vec<String>,
348                body: Option<Vec<u8>>,
349            ) -> Result<Result<Vec<u8>, String>>;
350
351            fn kv_get(&mut self, ns: String, key: String) -> Result<Option<String>>;
352
353            fn kv_put(&mut self, ns: String, key: String, val: String) -> Result<()>;
354        }
355
356        /// Registers the runner-host interfaces with the provided linker.
357        pub fn add_to_linker<T>(
358            linker: &mut Linker<T>,
359            get_host: impl Fn(&mut T) -> &mut (dyn RunnerHost + Send + Sync + 'static)
360                + Send
361                + Sync
362                + Copy
363                + 'static,
364        ) -> Result<()>
365        where
366            T: Send + 'static,
367        {
368            let mut http = linker.instance("greentic:host/http-v1@1.0.0")?;
369            http.func_wrap(
370                "request",
371                move |mut caller: StoreContextMut<'_, T>,
372                      (method, url, headers, body): (String, String, Vec<String>, Option<Vec<u8>>)| {
373                    let host = get_host(caller.data_mut());
374                    host.http_request(method, url, headers, body)
375                        .map(|res| (res,))
376                },
377            )?;
378
379            let mut kv = linker.instance("greentic:host/kv-v1@1.0.0")?;
380            kv.func_wrap(
381                "get",
382                move |mut caller: StoreContextMut<'_, T>, (ns, key): (String, String)| {
383                    let host = get_host(caller.data_mut());
384                    host.kv_get(ns, key).map(|res| (res,))
385                },
386            )?;
387            kv.func_wrap(
388                "put",
389                move |mut caller: StoreContextMut<'_, T>, (ns, key, val): (String, String, String)| {
390                    let host = get_host(caller.data_mut());
391                    host.kv_put(ns, key, val)
392                },
393            )?;
394
395            Ok(())
396        }
397
398        /// Canonical package identifier.
399        pub const PACKAGE_ID: &str = "greentic:host@1.0.0";
400    }
401);
402
403#[cfg(feature = "operator-hooks-v1")]
404declare_world!(
405    mod operator_hook_provider_v1,
406    path = "bundled-wit/greentic-operator-1.0.0",
407    world = "greentic:operator/hook-provider@1.0.0",
408    legacy = {
409        /// Canonical package identifier.
410        pub const PACKAGE_ID: &str = "greentic:operator@1.0.0";
411    }
412);
413
414#[cfg(feature = "pack-export-v0-2")]
415declare_world!(
416    mod pack_export_v0_2,
417    path = "bundled-wit/greentic-pack-export-0.2.0",
418    world = "greentic:pack-export/pack-exports@0.2.0",
419    legacy = {
420        /// Canonical package identifier.
421        pub const PACKAGE_ID: &str = "greentic:pack-export@0.2.0";
422    }
423);
424
425#[cfg(feature = "types-core-v0-2")]
426declare_world!(
427    mod types_core_v0_2,
428    path = "bundled-wit/greentic-types-core-0.2.0",
429    world = "greentic:types-core/core@0.2.0",
430    legacy = {
431        /// Canonical package identifier.
432        pub const PACKAGE_ID: &str = "greentic:types-core@0.2.0";
433    }
434);
435
436#[cfg(feature = "oauth-broker-v1")]
437declare_world!(
438    mod oauth_broker_v1,
439    path = "bundled-wit/greentic-oauth-broker-1.0.0",
440    world = "greentic:oauth-broker/broker@1.0.0",
441    legacy = {
442        /// Canonical package identifier.
443        pub const PACKAGE_ID: &str = "greentic:oauth-broker@1.0.0";
444    }
445);
446
447#[cfg(feature = "oauth-broker-v1")]
448declare_world!(
449    mod oauth_broker_client_v1,
450    path = "bundled-wit/greentic-oauth-broker-1.0.0",
451    world = "greentic:oauth-broker/broker-client@1.0.0",
452    legacy = {
453        /// Canonical package identifier.
454        pub const PACKAGE_ID: &str = "greentic:oauth-broker@1.0.0";
455    }
456);
457
458#[cfg(feature = "component-lifecycle-v1")]
459declare_world!(
460    mod component_lifecycle_v1,
461    path = "bundled-wit/greentic-lifecycle-1.0.0",
462    world = "greentic:lifecycle/component-lifecycle@1.0.0",
463    legacy = {
464        /// Canonical package identifier.
465        pub const PACKAGE_ID: &str = "greentic:lifecycle@1.0.0";
466    }
467);
468
469#[cfg(feature = "secrets-store-v1")]
470declare_world!(
471    mod secrets_store_v1,
472    path = "bundled-wit/greentic-secrets-store-1.0.0",
473    world = "greentic:secrets-store/store@1.0.0",
474    legacy = {
475        /// Canonical package identifier.
476        pub const PACKAGE_ID: &str = "greentic:secrets-store@1.0.0";
477    }
478);
479
480#[cfg(feature = "provider-core-v1")]
481declare_world!(
482    mod provider_schema_core_v1,
483    path = "bundled-wit/greentic-provider-schema-core-1.0.0",
484    world = "greentic:provider-schema-core/schema-core@1.0.0",
485    legacy = {
486        /// Canonical package identifier.
487        pub const PACKAGE_ID: &str = "greentic:provider-schema-core@1.0.0";
488    }
489);
490
491#[cfg(feature = "provider-common")]
492declare_world!(
493    mod provider_common,
494    path = "bundled-wit/provider-common-0.0.2",
495    world = "provider:common/common@0.0.2"
496);
497
498#[cfg(feature = "state-store-v1")]
499declare_world!(
500    mod state_store_v1,
501    path = "bundled-wit/greentic-state-1.0.0",
502    world = "greentic:state/store@1.0.0",
503    legacy = {
504        pub const PACKAGE_ID: &str = "greentic:state@1.0.0";
505    }
506);
507
508#[cfg(feature = "http-client-v1")]
509declare_world!(
510    mod http_client_v1,
511    path = "bundled-wit/greentic-http-1.0.0",
512    world = "greentic:http/client@1.0.0",
513    legacy = {
514        pub const PACKAGE_ID: &str = "greentic:http@1.0.0";
515    }
516);
517
518#[cfg(feature = "http-client-v1-1")]
519declare_world!(
520    mod http_client_v1_1,
521    path = "bundled-wit/greentic-http-1.1.0",
522    world = "greentic:http/client@1.1.0",
523    legacy = {
524        pub const PACKAGE_ID: &str = "greentic:http@1.1.0";
525    }
526);
527
528#[cfg(feature = "telemetry-logger-v1")]
529declare_world!(
530    mod telemetry_logger_v1,
531    path = "bundled-wit/greentic-telemetry-1.0.0",
532    world = "greentic:telemetry/logger@1.0.0",
533    legacy = {
534        pub const PACKAGE_ID: &str = "greentic:telemetry@1.0.0";
535    }
536);
537
538#[cfg(feature = "source-v1")]
539declare_world!(
540    mod source_v1,
541    path = "bundled-wit/greentic-source-1.0.0",
542    world = "greentic:source/source-sync@1.0.0",
543    legacy = {
544        pub const PACKAGE_ID: &str = "greentic:source@1.0.0";
545    }
546);
547
548#[cfg(feature = "build-v1")]
549declare_world!(
550    mod build_v1,
551    path = "bundled-wit/greentic-build-1.0.0",
552    world = "greentic:build/builder@1.0.0",
553    legacy = {
554        pub const PACKAGE_ID: &str = "greentic:build@1.0.0";
555    }
556);
557
558#[cfg(feature = "scan-v1")]
559declare_world!(
560    mod scan_v1,
561    path = "bundled-wit/greentic-scan-1.0.0",
562    world = "greentic:scan/scanner@1.0.0",
563    legacy = {
564        pub const PACKAGE_ID: &str = "greentic:scan@1.0.0";
565    }
566);
567
568#[cfg(feature = "signing-v1")]
569declare_world!(
570    mod signing_v1,
571    path = "bundled-wit/greentic-signing-1.0.0",
572    world = "greentic:signing/signer@1.0.0",
573    legacy = {
574        pub const PACKAGE_ID: &str = "greentic:signing@1.0.0";
575    }
576);
577
578#[cfg(feature = "attestation-v1")]
579declare_world!(
580    mod attestation_v1,
581    path = "bundled-wit/greentic-attestation-1.0.0",
582    world = "greentic:attestation/attester@1.0.0",
583    legacy = {
584        pub const PACKAGE_ID: &str = "greentic:attestation@1.0.0";
585    }
586);
587
588#[cfg(feature = "policy-v1")]
589declare_world!(
590    mod policy_v1,
591    path = "bundled-wit/greentic-policy-1.0.0",
592    world = "greentic:policy/policy-evaluator@1.0.0",
593    legacy = {
594        pub const PACKAGE_ID: &str = "greentic:policy@1.0.0";
595    }
596);
597
598#[cfg(feature = "metadata-v1")]
599declare_world!(
600    mod metadata_v1,
601    path = "bundled-wit/greentic-metadata-1.0.0",
602    world = "greentic:metadata/metadata-store@1.0.0",
603    legacy = {
604        pub const PACKAGE_ID: &str = "greentic:metadata@1.0.0";
605    }
606);
607
608#[cfg(feature = "distribution-v1")]
609declare_world!(
610    mod distribution_v1,
611    path = "bundled-wit/greentic-distribution-1.0.0",
612    world = "greentic:distribution/distribution@1.0.0",
613    legacy = {
614        pub const PACKAGE_ID: &str = "greentic:distribution@1.0.0";
615    }
616);
617
618#[cfg(feature = "distributor-api")]
619declare_world!(
620    mod distributor_api_v1,
621    path = "bundled-wit/greentic-distributor-api-1.0.0",
622    world = "greentic:distributor-api/distributor-api@1.0.0",
623    legacy = {
624        pub const PACKAGE_ID: &str = "greentic:distributor-api@1.0.0";
625    }
626);
627
628#[cfg(feature = "distributor-api-v1-1")]
629declare_world!(
630    mod distributor_api_v1_1,
631    path = "bundled-wit/greentic-distributor-api-1.1.0",
632    world = "greentic:distributor-api/distributor-api@1.1.0",
633    legacy = {
634        pub const PACKAGE_ID: &str = "greentic:distributor-api@1.1.0";
635    }
636);
637
638#[cfg(feature = "oci-v1")]
639declare_world!(
640    mod oci_v1,
641    path = "bundled-wit/greentic-oci-1.0.0",
642    world = "greentic:oci/oci-distribution@1.0.0",
643    legacy = {
644        pub const PACKAGE_ID: &str = "greentic:oci@1.0.0";
645    }
646);
647
648#[cfg(feature = "repo-ui-actions-v1")]
649declare_world!(
650    mod repo_ui_actions_repo_ui_worker_v1,
651    path = "bundled-wit/greentic-repo-ui-actions-1.0.0",
652    world = "greentic:repo-ui-actions/repo-ui-worker@1.0.0",
653    legacy = {
654        pub const PACKAGE_ID: &str = "greentic:repo-ui-actions@1.0.0";
655    }
656);
657
658#[cfg(feature = "gui-fragment")]
659declare_world!(
660    mod gui_fragment_v1,
661    path = "bundled-wit/greentic-gui-1.0.0",
662    world = "greentic:gui/gui-fragment@1.0.0",
663    legacy = {
664        pub const PACKAGE_ID: &str = "greentic:gui@1.0.0";
665    }
666);
667
668#[cfg(feature = "worker-api")]
669declare_world!(
670    mod worker_v1,
671    path = "bundled-wit/greentic-worker-1.0.0",
672    world = "greentic:worker/worker@1.0.0",
673    legacy = {
674        pub const PACKAGE_ID: &str = "greentic:worker@1.0.0";
675    }
676);
677
678#[cfg(feature = "wasix-mcp-24-11-05")]
679declare_world!(
680    mod wasix_mcp_24_11_05,
681    path = "wit/wasix-mcp@24.11.05.wit",
682    world = "mcp-router",
683    legacy = {
684        /// Canonical package identifier.
685        pub const PACKAGE_ID: &str = "wasix:mcp@24.11.5";
686    }
687);
688
689#[cfg(feature = "wasix-mcp-25-03-26")]
690declare_world!(
691    mod wasix_mcp_25_03_26,
692    path = "wit/wasix-mcp@25.03.26.wit",
693    world = "mcp-router",
694    legacy = {
695        /// Canonical package identifier.
696        pub const PACKAGE_ID: &str = "wasix:mcp@25.3.26";
697    }
698);
699
700#[cfg(feature = "wasix-mcp-25-06-18")]
701declare_world!(
702    mod wasix_mcp_25_06_18,
703    path = "wit/wasix-mcp@25.06.18.wit",
704    world = "mcp-router",
705    legacy = {
706        /// Canonical package identifier.
707        pub const PACKAGE_ID: &str = "wasix:mcp@25.6.18";
708    }
709);