Skip to content

Commit 41b7247

Browse files
authored
feat(language): generate library (googleapis#8227)
1 parent 4829312 commit 41b7247

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3317
-0
lines changed

BUILD.bazel

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ EXPERIMENTAL_LIBRARIES = [
4949
"ids",
5050
"iot",
5151
"kms",
52+
"language",
5253
"logging",
5354
"managedidentities",
5455
"memcache",

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ releasing them early in case they elicit some feedback that requires changes.
104104

105105
* [Data Catalog](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/datacatalog/README.md)
106106
* [Managed Service for Microsoft Active Directory](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/managedidentities/README.md)
107+
* [Natural Language AI](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/language/README.md)
107108

108109
</details>
109110

ci/etc/expected_install_directories

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@
134134
./include/google/cloud/kms/internal
135135
./include/google/cloud/kms/mocks
136136
./include/google/cloud/kms/v1
137+
./include/google/cloud/language
138+
./include/google/cloud/language/internal
139+
./include/google/cloud/language/mocks
140+
./include/google/cloud/language/v1
137141
./include/google/cloud/logging
138142
./include/google/cloud/logging/internal
139143
./include/google/cloud/logging/mocks
@@ -368,6 +372,7 @@
368372
./lib64/cmake/google_cloud_cpp_ids
369373
./lib64/cmake/google_cloud_cpp_iot
370374
./lib64/cmake/google_cloud_cpp_kms
375+
./lib64/cmake/google_cloud_cpp_language
371376
./lib64/cmake/google_cloud_cpp_logging
372377
./lib64/cmake/google_cloud_cpp_managedidentities
373378
./lib64/cmake/google_cloud_cpp_memcache

ci/etc/full_feature_list

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ iap
2828
ids
2929
iot
3030
kms
31+
language
3132
logging
3233
managedidentities
3334
memcache
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@com_google_googleapis//google/api:annotations_proto
2+
@com_google_googleapis//google/api:client_proto
3+
@com_google_googleapis//google/api:field_behavior_proto
4+
@com_google_googleapis//google/api:http_proto
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@com_google_googleapis//google/cloud/language/v1:language_service.proto

external/googleapis/update_libraries.sh

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ declare -A -r LIBRARIES=(
9292
["ids"]="@com_google_googleapis//google/cloud/ids/v1:ids_cc_grpc"
9393
["iot"]="@com_google_googleapis//google/cloud/iot/v1:iot_cc_grpc"
9494
["kms"]="@com_google_googleapis//google/cloud/kms/v1:kms_cc_grpc"
95+
["language"]="@com_google_googleapis//google/cloud/language/v1:language_cc_grpc"
9596
["logging_type"]="@com_google_googleapis//google/logging/type:type_cc_grpc"
9697
["logging"]="@com_google_googleapis//google/logging/v2:logging_cc_grpc"
9798
["managedidentities"]="@com_google_googleapis//google/cloud/managedidentities/v1:managedidentities_cc_grpc"

generator/generator_config.textproto

+8
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,14 @@ service {
385385
retryable_status_codes: ["kDeadlineExceeded", "kUnavailable"]
386386
}
387387

388+
# Language
389+
service {
390+
service_proto_path: "google/cloud/language/v1/language_service.proto"
391+
product_path: "google/cloud/language"
392+
initial_copyright_year: "2022"
393+
retryable_status_codes: ["kUnavailable"]
394+
}
395+
388396
# Logging
389397
service {
390398
service_proto_path: "google/logging/v2/logging.proto"

google/cloud/language/BUILD.bazel

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
package(default_visibility = ["//visibility:private"])
16+
17+
licenses(["notice"]) # Apache 2.0
18+
19+
SOURCE_GLOB = "**/*.cc"
20+
21+
MOCK_SOURCE_GLOB = "mocks/*.cc"
22+
23+
HEADER_GLOB = "**/*.h"
24+
25+
MOCK_HEADER_GLOB = "mocks/*.h"
26+
27+
cc_library(
28+
name = "google_cloud_cpp_language",
29+
srcs = glob(
30+
include = [SOURCE_GLOB],
31+
exclude = [MOCK_SOURCE_GLOB],
32+
),
33+
hdrs = glob(
34+
include = [HEADER_GLOB],
35+
exclude = [MOCK_HEADER_GLOB],
36+
),
37+
visibility = ["//:__pkg__"],
38+
deps = [
39+
"//google/cloud:google_cloud_cpp_common",
40+
"//google/cloud:google_cloud_cpp_grpc_utils",
41+
"@com_google_googleapis//google/cloud/language/v1:language_cc_grpc",
42+
],
43+
)
44+
45+
cc_library(
46+
name = "google_cloud_cpp_language_mocks",
47+
srcs = glob(
48+
include = [MOCK_SOURCE_GLOB],
49+
),
50+
hdrs = glob(
51+
include = [MOCK_HEADER_GLOB],
52+
),
53+
visibility = ["//:__pkg__"],
54+
deps = [
55+
":google_cloud_cpp_language",
56+
"//google/cloud:google_cloud_cpp_common",
57+
"//google/cloud:google_cloud_cpp_grpc_utils",
58+
],
59+
)

google/cloud/language/CMakeLists.txt

+191
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# ~~~
2+
# Copyright 2022 Google LLC
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+
# https://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+
# ~~~
16+
17+
include(GoogleapisConfig)
18+
set(DOXYGEN_PROJECT_NAME "Cloud Natural Language API C++ Client")
19+
set(DOXYGEN_PROJECT_BRIEF
20+
"A C++ Client Library for the Cloud Natural Language API")
21+
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)")
22+
set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "language_internal" "language_testing"
23+
"examples")
24+
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart)
25+
26+
# Creates the proto headers needed by doxygen.
27+
set(GOOGLE_CLOUD_CPP_DOXYGEN_DEPS google-cloud-cpp::language_protos)
28+
29+
find_package(gRPC REQUIRED)
30+
find_package(ProtobufWithTargets REQUIRED)
31+
find_package(absl CONFIG REQUIRED)
32+
33+
include(GoogleCloudCppCommon)
34+
35+
set(EXTERNAL_GOOGLEAPIS_SOURCE
36+
"${PROJECT_BINARY_DIR}/external/googleapis/src/googleapis_download")
37+
find_path(PROTO_INCLUDE_DIR google/protobuf/descriptor.proto)
38+
if (PROTO_INCLUDE_DIR)
39+
list(INSERT PROTOBUF_IMPORT_DIRS 0 "${PROTO_INCLUDE_DIR}")
40+
endif ()
41+
42+
include(CompileProtos)
43+
google_cloud_cpp_grpcpp_library(
44+
google_cloud_cpp_language_protos
45+
# cmake-format: sort
46+
${EXTERNAL_GOOGLEAPIS_SOURCE}/google/cloud/language/v1/language_service.proto
47+
PROTO_PATH_DIRECTORIES
48+
"${EXTERNAL_GOOGLEAPIS_SOURCE}"
49+
"${PROTO_INCLUDE_DIR}")
50+
external_googleapis_set_version_and_alias(language_protos)
51+
target_link_libraries(
52+
google_cloud_cpp_language_protos
53+
PUBLIC #
54+
google-cloud-cpp::api_annotations_protos
55+
google-cloud-cpp::api_client_protos
56+
google-cloud-cpp::api_field_behavior_protos
57+
google-cloud-cpp::api_http_protos)
58+
59+
file(
60+
GLOB source_files
61+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
62+
"*.h" "*.cc" "internal/*.h" "internal/*.cc")
63+
list(SORT source_files)
64+
add_library(google_cloud_cpp_language ${source_files})
65+
target_include_directories(
66+
google_cloud_cpp_language
67+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
68+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
69+
$<INSTALL_INTERFACE:include>)
70+
target_link_libraries(
71+
google_cloud_cpp_language
72+
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
73+
google-cloud-cpp::language_protos)
74+
google_cloud_cpp_add_common_options(google_cloud_cpp_language)
75+
set_target_properties(
76+
google_cloud_cpp_language
77+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-language
78+
VERSION "${PROJECT_VERSION}" SOVERSION
79+
"${PROJECT_VERSION_MAJOR}")
80+
target_compile_options(google_cloud_cpp_language
81+
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
82+
83+
add_library(google-cloud-cpp::experimental-language ALIAS
84+
google_cloud_cpp_language)
85+
86+
# Create a header-only library for the mocks. We use a CMake `INTERFACE` library
87+
# for these, a regular library would not work on macOS (where the library needs
88+
# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in
89+
# that they need absolute paths for their sources.
90+
file(
91+
GLOB relative_mock_files
92+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
93+
"mocks/*.h")
94+
list(SORT relative_mock_files)
95+
set(mock_files)
96+
foreach (file IN LISTS relative_mock_files)
97+
list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
98+
endforeach ()
99+
add_library(google_cloud_cpp_language_mocks INTERFACE)
100+
target_sources(google_cloud_cpp_language_mocks INTERFACE ${mock_files})
101+
target_link_libraries(
102+
google_cloud_cpp_language_mocks
103+
INTERFACE google-cloud-cpp::experimental-language GTest::gmock_main
104+
GTest::gmock GTest::gtest)
105+
set_target_properties(
106+
google_cloud_cpp_language_mocks
107+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-language_mocks)
108+
target_include_directories(
109+
google_cloud_cpp_language_mocks
110+
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
111+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
112+
$<INSTALL_INTERFACE:include>)
113+
target_compile_options(google_cloud_cpp_language_mocks
114+
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
115+
116+
# Get the destination directories based on the GNU recommendations.
117+
include(GNUInstallDirs)
118+
119+
# Export the CMake targets to make it easy to create configuration files.
120+
install(
121+
EXPORT google_cloud_cpp_language-targets
122+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_language"
123+
COMPONENT google_cloud_cpp_development)
124+
125+
# Install the libraries and headers in the locations determined by
126+
# GNUInstallDirs
127+
install(
128+
TARGETS google_cloud_cpp_language google_cloud_cpp_language_protos
129+
EXPORT google_cloud_cpp_language-targets
130+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
131+
COMPONENT google_cloud_cpp_runtime
132+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
133+
COMPONENT google_cloud_cpp_runtime
134+
NAMELINK_SKIP
135+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
136+
COMPONENT google_cloud_cpp_development)
137+
# With CMake-3.12 and higher we could avoid this separate command (and the
138+
# duplication).
139+
install(
140+
TARGETS google_cloud_cpp_language google_cloud_cpp_language_protos
141+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
142+
COMPONENT google_cloud_cpp_development
143+
NAMELINK_ONLY
144+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
145+
COMPONENT google_cloud_cpp_development)
146+
147+
google_cloud_cpp_install_proto_library_protos("google_cloud_cpp_language_protos"
148+
"${EXTERNAL_GOOGLEAPIS_SOURCE}")
149+
google_cloud_cpp_install_proto_library_headers(
150+
"google_cloud_cpp_language_protos")
151+
google_cloud_cpp_install_headers("google_cloud_cpp_language"
152+
"include/google/cloud/language")
153+
google_cloud_cpp_install_headers("google_cloud_cpp_language_mocks"
154+
"include/google/cloud/language")
155+
156+
# Setup global variables used in the following *.in files.
157+
set(GOOGLE_CLOUD_CONFIG_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
158+
set(GOOGLE_CLOUD_CONFIG_VERSION_MINOR ${PROJECT_VERSION_MINOR})
159+
set(GOOGLE_CLOUD_CONFIG_VERSION_PATCH ${PROJECT_VERSION_PATCH})
160+
set(GOOGLE_CLOUD_PC_NAME "The Cloud Natural Language API C++ Client Library")
161+
set(GOOGLE_CLOUD_PC_DESCRIPTION
162+
"Provides C++ APIs to use the Cloud Natural Language API.")
163+
set(GOOGLE_CLOUD_PC_LIBS "-lgoogle_cloud_cpp_language")
164+
string(CONCAT GOOGLE_CLOUD_PC_REQUIRES "google_cloud_cpp_grpc_utils"
165+
" google_cloud_cpp_common" " google_cloud_cpp_language_protos")
166+
167+
# Create and install the pkg-config files.
168+
configure_file("${PROJECT_SOURCE_DIR}/google/cloud/language/config.pc.in"
169+
"google_cloud_cpp_language.pc" @ONLY)
170+
install(
171+
FILES "${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_language.pc"
172+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
173+
COMPONENT google_cloud_cpp_development)
174+
175+
# Create and install the CMake configuration files.
176+
include(CMakePackageConfigHelpers)
177+
configure_file("config.cmake.in" "google_cloud_cpp_language-config.cmake" @ONLY)
178+
write_basic_package_version_file(
179+
"google_cloud_cpp_language-config-version.cmake"
180+
VERSION ${PROJECT_VERSION}
181+
COMPATIBILITY ExactVersion)
182+
183+
install(
184+
FILES
185+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_language-config.cmake"
186+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_language-config-version.cmake"
187+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_language"
188+
COMPONENT google_cloud_cpp_development)
189+
190+
external_googleapis_install_pc("google_cloud_cpp_language_protos"
191+
"${PROJECT_SOURCE_DIR}/external/googleapis")

0 commit comments

Comments
 (0)