pw_stream: Update CMake build
- Split the CMake build into separate libraries so that the socket
stream code is not automatically built.
- Fix public/private deps in the GN build.
- Add pw_rpc/system_server/CMakeLists.txt.
- In the CMake presubmit step, install Nanopb and build CMake's pw_apps.
Change-Id: Id29673d5d26e30e1b196768b8667805ec3094e3e
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/27581
Reviewed-by: Armando Montanez <amontanez@google.com>
Commit-Queue: Wyatt Hepler <hepler@google.com>
Pigweed-Auto-Submit: Wyatt Hepler <hepler@google.com>
diff --git a/pw_hdlc_lite/rpc_example/CMakeLists.txt b/pw_hdlc_lite/rpc_example/CMakeLists.txt
index be26438..d975789 100644
--- a/pw_hdlc_lite/rpc_example/CMakeLists.txt
+++ b/pw_hdlc_lite/rpc_example/CMakeLists.txt
@@ -24,4 +24,5 @@
pw_log
pw_rpc.nanopb.echo_service
pw_rpc.server
+ pw_rpc.system_server
)
diff --git a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
index 6df7ece..f8beb47 100755
--- a/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
+++ b/pw_presubmit/py/pw_presubmit/pigweed_presubmit.py
@@ -157,13 +157,15 @@
@filter_paths(endswith=(*format_code.C_FORMAT.extensions, '.cmake',
'CMakeLists.txt'))
def cmake_tests(ctx: PresubmitContext):
- toolchain = ctx.root / 'pw_toolchain' / 'host_clang' / 'toolchain.cmake'
+ build.install_package(ctx.package_root, 'nanopb')
+ toolchain = ctx.root / 'pw_toolchain' / 'host_clang' / 'toolchain.cmake'
build.cmake(ctx.root,
ctx.output_dir,
f'-DCMAKE_TOOLCHAIN_FILE={toolchain}',
+ f'-Ddir_pw_third_party_nanopb={ctx.package_root / "nanopb"}',
env=build.env_with_clang_vars())
- build.ninja(ctx.output_dir, 'pw_run_tests.modules')
+ build.ninja(ctx.output_dir, 'pw_apps', 'pw_run_tests.modules')
@filter_paths(endswith=(*format_code.C_FORMAT.extensions, '.bzl', 'BUILD'))
diff --git a/pw_rpc/CMakeLists.txt b/pw_rpc/CMakeLists.txt
index bbaf74b..50d9ab0 100644
--- a/pw_rpc/CMakeLists.txt
+++ b/pw_rpc/CMakeLists.txt
@@ -20,6 +20,7 @@
endif()
add_subdirectory(raw)
+add_subdirectory(system_server)
pw_add_module_library(pw_rpc.server
SOURCES
diff --git a/pw_rpc/system_server/CMakeLists.txt b/pw_rpc/system_server/CMakeLists.txt
new file mode 100644
index 0000000..93c5833
--- /dev/null
+++ b/pw_rpc/system_server/CMakeLists.txt
@@ -0,0 +1,43 @@
+# Copyright 2020 The Pigweed 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
+#
+# https://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.
+
+include("$ENV{PW_ROOT}/pw_build/pigweed.cmake")
+
+pw_add_facade(pw_rpc.system_server
+ PUBLIC_DEPS
+ pw_rpc.server
+ pw_stream
+)
+target_include_directories(pw_rpc.system_server.facade INTERFACE public)
+
+pw_add_module_library(pw_rpc.system_server.socket
+ IMPLEMENTS_FACADE
+ pw_rpc.system_server
+ SOURCES
+ socket_rpc_server.cc
+ PRIVATE_DEPS
+ pw_hdlc_lite
+ pw_rpc.server
+ pw_stream.socket_stream
+)
+
+pw_add_module_library(pw_rpc.system_server.sys_io
+ IMPLEMENTS_FACADE
+ pw_rpc.system_server
+ SOURCES
+ sys_io_rpc_server.cc
+ PUBLIC_DEPS
+ pw_hdlc_lite
+ pw_stream.sys_io_stream
+)
diff --git a/pw_stream/BUILD.gn b/pw_stream/BUILD.gn
index cb7d6cf..b3bf1c8 100644
--- a/pw_stream/BUILD.gn
+++ b/pw_stream/BUILD.gn
@@ -18,12 +18,13 @@
import("$dir_pw_docgen/docs.gni")
import("$dir_pw_unit_test/test.gni")
-config("default_config") {
+config("public_include_path") {
include_dirs = [ "public" ]
+ visibility = [ ":*" ]
}
pw_source_set("pw_stream") {
- public_configs = [ ":default_config" ]
+ public_configs = [ ":public_include_path" ]
public = [
"public/pw_stream/memory_stream.h",
"public/pw_stream/null_stream.h",
@@ -40,18 +41,15 @@
}
pw_source_set("socket_stream") {
- public_configs = [ ":default_config" ]
- deps = [
- "$dir_pw_stream",
- "$dir_pw_sys_io",
- ]
+ public_configs = [ ":public_include_path" ]
+ public_deps = [ "$dir_pw_stream" ]
sources = [ "socket_stream.cc" ]
public = [ "public/pw_stream/socket_stream.h" ]
}
pw_source_set("sys_io_stream") {
- public_configs = [ ":default_config" ]
- deps = [
+ public_configs = [ ":public_include_path" ]
+ public_deps = [
"$dir_pw_stream",
"$dir_pw_sys_io",
]
diff --git a/pw_stream/CMakeLists.txt b/pw_stream/CMakeLists.txt
index 27e58f6..55a9f96 100644
--- a/pw_stream/CMakeLists.txt
+++ b/pw_stream/CMakeLists.txt
@@ -14,15 +14,26 @@
include($ENV{PW_ROOT}/pw_build/pigweed.cmake)
-pw_auto_add_simple_module(pw_stream
+pw_add_module_library(pw_stream
+ SOURCES
+ memory_stream.cc
PUBLIC_DEPS
+ pw_assert
pw_bytes
- pw_containers
- pw_log
pw_result
pw_span
pw_status
+)
+
+pw_add_module_library(pw_stream.socket_stream
+ SOURCES
+ socket_stream.cc
PRIVATE_DEPS
- pw_assert
- pw_string
+ pw_stream
+)
+
+pw_add_module_library(pw_stream.sys_io_stream
+ PRIVATE_DEPS
+ pw_stream
+ pw_sys_io
)
diff --git a/pw_toolchain/host_clang/toolchain.cmake b/pw_toolchain/host_clang/toolchain.cmake
index 2628ee6..5457f94 100644
--- a/pw_toolchain/host_clang/toolchain.cmake
+++ b/pw_toolchain/host_clang/toolchain.cmake
@@ -16,6 +16,7 @@
pw_set_backend(pw_log pw_log_basic)
pw_set_backend(pw_assert pw_assert_log)
+pw_set_backend(pw_rpc.system_server pw_rpc.system_server.socket)
pw_set_backend(pw_sys_io pw_sys_io_stdio)
set(CMAKE_C_COMPILER clang)
diff --git a/pw_toolchain/host_gcc/toolchain.cmake b/pw_toolchain/host_gcc/toolchain.cmake
index 0826543..97e5360 100644
--- a/pw_toolchain/host_gcc/toolchain.cmake
+++ b/pw_toolchain/host_gcc/toolchain.cmake
@@ -16,6 +16,7 @@
pw_set_backend(pw_log pw_log_basic)
pw_set_backend(pw_assert pw_assert_log)
+pw_set_backend(pw_rpc.system_server pw_rpc.system_server.socket)
pw_set_backend(pw_sys_io pw_sys_io_stdio)
set(CMAKE_C_COMPILER gcc)