Merge pull request #18039 from jtattermusch/csharp_unity_android_il2cpp

C#: Fix il2cpp build on Unity Android.
pull/18076/head
Jan Tattermusch 6 years ago committed by GitHub
commit 04cdb18266
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 404
      src/csharp/unitypackage/unitypackage_skeleton/Plugins/Grpc.Core/runtimes/grpc_csharp_ext_dummy_stubs.c
  2. 93
      src/csharp/unitypackage/unitypackage_skeleton/Plugins/Grpc.Core/runtimes/grpc_csharp_ext_dummy_stubs.c.meta
  3. 122
      templates/src/csharp/Grpc.Core/Internal/NativeMethods.Generated.cs.template
  4. 109
      templates/src/csharp/Grpc.Core/Internal/native_methods.include
  5. 32
      templates/src/csharp/unitypackage/unitypackage_skeleton/Plugins/Grpc.Core/runtimes/grpc_csharp_ext_dummy_stubs.c.template

@ -0,0 +1,404 @@
// Copyright 2019 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// When building for Unity Android with il2cpp backend, Unity tries to link
// the __Internal PInvoke definitions (which are required by iOS) even though
// the .so/.dll will be actually used. This file provides dummy stubs to
// make il2cpp happy.
// See https://github.com/grpc/grpc/issues/16012
#include <stdio.h>
#include <stdlib.h>
void grpcsharp_init() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_shutdown() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_version_string() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_recv_initial_metadata() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_recv_message_length() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_recv_message_to_buffer() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_recv_status_on_client_status() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_recv_status_on_client_details() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_recv_status_on_client_trailing_metadata() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_recv_close_on_server_cancelled() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_reset() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_batch_context_destroy() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_request_call_context_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_request_call_context_call() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_request_call_context_method() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_request_call_context_host() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_request_call_context_deadline() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_request_call_context_request_metadata() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_request_call_context_reset() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_request_call_context_destroy() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_composite_call_credentials_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_credentials_release() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_cancel() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_cancel_with_status() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_start_unary() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_start_client_streaming() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_start_server_streaming() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_start_duplex_streaming() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_send_message() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_send_close_from_client() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_send_status_from_server() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_recv_message() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_recv_initial_metadata() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_start_serverside() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_send_initial_metadata() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_set_credentials() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_get_peer() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_destroy() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_args_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_args_set_string() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_args_set_integer() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_args_destroy() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_override_default_ssl_roots() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_ssl_credentials_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_composite_channel_credentials_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_credentials_release() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_insecure_channel_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_secure_channel_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_create_call() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_check_connectivity_state() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_watch_connectivity_state() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_get_target() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_channel_destroy() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_sizeof_grpc_event() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_completion_queue_create_async() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_completion_queue_create_sync() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_completion_queue_shutdown() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_completion_queue_next() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_completion_queue_pluck() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_completion_queue_destroy() {
fprintf(stderr, "Should never reach here");
abort();
}
void gprsharp_free() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_metadata_array_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_metadata_array_add() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_metadata_array_count() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_metadata_array_get_key() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_metadata_array_get_value() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_metadata_array_destroy_full() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_redirect_log() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_metadata_credentials_create_from_plugin() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_metadata_credentials_notify_from_plugin() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_ssl_server_credentials_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_credentials_release() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_create() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_register_completion_queue() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_add_insecure_http2_port() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_add_secure_http2_port() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_start() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_request_call() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_cancel_all_calls() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_shutdown_and_notify_callback() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_server_destroy() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_call_auth_context() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_auth_context_peer_identity_property_name() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_auth_context_property_iterator() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_auth_property_iterator_next() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_auth_context_release() {
fprintf(stderr, "Should never reach here");
abort();
}
void gprsharp_now() {
fprintf(stderr, "Should never reach here");
abort();
}
void gprsharp_inf_future() {
fprintf(stderr, "Should never reach here");
abort();
}
void gprsharp_inf_past() {
fprintf(stderr, "Should never reach here");
abort();
}
void gprsharp_convert_clock_type() {
fprintf(stderr, "Should never reach here");
abort();
}
void gprsharp_sizeof_timespec() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_test_callback() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_test_nop() {
fprintf(stderr, "Should never reach here");
abort();
}
void grpcsharp_test_override_method() {
fprintf(stderr, "Should never reach here");
abort();
}

