Skip to main content

alien_core/
lib.rs

1mod stack;
2pub use stack::*;
3
4pub mod permissions;
5pub use permissions::*;
6
7mod platform;
8pub use platform::*;
9
10mod build_targets;
11pub use build_targets::*;
12
13mod error;
14pub use error::*;
15
16mod resource;
17pub use resource::*;
18
19mod load_balancer;
20pub use load_balancer::*;
21
22mod resources;
23pub use resources::*;
24
25pub mod events;
26pub use events::*;
27
28pub mod app_events;
29pub use app_events::*;
30
31mod id_utils;
32pub use id_utils::*;
33
34mod stack_state;
35pub use stack_state::*;
36
37mod stack_settings;
38pub use stack_settings::*;
39
40pub mod bindings;
41pub use bindings::*;
42
43mod external_bindings;
44pub use external_bindings::*;
45
46mod client_config;
47pub use client_config::*;
48
49mod deployment;
50pub use deployment::*;
51
52mod dev_status;
53pub use dev_status::*;
54
55pub mod presigned;
56pub use presigned::*;
57
58pub mod arc_types;
59pub use arc_types::*;
60
61pub mod instance_catalog;
62
63pub use alien_macros::alien_event;
64
65pub const VERSION: &str = env!("CARGO_PKG_VERSION");
66
67// Workaround for wasm-bindgen interpreter panics with static constructors.
68// This is required because alien-core uses typetag, which depends on inventory,
69// which uses static constructors that need to be explicitly called in WASM.
70// See: https://docs.rs/inventory/0.3.21/inventory/index.html#webassembly-and-constructors
71#[cfg(all(target_arch = "wasm32", target_family = "wasm"))]
72mod wasm_constructor_workaround {
73    extern "C" {
74        // This function is implicitly provided by the linker when targeting Wasm
75        // and is responsible for running static constructors (used by typetag/inventory).
76        pub(super) fn __wasm_call_ctors();
77    }
78}
79
80/// Initialize WASM constructors required by typetag/inventory.
81///
82/// This function must be called at the entry point of any WASM binary that uses alien-core,
83/// before any code that relies on typetag's trait object deserialization.
84///
85/// # Safety
86///
87/// This function is safe to call multiple times (constructors are idempotent),
88/// but should ideally be called exactly once at module initialization.
89///
90/// # Example
91///
92/// ```ignore
93/// #[event(fetch)]
94/// async fn fetch(req: HttpRequest, env: Env, _ctx: Context) -> Result<Response> {
95///     alien_core::init_wasm_constructors();
96///     // ... rest of your code
97/// }
98/// ```
99#[cfg(all(target_arch = "wasm32", target_family = "wasm"))]
100pub fn init_wasm_constructors() {
101    unsafe {
102        wasm_constructor_workaround::__wasm_call_ctors();
103    }
104}
105
106/// No-op on non-WASM targets
107#[cfg(not(all(target_arch = "wasm32", target_family = "wasm")))]
108pub fn init_wasm_constructors() {
109    // No-op on non-WASM targets
110}