From c65ceefbe0681559a0bc3e745ad619d5c577fc0e Mon Sep 17 00:00:00 2001 From: Chris Bacon Date: Fri, 5 Feb 2016 09:04:46 +0000 Subject: [PATCH 01/48] Support coreclr platform detection Coreclr uses different platform detection primitives to full .NET --- src/csharp/Grpc.Core/Internal/PlatformApis.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/csharp/Grpc.Core/Internal/PlatformApis.cs b/src/csharp/Grpc.Core/Internal/PlatformApis.cs index f0c5b0f63f6..fb1acfb607b 100644 --- a/src/csharp/Grpc.Core/Internal/PlatformApis.cs +++ b/src/csharp/Grpc.Core/Internal/PlatformApis.cs @@ -53,12 +53,18 @@ namespace Grpc.Core.Internal static PlatformApis() { +#if DNXCORE50 + isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux); + isMacOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX); + isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows); +#else var platform = Environment.OSVersion.Platform; // PlatformID.MacOSX is never returned, commonly used trick is to identify Mac is by using uname. isMacOSX = (platform == PlatformID.Unix && GetUname() == "Darwin"); isLinux = (platform == PlatformID.Unix && !isMacOSX); isWindows = (platform == PlatformID.Win32NT || platform == PlatformID.Win32S || platform == PlatformID.Win32Windows); +#endif isMono = Type.GetType("Mono.Runtime") != null; } From 7492c7c38cefb5e45b789988da8e9d7a92d5cf98 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 12 Feb 2016 15:25:45 -0800 Subject: [PATCH 02/48] Update README.md --- examples/csharp/helloworld/README.md | 29 +++++----------------------- 1 file changed, 5 insertions(+), 24 deletions(-) diff --git a/examples/csharp/helloworld/README.md b/examples/csharp/helloworld/README.md index f1af1f6793c..63131ed98c0 100644 --- a/examples/csharp/helloworld/README.md +++ b/examples/csharp/helloworld/README.md @@ -16,35 +16,17 @@ PREREQUISITES - Visual Studio 2013 or 2015 **Linux** -- Mono -- Monodevelop 5.9 with NuGet Add-in installed +- Mono 4.0+ +- Monodevelop 5.9+ (with NuGet plugin installed) **Mac OS X** -- Xamarin Studio (with NuGet plugin installed) +- Xamarin Studio 5.9+ - [homebrew][] BUILD ------- -**Windows** - -- Open solution `Greeter.sln` with Visual Studio - -- Build the solution (this will automatically download NuGet dependencies) - -**Linux (Debian)** - -- Install gRPC C core and C# native extension using [How to use gRPC C#][] instructions - -- Open solution `Greeter.sln` in MonoDevelop. - -- Build the solution (you need to manually restore dependencies by using `mono nuget.exe restore` if you don't have NuGet add-in) - -**Mac OS X** - -- Install gRPC C core and C# native extension using [How to use gRPC C#][] instructions - -- Open solution `Greeter.sln` with Xamarin Studio +- Open solution `Greeter.sln` with Visual Studio, Monodevelop (on Linux) or Xamarin Studio (on Mac OS X) - Build the solution (this will automatically download NuGet dependencies) @@ -65,7 +47,7 @@ Try it! > GreeterClient.exe ``` -You can also run the server and client directly from Visual Studio. +You can also run the server and client directly from the IDE. On Linux or Mac, use `mono GreeterServer.exe` and `mono GreeterClient.exe` to run the server and client. @@ -76,5 +58,4 @@ You can find a more detailed tutorial in [gRPC Basics: C#][] [homebrew]:http://brew.sh [helloworld.proto]:../../protos/helloworld.proto -[How to use gRPC C#]:../../../src/csharp#how-to-use [gRPC Basics: C#]:http://www.grpc.io/docs/tutorials/basic/csharp.html From bfb240727d3fff50527335b85d0d705e199b262a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 12 Feb 2016 16:18:09 -0800 Subject: [PATCH 03/48] Update README.md --- src/csharp/README.md | 116 +++++++++++-------------------------------- 1 file changed, 28 insertions(+), 88 deletions(-) diff --git a/src/csharp/README.md b/src/csharp/README.md index 65ae0b5efda..b4fa945ac98 100644 --- a/src/csharp/README.md +++ b/src/csharp/README.md @@ -12,9 +12,9 @@ Beta PREREQUISITES -------------- -- Windows: .NET Framework 4.5+, Visual Studio 2013 or 2015. -- Linux: Mono 3.2.8+, MonoDevelop 5.9 with NuGet add-in installed. -- Mac OS X: [homebrew][], Xamarin Studio with NuGet add-in installed. +- Windows: .NET Framework 4.5+, Visual Studio 2013 or 2015 +- Linux: Mono 4+, MonoDevelop 5.9+ (with NuGet add-in installed) +- Mac OS X: Xamarin Studio 5.9+ HOW TO USE -------------- @@ -24,66 +24,28 @@ HOW TO USE - Open Visual Studio and start a new project/solution. - Add NuGet package `Grpc` as a dependency (Project options -> Manage NuGet Packages). - That will also pull all the transitive dependencies (including the native libraries that + That will also pull all the transitive dependencies (including the gRPC native library that gRPC C# is using internally). **Linux (Debian)** -- Add [Debian jessie-backports][] to your `sources.list` file. Example: - - ```sh - echo "deb http://http.debian.net/debian jessie-backports main" | \ - sudo tee -a /etc/apt/sources.list - ``` - -- Install the gRPC Debian package - - ```sh - sudo apt-get update - sudo apt-get install libgrpc0 - ``` - -- gRPC C# depends on native shared library `libgrpc_csharp_ext.so` (Unix flavor of grpc_csharp_ext.dll). - This library is not part of the base gRPC debian package and needs to be installed manually from - a `.deb` file. Download the debian package `libgrpc_csharp_ext` from corresponding gRPC release on GitHub - and install it using `dpkg`. - - ```sh - # choose version corresponding to the version of libgrpc you've installed. - wget https://github.com/grpc/grpc/releases/download/release-0_11_0/libgrpc-csharp-ext0_0.11.0.0-1_amd64.deb - dpkg -i libgrpc-csharp-ext0_0.11.0.0-1_amd64.deb - ``` - - Open MonoDevelop and start a new project/solution. - Add NuGet package `Grpc` as a dependency (Project -> Add NuGet packages). + That will also pull all the transitive dependencies (including the gRPC native library that + gRPC C# is using internally). -- NOTE: Currently, there are no debian packages for the latest version Protocol Buffers compiler (_protoc_) - and the gRPC _protoc_ plugin. You can install them using [gRPC Linuxbrew instructions][]. +- NOTE: gRPC C# doesn't have a good story yet for shipping precompiled Linux version of Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin. You can install them using [gRPC Linuxbrew instructions][]. **Mac OS X** -- WARNING: As of now gRPC C# only works on 64bit version of Mono (because we don't compile - the native extension for C# in 32bit mode yet). That means your development experience - with Xamarin Studio on MacOS will not be great, as you won't be able to run your - code directly from Xamarin Studio (which requires 32bit version of Mono). - -- Install [homebrew][]. Run the following command to install gRPC C# native dependencies. - - ```sh - $ curl -fsSL https://goo.gl/getgrpc | bash - - ``` - This will download and run the [gRPC install script][], then install the latest version of gRPC C core and native C# extension. - It also installs Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin for C#. - -- Install 64-bit version of mono with command `brew install mono`. - - Open Xamarin Studio and start a new project/solution. - Add NuGet package `Grpc` as a dependency (Project -> Add NuGet packages). + That will also pull all the transitive dependencies (including the gRPC native library that + gRPC C# is using internally). -- *You will be able to build your project in Xamarin Studio, but to run or test it, - you will need to run it under 64-bit version of Mono.* +- NOTE: gRPC C# doesn't have a good story yet for shipping precompiled Mac OS X version of Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin. You can install them using [gRPC Homebrew instructions][]. BUILD FROM SOURCE ----------------- @@ -94,7 +56,7 @@ If you are a user of gRPC C#, go to Usage section above. **Windows** - The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution. You can - either build the native solution in `vsprojects/grpc.sln` from Visual Studio manually, or you can use + either build the native solution in `vsprojects/grpc_csharp_ext.sln` from Visual Studio manually, or you can use a convenience batch script that builds everything for you. ``` @@ -102,30 +64,28 @@ If you are a user of gRPC C#, go to Usage section above. > buildall.bat ``` -- Open Grpc.sln using Visual Studio. NuGet dependencies will be restored - upon build (you need to have NuGet add-in installed). +- Open Grpc.sln using Visual Studio. **Linux** +- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution: ```sh - $ sudo apt-get install mono-devel - $ sudo apt-get install nunit nunit-console + # from the gRPC repository root + $ make CONFIG=dbg grpc_csharp_ext ``` -You can use older versions of MonoDevelop, but then you might need to restore -NuGet dependencies manually (by `nuget restore`), because older versions of MonoDevelop -don't support NuGet add-in. +- Use MonoDevelop to open the solution Grpc.sln + +**Mac OS X** -- Compile and install the gRPC C# extension library (that will be used via - P/Invoke from C#). +- The grpc_csharp_ext native library needs to be built so you can build the gRPC C# solution. + ```sh - $ make grpc_csharp_ext - $ sudo make install_grpc_csharp_ext + # from the gRPC repository root + $ tools/run_tests/run_tests.py -c dbg -l csharp --build_only ``` -- Use MonoDevelop to open the solution Grpc.sln - -- Build the solution & run all the tests from test view. +- Use Xamarin Studio to open the solution Grpc.sln RUNNING TESTS ------------- @@ -135,17 +95,9 @@ gRPC C# is using NUnit as the testing framework. Under Visual Studio, make sure NUnit test adapter is installed (under "Extensions and Updates"). Then you should be able to run all the tests using Test Explorer. -Under Monodevelop, make sure you installed "NUnit support" in Add-in manager. +Under Monodevelop or Xamarin Studio, make sure you installed "NUnit support" in Add-in manager. Then you should be able to run all the test from the Test View. -After building the solution, you can also run the tests from command line -using nunit-console tool. - -```sh -# from Grpc.Core.Test/bin/Debug directory -$ nunit-console Grpc.Core.Tests.dll -``` - gRPC team uses a Python script to simplify facilitate running tests for different languages. @@ -176,27 +128,15 @@ CONTENTS - Grpc.IntegrationTesting: Cross-language gRPC implementation testing (interop testing). -TROUBLESHOOTING +THE NATIVE DEPENDENCY --------------- -### Problem: Unable to load DLL 'grpc_csharp_ext.dll' - -Internally, gRPC C# uses a native library written in C (gRPC C core) and invokes its functionality via P/Invoke. `grpc_csharp_ext` library is a native extension library that facilitates this by wrapping some C core API into a form that's more digestible for P/Invoke. If you get the above error, it means that the native dependencies could not be located by the C# runtime (or they are incompatible with the current runtime, so they could not be loaded). The solution to this is environment specific. - -- If you are developing on Windows in Visual Studio, the `grpc_csharp_ext.dll` that is shipped by gRPC nuget packages should be automatically copied to your build destination folder once you build. By adjusting project properties in your VS project file, you can influence which exact configuration of `grpc_csharp_ext.dll` will be used (based on VS version, bitness, debug/release configuration). - -- If you are running your application that is using gRPC on Windows machine that doesn't have Visual Studio installed, you might need to install [Visual C++ 2013 redistributable](https://www.microsoft.com/en-us/download/details.aspx?id=40784) that contains some system .dll libraries that `grpc_csharp_ext.dll` depends on (see #905 for more details). - -- On Linux (or Docker), you need to first install gRPC C core and `libgrpc_csharp_ext.so` shared libraries. - See [How to Use](#how-to-use) section for details how to install it. - Installation on a machine where your application is going to be deployed is no different. - -- On Mac, you need to first install gRPC C core and `libgrpc_csharp_ext.dylib` shared libraries using Homebrew. See above for installation instruction. - Installation on a machine where your application is going to be deployed is no different. +Internally, gRPC C# uses a native library written in C (gRPC C core) and invokes its functionality via P/Invoke. `grpc_csharp_ext` library is a native extension library that facilitates this by wrapping some C core API into a form that's more digestible for P/Invoke. -- Possible cause for the problem is that the `grpc_csharp_ext` library is installed, but it has different bitness (32/64bit) than your C# runtime (in case you are using mono) or C# application. +Prior to version 0.13, installing `grpc_csharp_ext` was required to make gRPC work on Linux and MacOS. Starting with version 0.13, we have improved the packaging story significantly and precompiled versions of the native library for all supported platforms are now shipped with the NuGet package. Just installing the `Grpc` NuGet package should be the only step needed to use gRPC C#, regardless of your platform (Windows, Linux or Mac) and the bitness (32 or 64bit). [gRPC Linuxbrew instructions]:https://github.com/grpc/homebrew-grpc#quick-install-linux +[gRPC Homebrew instructions]:https://github.com/grpc/homebrew-grpc#quick-install-linux [homebrew]:http://brew.sh [gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install [grpc.io]: http://www.grpc.io/docs/installation/csharp.html From aa576ee179b7e0838c22ec4165fc0fd61686f136 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Fri, 12 Feb 2016 18:35:57 -0800 Subject: [PATCH 04/48] update nuget packages --- .../csharp/helloworld/.nuget/packages.config | 2 +- .../csharp/helloworld/Greeter/Greeter.csproj | 25 +++++++++---------- .../csharp/helloworld/Greeter/packages.config | 12 ++++----- .../GreeterClient/GreeterClient.csproj | 25 +++++++++---------- .../helloworld/GreeterClient/packages.config | 12 ++++----- .../GreeterServer/GreeterServer.csproj | 25 +++++++++---------- .../helloworld/GreeterServer/packages.config | 12 ++++----- .../csharp/route_guide/.nuget/packages.config | 2 +- .../route_guide/RouteGuide/RouteGuide.csproj | 20 +++++++-------- .../route_guide/RouteGuide/packages.config | 10 +++----- .../RouteGuideClient/RouteGuideClient.csproj | 20 +++++++-------- .../RouteGuideClient/packages.config | 10 +++----- .../RouteGuideServer/RouteGuideServer.csproj | 20 +++++++-------- .../RouteGuideServer/packages.config | 10 +++----- 14 files changed, 92 insertions(+), 113 deletions(-) diff --git a/examples/csharp/helloworld/.nuget/packages.config b/examples/csharp/helloworld/.nuget/packages.config index 1cbe7e1d65f..fb778311d1f 100644 --- a/examples/csharp/helloworld/.nuget/packages.config +++ b/examples/csharp/helloworld/.nuget/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/examples/csharp/helloworld/Greeter/Greeter.csproj b/examples/csharp/helloworld/Greeter/Greeter.csproj index fa1c20f5ff4..a25ad5f7910 100644 --- a/examples/csharp/helloworld/Greeter/Greeter.csproj +++ b/examples/csharp/helloworld/Greeter/Greeter.csproj @@ -10,7 +10,7 @@ Greeter Greeter v4.5 - 4eea1d1c + 39f4a691 true @@ -31,15 +31,18 @@ false - - ..\packages\Google.Protobuf.3.0.0-alpha4\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll + + False + ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll - - ..\packages\Grpc.Core.0.12.0\lib\net45\Grpc.Core.dll + + False + ..\packages\Grpc.Core.0.13.0\lib\net45\Grpc.Core.dll - - ..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll + + False + ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll @@ -53,15 +56,11 @@ - + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + - - \ No newline at end of file diff --git a/examples/csharp/helloworld/Greeter/packages.config b/examples/csharp/helloworld/Greeter/packages.config index cabcadc78f2..abe9ad08507 100644 --- a/examples/csharp/helloworld/Greeter/packages.config +++ b/examples/csharp/helloworld/Greeter/packages.config @@ -1,10 +1,8 @@  - - - - - - - + + + + + \ No newline at end of file diff --git a/examples/csharp/helloworld/GreeterClient/GreeterClient.csproj b/examples/csharp/helloworld/GreeterClient/GreeterClient.csproj index 164a6165eff..a71cfeeef33 100644 --- a/examples/csharp/helloworld/GreeterClient/GreeterClient.csproj +++ b/examples/csharp/helloworld/GreeterClient/GreeterClient.csproj @@ -10,7 +10,7 @@ GreeterClient GreeterClient v4.5 - 29206d49 + dcebbc77 true @@ -31,15 +31,18 @@ true - - ..\packages\Google.Protobuf.3.0.0-alpha4\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll + + False + ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll - - ..\packages\Grpc.Core.0.12.0\lib\net45\Grpc.Core.dll + + False + ..\packages\Grpc.Core.0.13.0\lib\net45\Grpc.Core.dll - - ..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll + + False + ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll @@ -56,15 +59,11 @@ - + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + - - \ No newline at end of file diff --git a/examples/csharp/helloworld/GreeterClient/packages.config b/examples/csharp/helloworld/GreeterClient/packages.config index cabcadc78f2..abe9ad08507 100644 --- a/examples/csharp/helloworld/GreeterClient/packages.config +++ b/examples/csharp/helloworld/GreeterClient/packages.config @@ -1,10 +1,8 @@  - - - - - - - + + + + + \ No newline at end of file diff --git a/examples/csharp/helloworld/GreeterServer/GreeterServer.csproj b/examples/csharp/helloworld/GreeterServer/GreeterServer.csproj index 56436d3834c..34eea8c246d 100644 --- a/examples/csharp/helloworld/GreeterServer/GreeterServer.csproj +++ b/examples/csharp/helloworld/GreeterServer/GreeterServer.csproj @@ -10,7 +10,7 @@ GreeterServer GreeterServer v4.5 - 8a2cae0f + 2ea5dfd0 true @@ -31,15 +31,18 @@ true - - ..\packages\Google.Protobuf.3.0.0-alpha4\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll + + False + ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll - - ..\packages\Grpc.Core.0.12.0\lib\net45\Grpc.Core.dll + + False + ..\packages\Grpc.Core.0.13.0\lib\net45\Grpc.Core.dll - - ..\packages\Ix-Async.1.2.3\lib\net45\System.Interactive.Async.dll + + False + ..\packages\Ix-Async.1.2.5\lib\net45\System.Interactive.Async.dll @@ -56,15 +59,11 @@ - + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + - - \ No newline at end of file diff --git a/examples/csharp/helloworld/GreeterServer/packages.config b/examples/csharp/helloworld/GreeterServer/packages.config index cabcadc78f2..abe9ad08507 100644 --- a/examples/csharp/helloworld/GreeterServer/packages.config +++ b/examples/csharp/helloworld/GreeterServer/packages.config @@ -1,10 +1,8 @@  - - - - - - - + + + + + \ No newline at end of file diff --git a/examples/csharp/route_guide/.nuget/packages.config b/examples/csharp/route_guide/.nuget/packages.config index 1cbe7e1d65f..fb778311d1f 100644 --- a/examples/csharp/route_guide/.nuget/packages.config +++ b/examples/csharp/route_guide/.nuget/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj b/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj index 3a2a29cface..1fbf1ce1831 100644 --- a/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj +++ b/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj @@ -11,7 +11,7 @@ RouteGuide v4.5 512 - 68b3dd23 + 5b6d924a true @@ -31,11 +31,13 @@ 4 - - ..\packages\Google.Protobuf.3.0.0-alpha4\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll + + False + ..\packages\Google.Protobuf.3.0.0-beta2\lib\portable-net45+netcore45+wpa81+wp8\Google.Protobuf.dll - - ..\packages\Grpc.Core.0.12.0\lib\net45\Grpc.Core.dll + + False + ..\packages\Grpc.Core.0.13.0\lib\net45\Grpc.Core.dll False @@ -65,17 +67,13 @@ - + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - + - -