Skip to content

Commit b595bc3

Browse files
authored
feat(optimization): generate library (#9002)
1 parent 9a05b0e commit b595bc3

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

+2778
-4
lines changed

BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ exports_files([
2323
EXPERIMENTAL_LIBRARIES = [
2424
# Introduced in 2022-05
2525
"baremetalsolution",
26+
"optimization",
2627
# Introduced in 2022-04
2728
"dataplex",
2829
"dialogflow_cx",

CHANGELOG.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,18 @@ to grant, change, and revoke access to all
130130

131131
### New Libraries
132132

133-
We are introducing a new client library: [Bare Metal Solution]. While we do not
134-
anticipate any API changes to this library before declaring it GA, we are
135-
releasing it early in case it elicits some feedback that requires changes.
133+
We are introducing 2 new client libraries for GCP services. While we do not
134+
anticipate any API changes to these libraries before declaring them GA, we are
135+
releasing them early in case they elicit some feedback that requires changes.
136+
137+
<details>
138+
<summary> Expand to see the full list of new libraries...</summary>
139+
<br>
136140

137-
[Bare Metal Solution]: https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/baremetalsolution/README.md
141+
* [Bare Metal Solution](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/baremetalsolution/README.md)
142+
* [Optimization AI](https://github.com/googleapis/google-cloud-cpp/blob/main/google/cloud/optimization/README.md)
143+
144+
</details>
138145

139146
## v1.40.0 - 2022-05
140147

ci/etc/expected_install_directories

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,10 @@
203203
./include/google/cloud/notebooks/internal
204204
./include/google/cloud/notebooks/mocks
205205
./include/google/cloud/notebooks/v1
206+
./include/google/cloud/optimization
207+
./include/google/cloud/optimization/internal
208+
./include/google/cloud/optimization/mocks
209+
./include/google/cloud/optimization/v1
206210
./include/google/cloud/orchestration
207211
./include/google/cloud/orchestration/airflow
208212
./include/google/cloud/orchestration/airflow/service
@@ -445,6 +449,7 @@
445449
./lib64/cmake/google_cloud_cpp_monitoring
446450
./lib64/cmake/google_cloud_cpp_networkmanagement
447451
./lib64/cmake/google_cloud_cpp_notebooks
452+
./lib64/cmake/google_cloud_cpp_optimization
448453
./lib64/cmake/google_cloud_cpp_orgpolicy
449454
./lib64/cmake/google_cloud_cpp_osconfig
450455
./lib64/cmake/google_cloud_cpp_oslogin

ci/etc/full_feature_list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ memcache
4444
monitoring
4545
networkmanagement
4646
notebooks
47+
optimization
4748
orgpolicy
4849
osconfig
4950
oslogin
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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
5+
@com_google_googleapis//google/longrunning:operations_proto
6+
@com_google_googleapis//google/rpc:status_proto
7+
@com_google_googleapis//google/type:latlng_proto
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
@com_google_googleapis//google/cloud/optimization/v1:async_model.proto
2+
@com_google_googleapis//google/cloud/optimization/v1:fleet_routing.proto

external/googleapis/update_libraries.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ declare -A -r LIBRARIES=(
121121
)"
122122
["networkmanagement"]="@com_google_googleapis//google/cloud/networkmanagement/v1:networkmanagement_cc_grpc"
123123
["notebooks"]="@com_google_googleapis//google/cloud/notebooks/v1:notebooks_cc_grpc"
124+
["optimization"]="@com_google_googleapis//google/cloud/optimization/v1:optimization_cc_grpc"
124125
["orgpolicy"]="@com_google_googleapis//google/cloud/orgpolicy/v2:orgpolicy_cc_grpc"
125126
["osconfig"]="$(
126127
printf ",%s" \

generator/generator_config.textproto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,14 @@ service {
905905
retryable_status_codes: ["kUnavailable"]
906906
}
907907

908+
# Optimization AI
909+
service {
910+
service_proto_path: "google/cloud/optimization/v1/fleet_routing.proto"
911+
product_path: "google/cloud/optimization"
912+
initial_copyright_year: "2022"
913+
retryable_status_codes: ["kUnavailable"]
914+
}
915+
908916
# Organization Policy
909917
service {
910918
service_proto_path: "google/cloud/orgpolicy/v2/orgpolicy.proto"
Lines changed: 59 additions & 0 deletions
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_optimization",
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+
"//:common",
40+
"//:grpc_utils",
41+
"@com_google_googleapis//google/cloud/optimization/v1:optimization_cc_grpc",
42+
],
43+
)
44+
45+
cc_library(
46+
name = "google_cloud_cpp_optimization_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_optimization",
56+
"//:common",
57+
"//:grpc_utils",
58+
],
59+
)
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
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 Optimization API C++ Client")
19+
set(DOXYGEN_PROJECT_BRIEF "A C++ Client Library for the Cloud Optimization API")
20+
set(DOXYGEN_PROJECT_NUMBER "${PROJECT_VERSION} (Experimental)")
21+
set(DOXYGEN_EXCLUDE_SYMBOLS "internal" "optimization_internal"
22+
"optimization_testing" "examples")
23+
set(DOXYGEN_EXAMPLE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/quickstart)
24+
25+
# Creates the proto headers needed by doxygen.
26+
set(GOOGLE_CLOUD_CPP_DOXYGEN_DEPS google-cloud-cpp::optimization_protos)
27+
28+
include(GoogleCloudCppCommon)
29+
30+
set(EXTERNAL_GOOGLEAPIS_SOURCE
31+
"${PROJECT_BINARY_DIR}/external/googleapis/src/googleapis_download")
32+
find_path(PROTO_INCLUDE_DIR google/protobuf/descriptor.proto)
33+
if (PROTO_INCLUDE_DIR)
34+
list(INSERT PROTOBUF_IMPORT_DIRS 0 "${PROTO_INCLUDE_DIR}")
35+
endif ()
36+
37+
include(CompileProtos)
38+
google_cloud_cpp_load_protolist(
39+
proto_list
40+
"${PROJECT_SOURCE_DIR}/external/googleapis/protolists/optimization.list")
41+
google_cloud_cpp_load_protodeps(
42+
proto_deps
43+
"${PROJECT_SOURCE_DIR}/external/googleapis/protodeps/optimization.deps")
44+
google_cloud_cpp_grpcpp_library(
45+
google_cloud_cpp_optimization_protos # cmake-format: sort
46+
${proto_list} PROTO_PATH_DIRECTORIES "${EXTERNAL_GOOGLEAPIS_SOURCE}"
47+
"${PROTO_INCLUDE_DIR}")
48+
external_googleapis_set_version_and_alias(optimization_protos)
49+
target_link_libraries(google_cloud_cpp_optimization_protos PUBLIC ${proto_deps})
50+
51+
file(
52+
GLOB source_files
53+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
54+
"*.h" "*.cc" "internal/*.h" "internal/*.cc")
55+
list(SORT source_files)
56+
add_library(google_cloud_cpp_optimization ${source_files})
57+
target_include_directories(
58+
google_cloud_cpp_optimization
59+
PUBLIC $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
60+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
61+
$<INSTALL_INTERFACE:include>)
62+
target_link_libraries(
63+
google_cloud_cpp_optimization
64+
PUBLIC google-cloud-cpp::grpc_utils google-cloud-cpp::common
65+
google-cloud-cpp::optimization_protos)
66+
google_cloud_cpp_add_common_options(google_cloud_cpp_optimization)
67+
set_target_properties(
68+
google_cloud_cpp_optimization
69+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-optimization
70+
VERSION "${PROJECT_VERSION}"
71+
SOVERSION "${PROJECT_VERSION_MAJOR}")
72+
target_compile_options(google_cloud_cpp_optimization
73+
PUBLIC ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
74+
75+
add_library(google-cloud-cpp::experimental-optimization ALIAS
76+
google_cloud_cpp_optimization)
77+
78+
# Create a header-only library for the mocks. We use a CMake `INTERFACE` library
79+
# for these, a regular library would not work on macOS (where the library needs
80+
# at least one .o file). Unfortunately INTERFACE libraries are a bit weird in
81+
# that they need absolute paths for their sources.
82+
file(
83+
GLOB relative_mock_files
84+
RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}"
85+
"mocks/*.h")
86+
list(SORT relative_mock_files)
87+
set(mock_files)
88+
foreach (file IN LISTS relative_mock_files)
89+
list(APPEND mock_files "${CMAKE_CURRENT_SOURCE_DIR}/${file}")
90+
endforeach ()
91+
add_library(google_cloud_cpp_optimization_mocks INTERFACE)
92+
target_sources(google_cloud_cpp_optimization_mocks INTERFACE ${mock_files})
93+
target_link_libraries(
94+
google_cloud_cpp_optimization_mocks
95+
INTERFACE google-cloud-cpp::experimental-optimization GTest::gmock_main
96+
GTest::gmock GTest::gtest)
97+
set_target_properties(
98+
google_cloud_cpp_optimization_mocks
99+
PROPERTIES EXPORT_NAME google-cloud-cpp::experimental-optimization_mocks)
100+
target_include_directories(
101+
google_cloud_cpp_optimization_mocks
102+
INTERFACE $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}>
103+
$<BUILD_INTERFACE:${PROJECT_BINARY_DIR}>
104+
$<INSTALL_INTERFACE:include>)
105+
target_compile_options(google_cloud_cpp_optimization_mocks
106+
INTERFACE ${GOOGLE_CLOUD_CPP_EXCEPTIONS_FLAG})
107+
108+
include(CTest)
109+
if (BUILD_TESTING)
110+
add_executable(optimization_quickstart "quickstart/quickstart.cc")
111+
target_link_libraries(optimization_quickstart
112+
PRIVATE google-cloud-cpp::experimental-optimization)
113+
google_cloud_cpp_add_common_options(optimization_quickstart)
114+
add_test(
115+
NAME optimization_quickstart
116+
COMMAND
117+
cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake"
118+
$<TARGET_FILE:optimization_quickstart> GOOGLE_CLOUD_PROJECT
119+
GOOGLE_CLOUD_CPP_STORAGE_TEST_BUCKET_NAME)
120+
set_tests_properties(optimization_quickstart
121+
PROPERTIES LABELS "integration-test;quickstart")
122+
endif ()
123+
124+
# Get the destination directories based on the GNU recommendations.
125+
include(GNUInstallDirs)
126+
127+
# Export the CMake targets to make it easy to create configuration files.
128+
install(
129+
EXPORT google_cloud_cpp_optimization-targets
130+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_optimization"
131+
COMPONENT google_cloud_cpp_development)
132+
133+
# Install the libraries and headers in the locations determined by
134+
# GNUInstallDirs
135+
install(
136+
TARGETS google_cloud_cpp_optimization google_cloud_cpp_optimization_protos
137+
EXPORT google_cloud_cpp_optimization-targets
138+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
139+
COMPONENT google_cloud_cpp_runtime
140+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
141+
COMPONENT google_cloud_cpp_runtime
142+
NAMELINK_SKIP
143+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
144+
COMPONENT google_cloud_cpp_development)
145+
# With CMake-3.12 and higher we could avoid this separate command (and the
146+
# duplication).
147+
install(
148+
TARGETS google_cloud_cpp_optimization google_cloud_cpp_optimization_protos
149+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
150+
COMPONENT google_cloud_cpp_development
151+
NAMELINK_ONLY
152+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
153+
COMPONENT google_cloud_cpp_development)
154+
155+
google_cloud_cpp_install_proto_library_protos(
156+
"google_cloud_cpp_optimization_protos" "${EXTERNAL_GOOGLEAPIS_SOURCE}")
157+
google_cloud_cpp_install_proto_library_headers(
158+
"google_cloud_cpp_optimization_protos")
159+
google_cloud_cpp_install_headers("google_cloud_cpp_optimization"
160+
"include/google/cloud/optimization")
161+
google_cloud_cpp_install_headers("google_cloud_cpp_optimization_mocks"
162+
"include/google/cloud/optimization")
163+
164+
google_cloud_cpp_add_pkgconfig(
165+
optimization
166+
"The Cloud Optimization API C++ Client Library"
167+
"Provides C++ APIs to use the Cloud Optimization API."
168+
"google_cloud_cpp_grpc_utils"
169+
" google_cloud_cpp_common"
170+
" google_cloud_cpp_optimization_protos")
171+
172+
# Create and install the CMake configuration files.
173+
include(CMakePackageConfigHelpers)
174+
configure_file("config.cmake.in" "google_cloud_cpp_optimization-config.cmake"
175+
@ONLY)
176+
write_basic_package_version_file(
177+
"google_cloud_cpp_optimization-config-version.cmake"
178+
VERSION ${PROJECT_VERSION}
179+
COMPATIBILITY ExactVersion)
180+
181+
install(
182+
FILES
183+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_optimization-config.cmake"
184+
"${CMAKE_CURRENT_BINARY_DIR}/google_cloud_cpp_optimization-config-version.cmake"
185+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/google_cloud_cpp_optimization"
186+
COMPONENT google_cloud_cpp_development)
187+
188+
external_googleapis_install_pc("google_cloud_cpp_optimization_protos"
189+
"${PROJECT_SOURCE_DIR}/external/googleapis")

0 commit comments

Comments
 (0)