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 sync;
59pub mod embedded_config;
60
61pub mod commands_types;
62pub use commands_types::*;
63
64pub mod instance_catalog;
65
66pub use alien_macros::alien_event;
67
68pub const VERSION: &str = env!("CARGO_PKG_VERSION");
69
70// Workaround for wasm-bindgen interpreter panics with static constructors.
71// This is required because alien-core uses typetag, which depends on inventory,
72// which uses static constructors that need to be explicitly called in WASM.
73// See: https://docs.rs/inventory/0.3.21/inventory/index.html#webassembly-and-constructors
74#[cfg(all(target_arch = "wasm32", target_family = "wasm"))]
75mod wasm_constructor_workaround {
76    extern "C" {
77        // This function is implicitly provided by the linker when targeting Wasm
78        // and is responsible for running static constructors (used by typetag/inventory).
79        pub(super) fn __wasm_call_ctors();
80    }
81}
82
83/// Initialize WASM constructors required by typetag/inventory.
84///
85/// This function must be called at the entry point of any WASM binary that uses alien-core,
86/// before any code that relies on typetag's trait object deserialization.
87///
88/// # Safety
89///
90/// This function is safe to call multiple times (constructors are idempotent),
91/// but should ideally be called exactly once at module initialization.
92///
93/// # Example
94///
95/// ```ignore
96/// #[event(fetch)]
97/// async fn fetch(req: HttpRequest, env: Env, _ctx: Context) -> Result<Response> {
98///     alien_core::init_wasm_constructors();
99///     // ... rest of your code
100/// }
101/// ```
102#[cfg(all(target_arch = "wasm32", target_family = "wasm"))]
103pub fn init_wasm_constructors() {
104    unsafe {
105        wasm_constructor_workaround::__wasm_call_ctors();
106    }
107}
108
109/// No-op on non-WASM targets
110#[cfg(not(all(target_arch = "wasm32", target_family = "wasm")))]
111pub fn init_wasm_constructors() {
112    // No-op on non-WASM targets
113}