use core::fmt;
pub fn write_prelude(output: &mut impl fmt::Write) -> fmt::Result {
output.write_str(C_ABI)
}
pub const C_ABI: &str = r#"/* Generated by zplugin. Native code is trusted; ABI checks are not a sandbox. */
#ifndef ZPLUGIN_ABI_V1_H
#define ZPLUGIN_ABI_V1_H
#include <stddef.h>
#include <stdint.h>
#if defined(_WIN32)
# define ZP_EXPORT __declspec(dllexport)
# define ZP_CALL __cdecl
#else
# define ZP_EXPORT __attribute__((visibility("default")))
# define ZP_CALL
#endif
#ifdef __cplusplus
# define ZP_EXTERN extern "C"
extern "C" {
#else
# define ZP_EXTERN extern
#endif
#define ZP_MAGIC UINT64_C(0x315f4e4947554c50)
#define ZP_ABI_MAJOR 1
#define ZP_ABI_MINOR 0
#define ZP_COOPERATIVE 1
#define ZP_OK 0
#define ZP_INVALID_ARGUMENT (-1)
#define ZP_INVALID_UTF8 (-2)
#define ZP_BUFFER_TOO_SMALL (-3)
#define ZP_BUSY (-4)
#define ZP_PANICKED (-5)
#define ZP_POISONED (-6)
#define ZP_UNSUPPORTED (-7)
#define ZP_CANCELLED (-8)
#define ZP_COMPLETED (-9)
#define ZP_PENDING 0
#define ZP_READY 1
#define ZP_EXTENSION_VERSION 1
typedef struct zp_header { uint64_t magic; uint16_t major, minor; uint32_t size; } zp_header;
typedef struct zp_version { uint32_t major, minor, patch; } zp_version;
typedef struct zp_bytes { const uint8_t *ptr; size_t len; } zp_bytes;
typedef struct zp_bytes_mut { uint8_t *ptr; size_t len; } zp_bytes_mut;
typedef int32_t (ZP_CALL *zp_call)(void *, const void *, void *);
typedef int32_t (ZP_CALL *zp_create)(void **);
typedef int32_t (ZP_CALL *zp_destroy)(void *);
typedef int32_t (ZP_CALL *zp_quiesce)(void);
typedef int32_t (ZP_CALL *zp_release)(void *, const uint8_t *, size_t);
typedef struct zp_method { zp_bytes signature; zp_call call; } zp_method;
typedef struct zp_interface_descriptor {
uint32_t size, version;
zp_bytes id;
uint32_t method_count;
const zp_method *methods;
zp_create create;
zp_destroy destroy;
} zp_interface_descriptor;
typedef struct zp_plugin_descriptor {
zp_header header;
zp_version plugin_version;
uint32_t flags, interface_count;
const zp_interface_descriptor *const *interfaces;
zp_quiesce quiesce;
} zp_plugin_descriptor;
typedef const zp_header *(ZP_CALL *zp_entry)(void);
typedef struct zp_raw_buffer {
const uint8_t *data;
size_t len;
void *context;
zp_release release;
} zp_raw_buffer;
/* The poll waker is borrowed. Retain before storing; wake borrows, release
* consumes one retained reference. All three operations are thread-safe. */
typedef int32_t (ZP_CALL *zp_wake_fn)(const void *);
typedef struct zp_waker_vtable {
uint32_t size, abi_version;
zp_wake_fn retain, wake, release;
} zp_waker_vtable;
typedef struct zp_raw_waker {
const void *context;
const zp_waker_vtable *vtable;
} zp_raw_waker;
typedef int32_t (ZP_CALL *zp_task_poll)(void *, const zp_raw_waker *, void *, uint32_t *);
typedef struct zp_task_vtable {
uint32_t size, abi_version;
size_t output_size, output_align;
zp_bytes output_schema;
zp_task_poll poll;
zp_destroy cancel, release;
} zp_task_vtable;
typedef struct zp_raw_task {
void *context;
const zp_task_vtable *vtable;
} zp_raw_task;
/* Resources and general callbacks are local-thread, serialized and
* nonreentrant. Callback retain/release use the creating library's allocator. */
typedef int32_t (ZP_CALL *zp_resource_call)(void *, uint32_t, zp_bytes, zp_bytes_mut, size_t *);
typedef struct zp_resource_vtable {
uint32_t size, abi_version;
zp_bytes type_id;
uint32_t resource_version;
zp_resource_call call;
zp_destroy release;
} zp_resource_vtable;
typedef struct zp_raw_resource {
void *context;
const zp_resource_vtable *vtable;
} zp_raw_resource;
typedef int32_t (ZP_CALL *zp_callback_call)(void *, zp_bytes, zp_bytes_mut, size_t *);
typedef struct zp_callback_vtable {
uint32_t size, abi_version;
zp_callback_call invoke;
zp_destroy retain, release;
} zp_callback_vtable;
typedef struct zp_raw_callback {
void *context;
const zp_callback_vtable *vtable;
} zp_raw_callback;
/* Use only on literals; dynamic views must supply their explicit byte length. */
#define ZP_LITERAL(text) {(const uint8_t *)(text), sizeof(text) - 1}
#define ZP_HEADER_INIT {ZP_MAGIC, ZP_ABI_MAJOR, ZP_ABI_MINOR, sizeof(zp_plugin_descriptor)}
/* This checks integer/range shape, not memory mapping, ownership, or aliasing. */
static inline int zp_range_valid(const void *ptr, size_t len) {
return len <= (size_t)PTRDIFF_MAX && (len == 0 || ptr != NULL)
&& (uintptr_t)ptr <= UINTPTR_MAX - len;
}
#ifdef __cplusplus
}
#endif
#endif /* ZPLUGIN_ABI_V1_H */
"#;