diff --git a/source/exe/BUILD b/source/exe/BUILD index d48f99ce33..7ed716a317 100644 --- a/source/exe/BUILD +++ b/source/exe/BUILD @@ -57,7 +57,8 @@ envoy_cc_library( ], deps = [ ":envoy_main_common_lib", - ] + envoy_cc_platform_dep("platform_impl_lib"), + ":platform_impl_lib", + ], ) envoy_cc_library( @@ -66,6 +67,7 @@ envoy_cc_library( hdrs = ["main_common.h"], deps = [ ":envoy_common_lib", + ":platform_impl_lib", ":process_wide_lib", "//source/common/api:os_sys_calls_lib", "//source/common/common:compiler_requirements_lib", @@ -80,7 +82,7 @@ envoy_cc_library( "//source/common/signal:sigaction_lib", ":terminate_handler_lib", ], - }) + envoy_cc_platform_dep("platform_impl_lib"), + }), ) envoy_cc_library( @@ -96,11 +98,26 @@ envoy_cc_library( ] + envoy_google_grpc_external_deps(), ) +envoy_cc_library( + name = "platform_impl_lib", + deps = [":platform_header_lib"] + + envoy_cc_platform_dep("platform_impl_lib"), +) + +envoy_cc_library( + name = "platform_header_lib", + hdrs = ["platform_impl.h"], + deps = [ + "//include/envoy/filesystem:filesystem_interface", + "//include/envoy/thread:thread_interface", + ], +) + envoy_cc_posix_library( name = "platform_impl_lib", - hdrs = ["posix/platform_impl.h"], - strip_include_prefix = "posix", + srcs = ["posix/platform_impl.cc"], deps = [ + ":platform_header_lib", "//source/common/common:thread_lib", "//source/common/filesystem:filesystem_lib", ], @@ -108,9 +125,9 @@ envoy_cc_posix_library( envoy_cc_win32_library( name = "platform_impl_lib", - hdrs = ["win32/platform_impl.h"], - strip_include_prefix = "win32", + srcs = ["win32/platform_impl.cc"], deps = [ + ":platform_header_lib", "//source/common/common:assert_lib", "//source/common/common:thread_lib", "//source/common/filesystem:filesystem_lib", diff --git a/source/exe/platform_impl.h b/source/exe/platform_impl.h new file mode 100644 index 0000000000..c52152c8fe --- /dev/null +++ b/source/exe/platform_impl.h @@ -0,0 +1,19 @@ +#pragma once + +#include "envoy/filesystem/filesystem.h" +#include "envoy/thread/thread.h" + +namespace Envoy { + +class PlatformImpl { +public: + PlatformImpl(); + Thread::ThreadFactory& threadFactory() { return *thread_factory_; } + Filesystem::Instance& fileSystem() { return *file_system_; } + +private: + std::unique_ptr thread_factory_; + std::unique_ptr file_system_; +}; + +} // namespace Envoy diff --git a/source/exe/posix/platform_impl.cc b/source/exe/posix/platform_impl.cc new file mode 100644 index 0000000000..f664071815 --- /dev/null +++ b/source/exe/posix/platform_impl.cc @@ -0,0 +1,12 @@ +#include "common/common/thread_impl.h" +#include "common/filesystem/filesystem_impl.h" + +#include "exe/platform_impl.h" + +namespace Envoy { + +PlatformImpl::PlatformImpl() + : thread_factory_(std::make_unique()), + file_system_(std::make_unique()) {} + +} // namespace Envoy diff --git a/source/exe/posix/platform_impl.h b/source/exe/posix/platform_impl.h deleted file mode 100644 index 45fbd73407..0000000000 --- a/source/exe/posix/platform_impl.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "common/common/thread_impl.h" -#include "common/filesystem/filesystem_impl.h" - -namespace Envoy { - -class PlatformImpl { -public: - Thread::ThreadFactory& threadFactory() { return thread_factory_; } - Filesystem::Instance& fileSystem() { return file_system_; } - -private: - Thread::ThreadFactoryImplPosix thread_factory_; - Filesystem::InstanceImplPosix file_system_; -}; - -} // namespace Envoy diff --git a/source/exe/win32/platform_impl.cc b/source/exe/win32/platform_impl.cc new file mode 100644 index 0000000000..860a209a8e --- /dev/null +++ b/source/exe/win32/platform_impl.cc @@ -0,0 +1,26 @@ +#include "common/common/assert.h" +#include "common/common/thread_impl.h" +#include "common/filesystem/filesystem_impl.h" + +#include "exe/platform_impl.h" + +// clang-format off +#include +// clang-format on + +namespace Envoy { + +PlatformImpl::PlatformImpl() + : thread_factory_(std::make_unique()), + file_system_(std::make_unique()) { + const WORD wVersionRequested = MAKEWORD(2, 2); + WSADATA wsaData; + const int rc = ::WSAStartup(wVersionRequested, &wsaData); + RELEASE_ASSERT(rc == 0, "WSAStartup failed with error"); +} + +~PlatformImpl() { ::WSACleanup(); } + +}; // namespace Envoy + +} // namespace Envoy diff --git a/source/exe/win32/platform_impl.h b/source/exe/win32/platform_impl.h deleted file mode 100644 index ffb239dd7e..0000000000 --- a/source/exe/win32/platform_impl.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once - -#include "common/common/assert.h" -#include "common/common/thread_impl.h" -#include "common/filesystem/filesystem_impl.h" - -// clang-format off -#include -// clang-format on - -namespace Envoy { - -class PlatformImpl { -public: - PlatformImpl() { - const WORD wVersionRequested = MAKEWORD(2, 2); - WSADATA wsaData; - const int rc = ::WSAStartup(wVersionRequested, &wsaData); - RELEASE_ASSERT(rc == 0, "WSAStartup failed with error"); - } - - ~PlatformImpl() { ::WSACleanup(); } - - Thread::ThreadFactory& threadFactory() { return thread_factory_; } - Filesystem::Instance& fileSystem() { return file_system_; } - -private: - Thread::ThreadFactoryImplWin32 thread_factory_; - Filesystem::InstanceImplWin32 file_system_; -}; - -} // namespace Envoy