ark-api-ffi 0.17.0-pre.15

Ark low-level Wasm FFI API
Documentation
// disable this compiler warning as it things our API functions name clash in name when the same
// function name is exported multiple times with the same name, for example `http_download__retrieve`.
// but that is not the case because we use #[link(wasm_import_module = "<api-name-and-version>")] to create unique imports for Wasm
#![allow(clashing_extern_declarations)]
// disable warning on the extern C definitions of the APIs
#![allow(dead_code)]
// allow deprecations as our hostshims can use deprecated functions in the APIs
#![allow(deprecated)]

// APIs
pub mod applet_v0;
pub mod applet_v1;
pub mod applet_v2;
pub mod applet_v3;
pub mod applet_v4;
pub mod applet_v5;
pub mod behavior_controller_v0;
pub mod behavior_controller_v1;
pub mod behavior_v0;
pub mod core_v0;
pub mod core_v1;
pub mod core_v2;
pub mod core_v3;
pub mod core_v4;
pub mod feature_toggle_v0;
pub mod file_ux_v0;
pub mod http_request_v1;
pub mod ml_inference_v0;
pub mod ml_v1;
pub mod ml_v2;
pub mod ml_v3;
pub mod ml_v4;
pub mod ml_v5;
pub mod module_run_v0;
pub mod profiler_v0;
pub mod render_v0;
pub mod render_v1;
pub mod resource_v0;
pub mod resource_v1;
pub mod storage_v1;
pub mod telemetry_v0;
pub mod time_v1;
pub mod user_v1;
pub mod world_v0;
pub mod world_v1;
pub mod world_v2;
pub mod world_v3;
pub mod world_v4;

// Unstable APIs

// Examples

#[cfg(feature = "examples")]
pub mod example_automatic;
#[cfg(feature = "examples")]
pub mod example_manual;

use crate::ApiId;

/// List of known current and previous API IDs and their names
#[doc(hidden)]
#[allow(deprecated)]
#[rustfmt::skip]
// APIs that are defined in this crate
pub static DEFINED_APIS: &[ApiId] = &[
    crate::applet_v0::API,
    crate::applet_v1::API,
    crate::applet_v2::API,
    crate::applet_v3::API,
    crate::applet_v4::API,
    crate::applet_v5::API,
    crate::behavior_controller_v0::API,
    crate::behavior_controller_v1::API,
    crate::behavior_v0::API,
    crate::core_v0::API,
    crate::core_v1::API,
    crate::core_v2::API,
    crate::core_v3::API,
    crate::core_v4::API,
    crate::feature_toggle_v0::API,
    crate::file_ux_v0::API,
    crate::http_request_v1::API,
    crate::ml_v1::API,
    crate::ml_v2::API,
    crate::ml_v3::API,
    crate::ml_v4::API,
    crate::ml_v5::API,
    crate::ml_inference_v0::API,
    crate::module_run_v0::API,
    crate::profiler_v0::API,
    crate::render_v0::API,
    crate::render_v1::API,
    crate::resource_v0::API,
    crate::resource_v1::API,
    crate::storage_v1::API,
    crate::telemetry_v0::API,
    crate::time_v1::API,
    crate::user_v1::API,
    crate::world_v0::API,
    crate::world_v1::API,
    crate::world_v2::API,
    crate::world_v3::API,
    crate::world_v4::API,
];

#[doc(hidden)]
#[allow(deprecated)]
#[rustfmt::skip]
// APIs we have removed, but keep the ID and name associations to get better error messages
pub static REMOVED_APIS: &[ApiId] = &[
    ApiId { id: 0xaed6_0109_4f07_3c6e, name: "unstable-ml-v0" },
    ApiId { id: 0x290f_0d1e_3c13_2a49, name: "unstable-applet-v0" },
    ApiId { id: 0x936b_f2af_ca83_48b3, name: "unstable-profiler-v0" },
    ApiId { id: 0xea8c_6fd2_06ad_4b8d, name: "canvas-v0" },
    ApiId { id: 0xba92_f306_29a4_9043, name: "imgui-v0" }, // Removed 2021-02-01
    ApiId { id: 0x6b6a_530d_a562_96fb, name: "scene-ext-poly"},
    ApiId { id: 0x2346_af34_cd79_ba23, name: "scene-ext-has-mesh-semantics"}, // removed 2021-04-14
    ApiId { id: 0x6dc8_e9c5_0714_4da6, name: "scene-ext-mesh-buffer"}, // removed 2021-04-14
    ApiId { id: 0x0ace_7d0c_cd62_1807, name: "scene-ext-mesh-style"}, // removed 2021-04-14
    ApiId { id: 0x1359_9673_ab35_8900, name: "scene-ext-ray-intersect"}, // removed 2021-04-14
    ApiId { id: 0xaed6_0109_4f07_3c7f, name: "ml-v0"}, // removed 2021-04-16
    ApiId { id: 0x2110_e04a_32df_fab0, name: "storage-v0" }, // removed 2021-08-13
    ApiId { id: 0xa611_870d_dd2d_94d0, name: "http-request-v0" }, // removed 2021-09-08
    ApiId { id: 0x7c17_633d_0906_cfa4, name: "user-v0" }, // removed 2022-03-10
    ApiId { id: 0x6b95_7be8_9952_68bd, name: "time-v0" }, // removed 2020-03-26
    ApiId { id: 6000, name: "scene-v0"}, // removed 2021-04-14
    ApiId { id: 6001, name: "scene-v1"}, // removed 2021-04-14
    ApiId { id: 6002, name: "scene-v2"}, // removed 2021-04-14
    ApiId { id: 6003, name: "scene-v3"}, // removed 2021-04-14
    ApiId { id: 6004, name: "scene-v4"}, // removed 2021-04-14
    ApiId { id: 5000, name: "mixer-v0" },
    ApiId { id: 5001, name: "mixer-v1" },
    ApiId { id: 5002, name: "mixer-v2" },
    ApiId { id: 5003, name: "mixer-v3" },
    ApiId { id: 5004, name: "mixer-v4" },
    ApiId { id: 5005, name: "mixer-v5" },
    ApiId { id: 4000, name: "log-v0" },
    ApiId { id: 4001, name: "log-v1" },
    ApiId { id: 3000, name: "http-download-v0" },
    ApiId { id: 3001, name: "http-download-v1" },
];

#[cfg(test)]
#[allow(clippy::panic)]
mod test {
    // verify APIs IDs do not clash
    #[test]
    fn validate_api_ids() {
        use super::*;
        let mut api_map = std::collections::BTreeMap::new();
        for api in DEFINED_APIS.iter().chain(REMOVED_APIS.iter()) {
            if let Some(api2_name) = api_map.insert(api.id, api.name) {
                panic!(
                    "API \"{}\" and API \"{}\" are using identical ID {:x}",
                    api.name, api2_name, api.id
                );
            }
        }
    }

    fn valid_api_name(name: &str) -> bool {
        name.chars()
            .all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-')
    }

    // verify API names follow our naming standard and do not clash
    #[test]
    fn validate_api_names() {
        use super::*;
        let mut api_map = std::collections::BTreeMap::new();
        for api in DEFINED_APIS.iter().chain(REMOVED_APIS.iter()) {
            assert!(valid_api_name(api.name));

            if let Some(api2_id) = api_map.insert(api.name, api.id) {
                panic!(
                    "Multiple APIs with the name \"{}\", id {:x} and {:x}",
                    api.name, api.id, api2_id
                );
            }
        }
    }
}