Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Windows Arm64 support #51

Merged
merged 9 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
build-win-x64:
name: Build Native library (win-x64)
if: ${{ !inputs.build-only-linux }}
runs-on: windows-2019
runs-on: windows-2022
timeout-minutes: 30
defaults:
run:
Expand All @@ -53,6 +53,52 @@ jobs:
retention-days: 1
- run: dotnet test -c ${{ env._DOTNET_BUILD_CONFIG }} ../test/YetAnotherHttpHandler.Test

build-win-arm64:
name: Build Native library (win-arm64)
if: ${{ !inputs.build-only-linux }}
runs-on: windows-2022
timeout-minutes: 30
defaults:
run:
working-directory: native
steps:
- uses: actions/checkout@v3
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- run: rustup target add aarch64-pc-windows-msvc
- run: |
$env:Path += ";C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\bin"
cargo build --target aarch64-pc-windows-msvc --profile ${{ env._RUST_BUILD_CONFIG == 'debug' && 'dev' || env._RUST_BUILD_CONFIG }}
- uses: actions/upload-artifact@v3
with:
name: win-arm64
path: native/target/aarch64-pc-windows-msvc/${{ env._RUST_BUILD_CONFIG }}/yaha_native.dll
retention-days: 1
#- run: dotnet test -c ${{ env._DOTNET_BUILD_CONFIG }} ../test/YetAnotherHttpHandler.Test

build-win-arm64-uwp:
name: Build Native library (win-arm64-uwp)
if: ${{ !inputs.build-only-linux }}
runs-on: windows-2022
timeout-minutes: 30
defaults:
run:
working-directory: native
steps:
- uses: actions/checkout@v3
- uses: Cysharp/Actions/.github/actions/setup-dotnet@main
- run: rustup toolchain install nightly-x86_64-pc-windows-msvc
- run: rustup component add rust-src --toolchain nightly-x86_64-pc-windows-msvc
- run: rustup default nightly
- run: |
$env:Path += ";C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Tools\Llvm\bin"
cargo -Z build-std build --target aarch64-uwp-windows-msvc --profile ${{ env._RUST_BUILD_CONFIG == 'debug' && 'dev' || env._RUST_BUILD_CONFIG }}
- uses: actions/upload-artifact@v3
with:
name: win-arm64-uwp
path: native/target/aarch64-uwp-windows-msvc/${{ env._RUST_BUILD_CONFIG }}/yaha_native.dll
retention-days: 1
#- run: dotnet test -c ${{ env._DOTNET_BUILD_CONFIG }} ../test/YetAnotherHttpHandler.Test

build-linux-x64:
name: Build Native library (linux-x64)
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -209,6 +255,8 @@ jobs:
if: ${{ inputs.build-only-linux && needs.build-linux-x64.result == 'success' || success() }}
needs:
- build-win-x64
- build-win-arm64
- build-win-arm64-uwp
- build-linux-x64
- build-osx-x64
- build-osx-arm64
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The handler is built on top of [hyper](https://hyper.rs/) and [Rustls](https://g
Architecture/Platform | Windows | macOS | Linux | Android | iOS
-- | -- | -- | -- | -- | --
<strong>x64 (x86_64)</strong> | ✔ | ✔ | ☁ | ☁ | ☁
<strong>arm64 (aarch64, Apple Silicon)</strong> | 📆 | ✔ | 📆 | ✔ | ✔
<strong>arm64 (aarch64, Apple Silicon)</strong> | | ✔ | 📆 | ✔ | ✔
<strong>armv7</strong> | - | - | - | ☁ | -

- ✔ (Tier 1): Verify that it works, and active development support.
Expand Down Expand Up @@ -50,15 +50,14 @@ Architecture/Platform | Windows | macOS | Linux | Android | iOS
- Multiple streams on a single connection
- Compatible with grpc-dotnet (Grpc.Net.Client)
- HTTP/2 over cleartext
- TLS 1.2 with ALPN
- TLS 1.2/1.3 with ALPN
- TLS support is powered by Rustls + webpki
- Client certificate

### Not supported yet
- Client certificate
- HTTP proxy support
- Verification of certificates by security features built into the OS
- More platform supports
- Windows on Arm
- Linux on Arm

### Not supported (not planned)
Expand Down
4 changes: 2 additions & 2 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion native/yaha_native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
16 changes: 16 additions & 0 deletions native/yaha_native/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,25 @@ fn main() -> Result<(), Box<dyn Error>> {
.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")
Expand Down
210 changes: 210 additions & 0 deletions src/YetAnotherHttpHandler/NativeMethods.Uwp.g.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
#if UNITY_WSA
// <auto-generated>
// This code is generated by csbindgen.
// DON'T CHANGE THIS DIRECTLY.
// </auto-generated>
#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
11 changes: 11 additions & 0 deletions src/YetAnotherHttpHandler/NativeMethods.Uwp.g.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/YetAnotherHttpHandler/NativeMethods.g.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#if !UNITY_WSA
// <auto-generated>
// This code is generated by csbindgen.
// DON'T CHANGE THIS DIRECTLY.
Expand Down Expand Up @@ -211,4 +212,4 @@ internal enum CompletionReason : int


}
#endif
1 change: 0 additions & 1 deletion src/YetAnotherHttpHandler/NativeMethodsFuncPtr.g.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,3 @@ internal static unsafe partial class NativeMethodsFuncPtr


}

Loading
Loading