diff options
86 files changed, 869 insertions, 657 deletions
diff --git a/.github/mergeable.yml b/.github/mergeable.yml index f0180b9979..660d8cb440 100644 --- a/.github/mergeable.yml +++ b/.github/mergeable.yml @@ -2,5 +2,5 @@ mergeable: pull_requests: label: must_include: - regex: "release notes:yes|release notes:no" + regex: "release notes: yes|release notes: no" message: "Add release notes yes/no label. For yes, add lang label" @@ -1,5 +1,44 @@ -workspace(name = "com_github_grpc_grpc") +workspace(name="com_github_grpc_grpc") load("//bazel:grpc_deps.bzl", "grpc_deps", "grpc_test_only_deps") grpc_deps() grpc_test_only_deps() + +new_http_archive( + name="cython", + sha256="d68138a2381afbdd0876c3cb2a22389043fa01c4badede1228ee073032b07a27", + urls=[ + "https://github.com/cython/cython/archive/c2b80d87658a8525ce091cbe146cb7eaa29fed5c.tar.gz", + ], + strip_prefix="cython-c2b80d87658a8525ce091cbe146cb7eaa29fed5c", + build_file="//third_party:cython.BUILD", +) + +load("//third_party/py:python_configure.bzl", "python_configure") +python_configure(name="local_config_python") + +git_repository( + name="io_bazel_rules_python", + remote="https://github.com/bazelbuild/rules_python.git", + commit="8b5d0683a7d878b28fffe464779c8a53659fc645", +) + +load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories", "pip_import") + +pip_repositories() +pip_import( + name="grpc_python_dependencies", + requirements="//:requirements.bazel.txt", +) + +load("@grpc_python_dependencies//:requirements.bzl", "pip_install") +pip_install() + +git_repository( + name="org_pubref_rules_protobuf", + remote="https://github.com/pubref/rules_protobuf", + tag="v0.8.2", +) + +load("@org_pubref_rules_protobuf//python:rules.bzl", "py_proto_repositories") +py_proto_repositories() diff --git a/bazel/cython_library.bzl b/bazel/cython_library.bzl new file mode 100644 index 0000000000..48b41d74e8 --- /dev/null +++ b/bazel/cython_library.bzl @@ -0,0 +1,74 @@ +"""Custom rules for gRPC Python""" + + +# Adapted with modifications from +# tensorflow/tensorflow/core/platform/default/build_config.bzl +# Native Bazel rules don't exist yet to compile Cython code, but rules have +# been written at cython/cython and tensorflow/tensorflow. We branch from +# Tensorflow's version as it is more actively maintained and works for gRPC +# Python's needs. +def pyx_library(name, deps=[], py_deps=[], srcs=[], **kwargs): + """Compiles a group of .pyx / .pxd / .py files. + + First runs Cython to create .cpp files for each input .pyx or .py + .pxd + pair. Then builds a shared object for each, passing "deps" to each cc_binary + rule (includes Python headers by default). Finally, creates a py_library rule + with the shared objects and any pure Python "srcs", with py_deps as its + dependencies; the shared objects can be imported like normal Python files. + + Args: + name: Name for the rule. + deps: C/C++ dependencies of the Cython (e.g. Numpy headers). + py_deps: Pure Python dependencies of the final library. + srcs: .py, .pyx, or .pxd files to either compile or pass through. + **kwargs: Extra keyword arguments passed to the py_library. + """ + # First filter out files that should be run compiled vs. passed through. + py_srcs = [] + pyx_srcs = [] + pxd_srcs = [] + for src in srcs: + if src.endswith(".pyx") or (src.endswith(".py") and + src[:-3] + ".pxd" in srcs): + pyx_srcs.append(src) + elif src.endswith(".py"): + py_srcs.append(src) + else: + pxd_srcs.append(src) + if src.endswith("__init__.py"): + pxd_srcs.append(src) + + # Invoke cython to produce the shared object libraries. + for filename in pyx_srcs: + native.genrule( + name=filename + "_cython_translation", + srcs=[filename], + outs=[filename.split(".")[0] + ".cpp"], + # Optionally use PYTHON_BIN_PATH on Linux platforms so that python 3 + # works. Windows has issues with cython_binary so skip PYTHON_BIN_PATH. + cmd= + "PYTHONHASHSEED=0 $(location @cython//:cython_binary) --cplus $(SRCS) --output-file $(OUTS)", + tools=["@cython//:cython_binary"] + pxd_srcs, + ) + + shared_objects = [] + for src in pyx_srcs: + stem = src.split(".")[0] + shared_object_name = stem + ".so" + native.cc_binary( + name=shared_object_name, + srcs=[stem + ".cpp"], + deps=deps + ["@local_config_python//:python_headers"], + linkshared=1, + ) + shared_objects.append(shared_object_name) + + # Now create a py_library with these shared objects as data. + native.py_library( + name=name, + srcs=py_srcs, + deps=py_deps, + srcs_version="PY2AND3", + data=shared_objects, + **kwargs) + diff --git a/doc/csharp/server_reflection.md b/doc/csharp/server_reflection.md new file mode 100644 index 0000000000..9721680269 --- /dev/null +++ b/doc/csharp/server_reflection.md @@ -0,0 +1,53 @@ +# gRPC C# Server Reflection + +This document shows how to use gRPC Server Reflection in gRPC C#. +Please see [C++ Server Reflection Tutorial](../server_reflection_tutorial.md) +for general information and more examples how to use server reflection. + +## Enable server reflection in C# servers + +C# Server Reflection is an add-on library. +To use it, first install the [Grpc.Reflection](https://www.nuget.org/packages/Grpc.Reflection/) +Nuget package into your project. + +Note that with C# you need to manually register the service +descriptors with the reflection service implementation when creating a server +(this isn't necessary with e.g. C++ or Java) +```csharp +// the reflection service will be aware of "Greeter" and "ServerReflection" services. +var reflectionServiceImpl = new ReflectionServiceImpl(Greeter.Descriptor, ServerReflection.Descriptor); +server = new Server() +{ + Services = + { + // the server will serve 2 services, the Greeter and the ServerReflection + ServerReflection.BindService(new GreeterImpl()), + ServerReflection.BindService(reflectionServiceImpl) + }, + Ports = { { "localhost", 50051, ServerCredentials.Insecure } } +}; +server.Start(); +``` + +After starting the server, you can verify that the server reflection +is working properly by using the `grpc_cli` command line tool: + + ```sh + $ grpc_cli ls localhost:50051 + ``` + + output: + ```sh + helloworld.Greeter + grpc.reflection.v1alpha.ServerReflection + ``` + + For more examples and instructions how to use the `grpc_cli` tool, + please refer to the [`grpc_cli` documentation](../command_line_tool.md) + and the [C++ Server Reflection Tutorial](../server_reflection_tutorial.md). + +## Additional Resources + +The [Server Reflection Protocol](../server-reflection.md) provides detailed +information about how the server reflection works and describes the server reflection +protocol in detail. diff --git a/doc/server-reflection.md b/doc/server-reflection.md index cceee1647f..c9b476599f 100644 --- a/doc/server-reflection.md +++ b/doc/server-reflection.md @@ -181,3 +181,16 @@ will need to index those FileDescriptorProtos by file and symbol and imports. One issue is that some grpc implementations are very loosely coupled with protobufs; in such implementations it probably makes sense to split apart these reflection APIs so as not to take an additional proto dependency. + +## Known Implementations + +Enabling server reflection differs language-to-language. Here are links to docs relevant to +each language: + +- [Java](https://github.com/grpc/grpc-java/blob/master/documentation/server-reflection-tutorial.md#enable-server-reflection) +- [Go](https://github.com/grpc/grpc-go/blob/master/Documentation/server-reflection-tutorial.md#enable-server-reflection) +- [C++](https://grpc.io/grpc/cpp/md_doc_server_reflection_tutorial.html) +- [C#](https://github.com/grpc/grpc/blob/master/doc/csharp/server_reflection.md) +- Python: (tutorial not yet written) +- Ruby: not yet implemented [#2567](https://github.com/grpc/grpc/issues/2567) +- Node: not yet implemented [#2568](https://github.com/grpc/grpc/issues/2568) diff --git a/doc/server_reflection_tutorial.md b/doc/server_reflection_tutorial.md index ecb176723c..06a257c1e8 100644 --- a/doc/server_reflection_tutorial.md +++ b/doc/server_reflection_tutorial.md @@ -10,7 +10,7 @@ RPCs. ### Enable server reflection in C++ servers -C++ Server Reflection is an add-on library, `libgrpc++_reflction`. To enable C++ +C++ Server Reflection is an add-on library, `libgrpc++_reflection`. To enable C++ server reflection, you can link this library to your server binary. Some platforms (e.g. Ubuntu 11.10 onwards) only link in libraries that directly diff --git a/examples/csharp/helloworld-from-cli/Greeter.sln b/examples/csharp/Helloworld/Greeter.sln index ca50470e66..ca50470e66 100644 --- a/examples/csharp/helloworld-from-cli/Greeter.sln +++ b/examples/csharp/Helloworld/Greeter.sln diff --git a/examples/csharp/helloworld-from-cli/Greeter/Greeter.csproj b/examples/csharp/Helloworld/Greeter/Greeter.csproj index 3bff4a576b..3d4be5da6b 100644 --- a/examples/csharp/helloworld-from-cli/Greeter/Greeter.csproj +++ b/examples/csharp/Helloworld/Greeter/Greeter.csproj @@ -11,8 +11,8 @@ <ItemGroup> <PackageReference Include="Google.Protobuf" Version="3.5.0" /> <PackageReference Include="Google.Protobuf.Tools" Version="3.5.0" /> - <PackageReference Include="Grpc" Version="1.8.0" /> - <PackageReference Include="Grpc.Tools" Version="1.8.0" /> + <PackageReference Include="Grpc" Version="1.13.1" /> + <PackageReference Include="Grpc.Tools" Version="1.13.1" /> </ItemGroup> </Project> diff --git a/examples/csharp/helloworld-from-cli/Greeter/Helloworld.cs b/examples/csharp/Helloworld/Greeter/Helloworld.cs index ecfc8e131c..ecfc8e131c 100644 --- a/examples/csharp/helloworld-from-cli/Greeter/Helloworld.cs +++ b/examples/csharp/Helloworld/Greeter/Helloworld.cs diff --git a/examples/csharp/helloworld-from-cli/Greeter/HelloworldGrpc.cs b/examples/csharp/Helloworld/Greeter/HelloworldGrpc.cs index c808884e57..c808884e57 100644 --- a/examples/csharp/helloworld-from-cli/Greeter/HelloworldGrpc.cs +++ b/examples/csharp/Helloworld/Greeter/HelloworldGrpc.cs diff --git a/examples/csharp/helloworld-from-cli/GreeterClient/GreeterClient.csproj b/examples/csharp/Helloworld/GreeterClient/GreeterClient.csproj index d1ed040411..d1ed040411 100644 --- a/examples/csharp/helloworld-from-cli/GreeterClient/GreeterClient.csproj +++ b/examples/csharp/Helloworld/GreeterClient/GreeterClient.csproj diff --git a/examples/csharp/helloworld-from-cli/GreeterClient/Program.cs b/examples/csharp/Helloworld/GreeterClient/Program.cs index 38e7625d14..38e7625d14 100644 --- a/examples/csharp/helloworld-from-cli/GreeterClient/Program.cs +++ b/examples/csharp/Helloworld/GreeterClient/Program.cs diff --git a/examples/csharp/helloworld-from-cli/GreeterServer/GreeterServer.csproj b/examples/csharp/Helloworld/GreeterServer/GreeterServer.csproj index 159fbd8a23..159fbd8a23 100644 --- a/examples/csharp/helloworld-from-cli/GreeterServer/GreeterServer.csproj +++ b/examples/csharp/Helloworld/GreeterServer/GreeterServer.csproj diff --git a/examples/csharp/helloworld-from-cli/GreeterServer/Program.cs b/examples/csharp/Helloworld/GreeterServer/Program.cs index 2b787ecf0f..2b787ecf0f 100644 --- a/examples/csharp/helloworld-from-cli/GreeterServer/Program.cs +++ b/examples/csharp/Helloworld/GreeterServer/Program.cs diff --git a/examples/csharp/helloworld-from-cli/README.md b/examples/csharp/Helloworld/README.md index b780fa1b2f..e603179438 100644 --- a/examples/csharp/helloworld-from-cli/README.md +++ b/examples/csharp/Helloworld/README.md @@ -3,9 +3,6 @@ gRPC in 3 minutes (C#) BACKGROUND ------------- -This is a different version of the helloworld example, using the dotnet sdk -tools to build and run. - For this sample, we've already generated the server and client stubs from [helloworld.proto][]. Example projects in this directory depend on the [Grpc](https://www.nuget.org/packages/Grpc/) @@ -15,17 +12,19 @@ which have been already added to the project for you. PREREQUISITES ------------- -- The [.NET Core SDK](https://www.microsoft.com/net/core). +- The [.NET Core SDK](https://www.microsoft.com/net/core) (version 2+ is recommended) + +You can also build the example directly using Visual Studio 2017, but it's not a requirement. BUILD ------- -From the `examples/csharp/helloworld-from-cli` directory: - -- `dotnet restore Greeter.sln` +From the `examples/csharp/Helloworld` directory: - `dotnet build Greeter.sln` +(if you're using dotnet SDK 1.x you need to run `dotnet restore Greeter.sln` first) + Try it! ------- diff --git a/examples/csharp/helloworld-from-cli/generate_protos.bat b/examples/csharp/Helloworld/generate_protos.bat index dcf60848f7..dcf60848f7 100644 --- a/examples/csharp/helloworld-from-cli/generate_protos.bat +++ b/examples/csharp/Helloworld/generate_protos.bat diff --git a/examples/csharp/helloworld/Greeter.sln b/examples/csharp/HelloworldLegacyCsproj/Greeter.sln index 49e364d91c..49e364d91c 100644 --- a/examples/csharp/helloworld/Greeter.sln +++ b/examples/csharp/HelloworldLegacyCsproj/Greeter.sln diff --git a/examples/csharp/helloworld/Greeter/.gitignore b/examples/csharp/HelloworldLegacyCsproj/Greeter/.gitignore index 1746e3269e..1746e3269e 100644 --- a/examples/csharp/helloworld/Greeter/.gitignore +++ b/examples/csharp/HelloworldLegacyCsproj/Greeter/.gitignore diff --git a/examples/csharp/helloworld/Greeter/Greeter.csproj b/examples/csharp/HelloworldLegacyCsproj/Greeter/Greeter.csproj index d2597f13b5..ab584c86d3 100644 --- a/examples/csharp/helloworld/Greeter/Greeter.csproj +++ b/examples/csharp/HelloworldLegacyCsproj/Greeter/Greeter.csproj @@ -36,15 +36,15 @@ <HintPath>..\packages\Google.Protobuf.3.5.0\lib\net45\Google.Protobuf.dll</HintPath> <Private>True</Private> </Reference> - <Reference Include="Grpc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL"> - <HintPath>..\packages\Grpc.Core.1.8.0\lib\net45\Grpc.Core.dll</HintPath> - <Private>True</Private> - </Reference> <Reference Include="System" /> <Reference Include="System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL"> <HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll</HintPath> <Private>True</Private> </Reference> + <Reference Include="Grpc.Core"> + <HintPath>..\packages\Grpc.Core.1.13.1\lib\net45\Grpc.Core.dll</HintPath> + </Reference> + <Reference Include="Microsoft.CSharp" /> </ItemGroup> <ItemGroup> <Compile Include="Properties\AssemblyInfo.cs" /> @@ -62,11 +62,5 @@ <None Include="packages.config" /> </ItemGroup> <ItemGroup /> - <Import Project="..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets" Condition="Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" /> - <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> - <PropertyGroup> - <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> - </PropertyGroup> - <Error Condition="!Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets'))" /> - </Target> + <Import Project="..\packages\Grpc.Core.1.13.1\build\net45\Grpc.Core.targets" Condition="Exists('..\packages\Grpc.Core.1.13.1\build\net45\Grpc.Core.targets')" /> </Project>
\ No newline at end of file diff --git a/examples/csharp/helloworld/Greeter/Helloworld.cs b/examples/csharp/HelloworldLegacyCsproj/Greeter/Helloworld.cs index ecfc8e131c..ecfc8e131c 100644 --- a/examples/csharp/helloworld/Greeter/Helloworld.cs +++ b/examples/csharp/HelloworldLegacyCsproj/Greeter/Helloworld.cs diff --git a/examples/csharp/helloworld/Greeter/HelloworldGrpc.cs b/examples/csharp/HelloworldLegacyCsproj/Greeter/HelloworldGrpc.cs index c808884e57..c808884e57 100644 --- a/examples/csharp/helloworld/Greeter/HelloworldGrpc.cs +++ b/examples/csharp/HelloworldLegacyCsproj/Greeter/HelloworldGrpc.cs diff --git a/examples/csharp/helloworld/Greeter/Properties/AssemblyInfo.cs b/examples/csharp/HelloworldLegacyCsproj/Greeter/Properties/AssemblyInfo.cs index bdf394f8d4..bdf394f8d4 100644 --- a/examples/csharp/helloworld/Greeter/Properties/AssemblyInfo.cs +++ b/examples/csharp/HelloworldLegacyCsproj/Greeter/Properties/AssemblyInfo.cs diff --git a/examples/csharp/helloworld/Greeter/packages.config b/examples/csharp/HelloworldLegacyCsproj/Greeter/packages.config index 38297f8d61..8e61429a8e 100644 --- a/examples/csharp/helloworld/Greeter/packages.config +++ b/examples/csharp/HelloworldLegacyCsproj/Greeter/packages.config @@ -1,8 +1,8 @@ <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Google.Protobuf" version="3.5.0" targetFramework="net45" /> - <package id="Grpc" version="1.8.0" targetFramework="net45" /> - <package id="Grpc.Core" version="1.8.0" targetFramework="net45" /> - <package id="Grpc.Tools" version="1.8.0" targetFramework="net45" /> + <package id="Grpc" version="1.13.1" targetFramework="net45" /> + <package id="Grpc.Core" version="1.13.1" targetFramework="net45" /> + <package id="Grpc.Tools" version="1.13.1" targetFramework="net45" /> <package id="System.Interactive.Async" version="3.1.1" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/examples/csharp/helloworld/GreeterClient/.gitignore b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/.gitignore index 1746e3269e..1746e3269e 100644 --- a/examples/csharp/helloworld/GreeterClient/.gitignore +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/.gitignore diff --git a/examples/csharp/helloworld/GreeterClient/GreeterClient.csproj b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/GreeterClient.csproj index 470749a2b2..2d2961d128 100644 --- a/examples/csharp/helloworld/GreeterClient/GreeterClient.csproj +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/GreeterClient.csproj @@ -36,15 +36,15 @@ <HintPath>..\packages\Google.Protobuf.3.5.0\lib\net45\Google.Protobuf.dll</HintPath> <Private>True</Private> </Reference> - <Reference Include="Grpc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL"> - <HintPath>..\packages\Grpc.Core.1.8.0\lib\net45\Grpc.Core.dll</HintPath> - <Private>True</Private> - </Reference> <Reference Include="System" /> <Reference Include="System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL"> <HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll</HintPath> <Private>True</Private> </Reference> + <Reference Include="Grpc.Core"> + <HintPath>..\packages\Grpc.Core.1.13.1\lib\net45\Grpc.Core.dll</HintPath> + </Reference> + <Reference Include="Microsoft.CSharp" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> @@ -60,11 +60,5 @@ <ItemGroup> <None Include="packages.config" /> </ItemGroup> - <Import Project="..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets" Condition="Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" /> - <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> - <PropertyGroup> - <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> - </PropertyGroup> - <Error Condition="!Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets'))" /> - </Target> + <Import Project="..\packages\Grpc.Core.1.13.1\build\net45\Grpc.Core.targets" Condition="Exists('..\packages\Grpc.Core.1.13.1\build\net45\Grpc.Core.targets')" /> </Project>
\ No newline at end of file diff --git a/examples/csharp/helloworld/GreeterClient/Program.cs b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/Program.cs index 38e7625d14..38e7625d14 100644 --- a/examples/csharp/helloworld/GreeterClient/Program.cs +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/Program.cs diff --git a/examples/csharp/helloworld/GreeterClient/Properties/AssemblyInfo.cs b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/Properties/AssemblyInfo.cs index c88280b417..c88280b417 100644 --- a/examples/csharp/helloworld/GreeterClient/Properties/AssemblyInfo.cs +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/Properties/AssemblyInfo.cs diff --git a/examples/csharp/helloworld/GreeterClient/packages.config b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/packages.config index 4b3684edfd..da7dbcd8cb 100644 --- a/examples/csharp/helloworld/GreeterClient/packages.config +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterClient/packages.config @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Google.Protobuf" version="3.5.0" targetFramework="net45" /> - <package id="Grpc" version="1.8.0" targetFramework="net45" /> - <package id="Grpc.Core" version="1.8.0" targetFramework="net45" /> + <package id="Grpc" version="1.13.1" targetFramework="net45" /> + <package id="Grpc.Core" version="1.13.1" targetFramework="net45" /> <package id="System.Interactive.Async" version="3.1.1" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/examples/csharp/helloworld/GreeterServer/.gitignore b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/.gitignore index 1746e3269e..1746e3269e 100644 --- a/examples/csharp/helloworld/GreeterServer/.gitignore +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/.gitignore diff --git a/examples/csharp/helloworld/GreeterServer/GreeterServer.csproj b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/GreeterServer.csproj index 82e2961cad..1d47d70595 100644 --- a/examples/csharp/helloworld/GreeterServer/GreeterServer.csproj +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/GreeterServer.csproj @@ -36,15 +36,15 @@ <HintPath>..\packages\Google.Protobuf.3.5.0\lib\net45\Google.Protobuf.dll</HintPath> <Private>True</Private> </Reference> - <Reference Include="Grpc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL"> - <HintPath>..\packages\Grpc.Core.1.8.0\lib\net45\Grpc.Core.dll</HintPath> - <Private>True</Private> - </Reference> <Reference Include="System" /> <Reference Include="System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL"> <HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll</HintPath> <Private>True</Private> </Reference> + <Reference Include="Grpc.Core"> + <HintPath>..\packages\Grpc.Core.1.13.1\lib\net45\Grpc.Core.dll</HintPath> + </Reference> + <Reference Include="Microsoft.CSharp" /> </ItemGroup> <ItemGroup> <Compile Include="Program.cs" /> @@ -60,11 +60,5 @@ <ItemGroup> <None Include="packages.config" /> </ItemGroup> - <Import Project="..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets" Condition="Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" /> - <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> - <PropertyGroup> - <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> - </PropertyGroup> - <Error Condition="!Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets'))" /> - </Target> + <Import Project="..\packages\Grpc.Core.1.13.1\build\net45\Grpc.Core.targets" Condition="Exists('..\packages\Grpc.Core.1.13.1\build\net45\Grpc.Core.targets')" /> </Project>
\ No newline at end of file diff --git a/examples/csharp/helloworld/GreeterServer/Program.cs b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/Program.cs index 2b787ecf0f..2b787ecf0f 100644 --- a/examples/csharp/helloworld/GreeterServer/Program.cs +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/Program.cs diff --git a/examples/csharp/helloworld/GreeterServer/Properties/AssemblyInfo.cs b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/Properties/AssemblyInfo.cs index c0f2961cd3..c0f2961cd3 100644 --- a/examples/csharp/helloworld/GreeterServer/Properties/AssemblyInfo.cs +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/Properties/AssemblyInfo.cs diff --git a/examples/csharp/helloworld/GreeterServer/packages.config b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/packages.config index 4b3684edfd..da7dbcd8cb 100644 --- a/examples/csharp/helloworld/GreeterServer/packages.config +++ b/examples/csharp/HelloworldLegacyCsproj/GreeterServer/packages.config @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="utf-8"?> <packages> <package id="Google.Protobuf" version="3.5.0" targetFramework="net45" /> - <package id="Grpc" version="1.8.0" targetFramework="net45" /> - <package id="Grpc.Core" version="1.8.0" targetFramework="net45" /> + <package id="Grpc" version="1.13.1" targetFramework="net45" /> + <package id="Grpc.Core" version="1.13.1" targetFramework="net45" /> <package id="System.Interactive.Async" version="3.1.1" targetFramework="net45" /> </packages>
\ No newline at end of file diff --git a/examples/csharp/helloworld/README.md b/examples/csharp/HelloworldLegacyCsproj/README.md index 55e3ab7030..6d42c5ef25 100644 --- a/examples/csharp/helloworld/README.md +++ b/examples/csharp/HelloworldLegacyCsproj/README.md @@ -3,6 +3,11 @@ gRPC in 3 minutes (C#) BACKGROUND ------------- +This is a different version of the helloworld example, using the old-style .csproj +files supported by VS2013 and VS2015 (and older versions of mono). +You can still use gRPC with the old-style .csproj files, but [using the new-style +.csproj projects](../helloworld/README.md) (supported by VS2017 and dotnet SDK) is recommended. + For this sample, we've already generated the server and client stubs from [helloworld.proto][]. Example projects depend on the [Grpc](https://www.nuget.org/packages/Grpc/), [Grpc.Tools](https://www.nuget.org/packages/Grpc.Tools/) @@ -28,7 +33,7 @@ BUILD # Using Monodevelop or Xamarin Studio The nuget add-in available for Xamarin Studio and Monodevelop IDEs is too old to -download all of the nuget dependencies of gRPC. One alternative to is to use the dotnet command line tools instead (see [helloworld-from-cli]). +download all of the nuget dependencies of gRPC. Using these IDEs, a workaround is as follows: * Obtain a nuget executable for your platform and update it with @@ -62,6 +67,5 @@ Tutorial You can find a more detailed tutorial in [gRPC Basics: C#][] -[helloworld-from-cli]:../helloworld-from-cli/README.md [helloworld.proto]:../../protos/helloworld.proto [gRPC Basics: C#]:https://grpc.io/docs/tutorials/basic/csharp.html diff --git a/examples/csharp/helloworld/generate_protos.bat b/examples/csharp/HelloworldLegacyCsproj/generate_protos.bat index 45b097e837..45b097e837 100644 --- a/examples/csharp/helloworld/generate_protos.bat +++ b/examples/csharp/HelloworldLegacyCsproj/generate_protos.bat diff --git a/examples/csharp/route_guide/.gitignore b/examples/csharp/RouteGuide/.gitignore index 585000ea2d..585000ea2d 100644 --- a/examples/csharp/route_guide/.gitignore +++ b/examples/csharp/RouteGuide/.gitignore diff --git a/examples/csharp/route_guide/README.md b/examples/csharp/RouteGuide/README.md index 3cfb14ae9a..3cfb14ae9a 100644 --- a/examples/csharp/route_guide/README.md +++ b/examples/csharp/RouteGuide/README.md diff --git a/examples/csharp/route_guide/RouteGuide.sln b/examples/csharp/RouteGuide/RouteGuide.sln index 00065b0ba9..73e6e306b1 100644 --- a/examples/csharp/route_guide/RouteGuide.sln +++ b/examples/csharp/RouteGuide/RouteGuide.sln @@ -1,13 +1,13 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 2013 -VisualStudioVersion = 12.0.31101.0 +# Visual Studio 15 +VisualStudioVersion = 15.0.26228.4 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuide", "RouteGuide\RouteGuide.csproj", "{49954D9C-5F17-4662-96B2-73BE833DD81A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuide", "RouteGuide\RouteGuide.csproj", "{49954D9C-5F17-4662-96B2-73BE833DD81A}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideClient", "RouteGuideClient\RouteGuideClient.csproj", "{D47BE663-4DE3-4206-B7A8-EA3FA066DADC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideClient", "RouteGuideClient\RouteGuideClient.csproj", "{D47BE663-4DE3-4206-B7A8-EA3FA066DADC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RouteGuideServer", "RouteGuideServer\RouteGuideServer.csproj", "{4B7C7794-BE24-4477-ACE7-18259EB73D27}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RouteGuideServer", "RouteGuideServer\RouteGuideServer.csproj", "{4B7C7794-BE24-4477-ACE7-18259EB73D27}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuide.cs b/examples/csharp/RouteGuide/RouteGuide/RouteGuide.cs index 603809ee76..603809ee76 100644 --- a/examples/csharp/route_guide/RouteGuide/RouteGuide.cs +++ b/examples/csharp/RouteGuide/RouteGuide/RouteGuide.cs diff --git a/examples/csharp/RouteGuide/RouteGuide/RouteGuide.csproj b/examples/csharp/RouteGuide/RouteGuide/RouteGuide.csproj new file mode 100644 index 0000000000..7419f1a277 --- /dev/null +++ b/examples/csharp/RouteGuide/RouteGuide/RouteGuide.csproj @@ -0,0 +1,25 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <AssemblyTitle>RouteGuide</AssemblyTitle> + <TargetFrameworks>netcoreapp1.0</TargetFrameworks> + <DebugType>portable</DebugType> + <AssemblyName>RouteGuide</AssemblyName> + <PackageId>RouteGuide</PackageId> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Google.Protobuf" Version="3.5.0" /> + <PackageReference Include="Google.Protobuf.Tools" Version="3.5.0" /> + <PackageReference Include="Grpc" Version="1.13.1" /> + <PackageReference Include="Grpc.Tools" Version="1.13.1" /> + <PackageReference Include="Newtonsoft.Json" Version="9.0.1" /> + </ItemGroup> + + <ItemGroup> + <None Include="route_guide_db.json"> + <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> + </None> + </ItemGroup> + +</Project> diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuideGrpc.cs b/examples/csharp/RouteGuide/RouteGuide/RouteGuideGrpc.cs index 765d5d520b..765d5d520b 100644 --- a/examples/csharp/route_guide/RouteGuide/RouteGuideGrpc.cs +++ b/examples/csharp/RouteGuide/RouteGuide/RouteGuideGrpc.cs diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuideUtil.cs b/examples/csharp/RouteGuide/RouteGuide/RouteGuideUtil.cs index f9af190888..f9af190888 100644 --- a/examples/csharp/route_guide/RouteGuide/RouteGuideUtil.cs +++ b/examples/csharp/RouteGuide/RouteGuide/RouteGuideUtil.cs diff --git a/examples/csharp/route_guide/RouteGuide/route_guide_db.json b/examples/csharp/RouteGuide/RouteGuide/route_guide_db.json index 9342beb579..9342beb579 100644 --- a/examples/csharp/route_guide/RouteGuide/route_guide_db.json +++ b/examples/csharp/RouteGuide/RouteGuide/route_guide_db.json diff --git a/examples/csharp/route_guide/RouteGuideClient/Program.cs b/examples/csharp/RouteGuide/RouteGuideClient/Program.cs index 9ce0cbcad3..9ce0cbcad3 100644 --- a/examples/csharp/route_guide/RouteGuideClient/Program.cs +++ b/examples/csharp/RouteGuide/RouteGuideClient/Program.cs diff --git a/examples/csharp/RouteGuide/RouteGuideClient/RouteGuideClient.csproj b/examples/csharp/RouteGuide/RouteGuideClient/RouteGuideClient.csproj new file mode 100644 index 0000000000..96cc204ba3 --- /dev/null +++ b/examples/csharp/RouteGuide/RouteGuideClient/RouteGuideClient.csproj @@ -0,0 +1,16 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <AssemblyTitle>RouteGuideClient</AssemblyTitle> + <TargetFrameworks>netcoreapp1.0</TargetFrameworks> + <DebugType>portable</DebugType> + <AssemblyName>RouteGuideClient</AssemblyName> + <OutputType>Exe</OutputType> + <PackageId>RouteGuideClient</PackageId> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\RouteGuide\RouteGuide.csproj" /> + </ItemGroup> + +</Project> diff --git a/examples/csharp/route_guide/RouteGuideServer/Program.cs b/examples/csharp/RouteGuide/RouteGuideServer/Program.cs index 4548ddf8e7..4548ddf8e7 100644 --- a/examples/csharp/route_guide/RouteGuideServer/Program.cs +++ b/examples/csharp/RouteGuide/RouteGuideServer/Program.cs diff --git a/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs b/examples/csharp/RouteGuide/RouteGuideServer/RouteGuideImpl.cs index f157ca08ab..f157ca08ab 100644 --- a/examples/csharp/route_guide/RouteGuideServer/RouteGuideImpl.cs +++ b/examples/csharp/RouteGuide/RouteGuideServer/RouteGuideImpl.cs diff --git a/examples/csharp/RouteGuide/RouteGuideServer/RouteGuideServer.csproj b/examples/csharp/RouteGuide/RouteGuideServer/RouteGuideServer.csproj new file mode 100644 index 0000000000..aa6315bf81 --- /dev/null +++ b/examples/csharp/RouteGuide/RouteGuideServer/RouteGuideServer.csproj @@ -0,0 +1,16 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <AssemblyTitle>RouteGuideServer</AssemblyTitle> + <TargetFrameworks>netcoreapp1.0</TargetFrameworks> + <DebugType>portable</DebugType> + <AssemblyName>RouteGuideServer</AssemblyName> + <OutputType>Exe</OutputType> + <PackageId>RouteGuideServer</PackageId> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\RouteGuide\RouteGuide.csproj" /> + </ItemGroup> + +</Project> diff --git a/examples/csharp/route_guide/generate_protos.bat b/examples/csharp/RouteGuide/generate_protos.bat index a8c9cb505a..a8c9cb505a 100644 --- a/examples/csharp/route_guide/generate_protos.bat +++ b/examples/csharp/RouteGuide/generate_protos.bat diff --git a/examples/csharp/route_guide/RouteGuide/Properties/AssemblyInfo.cs b/examples/csharp/route_guide/RouteGuide/Properties/AssemblyInfo.cs deleted file mode 100644 index dfee25c14c..0000000000 --- a/examples/csharp/route_guide/RouteGuide/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,54 +0,0 @@ -#region Copyright notice and license - -// Copyright 2015 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. - -#endregion - -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("RouteGuide")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("RouteGuide")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("ef6b85bc-ac27-46de-8714-a658236cc6fb")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj b/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj deleted file mode 100644 index e66e986f71..0000000000 --- a/examples/csharp/route_guide/RouteGuide/RouteGuide.csproj +++ /dev/null @@ -1,92 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{49954D9C-5F17-4662-96B2-73BE833DD81A}</ProjectGuid> - <OutputType>Library</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>RouteGuide</RootNamespace> - <AssemblyName>RouteGuide</AssemblyName> - <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <NuGetPackageImportStamp> - </NuGetPackageImportStamp> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <Reference Include="Google.Protobuf, Version=3.5.0.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> - <HintPath>..\packages\Google.Protobuf.3.5.0\lib\net45\Google.Protobuf.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Grpc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL"> - <HintPath>..\packages\Grpc.Core.1.8.0\lib\net45\Grpc.Core.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> - </Reference> - <Reference Include="System" /> - <Reference Include="System.Core" /> - <Reference Include="System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Data.DataSetExtensions" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Data" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="RouteGuide.cs" /> - <Compile Include="RouteGuideGrpc.cs" /> - <Compile Include="RouteGuideUtil.cs" /> - </ItemGroup> - <ItemGroup> - <None Include="..\..\..\protos\route_guide.proto"> - <Link>protos\route_guide.proto</Link> - </None> - <None Include="..\generate_protos.bat"> - <Link>generate_protos.bat</Link> - </None> - <None Include="packages.config" /> - <None Include="route_guide_db.json"> - <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> - </None> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <Import Project="..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets" Condition="Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" /> - <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> - <PropertyGroup> - <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> - </PropertyGroup> - <Error Condition="!Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets'))" /> - </Target> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> -</Project>
\ No newline at end of file diff --git a/examples/csharp/route_guide/RouteGuide/packages.config b/examples/csharp/route_guide/RouteGuide/packages.config deleted file mode 100644 index fe2c995f26..0000000000 --- a/examples/csharp/route_guide/RouteGuide/packages.config +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="Google.Protobuf" version="3.5.0" targetFramework="net45" /> - <package id="Grpc" version="1.8.0" targetFramework="net45" /> - <package id="Grpc.Core" version="1.8.0" targetFramework="net45" /> - <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" /> - <package id="System.Interactive.Async" version="3.1.1" targetFramework="net45" /> -</packages>
\ No newline at end of file diff --git a/examples/csharp/route_guide/RouteGuideClient/Properties/AssemblyInfo.cs b/examples/csharp/route_guide/RouteGuideClient/Properties/AssemblyInfo.cs deleted file mode 100644 index 4ccdf701d3..0000000000 --- a/examples/csharp/route_guide/RouteGuideClient/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,54 +0,0 @@ -#region Copyright notice and license - -// Copyright 2015 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. - -#endregion - -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("RouteGuideClient")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("RouteGuideClient")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("914644eb-47cd-4a37-9fba-5e62dd432333")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj b/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj deleted file mode 100644 index 612f60cba5..0000000000 --- a/examples/csharp/route_guide/RouteGuideClient/RouteGuideClient.csproj +++ /dev/null @@ -1,89 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{D47BE663-4DE3-4206-B7A8-EA3FA066DADC}</ProjectGuid> - <OutputType>Exe</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>RouteGuideClient</RootNamespace> - <AssemblyName>RouteGuideClient</AssemblyName> - <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <NuGetPackageImportStamp> - </NuGetPackageImportStamp> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <PlatformTarget>AnyCPU</PlatformTarget> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <PlatformTarget>AnyCPU</PlatformTarget> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <Reference Include="Google.Protobuf, Version=3.5.0.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> - <HintPath>..\packages\Google.Protobuf.3.5.0\lib\net45\Google.Protobuf.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Grpc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL"> - <HintPath>..\packages\Grpc.Core.1.8.0\lib\net45\Grpc.Core.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> - </Reference> - <Reference Include="System" /> - <Reference Include="System.Core" /> - <Reference Include="System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Data.DataSetExtensions" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Data" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="Program.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - </ItemGroup> - <ItemGroup> - <None Include="packages.config" /> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\RouteGuide\RouteGuide.csproj"> - <Project>{49954d9c-5f17-4662-96b2-73be833dd81a}</Project> - <Name>RouteGuide</Name> - </ProjectReference> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <Import Project="..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets" Condition="Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" /> - <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> - <PropertyGroup> - <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> - </PropertyGroup> - <Error Condition="!Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets'))" /> - </Target> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> -</Project>
\ No newline at end of file diff --git a/examples/csharp/route_guide/RouteGuideClient/packages.config b/examples/csharp/route_guide/RouteGuideClient/packages.config deleted file mode 100644 index fe2c995f26..0000000000 --- a/examples/csharp/route_guide/RouteGuideClient/packages.config +++ /dev/null @@ -1,8 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="Google.Protobuf" version="3.5.0" targetFramework="net45" /> - <package id="Grpc" version="1.8.0" targetFramework="net45" /> - <package id="Grpc.Core" version="1.8.0" targetFramework="net45" /> - <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" /> - <package id="System.Interactive.Async" version="3.1.1" targetFramework="net45" /> -</packages>
\ No newline at end of file diff --git a/examples/csharp/route_guide/RouteGuideServer/Properties/AssemblyInfo.cs b/examples/csharp/route_guide/RouteGuideServer/Properties/AssemblyInfo.cs deleted file mode 100644 index 679bc4c913..0000000000 --- a/examples/csharp/route_guide/RouteGuideServer/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,54 +0,0 @@ -#region Copyright notice and license - -// Copyright 2015 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. - -#endregion - -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("RouteGuideServer")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("RouteGuideServer")] -[assembly: AssemblyCopyright("Copyright © 2015")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("908bdeef-05cc-42bf-9498-c4c573df8925")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj b/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj deleted file mode 100644 index 4d9d9d74f2..0000000000 --- a/examples/csharp/route_guide/RouteGuideServer/RouteGuideServer.csproj +++ /dev/null @@ -1,90 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> - <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" /> - <PropertyGroup> - <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> - <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> - <ProjectGuid>{4B7C7794-BE24-4477-ACE7-18259EB73D27}</ProjectGuid> - <OutputType>Exe</OutputType> - <AppDesignerFolder>Properties</AppDesignerFolder> - <RootNamespace>RouteGuideServer</RootNamespace> - <AssemblyName>RouteGuideServer</AssemblyName> - <TargetFrameworkVersion>v4.5</TargetFrameworkVersion> - <FileAlignment>512</FileAlignment> - <NuGetPackageImportStamp> - </NuGetPackageImportStamp> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> - <PlatformTarget>AnyCPU</PlatformTarget> - <DebugSymbols>true</DebugSymbols> - <DebugType>full</DebugType> - <Optimize>false</Optimize> - <OutputPath>bin\Debug\</OutputPath> - <DefineConstants>DEBUG;TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> - <PlatformTarget>AnyCPU</PlatformTarget> - <DebugType>pdbonly</DebugType> - <Optimize>true</Optimize> - <OutputPath>bin\Release\</OutputPath> - <DefineConstants>TRACE</DefineConstants> - <ErrorReport>prompt</ErrorReport> - <WarningLevel>4</WarningLevel> - </PropertyGroup> - <ItemGroup> - <Reference Include="Google.Protobuf, Version=3.5.0.0, Culture=neutral, PublicKeyToken=a7d26565bac4d604, processorArchitecture=MSIL"> - <HintPath>..\packages\Google.Protobuf.3.5.0\lib\net45\Google.Protobuf.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Grpc.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad, processorArchitecture=MSIL"> - <HintPath>..\packages\Grpc.Core.1.8.0\lib\net45\Grpc.Core.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath> - </Reference> - <Reference Include="System" /> - <Reference Include="System.Core" /> - <Reference Include="System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263, processorArchitecture=MSIL"> - <HintPath>..\packages\System.Interactive.Async.3.1.1\lib\net45\System.Interactive.Async.dll</HintPath> - <Private>True</Private> - </Reference> - <Reference Include="System.Xml.Linq" /> - <Reference Include="System.Data.DataSetExtensions" /> - <Reference Include="Microsoft.CSharp" /> - <Reference Include="System.Data" /> - <Reference Include="System.Xml" /> - </ItemGroup> - <ItemGroup> - <Compile Include="Program.cs" /> - <Compile Include="Properties\AssemblyInfo.cs" /> - <Compile Include="RouteGuideImpl.cs" /> - </ItemGroup> - <ItemGroup> - <None Include="packages.config" /> - </ItemGroup> - <ItemGroup> - <ProjectReference Include="..\RouteGuide\RouteGuide.csproj"> - <Project>{49954d9c-5f17-4662-96b2-73be833dd81a}</Project> - <Name>RouteGuide</Name> - </ProjectReference> - </ItemGroup> - <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> - <Import Project="..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets" Condition="Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" /> - <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> - <PropertyGroup> - <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> - </PropertyGroup> - <Error Condition="!Exists('..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Grpc.Core.1.8.0\build\net45\Grpc.Core.targets'))" /> - </Target> - <!-- To modify your build process, add your task inside one of the targets below and uncomment it. - Other similar extension points exist, see Microsoft.Common.targets. - <Target Name="BeforeBuild"> - </Target> - <Target Name="AfterBuild"> - </Target> - --> -</Project>
\ No newline at end of file diff --git a/examples/csharp/route_guide/RouteGuideServer/packages.config b/examples/csharp/route_guide/RouteGuideServer/packages.config deleted file mode 100644 index 2bb1f0d0bf..0000000000 --- a/examples/csharp/route_guide/RouteGuideServer/packages.config +++ /dev/null @@ -1,9 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<packages> - <package id="Google.Protobuf" version="3.5.0" targetFramework="net45" /> - <package id="Grpc" version="1.8.0" targetFramework="net45" /> - <package id="Grpc.Core" version="1.8.0" targetFramework="net45" /> - <package id="Grpc.Tools" version="1.8.0" targetFramework="net45" /> - <package id="Newtonsoft.Json" version="7.0.1" targetFramework="net45" /> - <package id="System.Interactive.Async" version="3.1.1" targetFramework="net45" /> -</packages>
\ No newline at end of file diff --git a/include/grpc/grpc_security.h b/include/grpc/grpc_security.h index 102d20fcf9..02d87a493a 100644 --- a/include/grpc/grpc_security.h +++ b/include/grpc/grpc_security.h @@ -588,12 +588,6 @@ GRPCAPI grpc_server_credentials* grpc_alts_server_credentials_create( /** --- Local channel/server credentials --- **/ /** - * Type of local connection for which local channel/server credentials will be - * applied. It only supports UDS for now. - */ -typedef enum { UDS = 0 } grpc_local_connect_type; - -/** * This method creates a local channel credential object. It is used for * experimental purpose for now and subject to change. * diff --git a/include/grpc/grpc_security_constants.h b/include/grpc/grpc_security_constants.h index 92580ea35e..944a1e927f 100644 --- a/include/grpc/grpc_security_constants.h +++ b/include/grpc/grpc_security_constants.h @@ -100,6 +100,12 @@ typedef enum { GRPC_SSL_REQUEST_AND_REQUIRE_CLIENT_CERTIFICATE_AND_VERIFY } grpc_ssl_client_certificate_request_type; +/** + * Type of local connection for which local channel/server credentials will be + * applied. It only supports UDS for now. + */ +typedef enum { UDS = 0 } grpc_local_connect_type; + #ifdef __cplusplus } #endif diff --git a/include/grpcpp/security/credentials.h b/include/grpcpp/security/credentials.h index 36d95d1b42..bfadc15df5 100644 --- a/include/grpcpp/security/credentials.h +++ b/include/grpcpp/security/credentials.h @@ -23,6 +23,7 @@ #include <memory> #include <vector> +#include <grpc/grpc_security_constants.h> #include <grpcpp/impl/codegen/grpc_library.h> #include <grpcpp/security/auth_context.h> #include <grpcpp/support/status.h> @@ -234,6 +235,10 @@ struct AltsCredentialsOptions { std::shared_ptr<ChannelCredentials> AltsCredentials( const AltsCredentialsOptions& options); +/// Builds Local Credentials. +std::shared_ptr<ChannelCredentials> LocalCredentials( + grpc_local_connect_type type); + } // namespace experimental } // namespace grpc diff --git a/include/grpcpp/security/server_credentials.h b/include/grpcpp/security/server_credentials.h index cf57e275f5..bd00a0a173 100644 --- a/include/grpcpp/security/server_credentials.h +++ b/include/grpcpp/security/server_credentials.h @@ -97,6 +97,10 @@ struct AltsServerCredentialsOptions { std::shared_ptr<ServerCredentials> AltsServerCredentials( const AltsServerCredentialsOptions& options); +/// Builds Local ServerCredentials. +std::shared_ptr<ServerCredentials> LocalServerCredentials( + grpc_local_connect_type type); + } // namespace experimental } // namespace grpc diff --git a/requirements.bazel.txt b/requirements.bazel.txt new file mode 100644 index 0000000000..16f31f9e94 --- /dev/null +++ b/requirements.bazel.txt @@ -0,0 +1,10 @@ +# GRPC Python setup requirements +coverage>=4.0 +cython==0.28.3 +enum34>=1.0.4 +protobuf>=3.5.0.post1 +six>=1.10 +wheel>=0.29 +futures>=2.2.0 +google-auth>=1.0.0 +oauth2client==4.1.0 diff --git a/src/core/ext/filters/client_channel/client_channel_channelz.cc b/src/core/ext/filters/client_channel/client_channel_channelz.cc index 4c9c9a6bd6..86c765df52 100644 --- a/src/core/ext/filters/client_channel/client_channel_channelz.cc +++ b/src/core/ext/filters/client_channel/client_channel_channelz.cc @@ -105,8 +105,8 @@ grpc_arg ClientChannelNode::CreateChannelArg() { RefCountedPtr<ChannelNode> ClientChannelNode::MakeClientChannelNode( grpc_channel* channel, size_t channel_tracer_max_nodes, bool is_top_level_channel) { - return MakePolymorphicRefCounted<ChannelNode, ClientChannelNode>( - channel, channel_tracer_max_nodes, is_top_level_channel); + return MakeRefCounted<ClientChannelNode>(channel, channel_tracer_max_nodes, + is_top_level_channel); } } // namespace channelz diff --git a/src/core/lib/gprpp/orphanable.h b/src/core/lib/gprpp/orphanable.h index d0ec9b6461..3123e3f5a3 100644 --- a/src/core/lib/gprpp/orphanable.h +++ b/src/core/lib/gprpp/orphanable.h @@ -86,7 +86,8 @@ class InternallyRefCounted : public Orphanable { GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE // Allow RefCountedPtr<> to access Unref() and IncrementRefCount(). - friend class RefCountedPtr<Child>; + template <typename T> + friend class RefCountedPtr; InternallyRefCounted() { gpr_ref_init(&refs_, 1); } virtual ~InternallyRefCounted() {} @@ -129,7 +130,8 @@ class InternallyRefCountedWithTracing : public Orphanable { GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE // Allow RefCountedPtr<> to access Unref() and IncrementRefCount(). - friend class RefCountedPtr<Child>; + template <typename T> + friend class RefCountedPtr; InternallyRefCountedWithTracing() : InternallyRefCountedWithTracing(static_cast<TraceFlag*>(nullptr)) {} diff --git a/src/core/lib/gprpp/ref_counted.h b/src/core/lib/gprpp/ref_counted.h index ddac5bd475..03c293f6ed 100644 --- a/src/core/lib/gprpp/ref_counted.h +++ b/src/core/lib/gprpp/ref_counted.h @@ -73,7 +73,8 @@ class RefCounted { private: // Allow RefCountedPtr<> to access IncrementRefCount(). - friend class RefCountedPtr<Child>; + template <typename T> + friend class RefCountedPtr; void IncrementRefCount() { gpr_ref(&refs_); } @@ -152,7 +153,8 @@ class RefCountedWithTracing { private: // Allow RefCountedPtr<> to access IncrementRefCount(). - friend class RefCountedPtr<Child>; + template <typename T> + friend class RefCountedPtr; void IncrementRefCount() { gpr_ref(&refs_); } diff --git a/src/core/lib/gprpp/ref_counted_ptr.h b/src/core/lib/gprpp/ref_counted_ptr.h index 534d3d03cb..c2dfbdd90f 100644 --- a/src/core/lib/gprpp/ref_counted_ptr.h +++ b/src/core/lib/gprpp/ref_counted_ptr.h @@ -36,25 +36,49 @@ class RefCountedPtr { RefCountedPtr(std::nullptr_t) {} // If value is non-null, we take ownership of a ref to it. - explicit RefCountedPtr(T* value) { value_ = value; } + template <typename Y> + explicit RefCountedPtr(Y* value) { + value_ = value; + } - // Move support. + // Move ctors. RefCountedPtr(RefCountedPtr&& other) { value_ = other.value_; other.value_ = nullptr; } + template <typename Y> + RefCountedPtr(RefCountedPtr<Y>&& other) { + value_ = other.value_; + other.value_ = nullptr; + } + + // Move assignment. RefCountedPtr& operator=(RefCountedPtr&& other) { if (value_ != nullptr) value_->Unref(); value_ = other.value_; other.value_ = nullptr; return *this; } + template <typename Y> + RefCountedPtr& operator=(RefCountedPtr<Y>&& other) { + if (value_ != nullptr) value_->Unref(); + value_ = other.value_; + other.value_ = nullptr; + return *this; + } - // Copy support. + // Copy ctors. RefCountedPtr(const RefCountedPtr& other) { if (other.value_ != nullptr) other.value_->IncrementRefCount(); value_ = other.value_; } + template <typename Y> + RefCountedPtr(const RefCountedPtr<Y>& other) { + if (other.value_ != nullptr) other.value_->IncrementRefCount(); + value_ = other.value_; + } + + // Copy assignment. RefCountedPtr& operator=(const RefCountedPtr& other) { // Note: Order of reffing and unreffing is important here in case value_ // and other.value_ are the same object. @@ -63,17 +87,32 @@ class RefCountedPtr { value_ = other.value_; return *this; } + template <typename Y> + RefCountedPtr& operator=(const RefCountedPtr<Y>& other) { + // Note: Order of reffing and unreffing is important here in case value_ + // and other.value_ are the same object. + if (other.value_ != nullptr) other.value_->IncrementRefCount(); + if (value_ != nullptr) value_->Unref(); + value_ = other.value_; + return *this; + } ~RefCountedPtr() { if (value_ != nullptr) value_->Unref(); } // If value is non-null, we take ownership of a ref to it. - void reset(T* value = nullptr) { + template <typename Y> + void reset(Y* value) { if (value_ != nullptr) value_->Unref(); value_ = value; } + void reset() { + if (value_ != nullptr) value_->Unref(); + value_ = nullptr; + } + // TODO(roth): This method exists solely as a transition mechanism to allow // us to pass a ref to idiomatic C code that does not use RefCountedPtr<>. // Once all of our code has been converted to idiomatic C++, this @@ -89,16 +128,34 @@ class RefCountedPtr { T& operator*() const { return *value_; } T* operator->() const { return value_; } - bool operator==(const RefCountedPtr& other) const { + template <typename Y> + bool operator==(const RefCountedPtr<Y>& other) const { return value_ == other.value_; } - bool operator==(const T* other) const { return value_ == other; } - bool operator!=(const RefCountedPtr& other) const { + + template <typename Y> + bool operator==(const Y* other) const { + return value_ == other; + } + + bool operator==(std::nullptr_t) const { return value_ == nullptr; } + + template <typename Y> + bool operator!=(const RefCountedPtr<Y>& other) const { return value_ != other.value_; } - bool operator!=(const T* other) const { return value_ != other; } + + template <typename Y> + bool operator!=(const Y* other) const { + return value_ != other; + } + + bool operator!=(std::nullptr_t) const { return value_ != nullptr; } private: + template <typename Y> + friend class RefCountedPtr; + T* value_ = nullptr; }; @@ -107,11 +164,6 @@ inline RefCountedPtr<T> MakeRefCounted(Args&&... args) { return RefCountedPtr<T>(New<T>(std::forward<Args>(args)...)); } -template <typename Parent, typename Child, typename... Args> -inline RefCountedPtr<Parent> MakePolymorphicRefCounted(Args&&... args) { - return RefCountedPtr<Parent>(New<Child>(std::forward<Args>(args)...)); -} - } // namespace grpc_core #endif /* GRPC_CORE_LIB_GPRPP_REF_COUNTED_PTR_H */ diff --git a/src/core/lib/iomgr/ev_epoll1_linux.cc b/src/core/lib/iomgr/ev_epoll1_linux.cc index 86a0243d2e..ecb7eadf85 100644 --- a/src/core/lib/iomgr/ev_epoll1_linux.cc +++ b/src/core/lib/iomgr/ev_epoll1_linux.cc @@ -140,10 +140,6 @@ struct grpc_fd { struct grpc_fd* freelist_next; - /* The pollset that last noticed that the fd is readable. The actual type - * stored in this is (grpc_pollset *) */ - gpr_atm read_notifier_pollset; - grpc_iomgr_object iomgr_object; }; @@ -293,7 +289,6 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) { new_fd->read_closure->InitEvent(); new_fd->write_closure->InitEvent(); new_fd->error_closure->InitEvent(); - gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL); new_fd->freelist_next = nullptr; @@ -376,11 +371,6 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, gpr_mu_unlock(&fd_freelist_mu); } -static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { - gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset); - return (grpc_pollset*)notifier; -} - static bool fd_is_shutdown(grpc_fd* fd) { return fd->read_closure->IsShutdown(); } @@ -397,11 +387,7 @@ static void fd_notify_on_error(grpc_fd* fd, grpc_closure* closure) { fd->error_closure->NotifyOn(closure); } -static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { - fd->read_closure->SetReady(); - /* Use release store to match with acquire load in fd_get_read_notifier */ - gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier); -} +static void fd_become_readable(grpc_fd* fd) { fd->read_closure->SetReady(); } static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); } @@ -642,7 +628,7 @@ static grpc_error* process_epoll_events(grpc_pollset* pollset) { } if (read_ev || cancel || err_fallback) { - fd_become_readable(fd, pollset); + fd_become_readable(fd); } if (write_ev || cancel || err_fallback) { @@ -1218,7 +1204,6 @@ static const grpc_event_engine_vtable vtable = { fd_notify_on_write, fd_notify_on_error, fd_is_shutdown, - fd_get_read_notifier_pollset, pollset_init, pollset_shutdown, diff --git a/src/core/lib/iomgr/ev_epollex_linux.cc b/src/core/lib/iomgr/ev_epollex_linux.cc index e1f3e43af7..6ec8267799 100644 --- a/src/core/lib/iomgr/ev_epollex_linux.cc +++ b/src/core/lib/iomgr/ev_epollex_linux.cc @@ -220,10 +220,6 @@ struct grpc_fd { struct grpc_fd* freelist_next; grpc_closure* on_done_closure; - // The pollset that last noticed that the fd is readable. The actual type - // stored in this is (grpc_pollset *) - gpr_atm read_notifier_pollset; - grpc_iomgr_object iomgr_object; // Do we need to track EPOLLERR events separately? @@ -353,7 +349,6 @@ static void invalidate_fd(grpc_fd* fd) { memset(&fd->pollable_mu, -1, sizeof(fd->pollable_mu)); fd->pollable_obj = nullptr; fd->on_done_closure = nullptr; - gpr_atm_no_barrier_store(&fd->read_notifier_pollset, 0); memset(&fd->iomgr_object, -1, sizeof(fd->iomgr_object)); fd->track_err = false; } @@ -445,7 +440,6 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) { new_fd->error_closure->InitEvent(); new_fd->freelist_next = nullptr; new_fd->on_done_closure = nullptr; - gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL); char* fd_name; gpr_asprintf(&fd_name, "%s fd=%d", name, fd); @@ -514,11 +508,6 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, UNREF_BY(fd, 2, reason); /* Drop the reference */ } -static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { - gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset); - return (grpc_pollset*)notifier; -} - static bool fd_is_shutdown(grpc_fd* fd) { return fd->read_closure->IsShutdown(); } @@ -875,17 +864,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) { return static_cast<int>(delta); } -static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { - fd->read_closure->SetReady(); - - /* Note, it is possible that fd_become_readable might be called twice with - different 'notifier's when an fd becomes readable and it is in two epoll - sets (This can happen briefly during polling island merges). In such cases - it does not really matter which notifer is set as the read_notifier_pollset - (They would both point to the same polling island anyway) */ - /* Use release store to match with acquire load in fd_get_read_notifier */ - gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier); -} +static void fd_become_readable(grpc_fd* fd) { fd->read_closure->SetReady(); } static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); } @@ -983,7 +962,7 @@ static grpc_error* pollable_process_events(grpc_pollset* pollset, fd_has_errors(fd); } if (read_ev || cancel || err_fallback) { - fd_become_readable(fd, pollset); + fd_become_readable(fd); } if (write_ev || cancel || err_fallback) { fd_become_writable(fd); @@ -1637,7 +1616,6 @@ static const grpc_event_engine_vtable vtable = { fd_notify_on_write, fd_notify_on_error, fd_is_shutdown, - fd_get_read_notifier_pollset, pollset_init, pollset_shutdown, diff --git a/src/core/lib/iomgr/ev_epollsig_linux.cc b/src/core/lib/iomgr/ev_epollsig_linux.cc index 2189801c18..28656b0666 100644 --- a/src/core/lib/iomgr/ev_epollsig_linux.cc +++ b/src/core/lib/iomgr/ev_epollsig_linux.cc @@ -137,10 +137,6 @@ struct grpc_fd { struct grpc_fd* freelist_next; grpc_closure* on_done_closure; - /* The pollset that last noticed that the fd is readable. The actual type - * stored in this is (grpc_pollset *) */ - gpr_atm read_notifier_pollset; - grpc_iomgr_object iomgr_object; /* Do we need to track EPOLLERR events separately? */ @@ -845,7 +841,6 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) { new_fd->write_closure->InitEvent(); new_fd->error_closure->InitEvent(); new_fd->track_err = track_err; - gpr_atm_no_barrier_store(&new_fd->read_notifier_pollset, (gpr_atm)NULL); new_fd->freelist_next = nullptr; new_fd->on_done_closure = nullptr; @@ -927,11 +922,6 @@ static void fd_orphan(grpc_fd* fd, grpc_closure* on_done, int* release_fd, GRPC_ERROR_UNREF(error); } -static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { - gpr_atm notifier = gpr_atm_acq_load(&fd->read_notifier_pollset); - return (grpc_pollset*)notifier; -} - static bool fd_is_shutdown(grpc_fd* fd) { return fd->read_closure->IsShutdown(); } @@ -1115,17 +1105,7 @@ static int poll_deadline_to_millis_timeout(grpc_millis millis) { return static_cast<int>(delta); } -static void fd_become_readable(grpc_fd* fd, grpc_pollset* notifier) { - fd->read_closure->SetReady(); - - /* Note, it is possible that fd_become_readable might be called twice with - different 'notifier's when an fd becomes readable and it is in two epoll - sets (This can happen briefly during polling island merges). In such cases - it does not really matter which notifer is set as the read_notifier_pollset - (They would both point to the same polling island anyway) */ - /* Use release store to match with acquire load in fd_get_read_notifier */ - gpr_atm_rel_store(&fd->read_notifier_pollset, (gpr_atm)notifier); -} +static void fd_become_readable(grpc_fd* fd) { fd->read_closure->SetReady(); } static void fd_become_writable(grpc_fd* fd) { fd->write_closure->SetReady(); } @@ -1283,7 +1263,7 @@ static void pollset_work_and_unlock(grpc_pollset* pollset, fd_has_errors(fd); } if (read_ev || cancel || err_fallback) { - fd_become_readable(fd, pollset); + fd_become_readable(fd); } if (write_ev || cancel || err_fallback) { fd_become_writable(fd); @@ -1668,7 +1648,6 @@ static const grpc_event_engine_vtable vtable = { fd_notify_on_write, fd_notify_on_error, fd_is_shutdown, - fd_get_read_notifier_pollset, pollset_init, pollset_shutdown, diff --git a/src/core/lib/iomgr/ev_poll_posix.cc b/src/core/lib/iomgr/ev_poll_posix.cc index c9c09881a2..a4a83c4ad7 100644 --- a/src/core/lib/iomgr/ev_poll_posix.cc +++ b/src/core/lib/iomgr/ev_poll_posix.cc @@ -108,9 +108,6 @@ struct grpc_fd { grpc_closure* on_done_closure; grpc_iomgr_object iomgr_object; - - /* The pollset that last noticed and notified that the fd is readable */ - grpc_pollset* read_notifier_pollset; }; /* Begin polling on an fd. @@ -131,8 +128,7 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, MUST NOT be called with a pollset lock taken if got_read or got_write are 1, also does the become_{readable,writable} as appropriate. */ -static void fd_end_poll(grpc_fd_watcher* rec, int got_read, int got_write, - grpc_pollset* read_notifier_pollset); +static void fd_end_poll(grpc_fd_watcher* rec, int got_read, int got_write); /* Return 1 if this fd is orphaned, 0 otherwise */ static bool fd_is_orphaned(grpc_fd* fd); @@ -346,7 +342,6 @@ static grpc_fd* fd_create(int fd, const char* name, bool track_err) { r->closed = 0; r->released = 0; gpr_atm_no_barrier_store(&r->pollhup, 0); - r->read_notifier_pollset = nullptr; char* name2; gpr_asprintf(&name2, "%s fd=%d", name, fd); @@ -359,17 +354,6 @@ static bool fd_is_orphaned(grpc_fd* fd) { return (gpr_atm_acq_load(&fd->refst) & 1) == 0; } -/* Return the read-notifier pollset */ -static grpc_pollset* fd_get_read_notifier_pollset(grpc_fd* fd) { - grpc_pollset* notifier = nullptr; - - gpr_mu_lock(&fd->mu); - notifier = fd->read_notifier_pollset; - gpr_mu_unlock(&fd->mu); - - return notifier; -} - static grpc_error* pollset_kick_locked(grpc_fd_watcher* watcher) { gpr_mu_lock(&watcher->pollset->mu); GPR_ASSERT(watcher->worker); @@ -512,11 +496,6 @@ static int set_ready_locked(grpc_fd* fd, grpc_closure** st) { } } -static void set_read_notifier_pollset_locked( - grpc_fd* fd, grpc_pollset* read_notifier_pollset) { - fd->read_notifier_pollset = read_notifier_pollset; -} - static void fd_shutdown(grpc_fd* fd, grpc_error* why) { gpr_mu_lock(&fd->mu); /* only shutdown once */ @@ -553,8 +532,10 @@ static void fd_notify_on_write(grpc_fd* fd, grpc_closure* closure) { } static void fd_notify_on_error(grpc_fd* fd, grpc_closure* closure) { - gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); - abort(); + if (grpc_polling_trace.enabled()) { + gpr_log(GPR_ERROR, "Polling engine does not support tracking errors."); + } + GRPC_CLOSURE_SCHED(closure, GRPC_ERROR_CANCELLED); } static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, @@ -608,8 +589,7 @@ static uint32_t fd_begin_poll(grpc_fd* fd, grpc_pollset* pollset, return mask; } -static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write, - grpc_pollset* read_notifier_pollset) { +static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write) { int was_polling = 0; int kick = 0; grpc_fd* fd = watcher->fd; @@ -645,9 +625,6 @@ static void fd_end_poll(grpc_fd_watcher* watcher, int got_read, int got_write, if (set_ready_locked(fd, &fd->read_closure)) { kick = 1; } - if (read_notifier_pollset != nullptr) { - set_read_notifier_pollset_locked(fd, read_notifier_pollset); - } } if (got_write) { if (set_ready_locked(fd, &fd->write_closure)) { @@ -997,16 +974,16 @@ static grpc_error* pollset_work(grpc_pollset* pollset, for (i = 1; i < pfd_count; i++) { if (watchers[i].fd == nullptr) { - fd_end_poll(&watchers[i], 0, 0, nullptr); + fd_end_poll(&watchers[i], 0, 0); } else { // Wake up all the file descriptors, if we have an invalid one // we can identify it on the next pollset_work() - fd_end_poll(&watchers[i], 1, 1, pollset); + fd_end_poll(&watchers[i], 1, 1); } } } else if (r == 0) { for (i = 1; i < pfd_count; i++) { - fd_end_poll(&watchers[i], 0, 0, nullptr); + fd_end_poll(&watchers[i], 0, 0); } } else { if (pfds[0].revents & POLLIN_CHECK) { @@ -1018,7 +995,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, } for (i = 1; i < pfd_count; i++) { if (watchers[i].fd == nullptr) { - fd_end_poll(&watchers[i], 0, 0, nullptr); + fd_end_poll(&watchers[i], 0, 0); } else { if (grpc_polling_trace.enabled()) { gpr_log(GPR_INFO, "%p got_event: %d r:%d w:%d [%d]", pollset, @@ -1032,7 +1009,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset, gpr_atm_no_barrier_store(&watchers[i].fd->pollhup, 1); } fd_end_poll(&watchers[i], pfds[i].revents & POLLIN_CHECK, - pfds[i].revents & POLLOUT_CHECK, pollset); + pfds[i].revents & POLLOUT_CHECK); } } } @@ -1724,7 +1701,6 @@ static const grpc_event_engine_vtable vtable = { fd_notify_on_write, fd_notify_on_error, fd_is_shutdown, - fd_get_read_notifier_pollset, pollset_init, pollset_shutdown, diff --git a/src/core/lib/iomgr/ev_posix.h b/src/core/lib/iomgr/ev_posix.h index b4c17fc80d..393c3dd05e 100644 --- a/src/core/lib/iomgr/ev_posix.h +++ b/src/core/lib/iomgr/ev_posix.h @@ -52,7 +52,6 @@ typedef struct grpc_event_engine_vtable { void (*fd_notify_on_write)(grpc_fd* fd, grpc_closure* closure); void (*fd_notify_on_error)(grpc_fd* fd, grpc_closure* closure); bool (*fd_is_shutdown)(grpc_fd* fd); - grpc_pollset* (*fd_get_read_notifier_pollset)(grpc_fd* fd); void (*pollset_init)(grpc_pollset* pollset, gpr_mu** mu); void (*pollset_shutdown)(grpc_pollset* pollset, grpc_closure* closure); @@ -142,9 +141,6 @@ void grpc_fd_notify_on_write(grpc_fd* fd, grpc_closure* closure); * needs to have been set on grpc_fd_create */ void grpc_fd_notify_on_error(grpc_fd* fd, grpc_closure* closure); -/* Return the read notifier pollset from the fd */ -grpc_pollset* grpc_fd_get_read_notifier_pollset(grpc_fd* fd); - /* pollset_posix functions */ /* Add an fd to a pollset */ diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 847bb87f7e..dbad5ded4d 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -529,6 +529,7 @@ void grpc_call_internal_unref(grpc_call* c REF_ARG) { static void release_call(void* call, grpc_error* error) { grpc_call* c = static_cast<grpc_call*>(call); grpc_channel* channel = c->channel; + gpr_free(static_cast<void*>(const_cast<char*>(c->final_info.error_string))); grpc_call_combiner_destroy(&c->call_combiner); grpc_channel_update_call_size_estimate(channel, gpr_arena_destroy(c->arena)); GRPC_CHANNEL_INTERNAL_UNREF(channel, "call"); @@ -573,7 +574,6 @@ static void destroy_call(void* call, grpc_error* error) { grpc_call_stack_destroy(CALL_STACK_FROM_CALL(c), &c->final_info, GRPC_CLOSURE_INIT(&c->release_call, release_call, c, grpc_schedule_on_exec_ctx)); - gpr_free(static_cast<void*>(const_cast<char*>(c->final_info.error_string))); } void grpc_call_ref(grpc_call* c) { gpr_ref(&c->ext_ref); } diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index bdb6359632..e48fbeb86d 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -107,6 +107,13 @@ std::shared_ptr<ChannelCredentials> AltsCredentials( return WrapChannelCredentials(c_creds); } +// Builds Local Credentials +std::shared_ptr<ChannelCredentials> LocalCredentials( + grpc_local_connect_type type) { + GrpcLibraryCodegen init; // To call grpc_init(). + return WrapChannelCredentials(grpc_local_credentials_create(type)); +} + } // namespace experimental // Builds credentials for use when running in GCE diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index a5af25751a..536bf022dd 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -139,5 +139,11 @@ std::shared_ptr<ServerCredentials> AltsServerCredentials( new SecureServerCredentials(c_creds)); } +std::shared_ptr<ServerCredentials> LocalServerCredentials( + grpc_local_connect_type type) { + return std::shared_ptr<ServerCredentials>( + new SecureServerCredentials(grpc_local_server_credentials_create(type))); +} + } // namespace experimental } // namespace grpc diff --git a/src/objective-c/tests/build_one_example.sh b/src/objective-c/tests/build_one_example.sh index 1eace541e6..084147f1d4 100755 --- a/src/objective-c/tests/build_one_example.sh +++ b/src/objective-c/tests/build_one_example.sh @@ -43,7 +43,7 @@ xcodebuild \ -workspace *.xcworkspace \ -scheme $SCHEME \ -destination generic/platform=iOS \ - -derivedDataPath Build \ + -derivedDataPath Build/Build \ CODE_SIGN_IDENTITY="" \ CODE_SIGNING_REQUIRED=NO \ | egrep -v "$XCODEBUILD_FILTER" \ diff --git a/test/core/channel/channel_trace_test.cc b/test/core/channel/channel_trace_test.cc index 99d9a4847f..f224457a55 100644 --- a/test/core/channel/channel_trace_test.cc +++ b/test/core/channel/channel_trace_test.cc @@ -187,8 +187,8 @@ TEST_P(ChannelTracerTest, ComplexTest) { AddSimpleTrace(&tracer); AddSimpleTrace(&tracer); AddSimpleTrace(&tracer); - sc1.reset(nullptr); - sc2.reset(nullptr); + sc1.reset(); + sc2.reset(); } // Test a case in which the parent channel has subchannels and the subchannels @@ -234,9 +234,9 @@ TEST_P(ChannelTracerTest, TestNesting) { grpc_slice_from_static_string("subchannel one inactive"), sc1); AddSimpleTrace(&tracer); ValidateChannelTrace(&tracer, 8, GetParam()); - sc1.reset(nullptr); - sc2.reset(nullptr); - conn1.reset(nullptr); + sc1.reset(); + sc2.reset(); + conn1.reset(); } INSTANTIATE_TEST_CASE_P(ChannelTracerTestSweep, ChannelTracerTest, diff --git a/test/core/gprpp/ref_counted_ptr_test.cc b/test/core/gprpp/ref_counted_ptr_test.cc index aa30b72282..463b5e8966 100644 --- a/test/core/gprpp/ref_counted_ptr_test.cc +++ b/test/core/gprpp/ref_counted_ptr_test.cc @@ -127,7 +127,7 @@ TEST(RefCountedPtr, ResetFromNonNullToNull) { TEST(RefCountedPtr, ResetFromNullToNull) { RefCountedPtr<Foo> foo; EXPECT_EQ(nullptr, foo.get()); - foo.reset(nullptr); + foo.reset(); EXPECT_EQ(nullptr, foo.get()); } @@ -175,6 +175,67 @@ TEST(RefCountedPtr, RefCountedWithTracing) { foo->Unref(DEBUG_LOCATION, "foo"); } +class BaseClass : public RefCounted<BaseClass> { + public: + BaseClass() {} +}; + +class Subclass : public BaseClass { + public: + Subclass() {} +}; + +TEST(RefCountedPtr, ConstructFromSubclass) { + RefCountedPtr<BaseClass> p(New<Subclass>()); +} + +TEST(RefCountedPtr, CopyAssignFromSubclass) { + RefCountedPtr<BaseClass> b; + EXPECT_EQ(nullptr, b.get()); + RefCountedPtr<Subclass> s = MakeRefCounted<Subclass>(); + b = s; + EXPECT_NE(nullptr, b.get()); +} + +TEST(RefCountedPtr, MoveAssignFromSubclass) { + RefCountedPtr<BaseClass> b; + EXPECT_EQ(nullptr, b.get()); + RefCountedPtr<Subclass> s = MakeRefCounted<Subclass>(); + b = std::move(s); + EXPECT_NE(nullptr, b.get()); +} + +TEST(RefCountedPtr, ResetFromSubclass) { + RefCountedPtr<BaseClass> b; + EXPECT_EQ(nullptr, b.get()); + b.reset(New<Subclass>()); + EXPECT_NE(nullptr, b.get()); +} + +TEST(RefCountedPtr, EqualityWithSubclass) { + Subclass* s = New<Subclass>(); + RefCountedPtr<BaseClass> b(s); + EXPECT_EQ(b, s); +} + +void FunctionTakingBaseClass(RefCountedPtr<BaseClass> p) { + p.reset(); // To appease clang-tidy. +} + +TEST(RefCountedPtr, CanPassSubclassToFunctionExpectingBaseClass) { + RefCountedPtr<Subclass> p = MakeRefCounted<Subclass>(); + FunctionTakingBaseClass(p); +} + +void FunctionTakingSubclass(RefCountedPtr<Subclass> p) { + p.reset(); // To appease clang-tidy. +} + +TEST(RefCountedPtr, CanPassSubclassToFunctionExpectingSubclass) { + RefCountedPtr<Subclass> p = MakeRefCounted<Subclass>(); + FunctionTakingSubclass(p); +} + } // namespace } // namespace testing } // namespace grpc_core diff --git a/third_party/BUILD b/third_party/BUILD index f06c5e9c67..5ec919dc48 100644 --- a/third_party/BUILD +++ b/third_party/BUILD @@ -8,4 +8,5 @@ exports_files([ "incremental.BUILD", "zope_interface.BUILD", "constantly.BUILD", + "cython.BUILD", ]) diff --git a/third_party/cython.BUILD b/third_party/cython.BUILD new file mode 100644 index 0000000000..ce9283e2a4 --- /dev/null +++ b/third_party/cython.BUILD @@ -0,0 +1,29 @@ +# Adapted with modifications from tensorflow/third_party/cython.BUILD + +py_library( + name="cython_lib", + srcs=glob( + ["Cython/**/*.py"], + exclude=[ + "**/Tests/*.py", + ], + ) + ["cython.py"], + data=glob([ + "Cython/**/*.pyx", + "Cython/Utility/*.*", + "Cython/Includes/**/*.pxd", + ]), + srcs_version="PY2AND3", + visibility=["//visibility:public"], +) + +# May not be named "cython", since that conflicts with Cython/ on OSX +py_binary( + name="cython_binary", + srcs=["cython.py"], + main="cython.py", + srcs_version="PY2AND3", + visibility=["//visibility:public"], + deps=["cython_lib"], +) + diff --git a/third_party/py/BUILD b/third_party/py/BUILD new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/third_party/py/BUILD diff --git a/third_party/py/BUILD.tpl b/third_party/py/BUILD.tpl new file mode 100644 index 0000000000..2283c573bc --- /dev/null +++ b/third_party/py/BUILD.tpl @@ -0,0 +1,36 @@ +# Adapted with modifications from tensorflow/third_party/py/ + +package(default_visibility=["//visibility:public"]) + +# To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib +# See https://docs.python.org/3/extending/windows.html +cc_import( + name="python_lib", + interface_library=select({ + ":windows": ":python_import_lib", + # A placeholder for Unix platforms which makes --no_build happy. + "//conditions:default": "not-existing.lib", + }), + system_provided=1, +) + +cc_library( + name="python_headers", + hdrs=[":python_include"], + deps=select({ + ":windows": [":python_lib"], + "//conditions:default": [], + }), + includes=["python_include"], +) + +config_setting( + name="windows", + values={"cpu": "x64_windows"}, + visibility=["//visibility:public"], +) + +%{PYTHON_INCLUDE_GENRULE} +%{PYTHON_IMPORT_LIB_GENRULE} + + diff --git a/third_party/py/python_configure.bzl b/third_party/py/python_configure.bzl new file mode 100644 index 0000000000..2ba1e07049 --- /dev/null +++ b/third_party/py/python_configure.bzl @@ -0,0 +1,305 @@ +# Adapted with modifications from tensorflow/third_party/py/ +"""Repository rule for Python autoconfiguration. + +`python_configure` depends on the following environment variables: + + * `PYTHON_BIN_PATH`: location of python binary. + * `PYTHON_LIB_PATH`: Location of python libraries. +""" + +_BAZEL_SH = "BAZEL_SH" +_PYTHON_BIN_PATH = "PYTHON_BIN_PATH" +_PYTHON_LIB_PATH = "PYTHON_LIB_PATH" +_PYTHON_CONFIG_REPO = "PYTHON_CONFIG_REPO" + + +def _tpl(repository_ctx, tpl, substitutions={}, out=None): + if not out: + out = tpl + repository_ctx.template(out, Label("//third_party/py:%s.tpl" % tpl), + substitutions) + + +def _fail(msg): + """Output failure message when auto configuration fails.""" + red = "\033[0;31m" + no_color = "\033[0m" + fail("%sPython Configuration Error:%s %s\n" % (red, no_color, msg)) + + +def _is_windows(repository_ctx): + """Returns true if the host operating system is windows.""" + os_name = repository_ctx.os.name.lower() + return os_name.find("windows") != -1 + + +def _execute(repository_ctx, + cmdline, + error_msg=None, + error_details=None, + empty_stdout_fine=False): + """Executes an arbitrary shell command. + + Args: + repository_ctx: the repository_ctx object + cmdline: list of strings, the command to execute + error_msg: string, a summary of the error if the command fails + error_details: string, details about the error or steps to fix it + empty_stdout_fine: bool, if True, an empty stdout result is fine, otherwise + it's an error + Return: + the result of repository_ctx.execute(cmdline) + """ + result = repository_ctx.execute(cmdline) + if result.stderr or not (empty_stdout_fine or result.stdout): + _fail("\n".join([ + error_msg.strip() if error_msg else "Repository command failed", + result.stderr.strip(), error_details if error_details else "" + ])) + else: + return result + + +def _read_dir(repository_ctx, src_dir): + """Returns a string with all files in a directory. + + Finds all files inside a directory, traversing subfolders and following + symlinks. The returned string contains the full path of all files + separated by line breaks. + """ + if _is_windows(repository_ctx): + src_dir = src_dir.replace("/", "\\") + find_result = _execute( + repository_ctx, + ["cmd.exe", "/c", "dir", src_dir, "/b", "/s", "/a-d"], + empty_stdout_fine=True) + # src_files will be used in genrule.outs where the paths must + # use forward slashes. + return find_result.stdout.replace("\\", "/") + else: + find_result = _execute( + repository_ctx, ["find", src_dir, "-follow", "-type", "f"], + empty_stdout_fine=True) + return find_result.stdout + + +def _genrule(src_dir, genrule_name, command, outs): + """Returns a string with a genrule. + + Genrule executes the given command and produces the given outputs. + """ + return ('genrule(\n' + ' name = "' + genrule_name + '",\n' + + ' outs = [\n' + outs + '\n ],\n' + ' cmd = """\n' + + command + '\n """,\n' + ')\n') + + +def _normalize_path(path): + """Returns a path with '/' and remove the trailing slash.""" + path = path.replace("\\", "/") + if path[-1] == "/": + path = path[:-1] + return path + + +def _symlink_genrule_for_dir(repository_ctx, + src_dir, + dest_dir, + genrule_name, + src_files=[], + dest_files=[]): + """Returns a genrule to symlink(or copy if on Windows) a set of files. + + If src_dir is passed, files will be read from the given directory; otherwise + we assume files are in src_files and dest_files + """ + if src_dir != None: + src_dir = _normalize_path(src_dir) + dest_dir = _normalize_path(dest_dir) + files = '\n'.join( + sorted(_read_dir(repository_ctx, src_dir).splitlines())) + # Create a list with the src_dir stripped to use for outputs. + dest_files = files.replace(src_dir, '').splitlines() + src_files = files.splitlines() + command = [] + outs = [] + for i in range(len(dest_files)): + if dest_files[i] != "": + # If we have only one file to link we do not want to use the dest_dir, as + # $(@D) will include the full path to the file. + dest = '$(@D)/' + dest_dir + dest_files[i] if len( + dest_files) != 1 else '$(@D)/' + dest_files[i] + # On Windows, symlink is not supported, so we just copy all the files. + cmd = 'cp -f' if _is_windows(repository_ctx) else 'ln -s' + command.append(cmd + ' "%s" "%s"' % (src_files[i], dest)) + outs.append(' "' + dest_dir + dest_files[i] + '",') + return _genrule(src_dir, genrule_name, " && ".join(command), + "\n".join(outs)) + + +def _get_python_bin(repository_ctx): + """Gets the python bin path.""" + python_bin = repository_ctx.os.environ.get(_PYTHON_BIN_PATH) + if python_bin != None: + return python_bin + python_bin_path = repository_ctx.which("python") + if python_bin_path != None: + return str(python_bin_path) + _fail("Cannot find python in PATH, please make sure " + + "python is installed and add its directory in PATH, or --define " + + "%s='/something/else'.\nPATH=%s" % + (_PYTHON_BIN_PATH, repository_ctx.os.environ.get("PATH", ""))) + + +def _get_bash_bin(repository_ctx): + """Gets the bash bin path.""" + bash_bin = repository_ctx.os.environ.get(_BAZEL_SH) + if bash_bin != None: + return bash_bin + else: + bash_bin_path = repository_ctx.which("bash") + if bash_bin_path != None: + return str(bash_bin_path) + else: + _fail( + "Cannot find bash in PATH, please make sure " + + "bash is installed and add its directory in PATH, or --define " + + "%s='/path/to/bash'.\nPATH=%s" % + (_BAZEL_SH, repository_ctx.os.environ.get("PATH", ""))) + + +def _get_python_lib(repository_ctx, python_bin): + """Gets the python lib path.""" + python_lib = repository_ctx.os.environ.get(_PYTHON_LIB_PATH) + if python_lib != None: + return python_lib + print_lib = ( + "<<END\n" + "from __future__ import print_function\n" + + "import site\n" + "import os\n" + "\n" + "try:\n" + + " input = raw_input\n" + "except NameError:\n" + " pass\n" + "\n" + + "python_paths = []\n" + "if os.getenv('PYTHONPATH') is not None:\n" + + " python_paths = os.getenv('PYTHONPATH').split(':')\n" + "try:\n" + + " library_paths = site.getsitepackages()\n" + + "except AttributeError:\n" + + " from distutils.sysconfig import get_python_lib\n" + + " library_paths = [get_python_lib()]\n" + + "all_paths = set(python_paths + library_paths)\n" + "paths = []\n" + + "for path in all_paths:\n" + " if os.path.isdir(path):\n" + + " paths.append(path)\n" + "if len(paths) >=1:\n" + + " print(paths[0])\n" + "END") + cmd = '%s - %s' % (python_bin, print_lib) + result = repository_ctx.execute([_get_bash_bin(repository_ctx), "-c", cmd]) + return result.stdout.strip('\n') + + +def _check_python_lib(repository_ctx, python_lib): + """Checks the python lib path.""" + cmd = 'test -d "%s" -a -x "%s"' % (python_lib, python_lib) + result = repository_ctx.execute([_get_bash_bin(repository_ctx), "-c", cmd]) + if result.return_code == 1: + _fail("Invalid python library path: %s" % python_lib) + + +def _check_python_bin(repository_ctx, python_bin): + """Checks the python bin path.""" + cmd = '[[ -x "%s" ]] && [[ ! -d "%s" ]]' % (python_bin, python_bin) + result = repository_ctx.execute([_get_bash_bin(repository_ctx), "-c", cmd]) + if result.return_code == 1: + _fail("--define %s='%s' is not executable. Is it the python binary?" % + (_PYTHON_BIN_PATH, python_bin)) + + +def _get_python_include(repository_ctx, python_bin): + """Gets the python include path.""" + result = _execute( + repository_ctx, [ + python_bin, "-c", 'from __future__ import print_function;' + + 'from distutils import sysconfig;' + + 'print(sysconfig.get_python_inc())' + ], + error_msg="Problem getting python include path.", + error_details=( + "Is the Python binary path set up right? " + "(See ./configure or " + + _PYTHON_BIN_PATH + ".) " + "Is distutils installed?")) + return result.stdout.splitlines()[0] + + +def _get_python_import_lib_name(repository_ctx, python_bin): + """Get Python import library name (pythonXY.lib) on Windows.""" + result = _execute( + repository_ctx, [ + python_bin, "-c", + 'import sys;' + 'print("python" + str(sys.version_info[0]) + ' + + ' str(sys.version_info[1]) + ".lib")' + ], + error_msg="Problem getting python import library.", + error_details=("Is the Python binary path set up right? " + + "(See ./configure or " + _PYTHON_BIN_PATH + ".) ")) + return result.stdout.splitlines()[0] + + +def _create_local_python_repository(repository_ctx): + """Creates the repository containing files set up to build with Python.""" + python_bin = _get_python_bin(repository_ctx) + _check_python_bin(repository_ctx, python_bin) + python_lib = _get_python_lib(repository_ctx, python_bin) + _check_python_lib(repository_ctx, python_lib) + python_include = _get_python_include(repository_ctx, python_bin) + python_include_rule = _symlink_genrule_for_dir( + repository_ctx, python_include, 'python_include', 'python_include') + python_import_lib_genrule = "" + # To build Python C/C++ extension on Windows, we need to link to python import library pythonXY.lib + # See https://docs.python.org/3/extending/windows.html + if _is_windows(repository_ctx): + python_include = _normalize_path(python_include) + python_import_lib_name = _get_python_import_lib_name( + repository_ctx, python_bin) + python_import_lib_src = python_include.rsplit( + '/', 1)[0] + "/libs/" + python_import_lib_name + python_import_lib_genrule = _symlink_genrule_for_dir( + repository_ctx, None, '', 'python_import_lib', + [python_import_lib_src], [python_import_lib_name]) + _tpl( + repository_ctx, "BUILD", { + "%{PYTHON_INCLUDE_GENRULE}": python_include_rule, + "%{PYTHON_IMPORT_LIB_GENRULE}": python_import_lib_genrule, + }) + + +def _create_remote_python_repository(repository_ctx, remote_config_repo): + """Creates pointers to a remotely configured repo set up to build with Python. + """ + _tpl(repository_ctx, "remote.BUILD", { + "%{REMOTE_PYTHON_REPO}": remote_config_repo, + }, "BUILD") + + +def _python_autoconf_impl(repository_ctx): + """Implementation of the python_autoconf repository rule.""" + if _PYTHON_CONFIG_REPO in repository_ctx.os.environ: + _create_remote_python_repository( + repository_ctx, repository_ctx.os.environ[_PYTHON_CONFIG_REPO]) + else: + _create_local_python_repository(repository_ctx) + + +python_configure = repository_rule( + implementation=_python_autoconf_impl, + environ=[ + _BAZEL_SH, + _PYTHON_BIN_PATH, + _PYTHON_LIB_PATH, + _PYTHON_CONFIG_REPO, + ], +) +"""Detects and configures the local Python. + +Add the following to your WORKSPACE FILE: + +```python +python_configure(name = "local_config_python") +``` + +Args: + name: A unique name for this workspace rule. +""" + diff --git a/third_party/py/remote.BUILD.tpl b/third_party/py/remote.BUILD.tpl new file mode 100644 index 0000000000..1bfe1f0bf6 --- /dev/null +++ b/third_party/py/remote.BUILD.tpl @@ -0,0 +1,10 @@ +# Adapted with modifications from tensorflow/third_party/py/ + +package(default_visibility=["//visibility:public"]) + +alias( + name="python_headers", + actual="%{REMOTE_PYTHON_REPO}:python_headers", +) + + diff --git a/tools/internal_ci/helper_scripts/prepare_build_macos_rc b/tools/internal_ci/helper_scripts/prepare_build_macos_rc index bc7fff1b14..cbc42f5295 100644 --- a/tools/internal_ci/helper_scripts/prepare_build_macos_rc +++ b/tools/internal_ci/helper_scripts/prepare_build_macos_rc @@ -89,3 +89,7 @@ export DOTNET_CLI_TELEMETRY_OPTOUT=true date git submodule update --init + +# Store intermediate build files of ios binary size test into /tmpfs +mkdir /tmpfs/Build-ios-binary-size +ln -s /tmpfs/Build-ios-binary-size src/objective-c/examples/Sample/Build diff --git a/tools/profiling/ios_bin/binary_size.py b/tools/profiling/ios_bin/binary_size.py index b07adb5734..91c43f4424 100755 --- a/tools/profiling/ios_bin/binary_size.py +++ b/tools/profiling/ios_bin/binary_size.py @@ -55,7 +55,7 @@ def dir_size(dir): def get_size(where, frameworks): - build_dir = 'src/objective-c/examples/Sample/Build-%s/' % where + build_dir = 'src/objective-c/examples/Sample/Build/Build-%s/' % where if not frameworks: link_map_filename = 'Build/Intermediates.noindex/Sample.build/Release-iphoneos/Sample.build/Sample-LinkMap-normal-arm64.txt' return parse_link_map(build_dir + link_map_filename) @@ -76,14 +76,15 @@ def get_size(where, frameworks): def build(where, frameworks): shutil.rmtree( - 'src/objective-c/examples/Sample/Build-%s' % where, ignore_errors=True) + 'src/objective-c/examples/Sample/Build/Build-%s' % where, + ignore_errors=True) subprocess.check_call( 'CONFIG=opt EXAMPLE_PATH=src/objective-c/examples/Sample SCHEME=Sample FRAMEWORKS=%s ./build_one_example.sh' % ('YES' if frameworks else 'NO'), shell=True, cwd='src/objective-c/tests') - os.rename('src/objective-c/examples/Sample/Build', - 'src/objective-c/examples/Sample/Build-%s' % where) + os.rename('src/objective-c/examples/Sample/Build/Build', + 'src/objective-c/examples/Sample/Build/Build-%s' % where) text = 'Objective-C binary sizes\n' |