aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-04-19 10:43:28 +0200
committerStefan Boberg <[email protected]>2023-04-19 10:52:48 +0200
commit9fb9d6ce5aaedd4ecf4f7bdc9c33a94b1e6597b2 (patch)
tree924c8ede64e087a5bdfeeb87862bc08e325f4ddc
parentadded missing #pragma once (diff)
downloadzen-9fb9d6ce5aaedd4ecf4f7bdc9c33a94b1e6597b2.tar.xz
zen-9fb9d6ce5aaedd4ecf4f7bdc9c33a94b1e6597b2.zip
tweaks for enabling unity builds
mostly changes to make sure anonymous namespaces don't clash and a change to avoid windows headers from leaking into other compilation units unity builds are not yet enabled by default, but can be enabled by uncommenting this line in the root `xmake.lua` ``` --add_rules("c++.unity_build") ```
-rw-r--r--xmake.lua1
-rw-r--r--zen/xmake.lua1
-rw-r--r--zenhttp/httpserver.cpp6
-rw-r--r--zenhttp/httpsys.cpp6
-rw-r--r--zenhttp/xmake.lua1
-rw-r--r--zenhttp/zenhttp.cpp1
-rw-r--r--zenserver-test/xmake.lua1
-rw-r--r--zenserver/auth/authservice.cpp3
-rw-r--r--zenserver/diag/logging.cpp6
-rw-r--r--zenserver/xmake.lua4
-rw-r--r--zenstore/blockstore.cpp16
-rw-r--r--zenstore/compactcas.cpp18
-rw-r--r--zenstore/filecas.cpp22
-rw-r--r--zenstore/gc.cpp10
-rw-r--r--zenutil/zenserverprocess.cpp4
15 files changed, 72 insertions, 28 deletions
diff --git a/xmake.lua b/xmake.lua
index 7b5822371..1b6724044 100644
--- a/xmake.lua
+++ b/xmake.lua
@@ -32,6 +32,7 @@ if not is_arch("arm64") then
end
add_rules("mode.debug", "mode.release")
+--add_rules("c++.unity_build")
if is_mode("release") then
set_optimize("smallest")
diff --git a/zen/xmake.lua b/zen/xmake.lua
index 86d95406e..b83999efc 100644
--- a/zen/xmake.lua
+++ b/zen/xmake.lua
@@ -4,6 +4,7 @@ target("zen")
set_kind("binary")
add_headerfiles("**.h")
add_files("**.cpp")
+ add_files("zen.cpp", {unity_ignored = true })
add_deps("zencore", "zenhttp", "zenutil")
add_includedirs(".")
set_symbols("debug")
diff --git a/zenhttp/httpserver.cpp b/zenhttp/httpserver.cpp
index 952857f2c..3576d9b3d 100644
--- a/zenhttp/httpserver.cpp
+++ b/zenhttp/httpserver.cpp
@@ -4,7 +4,6 @@
#include "httpasio.h"
#include "httpnull.h"
-#include "httpsys.h"
#include <zencore/compactbinary.h>
#include <zencore/compactbinarybuilder.h>
@@ -705,6 +704,9 @@ enum class HttpServerClass
kHttpNull
};
+// Implemented in httpsys.cpp
+Ref<HttpServer> CreateHttpSysServer(int Concurrency, int BackgroundWorkerThreads);
+
Ref<HttpServer>
CreateHttpServer(std::string_view ServerClass)
{
@@ -741,7 +743,7 @@ CreateHttpServer(std::string_view ServerClass)
#if ZEN_WITH_HTTPSYS
case HttpServerClass::kHttpSys:
ZEN_INFO("using http.sys server implementation");
- return new HttpSysServer(std::thread::hardware_concurrency(), /* background worker threads */ 16);
+ return CreateHttpSysServer(std::thread::hardware_concurrency(), /* background worker threads */ 16);
#endif
case HttpServerClass::kHttpNull:
diff --git a/zenhttp/httpsys.cpp b/zenhttp/httpsys.cpp
index 4b566905e..16ec135cd 100644
--- a/zenhttp/httpsys.cpp
+++ b/zenhttp/httpsys.cpp
@@ -1662,5 +1662,11 @@ HttpSysServer::RegisterService(HttpService& Service)
RegisterService(Service.BaseUri(), Service);
}
+Ref<HttpServer>
+CreateHttpSysServer(int Concurrency, int BackgroundWorkerThreads)
+{
+ return Ref<HttpServer>(new HttpSysServer(Concurrency, BackgroundWorkerThreads));
+}
+
} // namespace zen
#endif
diff --git a/zenhttp/xmake.lua b/zenhttp/xmake.lua
index 528b72d52..b0dbdbc79 100644
--- a/zenhttp/xmake.lua
+++ b/zenhttp/xmake.lua
@@ -4,6 +4,7 @@ target('zenhttp')
set_kind("static")
add_headerfiles("**.h")
add_files("**.cpp")
+ add_files("httpsys.cpp", {unity_ignored=true})
add_includedirs("include", {public=true})
add_deps("zencore")
add_packages(
diff --git a/zenhttp/zenhttp.cpp b/zenhttp/zenhttp.cpp
index 0194abdcb..1adca30e8 100644
--- a/zenhttp/zenhttp.cpp
+++ b/zenhttp/zenhttp.cpp
@@ -2,6 +2,7 @@
#include <zenhttp/zenhttp.h>
+#include <zenhttp/httpclient.h>
#include <zenhttp/httpserver.h>
#include <zenhttp/httpshared.h>
diff --git a/zenserver-test/xmake.lua b/zenserver-test/xmake.lua
index 57df8b356..f0b34f6ca 100644
--- a/zenserver-test/xmake.lua
+++ b/zenserver-test/xmake.lua
@@ -4,6 +4,7 @@ target("zenserver-test")
set_kind("binary")
add_headerfiles("**.h")
add_files("*.cpp")
+ add_files("zenserver-test.cpp", {unity_ignored = true })
add_deps("zencore", "zenutil", "zenhttp")
add_deps("zenserver", {inherit=false})
add_packages("vcpkg::http-parser", "vcpkg::mimalloc")
diff --git a/zenserver/auth/authservice.cpp b/zenserver/auth/authservice.cpp
index 761c087f4..1cc679540 100644
--- a/zenserver/auth/authservice.cpp
+++ b/zenserver/auth/authservice.cpp
@@ -1,8 +1,9 @@
// Copyright Epic Games, Inc. All Rights Reserved.
-#include <auth/authmgr.h>
#include <auth/authservice.h>
+#include <auth/authmgr.h>
+
#include <zencore/compactbinarybuilder.h>
#include <zencore/string.h>
diff --git a/zenserver/diag/logging.cpp b/zenserver/diag/logging.cpp
index 1a8b427ca..ca569c467 100644
--- a/zenserver/diag/logging.cpp
+++ b/zenserver/diag/logging.cpp
@@ -326,7 +326,6 @@ private:
memory_buf_t m_CachedDatetime;
std::string m_LogId;
};
-} // namespace logging
bool
EnableVTMode()
@@ -355,6 +354,8 @@ EnableVTMode()
return true;
}
+} // namespace logging
+
#if ZEN_USE_SENTRY
class sentry_sink final : public spdlog::sinks::base_sink<spdlog::details::null_mutex>
@@ -391,8 +392,7 @@ void
InitializeLogging(const ZenServerOptions& GlobalOptions)
{
zen::logging::InitializeLogging();
-
- EnableVTMode();
+ logging::EnableVTMode();
bool IsAsync = true;
spdlog::level::level_enum LogLevel = spdlog::level::info;
diff --git a/zenserver/xmake.lua b/zenserver/xmake.lua
index 992923d48..23bfb9535 100644
--- a/zenserver/xmake.lua
+++ b/zenserver/xmake.lua
@@ -2,9 +2,10 @@
target("zenserver")
set_kind("binary")
+ add_deps("zencore", "zenhttp", "zenstore", "zenutil")
add_headerfiles("**.h")
add_files("**.cpp")
- add_deps("zencore", "zenhttp", "zenstore", "zenutil")
+ add_files("zenserver.cpp", {unity_ignored = true })
add_includedirs(".")
set_symbols("debug")
@@ -17,6 +18,7 @@ target("zenserver")
add_ldflags("/MANIFEST:EMBED")
add_ldflags("/LTCG")
add_files("zenserver.rc")
+ add_cxxflags("/bigobj")
else
remove_files("windows/**")
end
diff --git a/zenstore/blockstore.cpp b/zenstore/blockstore.cpp
index 5d81d1120..d743c431f 100644
--- a/zenstore/blockstore.cpp
+++ b/zenstore/blockstore.cpp
@@ -859,7 +859,7 @@ TEST_CASE("blockstore.blockfile")
CHECK(!std::filesystem::exists(RootDirectory / "1"));
}
-namespace {
+namespace blockstore::impl {
BlockStoreLocation WriteStringAsChunk(BlockStore& Store, std::string_view String, size_t PayloadAlignment)
{
BlockStoreLocation Location;
@@ -907,10 +907,12 @@ namespace {
return IoBufferBuilder::MakeCloneFromMemory(Values.data(), Values.size());
}
-} // namespace
+} // namespace blockstore::impl
TEST_CASE("blockstore.chunks")
{
+ using namespace blockstore::impl;
+
ScopedTemporaryDirectory TempDir;
auto RootDirectory = TempDir.Path();
@@ -939,6 +941,8 @@ TEST_CASE("blockstore.chunks")
TEST_CASE("blockstore.clean.stray.blocks")
{
+ using namespace blockstore::impl;
+
ScopedTemporaryDirectory TempDir;
auto RootDirectory = TempDir.Path();
@@ -963,6 +967,8 @@ TEST_CASE("blockstore.clean.stray.blocks")
TEST_CASE("blockstore.flush.forces.new.block")
{
+ using namespace blockstore::impl;
+
ScopedTemporaryDirectory TempDir;
auto RootDirectory = TempDir.Path();
@@ -984,6 +990,8 @@ TEST_CASE("blockstore.flush.forces.new.block")
TEST_CASE("blockstore.iterate.chunks")
{
+ using namespace blockstore::impl;
+
ScopedTemporaryDirectory TempDir;
auto RootDirectory = TempDir.Path();
@@ -1078,6 +1086,8 @@ TEST_CASE("blockstore.iterate.chunks")
TEST_CASE("blockstore.reclaim.space")
{
+ using namespace blockstore::impl;
+
ScopedTemporaryDirectory TempDir;
auto RootDirectory = TempDir.Path();
@@ -1193,6 +1203,8 @@ TEST_CASE("blockstore.reclaim.space")
TEST_CASE("blockstore.thread.read.write")
{
+ using namespace blockstore::impl;
+
ScopedTemporaryDirectory TempDir;
auto RootDirectory = TempDir.Path();
diff --git a/zenstore/compactcas.cpp b/zenstore/compactcas.cpp
index 70a88ecad..60644847f 100644
--- a/zenstore/compactcas.cpp
+++ b/zenstore/compactcas.cpp
@@ -732,7 +732,7 @@ CasContainerStrategy::OpenContainer(bool IsNewStore)
#if ZEN_WITH_TESTS
namespace {
- static IoBuffer CreateChunk(uint64_t Size)
+ static IoBuffer CreateRandomChunk(uint64_t Size)
{
static std::random_device rd;
static std::mt19937 g(rd());
@@ -865,7 +865,7 @@ TEST_CASE("compactcas.compact.totalsize")
for (int32_t Idx = 0; Idx < kChunkCount; ++Idx)
{
- IoBuffer Chunk = CreateChunk(kChunkSize);
+ IoBuffer Chunk = CreateRandomChunk(kChunkSize);
const IoHash Hash = HashBuffer(Chunk);
CasStore::InsertResult InsertResult = Cas.InsertChunk(Chunk, Hash);
ZEN_ASSERT(InsertResult.New);
@@ -904,7 +904,7 @@ TEST_CASE("compactcas.gc.basic")
CasContainerStrategy Cas(Gc);
Cas.Initialize(TempDir.Path(), "cb", 65536, 1 << 4, true);
- IoBuffer Chunk = CreateChunk(128);
+ IoBuffer Chunk = CreateRandomChunk(128);
IoHash ChunkHash = IoHash::HashBuffer(Chunk);
const CasStore::InsertResult InsertResult = Cas.InsertChunk(Chunk, ChunkHash);
@@ -923,7 +923,7 @@ TEST_CASE("compactcas.gc.removefile")
{
ScopedTemporaryDirectory TempDir;
- IoBuffer Chunk = CreateChunk(128);
+ IoBuffer Chunk = CreateRandomChunk(128);
IoHash ChunkHash = IoHash::HashBuffer(Chunk);
{
GcManager Gc;
@@ -964,7 +964,7 @@ TEST_CASE("compactcas.gc.compact")
Chunks.reserve(9);
for (uint64_t Size : ChunkSizes)
{
- Chunks.push_back(CreateChunk(Size));
+ Chunks.push_back(CreateRandomChunk(Size));
}
std::vector<IoHash> ChunkHashes;
@@ -1190,7 +1190,7 @@ TEST_CASE("compactcas.gc.deleteblockonopen")
Chunks.reserve(20);
for (uint64_t Size : ChunkSizes)
{
- Chunks.push_back(CreateChunk(Size));
+ Chunks.push_back(CreateRandomChunk(Size));
}
std::vector<IoHash> ChunkHashes;
@@ -1256,7 +1256,7 @@ TEST_CASE("compactcas.gc.handleopeniobuffer")
Chunks.reserve(20);
for (const uint64_t& Size : ChunkSizes)
{
- Chunks.push_back(CreateChunk(Size));
+ Chunks.push_back(CreateRandomChunk(Size));
}
std::vector<IoHash> ChunkHashes;
@@ -1308,7 +1308,7 @@ TEST_CASE("compactcas.threadedinsert")
{
while (true)
{
- IoBuffer Chunk = CreateChunk(kChunkSize);
+ IoBuffer Chunk = CreateRandomChunk(kChunkSize);
IoHash Hash = HashBuffer(Chunk);
if (Chunks.contains(Hash))
{
@@ -1377,7 +1377,7 @@ TEST_CASE("compactcas.threadedinsert")
for (int32_t Idx = 0; Idx < kChunkCount; ++Idx)
{
- IoBuffer Chunk = CreateChunk(kChunkSize);
+ IoBuffer Chunk = CreateRandomChunk(kChunkSize);
IoHash Hash = HashBuffer(Chunk);
NewChunks[Hash] = Chunk;
}
diff --git a/zenstore/filecas.cpp b/zenstore/filecas.cpp
index b4729d558..986cc9ae6 100644
--- a/zenstore/filecas.cpp
+++ b/zenstore/filecas.cpp
@@ -39,7 +39,7 @@ ZEN_THIRD_PARTY_INCLUDES_END
namespace zen {
-namespace {
+namespace filecas::impl {
const char* IndexExtension = ".uidx";
const char* LogExtension = ".ulog";
@@ -77,7 +77,7 @@ namespace {
#pragma pack(pop)
-} // namespace
+} // namespace filecas::impl
FileCasStrategy::ShardingHelper::ShardingHelper(const std::filesystem::path& RootPath, const IoHash& ChunkHash)
{
@@ -125,6 +125,8 @@ FileCasStrategy::~FileCasStrategy()
void
FileCasStrategy::Initialize(const std::filesystem::path& RootDirectory, bool IsNewStore)
{
+ using namespace filecas::impl;
+
m_IsInitialized = true;
m_RootDirectory = RootDirectory;
@@ -1013,6 +1015,8 @@ FileCasStrategy::ValidateEntry(const FileCasIndexEntry& Entry, std::string& OutR
void
FileCasStrategy::MakeIndexSnapshot()
{
+ using namespace filecas::impl;
+
uint64_t LogCount = m_CasLog.GetLogCount();
if (m_LogFlushPosition == LogCount)
{
@@ -1062,12 +1066,12 @@ FileCasStrategy::MakeIndexSnapshot()
BasicFile ObjectIndexFile;
ObjectIndexFile.Open(IndexPath, BasicFile::Mode::kTruncate);
- FileCasIndexHeader Header = {.EntryCount = Entries.size(), .LogPosition = LogCount};
+ filecas::impl::FileCasIndexHeader Header = {.EntryCount = Entries.size(), .LogPosition = LogCount};
- Header.Checksum = FileCasIndexHeader::ComputeChecksum(Header);
+ Header.Checksum = filecas::impl::FileCasIndexHeader::ComputeChecksum(Header);
- ObjectIndexFile.Write(&Header, sizeof(FileCasIndexHeader), 0);
- ObjectIndexFile.Write(Entries.data(), Entries.size() * sizeof(FileCasIndexEntry), sizeof(FileCasIndexHeader));
+ ObjectIndexFile.Write(&Header, sizeof(filecas::impl::FileCasIndexHeader), 0);
+ ObjectIndexFile.Write(Entries.data(), Entries.size() * sizeof(FileCasIndexEntry), sizeof(filecas::impl::FileCasIndexHeader));
ObjectIndexFile.Flush();
ObjectIndexFile.Close();
EntryCount = Entries.size();
@@ -1093,6 +1097,8 @@ FileCasStrategy::MakeIndexSnapshot()
uint64_t
FileCasStrategy::ReadIndexFile()
{
+ using namespace filecas::impl;
+
std::vector<FileCasIndexEntry> Entries;
std::filesystem::path IndexPath = GetIndexPath(m_RootDirectory);
if (std::filesystem::is_regular_file(IndexPath))
@@ -1179,6 +1185,8 @@ FileCasStrategy::ReadIndexFile()
uint64_t
FileCasStrategy::ReadLog(uint64_t SkipEntryCount)
{
+ using namespace filecas::impl;
+
std::filesystem::path LogPath = GetLogPath(m_RootDirectory);
if (std::filesystem::is_regular_file(LogPath))
{
@@ -1230,6 +1238,8 @@ FileCasStrategy::ReadLog(uint64_t SkipEntryCount)
std::vector<FileCasStrategy::FileCasIndexEntry>
FileCasStrategy::ScanFolderForCasFiles(const std::filesystem::path& RootDir)
{
+ using namespace filecas::impl;
+
std::vector<FileCasIndexEntry> Entries;
struct Visitor : public FileSystemTraversal::TreeVisitor
{
diff --git a/zenstore/gc.cpp b/zenstore/gc.cpp
index 8d3b8d018..370c3c965 100644
--- a/zenstore/gc.cpp
+++ b/zenstore/gc.cpp
@@ -888,7 +888,7 @@ GcScheduler::CollectGarbage(const GcClock::TimePoint& ExpireTime, bool Delete, b
#if ZEN_WITH_TESTS
-namespace {
+namespace gc::impl {
static IoBuffer CreateChunk(uint64_t Size)
{
static std::random_device rd;
@@ -909,10 +909,12 @@ namespace {
{
return CompressedBuffer::Compress(SharedBuffer::MakeView(Buffer.GetData(), Buffer.GetSize()));
}
-} // namespace
+} // namespace gc::impl
TEST_CASE("gc.basic")
{
+ using namespace gc::impl;
+
ScopedTemporaryDirectory TempDir;
CidStoreConfiguration CasConfig;
@@ -940,6 +942,8 @@ TEST_CASE("gc.basic")
TEST_CASE("gc.full")
{
+ using namespace gc::impl;
+
ScopedTemporaryDirectory TempDir;
CidStoreConfiguration CasConfig;
@@ -1140,6 +1144,8 @@ TEST_CASE("gc.full")
TEST_CASE("gc.diskusagewindow")
{
+ using namespace gc::impl;
+
DiskUsageWindow Stats;
Stats.Append({.SampleTime = 0, .DiskUsage = 0}); // 0 0
Stats.Append({.SampleTime = 10, .DiskUsage = 10}); // 1 10
diff --git a/zenutil/zenserverprocess.cpp b/zenutil/zenserverprocess.cpp
index 3d9324af9..b43313b7c 100644
--- a/zenutil/zenserverprocess.cpp
+++ b/zenutil/zenserverprocess.cpp
@@ -376,7 +376,7 @@ ZenServerState::ZenServerEntry::AddSponsorProcess(uint32_t PidToAdd)
//////////////////////////////////////////////////////////////////////////
-std::atomic<int> TestCounter{0};
+std::atomic<int> ZenServerTestCounter{0};
ZenServerEnvironment::ZenServerEnvironment()
{
@@ -416,7 +416,7 @@ ZenServerEnvironment::CreateNewTestDir()
using namespace std::literals;
ExtendableWideStringBuilder<256> TestDir;
- TestDir << "test"sv << int64_t(++TestCounter);
+ TestDir << "test"sv << int64_t(++ZenServerTestCounter);
std::filesystem::path TestPath = m_TestBaseDir / TestDir.c_str();