@ -0,0 +1,93 @@
fileFormatVersion: 2
guid: 576b78662f1f8af4fa751f709b620f52
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
isPreloaded: 0
isOverridable: 0
platformData:
- first:
'': Any
second:
enabled: 0
settings:
Exclude Android: 0
Exclude Editor: 1
Exclude Linux: 1
Exclude Linux64: 1
Exclude LinuxUniversal: 1
Exclude OSXUniversal: 1
Exclude Win: 0
Exclude Win64: 0
- first:
Android: Android
second:
enabled: 1
settings:
CPU: ARMv7
- first:
Any:
second:
enabled: 0
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
CPU: AnyCPU
DefaultValueInitialized: true
OS: AnyOS
- first:
Facebook: Win
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Facebook: Win64
second:
enabled: 0
settings:
CPU: AnyCPU
- first:
Standalone: Linux
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Linux64
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: LinuxUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: OSXUniversal
second:
enabled: 0
settings:
CPU: None
- first:
Standalone: Win
second:
enabled: 1
settings:
CPU: AnyCPU
- first:
Standalone: Win64
second:
enabled: 1
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:

@ -1,112 +1,6 @@
%YAML 1.2
--- |
<%
native_method_signatures = [
'void grpcsharp_init()',
'void grpcsharp_shutdown()',
'IntPtr grpcsharp_version_string() // returns not-owned const char*',
'BatchContextSafeHandle grpcsharp_batch_context_create()',
'IntPtr grpcsharp_batch_context_recv_initial_metadata(BatchContextSafeHandle ctx)',
'IntPtr grpcsharp_batch_context_recv_message_length(BatchContextSafeHandle ctx)',
'void grpcsharp_batch_context_recv_message_to_buffer(BatchContextSafeHandle ctx, byte[] buffer, UIntPtr bufferLen)',
'StatusCode grpcsharp_batch_context_recv_status_on_client_status(BatchContextSafeHandle ctx)',
'IntPtr grpcsharp_batch_context_recv_status_on_client_details(BatchContextSafeHandle ctx, out UIntPtr detailsLength)',
'IntPtr grpcsharp_batch_context_recv_status_on_client_trailing_metadata(BatchContextSafeHandle ctx)',
'int grpcsharp_batch_context_recv_close_on_server_cancelled(BatchContextSafeHandle ctx)',
'void grpcsharp_batch_context_reset(BatchContextSafeHandle ctx)',
'void grpcsharp_batch_context_destroy(IntPtr ctx)',
'RequestCallContextSafeHandle grpcsharp_request_call_context_create()',
'CallSafeHandle grpcsharp_request_call_context_call(RequestCallContextSafeHandle ctx)',
'IntPtr grpcsharp_request_call_context_method(RequestCallContextSafeHandle ctx, out UIntPtr methodLength)',
'IntPtr grpcsharp_request_call_context_host(RequestCallContextSafeHandle ctx, out UIntPtr hostLength)',
'Timespec grpcsharp_request_call_context_deadline(RequestCallContextSafeHandle ctx)',
'IntPtr grpcsharp_request_call_context_request_metadata(RequestCallContextSafeHandle ctx)',
'void grpcsharp_request_call_context_reset(RequestCallContextSafeHandle ctx)',
'void grpcsharp_request_call_context_destroy(IntPtr ctx)',
'CallCredentialsSafeHandle grpcsharp_composite_call_credentials_create(CallCredentialsSafeHandle creds1, CallCredentialsSafeHandle creds2)',
'void grpcsharp_call_credentials_release(IntPtr credentials)',
'CallError grpcsharp_call_cancel(CallSafeHandle call)',
'CallError grpcsharp_call_cancel_with_status(CallSafeHandle call, StatusCode status, string description)',
'CallError grpcsharp_call_start_unary(CallSafeHandle call, BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags)',
'CallError grpcsharp_call_start_client_streaming(CallSafeHandle call, BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags)',
'CallError grpcsharp_call_start_server_streaming(CallSafeHandle call, BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags)',
'CallError grpcsharp_call_start_duplex_streaming(CallSafeHandle call, BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags)',
'CallError grpcsharp_call_send_message(CallSafeHandle call, BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, int sendEmptyInitialMetadata)',
'CallError grpcsharp_call_send_close_from_client(CallSafeHandle call, BatchContextSafeHandle ctx)',
'CallError grpcsharp_call_send_status_from_server(CallSafeHandle call, BatchContextSafeHandle ctx, StatusCode statusCode, byte[] statusMessage, UIntPtr statusMessageLen, MetadataArraySafeHandle metadataArray, int sendEmptyInitialMetadata, byte[] optionalSendBuffer, UIntPtr optionalSendBufferLen, WriteFlags writeFlags)',
'CallError grpcsharp_call_recv_message(CallSafeHandle call, BatchContextSafeHandle ctx)',
'CallError grpcsharp_call_recv_initial_metadata(CallSafeHandle call, BatchContextSafeHandle ctx)',
'CallError grpcsharp_call_start_serverside(CallSafeHandle call, BatchContextSafeHandle ctx)',
'CallError grpcsharp_call_send_initial_metadata(CallSafeHandle call, BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray)',
'CallError grpcsharp_call_set_credentials(CallSafeHandle call, CallCredentialsSafeHandle credentials)',
'CStringSafeHandle grpcsharp_call_get_peer(CallSafeHandle call)',
'void grpcsharp_call_destroy(IntPtr call)',
'ChannelArgsSafeHandle grpcsharp_channel_args_create(UIntPtr numArgs)',
'void grpcsharp_channel_args_set_string(ChannelArgsSafeHandle args, UIntPtr index, string key, string value)',
'void grpcsharp_channel_args_set_integer(ChannelArgsSafeHandle args, UIntPtr index, string key, int value)',
'void grpcsharp_channel_args_destroy(IntPtr args)',
'void grpcsharp_override_default_ssl_roots(string pemRootCerts)',
'ChannelCredentialsSafeHandle grpcsharp_ssl_credentials_create(string pemRootCerts, string keyCertPairCertChain, string keyCertPairPrivateKey)',
'ChannelCredentialsSafeHandle grpcsharp_composite_channel_credentials_create(ChannelCredentialsSafeHandle channelCreds, CallCredentialsSafeHandle callCreds)',
'void grpcsharp_channel_credentials_release(IntPtr credentials)',
'ChannelSafeHandle grpcsharp_insecure_channel_create(string target, ChannelArgsSafeHandle channelArgs)',
'ChannelSafeHandle grpcsharp_secure_channel_create(ChannelCredentialsSafeHandle credentials, string target, ChannelArgsSafeHandle channelArgs)',
'CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline)',
'ChannelState grpcsharp_channel_check_connectivity_state(ChannelSafeHandle channel, int tryToConnect)',
'void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx)',
'CStringSafeHandle grpcsharp_channel_get_target(ChannelSafeHandle call)',
'void grpcsharp_channel_destroy(IntPtr channel)',
'int grpcsharp_sizeof_grpc_event()',
'CompletionQueueSafeHandle grpcsharp_completion_queue_create_async()',
'CompletionQueueSafeHandle grpcsharp_completion_queue_create_sync()',
'void grpcsharp_completion_queue_shutdown(CompletionQueueSafeHandle cq)',
'CompletionQueueEvent grpcsharp_completion_queue_next(CompletionQueueSafeHandle cq)',
'CompletionQueueEvent grpcsharp_completion_queue_pluck(CompletionQueueSafeHandle cq, IntPtr tag)',
'void grpcsharp_completion_queue_destroy(IntPtr cq)',
'void gprsharp_free(IntPtr ptr)',
'MetadataArraySafeHandle grpcsharp_metadata_array_create(UIntPtr capacity)',
'void grpcsharp_metadata_array_add(MetadataArraySafeHandle array, string key, byte[] value, UIntPtr valueLength)',
'UIntPtr grpcsharp_metadata_array_count(IntPtr metadataArray)',
'IntPtr grpcsharp_metadata_array_get_key(IntPtr metadataArray, UIntPtr index, out UIntPtr keyLength)',
'IntPtr grpcsharp_metadata_array_get_value(IntPtr metadataArray, UIntPtr index, out UIntPtr valueLength)',
'void grpcsharp_metadata_array_destroy_full(IntPtr array)',
'void grpcsharp_redirect_log(GprLogDelegate callback)',
'CallCredentialsSafeHandle grpcsharp_metadata_credentials_create_from_plugin(NativeMetadataInterceptor interceptor)',
'void grpcsharp_metadata_credentials_notify_from_plugin(IntPtr callbackPtr, IntPtr userData, MetadataArraySafeHandle metadataArray, StatusCode statusCode, string errorDetails)',
'ServerCredentialsSafeHandle grpcsharp_ssl_server_credentials_create(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs, SslClientCertificateRequestType clientCertificateRequest)',
'void grpcsharp_server_credentials_release(IntPtr credentials)',
'ServerSafeHandle grpcsharp_server_create(ChannelArgsSafeHandle args)',
'void grpcsharp_server_register_completion_queue(ServerSafeHandle server, CompletionQueueSafeHandle cq)',
'int grpcsharp_server_add_insecure_http2_port(ServerSafeHandle server, string addr)',
'int grpcsharp_server_add_secure_http2_port(ServerSafeHandle server, string addr, ServerCredentialsSafeHandle creds)',
'void grpcsharp_server_start(ServerSafeHandle server)',
'CallError grpcsharp_server_request_call(ServerSafeHandle server, CompletionQueueSafeHandle cq, RequestCallContextSafeHandle ctx)',
'void grpcsharp_server_cancel_all_calls(ServerSafeHandle server)',
'void grpcsharp_server_shutdown_and_notify_callback(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx)',
'void grpcsharp_server_destroy(IntPtr server)',
'AuthContextSafeHandle grpcsharp_call_auth_context(CallSafeHandle call)',
'IntPtr grpcsharp_auth_context_peer_identity_property_name(AuthContextSafeHandle authContext) // returns const char*',
'AuthContextSafeHandle.NativeAuthPropertyIterator grpcsharp_auth_context_property_iterator(AuthContextSafeHandle authContext)',
'IntPtr grpcsharp_auth_property_iterator_next(ref AuthContextSafeHandle.NativeAuthPropertyIterator iterator) // returns const auth_property*',
'void grpcsharp_auth_context_release(IntPtr authContext)',
'Timespec gprsharp_now(ClockType clockType)',
'Timespec gprsharp_inf_future(ClockType clockType)',
'Timespec gprsharp_inf_past(ClockType clockType)',
'Timespec gprsharp_convert_clock_type(Timespec t, ClockType targetClock)',
'int gprsharp_sizeof_timespec()',
'CallError grpcsharp_test_callback([MarshalAs(UnmanagedType.FunctionPtr)] NativeCallbackTestDelegate callback)',
'IntPtr grpcsharp_test_nop(IntPtr ptr)',
'void grpcsharp_test_override_method(string methodName, string variant)',
]
import re
native_methods = []
for signature in native_method_signatures:
match = re.match('([A-Za-z0-9_.]+) +([A-Za-z0-9_]+)\\((.*)\\)(.*)', signature)
if not match:
raise Exception('Malformed signature "%s"' % signature)
native_methods.append({'returntype': match.group(1), 'name': match.group(2), 'params': match.group(3), 'comment': match.group(4)})
%>
<%namespace file="native_methods.include" import="get_native_methods"/>
#region Copyright notice and license
// Copyright 2015 gRPC authors.
@ -142,7 +36,7 @@
{
#region Native methods
% for method in native_methods:
% for method in get_native_methods():
public readonly Delegates.${method['name']}_delegate ${method['name']};
% endfor
@ -150,21 +44,21 @@
public NativeMethods(UnmanagedLibrary library)
{
% for method in native_methods:
% for method in get_native_methods():
this.${method['name']} = GetMethodDelegate<Delegates.${method['name']}_delegate>(library);
% endfor
}
public NativeMethods(DllImportsFromStaticLib unusedInstance)
{
% for method in native_methods:
% for method in get_native_methods():
this.${method['name']} = DllImportsFromStaticLib.${method['name']};
% endfor
}
public NativeMethods(DllImportsFromSharedLib unusedInstance)
{
% for method in native_methods:
% for method in get_native_methods():
this.${method['name']} = DllImportsFromSharedLib.${method['name']};
% endfor
}
@ -174,7 +68,7 @@
/// </summary>
public class Delegates
{
% for method in native_methods:
% for method in get_native_methods():
public delegate ${method['returntype']} ${method['name']}_delegate(${method['params']});${method['comment']}
% endfor
}
@ -185,7 +79,7 @@
internal class DllImportsFromStaticLib
{
private const string ImportName = "__Internal";
% for method in native_methods:
% for method in get_native_methods():
[DllImport(ImportName)]
public static extern ${method['returntype']} ${method['name']}(${method['params']});
@ -198,7 +92,7 @@
internal class DllImportsFromSharedLib
{
private const string ImportName = "grpc_csharp_ext";
% for method in native_methods:
% for method in get_native_methods():
[DllImport(ImportName)]
public static extern ${method['returntype']} ${method['name']}(${method['params']});

@ -0,0 +1,109 @@
<%def name="get_native_methods()"><%
native_method_signatures = [
'void grpcsharp_init()',
'void grpcsharp_shutdown()',
'IntPtr grpcsharp_version_string() // returns not-owned const char*',
'BatchContextSafeHandle grpcsharp_batch_context_create()',
'IntPtr grpcsharp_batch_context_recv_initial_metadata(BatchContextSafeHandle ctx)',
'IntPtr grpcsharp_batch_context_recv_message_length(BatchContextSafeHandle ctx)',
'void grpcsharp_batch_context_recv_message_to_buffer(BatchContextSafeHandle ctx, byte[] buffer, UIntPtr bufferLen)',
'StatusCode grpcsharp_batch_context_recv_status_on_client_status(BatchContextSafeHandle ctx)',
'IntPtr grpcsharp_batch_context_recv_status_on_client_details(BatchContextSafeHandle ctx, out UIntPtr detailsLength)',
'IntPtr grpcsharp_batch_context_recv_status_on_client_trailing_metadata(BatchContextSafeHandle ctx)',
'int grpcsharp_batch_context_recv_close_on_server_cancelled(BatchContextSafeHandle ctx)',
'void grpcsharp_batch_context_reset(BatchContextSafeHandle ctx)',
'void grpcsharp_batch_context_destroy(IntPtr ctx)',
'RequestCallContextSafeHandle grpcsharp_request_call_context_create()',
'CallSafeHandle grpcsharp_request_call_context_call(RequestCallContextSafeHandle ctx)',
'IntPtr grpcsharp_request_call_context_method(RequestCallContextSafeHandle ctx, out UIntPtr methodLength)',
'IntPtr grpcsharp_request_call_context_host(RequestCallContextSafeHandle ctx, out UIntPtr hostLength)',
'Timespec grpcsharp_request_call_context_deadline(RequestCallContextSafeHandle ctx)',
'IntPtr grpcsharp_request_call_context_request_metadata(RequestCallContextSafeHandle ctx)',
'void grpcsharp_request_call_context_reset(RequestCallContextSafeHandle ctx)',
'void grpcsharp_request_call_context_destroy(IntPtr ctx)',
'CallCredentialsSafeHandle grpcsharp_composite_call_credentials_create(CallCredentialsSafeHandle creds1, CallCredentialsSafeHandle creds2)',
'void grpcsharp_call_credentials_release(IntPtr credentials)',
'CallError grpcsharp_call_cancel(CallSafeHandle call)',
'CallError grpcsharp_call_cancel_with_status(CallSafeHandle call, StatusCode status, string description)',
'CallError grpcsharp_call_start_unary(CallSafeHandle call, BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags)',
'CallError grpcsharp_call_start_client_streaming(CallSafeHandle call, BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags)',
'CallError grpcsharp_call_start_server_streaming(CallSafeHandle call, BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags)',
'CallError grpcsharp_call_start_duplex_streaming(CallSafeHandle call, BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray, CallFlags metadataFlags)',
'CallError grpcsharp_call_send_message(CallSafeHandle call, BatchContextSafeHandle ctx, byte[] sendBuffer, UIntPtr sendBufferLen, WriteFlags writeFlags, int sendEmptyInitialMetadata)',
'CallError grpcsharp_call_send_close_from_client(CallSafeHandle call, BatchContextSafeHandle ctx)',
'CallError grpcsharp_call_send_status_from_server(CallSafeHandle call, BatchContextSafeHandle ctx, StatusCode statusCode, byte[] statusMessage, UIntPtr statusMessageLen, MetadataArraySafeHandle metadataArray, int sendEmptyInitialMetadata, byte[] optionalSendBuffer, UIntPtr optionalSendBufferLen, WriteFlags writeFlags)',
'CallError grpcsharp_call_recv_message(CallSafeHandle call, BatchContextSafeHandle ctx)',
'CallError grpcsharp_call_recv_initial_metadata(CallSafeHandle call, BatchContextSafeHandle ctx)',
'CallError grpcsharp_call_start_serverside(CallSafeHandle call, BatchContextSafeHandle ctx)',
'CallError grpcsharp_call_send_initial_metadata(CallSafeHandle call, BatchContextSafeHandle ctx, MetadataArraySafeHandle metadataArray)',
'CallError grpcsharp_call_set_credentials(CallSafeHandle call, CallCredentialsSafeHandle credentials)',
'CStringSafeHandle grpcsharp_call_get_peer(CallSafeHandle call)',
'void grpcsharp_call_destroy(IntPtr call)',
'ChannelArgsSafeHandle grpcsharp_channel_args_create(UIntPtr numArgs)',
'void grpcsharp_channel_args_set_string(ChannelArgsSafeHandle args, UIntPtr index, string key, string value)',
'void grpcsharp_channel_args_set_integer(ChannelArgsSafeHandle args, UIntPtr index, string key, int value)',
'void grpcsharp_channel_args_destroy(IntPtr args)',
'void grpcsharp_override_default_ssl_roots(string pemRootCerts)',
'ChannelCredentialsSafeHandle grpcsharp_ssl_credentials_create(string pemRootCerts, string keyCertPairCertChain, string keyCertPairPrivateKey)',
'ChannelCredentialsSafeHandle grpcsharp_composite_channel_credentials_create(ChannelCredentialsSafeHandle channelCreds, CallCredentialsSafeHandle callCreds)',
'void grpcsharp_channel_credentials_release(IntPtr credentials)',
'ChannelSafeHandle grpcsharp_insecure_channel_create(string target, ChannelArgsSafeHandle channelArgs)',
'ChannelSafeHandle grpcsharp_secure_channel_create(ChannelCredentialsSafeHandle credentials, string target, ChannelArgsSafeHandle channelArgs)',
'CallSafeHandle grpcsharp_channel_create_call(ChannelSafeHandle channel, CallSafeHandle parentCall, ContextPropagationFlags propagationMask, CompletionQueueSafeHandle cq, string method, string host, Timespec deadline)',
'ChannelState grpcsharp_channel_check_connectivity_state(ChannelSafeHandle channel, int tryToConnect)',
'void grpcsharp_channel_watch_connectivity_state(ChannelSafeHandle channel, ChannelState lastObservedState, Timespec deadline, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx)',
'CStringSafeHandle grpcsharp_channel_get_target(ChannelSafeHandle call)',
'void grpcsharp_channel_destroy(IntPtr channel)',
'int grpcsharp_sizeof_grpc_event()',
'CompletionQueueSafeHandle grpcsharp_completion_queue_create_async()',
'CompletionQueueSafeHandle grpcsharp_completion_queue_create_sync()',
'void grpcsharp_completion_queue_shutdown(CompletionQueueSafeHandle cq)',
'CompletionQueueEvent grpcsharp_completion_queue_next(CompletionQueueSafeHandle cq)',
'CompletionQueueEvent grpcsharp_completion_queue_pluck(CompletionQueueSafeHandle cq, IntPtr tag)',
'void grpcsharp_completion_queue_destroy(IntPtr cq)',
'void gprsharp_free(IntPtr ptr)',
'MetadataArraySafeHandle grpcsharp_metadata_array_create(UIntPtr capacity)',
'void grpcsharp_metadata_array_add(MetadataArraySafeHandle array, string key, byte[] value, UIntPtr valueLength)',
'UIntPtr grpcsharp_metadata_array_count(IntPtr metadataArray)',
'IntPtr grpcsharp_metadata_array_get_key(IntPtr metadataArray, UIntPtr index, out UIntPtr keyLength)',
'IntPtr grpcsharp_metadata_array_get_value(IntPtr metadataArray, UIntPtr index, out UIntPtr valueLength)',
'void grpcsharp_metadata_array_destroy_full(IntPtr array)',
'void grpcsharp_redirect_log(GprLogDelegate callback)',
'CallCredentialsSafeHandle grpcsharp_metadata_credentials_create_from_plugin(NativeMetadataInterceptor interceptor)',
'void grpcsharp_metadata_credentials_notify_from_plugin(IntPtr callbackPtr, IntPtr userData, MetadataArraySafeHandle metadataArray, StatusCode statusCode, string errorDetails)',
'ServerCredentialsSafeHandle grpcsharp_ssl_server_credentials_create(string pemRootCerts, string[] keyCertPairCertChainArray, string[] keyCertPairPrivateKeyArray, UIntPtr numKeyCertPairs, SslClientCertificateRequestType clientCertificateRequest)',
'void grpcsharp_server_credentials_release(IntPtr credentials)',
'ServerSafeHandle grpcsharp_server_create(ChannelArgsSafeHandle args)',
'void grpcsharp_server_register_completion_queue(ServerSafeHandle server, CompletionQueueSafeHandle cq)',
'int grpcsharp_server_add_insecure_http2_port(ServerSafeHandle server, string addr)',
'int grpcsharp_server_add_secure_http2_port(ServerSafeHandle server, string addr, ServerCredentialsSafeHandle creds)',
'void grpcsharp_server_start(ServerSafeHandle server)',
'CallError grpcsharp_server_request_call(ServerSafeHandle server, CompletionQueueSafeHandle cq, RequestCallContextSafeHandle ctx)',
'void grpcsharp_server_cancel_all_calls(ServerSafeHandle server)',
'void grpcsharp_server_shutdown_and_notify_callback(ServerSafeHandle server, CompletionQueueSafeHandle cq, BatchContextSafeHandle ctx)',
'void grpcsharp_server_destroy(IntPtr server)',
'AuthContextSafeHandle grpcsharp_call_auth_context(CallSafeHandle call)',
'IntPtr grpcsharp_auth_context_peer_identity_property_name(AuthContextSafeHandle authContext) // returns const char*',
'AuthContextSafeHandle.NativeAuthPropertyIterator grpcsharp_auth_context_property_iterator(AuthContextSafeHandle authContext)',
'IntPtr grpcsharp_auth_property_iterator_next(ref AuthContextSafeHandle.NativeAuthPropertyIterator iterator) // returns const auth_property*',
'void grpcsharp_auth_context_release(IntPtr authContext)',
'Timespec gprsharp_now(ClockType clockType)',
'Timespec gprsharp_inf_future(ClockType clockType)',
'Timespec gprsharp_inf_past(ClockType clockType)',
'Timespec gprsharp_convert_clock_type(Timespec t, ClockType targetClock)',
'int gprsharp_sizeof_timespec()',
'CallError grpcsharp_test_callback([MarshalAs(UnmanagedType.FunctionPtr)] NativeCallbackTestDelegate callback)',
'IntPtr grpcsharp_test_nop(IntPtr ptr)',
'void grpcsharp_test_override_method(string methodName, string variant)',
]
import re
native_methods = []
for signature in native_method_signatures:
match = re.match('([A-Za-z0-9_.]+) +([A-Za-z0-9_]+)\\((.*)\\)(.*)', signature)
if not match:
raise Exception('Malformed signature "%s"' % signature)
native_methods.append({'returntype': match.group(1), 'name': match.group(2), 'params': match.group(3), 'comment': match.group(4)})
return list(native_methods)
%></%def>

@ -0,0 +1,32 @@
%YAML 1.2
--- |
<%namespace file="../../../../../Grpc.Core/Internal/native_methods.include" import="get_native_methods"/>
// Copyright 2019 The gRPC Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// When building for Unity Android with il2cpp backend, Unity tries to link
// the __Internal PInvoke definitions (which are required by iOS) even though
// the .so/.dll will be actually used. This file provides dummy stubs to
// make il2cpp happy.
// See https://github.com/grpc/grpc/issues/16012
#include <stdio.h>
#include <stdlib.h>
% for method in get_native_methods():
void ${method['name']}() {
fprintf(stderr, "Should never reach here");
abort();
}
% endfor
Loading…
Cancel
Save