xref: /aosp_15_r20/external/grpc-grpc/src/csharp/build_nuget.sh (revision cc02d7e222339f7a4f6ba5f422e6413f4bd931f2)
1#!/bin/bash
2# Copyright 2020 The gRPC Authors
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16set -ex
17
18cd "$(dirname "$0")"
19
20mkdir -p ../../artifacts
21
22# Collect protoc artifacts built by the previous build step
23mkdir -p protoc_plugins
24cp -r "${EXTERNAL_GIT_ROOT}"/input_artifacts/protoc_* protoc_plugins || true
25
26# Add current timestamp to dev nugets
27./nuget_helpers/expand_dev_version.sh
28
29# For building the nugets we normally need native libraries and binaries
30# built on multiple different platforms (linux, mac, windows), which makes
31# it difficult to support a local build of the nuget.
32# To allow simple local builds (restricted to a single platform),
33# we provide a way of building "partial" nugets that only include artifacts
34# that can be built locally on a given platform (e.g. linux), and
35# contain placeholders (empty files) for artifacts that normally need
36# to be built on a different platform. Because such nugets obviously
37# only work on a single platform (and are broken on other platform),
38# whenever we are building such nugets, we clearly mark them as
39# "singleplatform only" to avoid mixing them up with the full "multiplatform"
40# nugets by accident.
41if [ "${GRPC_CSHARP_BUILD_SINGLE_PLATFORM_NUGET}" != "" ]
42then
43  # create placeholders for artifacts that can't be built
44  # on the current platform.
45  ./nuget_helpers/create_fake_native_artifacts.sh || true
46
47  # add a suffix to the nuget's version
48  # to avoid confusing the package with a full nuget package.
49  # NOTE: adding the suffix must be done AFTER expand_dev_version.sh has run.
50  sed -ibak "s/<\/GrpcCsharpVersion>/-singleplatform<\/GrpcCsharpVersion>/" build/dependencies.props
51fi
52
53dotnet restore Grpc.sln
54
55dotnet pack --configuration Release Grpc.Tools --output ../../artifacts
56
57# Create a zipfile with all the nugets we just created
58cd ../../artifacts
59zip csharp_nugets_windows_dotnetcli.zip *.nupkg
60