From a2fd5b0ebd6bff4d5b06e883f0f59f3ea7d3a947 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Wed, 31 Aug 2022 11:22:56 +0200 Subject: [PATCH] Autogenerate the `operator_api.h` header file --- Cargo.lock | 41 +++++++ Cargo.toml | 2 +- apis/c/operator/Cargo.toml | 9 ++ apis/c/operator/build.rs | 6 + apis/c/operator/operator_api.h | 164 +++++++++++++++++++++++++--- apis/c/operator/src/lib.rs | 0 apis/rust/operator/types/Cargo.toml | 2 +- apis/rust/operator/types/src/lib.rs | 6 + 8 files changed, 212 insertions(+), 18 deletions(-) create mode 100644 apis/c/operator/Cargo.toml create mode 100644 apis/c/operator/build.rs create mode 100644 apis/c/operator/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 5cb6aa90..fb9f522f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -835,6 +835,13 @@ dependencies = [ "dora-operator-api-types", ] +[[package]] +name = "dora-operator-api-c" +version = "0.1.0" +dependencies = [ + "dora-operator-api-types", +] + [[package]] name = "dora-operator-api-macros" version = "0.1.0" @@ -1156,6 +1163,17 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "ghost" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb19fe8de3ea0920d282f7b77dd4227aea6b8b999b42cdf0ca41b2472b14443a" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "git-version" version = "0.3.5" @@ -1397,6 +1415,28 @@ version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e85a1509a128c855368e135cffcde7eac17d8e1083f41e2b98c58bc1a5074be" +[[package]] +name = "inventory" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0eb5160c60ba1e809707918ee329adb99d222888155835c6feedba19f6c3fd4" +dependencies = [ + "ctor", + "ghost", + "inventory-impl", +] + +[[package]] +name = "inventory-impl" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e41b53715c6f0c4be49510bb82dee2c1e51c8586d885abe65396e82ed518548" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "ipnetwork" version = "0.18.0" @@ -2699,6 +2739,7 @@ name = "safer-ffi" version = "0.1.0" source = "git+https://github.com/getditto/safer_ffi.git#f69aeb1727bc2f2d68ea5de6bc887411bad12b0a" dependencies = [ + "inventory", "libc", "macro_rules_attribute", "mini_paste", diff --git a/Cargo.toml b/Cargo.toml index 9077db7d..edf1d0ec 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ - "apis/c/node", + "apis/c/*", "apis/python/node", "apis/rust/*", "apis/rust/operator/macros", diff --git a/apis/c/operator/Cargo.toml b/apis/c/operator/Cargo.toml new file mode 100644 index 00000000..ca457efd --- /dev/null +++ b/apis/c/operator/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "dora-operator-api-c" +version = "0.1.0" +edition = "2021" +license = "Apache-2.0" +description = "C API implemetation for Dora Operator" + +[build-dependencies] +dora-operator-api-types = { path = "../../rust/operator/types" } diff --git a/apis/c/operator/build.rs b/apis/c/operator/build.rs new file mode 100644 index 00000000..263668f2 --- /dev/null +++ b/apis/c/operator/build.rs @@ -0,0 +1,6 @@ +use std::path::Path; + +fn main() { + dora_operator_api_types::generate_headers(Path::new("operator_api.h")) + .expect("failed to create operator_api.h"); +} diff --git a/apis/c/operator/operator_api.h b/apis/c/operator/operator_api.h index 9118e98d..7d5bded5 100644 --- a/apis/c/operator/operator_api.h +++ b/apis/c/operator/operator_api.h @@ -1,18 +1,150 @@ +/*! \file */ +/******************************************* + * * + * File auto-generated by `::safer_ffi`. * + * * + * Do not manually edit this file. * + * * + *******************************************/ + +#ifndef __RUST_DORA_OPERATOR_API_C__ +#define __RUST_DORA_OPERATOR_API_C__ +#ifdef __cplusplus +extern "C" { +#endif + + #include +#include + +/** \brief + * Same as [`Vec`][`rust::Vec`], but with guaranteed `#[repr(C)]` layout + */ +typedef struct Vec_uint8 { + /** */ + uint8_t * ptr; + + /** */ + size_t len; + + /** */ + size_t cap; +} Vec_uint8_t; + +/** */ +typedef struct DoraResult { + /** */ + Vec_uint8_t error; +} DoraResult_t; + +/** */ +typedef struct DoraDropOperator { + /** */ + DoraResult_t (*drop_operator)(void *); +} DoraDropOperator_t; + +/** */ +typedef struct InitResult { + /** */ + DoraResult_t result; + + /** */ + void * operator_context; +} InitResult_t; + +/** */ +typedef struct DoraInitOperator { + /** */ + InitResult_t (*init_operator)(void); +} DoraInitOperator_t; + +/** */ +/** \remark Has the same ABI as `uint8_t` **/ +#ifdef DOXYGEN +typedef +#endif +enum DoraStatus { + /** */ + DORA_STATUS_CONTINUE = 0, + /** */ + DORA_STATUS_STOP = 1, +} +#ifndef DOXYGEN +; typedef uint8_t +#endif +DoraStatus_t; + +/** */ +typedef struct OnInputResult { + /** */ + DoraResult_t result; + + /** */ + DoraStatus_t status; +} OnInputResult_t; + +/** */ +typedef struct Metadata { + /** */ + Vec_uint8_t open_telemetry_context; +} Metadata_t; + +/** */ +typedef struct Input { + /** */ + Vec_uint8_t id; + + /** */ + Vec_uint8_t data; + + /** */ + Metadata_t metadata; +} Input_t; + +/** */ +typedef struct Output { + /** */ + Vec_uint8_t id; + + /** */ + Vec_uint8_t data; + + /** */ + Metadata_t metadata; +} Output_t; + +/** \brief + * `Arc Ret>` + */ +typedef struct ArcDynFn1_DoraResult_Output { + /** */ + void * env_ptr; + + /** */ + DoraResult_t (*call)(void *, Output_t); + + /** */ + void (*release)(void *); + + /** */ + void (*retain)(void *); +} ArcDynFn1_DoraResult_Output_t; + +/** */ +typedef struct SendOutput { + /** */ + ArcDynFn1_DoraResult_Output_t send_output; +} SendOutput_t; + +/** */ +typedef struct DoraOnInput { + /** */ + OnInputResult_t (*on_input)(Input_t const *, SendOutput_t, void *); +} DoraOnInput_t; + + +#ifdef __cplusplus +} /* extern \"C\" */ +#endif -int dora_init_operator(void **operator_context); - -void dora_drop_operator(void *operator_context); - -int dora_on_input( - const char *id_start, - size_t id_len, - const char *data_start, - size_t data_len, - const int (*output_fn_raw)(const char *id_start, - size_t id_len, - const char *data_start, - size_t data_len, - const void *output_context), - void *output_context, - const void *operator_context); +#endif /* __RUST_DORA_OPERATOR_API_C__ */ diff --git a/apis/c/operator/src/lib.rs b/apis/c/operator/src/lib.rs new file mode 100644 index 00000000..e69de29b diff --git a/apis/rust/operator/types/Cargo.toml b/apis/rust/operator/types/Cargo.toml index a8cd146a..43cab511 100644 --- a/apis/rust/operator/types/Cargo.toml +++ b/apis/rust/operator/types/Cargo.toml @@ -7,4 +7,4 @@ edition = "2021" [dependencies.safer-ffi] git = "https://github.com/getditto/safer_ffi.git" -features = ["proc_macros"] +features = ["proc_macros", "headers"] diff --git a/apis/rust/operator/types/src/lib.rs b/apis/rust/operator/types/src/lib.rs index 2afe9edd..221342fa 100644 --- a/apis/rust/operator/types/src/lib.rs +++ b/apis/rust/operator/types/src/lib.rs @@ -104,3 +104,9 @@ pub enum DoraStatus { Continue = 0, Stop = 1, } + +pub fn generate_headers(target_file: &Path) -> ::std::io::Result<()> { + ::safer_ffi::headers::builder() + .to_file(target_file)? + .generate() +}