diff --git a/native/Cargo.lock b/native/Cargo.lock index a6e35a8..d648e08 100644 --- a/native/Cargo.lock +++ b/native/Cargo.lock @@ -98,9 +98,9 @@ checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" [[package]] name = "csbindgen" -version = "1.8.3" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df2f2752e26ade4753a17512e2b072489b7eb1df357a8c62cbdb464cff809b27" +checksum = "cf70eb656f35e0e6956cbde31c66431c53d8a546823489719099c71525767a9c" dependencies = [ "regex", "syn 1.0.109", diff --git a/native/yaha_native/Cargo.toml b/native/yaha_native/Cargo.toml index 0001678..f60a0d4 100644 --- a/native/yaha_native/Cargo.toml +++ b/native/yaha_native/Cargo.toml @@ -10,7 +10,7 @@ license = "MIT" crate-type = ["staticlib", "cdylib"] [build-dependencies] -csbindgen = "1.8.3" +csbindgen = "1.9.1" [dependencies] tokio = { version = "1", features = ["full"] } diff --git a/native/yaha_native/build.rs b/native/yaha_native/build.rs index 8afd5a0..f8afee9 100644 --- a/native/yaha_native/build.rs +++ b/native/yaha_native/build.rs @@ -11,9 +11,25 @@ fn main() -> Result<(), Box> { .csharp_dll_name("Cysharp.Net.Http.YetAnotherHttpHandler.Native") .csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal") .csharp_use_function_pointer(false) + .csharp_file_header("#if !UNITY_WSA") + .csharp_file_footer("#endif") .generate_csharp_file("../../src/YetAnotherHttpHandler/NativeMethods.g.cs") .unwrap(); + csbindgen::Builder::default() + .input_extern_file("src/lib.rs") + .input_extern_file("src/binding.rs") + .input_extern_file("src/interop.rs") + .input_extern_file("src/context.rs") + .input_extern_file("src/primitives.rs") + .csharp_namespace("Cysharp.Net.Http") + .csharp_dll_name("Cysharp.Net.Http.YetAnotherHttpHandler.Native.dll") + .csharp_file_header("#if UNITY_WSA") + .csharp_file_footer("#endif") + .csharp_use_function_pointer(false) + .generate_csharp_file("../../src/YetAnotherHttpHandler/NativeMethods.Uwp.g.cs") + .unwrap(); + csbindgen::Builder::default() .input_extern_file("src/binding.rs") .csharp_namespace("Cysharp.Net.Http") diff --git a/src/YetAnotherHttpHandler/NativeMethods.Uwp.g.cs b/src/YetAnotherHttpHandler/NativeMethods.Uwp.g.cs new file mode 100644 index 0000000..cc50940 --- /dev/null +++ b/src/YetAnotherHttpHandler/NativeMethods.Uwp.g.cs @@ -0,0 +1,210 @@ +#if UNITY_WSA +// +// This code is generated by csbindgen. +// DON'T CHANGE THIS DIRECTLY. +// +#pragma warning disable CS8500 +#pragma warning disable CS8981 +using System; +using System.Runtime.InteropServices; + + +namespace Cysharp.Net.Http +{ + internal static unsafe partial class NativeMethods + { + const string __DllName = "Cysharp.Net.Http.YetAnotherHttpHandler.Native.dll"; + + + + [DllImport(__DllName, EntryPoint = "yaha_get_last_error", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern ByteBuffer* yaha_get_last_error(); + + [DllImport(__DllName, EntryPoint = "yaha_free_byte_buffer", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_free_byte_buffer(ByteBuffer* s); + + [DllImport(__DllName, EntryPoint = "yaha_init_runtime", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern YahaNativeRuntimeContext* yaha_init_runtime(); + + [DllImport(__DllName, EntryPoint = "yaha_dispose_runtime", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_dispose_runtime(YahaNativeRuntimeContext* ctx); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void yaha_init_context_on_status_code_and_headers_receive_delegate(int req_seq, nint state, int status_code, YahaHttpVersion version); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void yaha_init_context_on_receive_delegate(int req_seq, nint state, nuint length, byte* buf); + + [UnmanagedFunctionPointer(CallingConvention.Cdecl)] + public delegate void yaha_init_context_on_complete_delegate(int req_seq, nint state, CompletionReason reason); + + [DllImport(__DllName, EntryPoint = "yaha_init_context", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern YahaNativeContext* yaha_init_context(YahaNativeRuntimeContext* runtime_ctx, yaha_init_context_on_status_code_and_headers_receive_delegate on_status_code_and_headers_receive, yaha_init_context_on_receive_delegate on_receive, yaha_init_context_on_complete_delegate on_complete); + + [DllImport(__DllName, EntryPoint = "yaha_dispose_context", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_dispose_context(YahaNativeContext* ctx); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_add_root_certificates", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern nuint yaha_client_config_add_root_certificates(YahaNativeContext* ctx, StringBuffer* root_certs); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_add_client_auth_certificates", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern nuint yaha_client_config_add_client_auth_certificates(YahaNativeContext* ctx, StringBuffer* auth_certs); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_add_client_auth_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern nuint yaha_client_config_add_client_auth_key(YahaNativeContext* ctx, StringBuffer* auth_key); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_skip_certificate_verification", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_skip_certificate_verification(YahaNativeContext* ctx, [MarshalAs(UnmanagedType.U1)] bool val); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_pool_idle_timeout", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_pool_idle_timeout(YahaNativeContext* ctx, ulong val_milliseconds); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_pool_max_idle_per_host", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_pool_max_idle_per_host(YahaNativeContext* ctx, nuint max_idle); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_only", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_only(YahaNativeContext* ctx, [MarshalAs(UnmanagedType.U1)] bool val); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_initial_stream_window_size", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_initial_stream_window_size(YahaNativeContext* ctx, uint val); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_initial_connection_window_size", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_initial_connection_window_size(YahaNativeContext* ctx, uint val); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_adaptive_window", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_adaptive_window(YahaNativeContext* ctx, [MarshalAs(UnmanagedType.U1)] bool val); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_max_frame_size", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_max_frame_size(YahaNativeContext* ctx, uint val); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_keep_alive_interval", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_keep_alive_interval(YahaNativeContext* ctx, ulong interval_milliseconds); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_keep_alive_timeout", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_keep_alive_timeout(YahaNativeContext* ctx, ulong timeout_milliseconds); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_keep_alive_while_idle", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_keep_alive_while_idle(YahaNativeContext* ctx, [MarshalAs(UnmanagedType.U1)] bool val); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_max_concurrent_reset_streams", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_max_concurrent_reset_streams(YahaNativeContext* ctx, nuint max); + + [DllImport(__DllName, EntryPoint = "yaha_client_config_http2_max_send_buf_size", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_client_config_http2_max_send_buf_size(YahaNativeContext* ctx, nuint max); + + [DllImport(__DllName, EntryPoint = "yaha_build_client", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_build_client(YahaNativeContext* ctx); + + [DllImport(__DllName, EntryPoint = "yaha_request_new", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern YahaNativeRequestContext* yaha_request_new(YahaNativeContext* ctx, int seq); + + [DllImport(__DllName, EntryPoint = "yaha_request_set_method", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool yaha_request_set_method(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, StringBuffer* value); + + [DllImport(__DllName, EntryPoint = "yaha_request_set_has_body", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool yaha_request_set_has_body(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, [MarshalAs(UnmanagedType.U1)] bool value); + + [DllImport(__DllName, EntryPoint = "yaha_request_set_uri", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool yaha_request_set_uri(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, StringBuffer* value); + + [DllImport(__DllName, EntryPoint = "yaha_request_set_version", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool yaha_request_set_version(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, YahaHttpVersion value); + + [DllImport(__DllName, EntryPoint = "yaha_request_set_header", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool yaha_request_set_header(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, StringBuffer* key, StringBuffer* value); + + [DllImport(__DllName, EntryPoint = "yaha_request_begin", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool yaha_request_begin(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, nint state); + + [DllImport(__DllName, EntryPoint = "yaha_request_abort", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void yaha_request_abort(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx); + + [DllImport(__DllName, EntryPoint = "yaha_request_write_body", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool yaha_request_write_body(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, byte* buf, nuint len); + + [DllImport(__DllName, EntryPoint = "yaha_request_complete_body", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool yaha_request_complete_body(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx); + + [DllImport(__DllName, EntryPoint = "yaha_request_response_get_headers_count", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern int yaha_request_response_get_headers_count(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx); + + [DllImport(__DllName, EntryPoint = "yaha_request_response_get_header_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern ByteBuffer* yaha_request_response_get_header_key(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, int index); + + [DllImport(__DllName, EntryPoint = "yaha_request_response_get_header_value", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern ByteBuffer* yaha_request_response_get_header_value(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, int index); + + [DllImport(__DllName, EntryPoint = "yaha_request_response_get_trailers_count", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern int yaha_request_response_get_trailers_count(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx); + + [DllImport(__DllName, EntryPoint = "yaha_request_response_get_trailers_key", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern ByteBuffer* yaha_request_response_get_trailers_key(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, int index); + + [DllImport(__DllName, EntryPoint = "yaha_request_response_get_trailers_value", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern ByteBuffer* yaha_request_response_get_trailers_value(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx, int index); + + [DllImport(__DllName, EntryPoint = "yaha_request_destroy", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + [return: MarshalAs(UnmanagedType.U1)] + public static extern bool yaha_request_destroy(YahaNativeContext* ctx, YahaNativeRequestContext* req_ctx); + + + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct StringBuffer + { + public byte* ptr; + public int length; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct ByteBuffer + { + public byte* ptr; + public int length; + public int capacity; + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct YahaNativeRuntimeContext + { + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct YahaNativeContext + { + } + + [StructLayout(LayoutKind.Sequential)] + internal unsafe partial struct YahaNativeRequestContext + { + } + + + internal enum YahaHttpVersion : int + { + Http09, + Http10, + Http11, + Http2, + Http3, + } + + internal enum CompletionReason : int + { + Success, + Error, + Aborted, + } + + +} +#endif \ No newline at end of file diff --git a/src/YetAnotherHttpHandler/NativeMethods.g.cs b/src/YetAnotherHttpHandler/NativeMethods.g.cs index 92b2290..2faa047 100644 --- a/src/YetAnotherHttpHandler/NativeMethods.g.cs +++ b/src/YetAnotherHttpHandler/NativeMethods.g.cs @@ -1,3 +1,4 @@ +#if !UNITY_WSA // // This code is generated by csbindgen. // DON'T CHANGE THIS DIRECTLY. @@ -211,4 +212,4 @@ internal enum CompletionReason : int } - \ No newline at end of file +#endif \ No newline at end of file diff --git a/src/YetAnotherHttpHandler/NativeMethodsFuncPtr.g.cs b/src/YetAnotherHttpHandler/NativeMethodsFuncPtr.g.cs index 0fa9d47..cde7462 100644 --- a/src/YetAnotherHttpHandler/NativeMethodsFuncPtr.g.cs +++ b/src/YetAnotherHttpHandler/NativeMethodsFuncPtr.g.cs @@ -151,4 +151,3 @@ internal static unsafe partial class NativeMethodsFuncPtr } - \ No newline at end of file