Skip to content

Commit 3a17230

Browse files
authored
chore: Remove unity builds (XRPLF#6300)
Unity builds were intended to speed up builds, by bundling multiple files into compilation units. However, now that ccache is available on all platforms, there is no need for unity builds anymore, as ccache stores compiled individual build objects for reuse. This change therefore removes the ability to make unity builds.
1 parent 6c1a92f commit 3a17230

File tree

11 files changed

+58
-83
lines changed

11 files changed

+58
-83
lines changed

.github/scripts/strategy-matrix/generate.py

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -51,138 +51,122 @@ def generate_strategy_matrix(all: bool, config: Config) -> list:
5151
# Only generate a subset of configurations in PRs.
5252
if not all:
5353
# Debian:
54-
# - Bookworm using GCC 13: Release and Unity on linux/amd64, set
55-
# the reference fee to 500.
56-
# - Bookworm using GCC 15: Debug and no Unity on linux/amd64, enable
57-
# code coverage (which will be done below).
58-
# - Bookworm using Clang 16: Debug and no Unity on linux/arm64,
59-
# enable voidstar.
60-
# - Bookworm using Clang 17: Release and no Unity on linux/amd64,
61-
# set the reference fee to 1000.
62-
# - Bookworm using Clang 20: Debug and Unity on linux/amd64.
54+
# - Bookworm using GCC 13: Release on linux/amd64, set the reference
55+
# fee to 500.
56+
# - Bookworm using GCC 15: Debug on linux/amd64, enable code
57+
# coverage (which will be done below).
58+
# - Bookworm using Clang 16: Debug on linux/arm64, enable voidstar.
59+
# - Bookworm using Clang 17: Release on linux/amd64, set the
60+
# reference fee to 1000.
61+
# - Bookworm using Clang 20: Debug on linux/amd64.
6362
if os["distro_name"] == "debian":
6463
skip = True
6564
if os["distro_version"] == "bookworm":
6665
if (
6766
f"{os['compiler_name']}-{os['compiler_version']}" == "gcc-13"
6867
and build_type == "Release"
69-
and "-Dunity=ON" in cmake_args
7068
and architecture["platform"] == "linux/amd64"
7169
):
7270
cmake_args = f"-DUNIT_TEST_REFERENCE_FEE=500 {cmake_args}"
7371
skip = False
7472
if (
7573
f"{os['compiler_name']}-{os['compiler_version']}" == "gcc-15"
7674
and build_type == "Debug"
77-
and "-Dunity=OFF" in cmake_args
7875
and architecture["platform"] == "linux/amd64"
7976
):
8077
skip = False
8178
if (
8279
f"{os['compiler_name']}-{os['compiler_version']}" == "clang-16"
8380
and build_type == "Debug"
84-
and "-Dunity=OFF" in cmake_args
8581
and architecture["platform"] == "linux/arm64"
8682
):
8783
cmake_args = f"-Dvoidstar=ON {cmake_args}"
8884
skip = False
8985
if (
9086
f"{os['compiler_name']}-{os['compiler_version']}" == "clang-17"
9187
and build_type == "Release"
92-
and "-Dunity=ON" in cmake_args
9388
and architecture["platform"] == "linux/amd64"
9489
):
9590
cmake_args = f"-DUNIT_TEST_REFERENCE_FEE=1000 {cmake_args}"
9691
skip = False
9792
if (
9893
f"{os['compiler_name']}-{os['compiler_version']}" == "clang-20"
9994
and build_type == "Debug"
100-
and "-Dunity=ON" in cmake_args
10195
and architecture["platform"] == "linux/amd64"
10296
):
10397
skip = False
10498
if skip:
10599
continue
106100

107101
# RHEL:
108-
# - 9 using GCC 12: Debug and Unity on linux/amd64.
109-
# - 10 using Clang: Release and no Unity on linux/amd64.
102+
# - 9 using GCC 12: Debug on linux/amd64.
103+
# - 10 using Clang: Release on linux/amd64.
110104
if os["distro_name"] == "rhel":
111105
skip = True
112106
if os["distro_version"] == "9":
113107
if (
114108
f"{os['compiler_name']}-{os['compiler_version']}" == "gcc-12"
115109
and build_type == "Debug"
116-
and "-Dunity=ON" in cmake_args
117110
and architecture["platform"] == "linux/amd64"
118111
):
119112
skip = False
120113
elif os["distro_version"] == "10":
121114
if (
122115
f"{os['compiler_name']}-{os['compiler_version']}" == "clang-any"
123116
and build_type == "Release"
124-
and "-Dunity=OFF" in cmake_args
125117
and architecture["platform"] == "linux/amd64"
126118
):
127119
skip = False
128120
if skip:
129121
continue
130122

131123
# Ubuntu:
132-
# - Jammy using GCC 12: Debug and no Unity on linux/arm64.
133-
# - Noble using GCC 14: Release and Unity on linux/amd64.
134-
# - Noble using Clang 18: Debug and no Unity on linux/amd64.
135-
# - Noble using Clang 19: Release and Unity on linux/arm64.
124+
# - Jammy using GCC 12: Debug on linux/arm64.
125+
# - Noble using GCC 14: Release on linux/amd64.
126+
# - Noble using Clang 18: Debug on linux/amd64.
127+
# - Noble using Clang 19: Release on linux/arm64.
136128
if os["distro_name"] == "ubuntu":
137129
skip = True
138130
if os["distro_version"] == "jammy":
139131
if (
140132
f"{os['compiler_name']}-{os['compiler_version']}" == "gcc-12"
141133
and build_type == "Debug"
142-
and "-Dunity=OFF" in cmake_args
143134
and architecture["platform"] == "linux/arm64"
144135
):
145136
skip = False
146137
elif os["distro_version"] == "noble":
147138
if (
148139
f"{os['compiler_name']}-{os['compiler_version']}" == "gcc-14"
149140
and build_type == "Release"
150-
and "-Dunity=ON" in cmake_args
151141
and architecture["platform"] == "linux/amd64"
152142
):
153143
skip = False
154144
if (
155145
f"{os['compiler_name']}-{os['compiler_version']}" == "clang-18"
156146
and build_type == "Debug"
157-
and "-Dunity=OFF" in cmake_args
158147
and architecture["platform"] == "linux/amd64"
159148
):
160149
skip = False
161150
if (
162151
f"{os['compiler_name']}-{os['compiler_version']}" == "clang-19"
163152
and build_type == "Release"
164-
and "-Dunity=ON" in cmake_args
165153
and architecture["platform"] == "linux/arm64"
166154
):
167155
skip = False
168156
if skip:
169157
continue
170158

171159
# MacOS:
172-
# - Debug and no Unity on macos/arm64.
160+
# - Debug on macos/arm64.
173161
if os["distro_name"] == "macos" and not (
174-
build_type == "Debug"
175-
and "-Dunity=OFF" in cmake_args
176-
and architecture["platform"] == "macos/arm64"
162+
build_type == "Debug" and architecture["platform"] == "macos/arm64"
177163
):
178164
continue
179165

180166
# Windows:
181-
# - Release and Unity on windows/amd64.
167+
# - Release on windows/amd64.
182168
if os["distro_name"] == "windows" and not (
183-
build_type == "Release"
184-
and "-Dunity=ON" in cmake_args
185-
and architecture["platform"] == "windows/amd64"
169+
build_type == "Release" and architecture["platform"] == "windows/amd64"
186170
):
187171
continue
188172

@@ -209,18 +193,17 @@ def generate_strategy_matrix(all: bool, config: Config) -> list:
209193
):
210194
continue
211195

212-
# Enable code coverage for Debian Bookworm using GCC 15 in Debug and no
213-
# Unity on linux/amd64
196+
# Enable code coverage for Debian Bookworm using GCC 15 in Debug on
197+
# linux/amd64
214198
if (
215199
f"{os['compiler_name']}-{os['compiler_version']}" == "gcc-15"
216200
and build_type == "Debug"
217-
and "-Dunity=OFF" in cmake_args
218201
and architecture["platform"] == "linux/amd64"
219202
):
220203
cmake_args = f"-Dcoverage=ON -Dcoverage_format=xml -DCODE_COVERAGE_VERBOSE=ON -DCMAKE_C_FLAGS=-O0 -DCMAKE_CXX_FLAGS=-O0 {cmake_args}"
221204

222205
# Generate a unique name for the configuration, e.g. macos-arm64-debug
223-
# or debian-bookworm-gcc-12-amd64-release-unity.
206+
# or debian-bookworm-gcc-12-amd64-release.
224207
config_name = os["distro_name"]
225208
if (n := os["distro_version"]) != "":
226209
config_name += f"-{n}"
@@ -234,8 +217,6 @@ def generate_strategy_matrix(all: bool, config: Config) -> list:
234217
config_name += f"-{build_type.lower()}"
235218
if "-Dcoverage=ON" in cmake_args:
236219
config_name += "-coverage"
237-
if "-Dunity=ON" in cmake_args:
238-
config_name += "-unity"
239220

240221
# Add the configuration to the list, with the most unique fields first,
241222
# so that they are easier to identify in the GitHub Actions UI, as long

.github/scripts/strategy-matrix/linux.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,5 @@
208208
}
209209
],
210210
"build_type": ["Debug", "Release"],
211-
"cmake_args": ["-Dunity=OFF", "-Dunity=ON"]
211+
"cmake_args": [""]
212212
}

.github/scripts/strategy-matrix/macos.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,5 @@
1515
}
1616
],
1717
"build_type": ["Debug", "Release"],
18-
"cmake_args": [
19-
"-Dunity=OFF -DCMAKE_POLICY_VERSION_MINIMUM=3.5",
20-
"-Dunity=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5"
21-
]
18+
"cmake_args": ["-DCMAKE_POLICY_VERSION_MINIMUM=3.5"]
2219
}

.github/scripts/strategy-matrix/windows.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
}
1616
],
1717
"build_type": ["Debug", "Release"],
18-
"cmake_args": ["-Dunity=OFF", "-Dunity=ON"]
18+
"cmake_args": [""]
1919
}

BUILD.md

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,36 @@ The workaround for this error is to add two lines to your profile:
368368
tools.build:cxxflags=['-DBOOST_ASIO_DISABLE_CONCEPTS']
369369
```
370370

371+
### Set Up Ccache
372+
373+
To speed up repeated compilations, we recommend that you install
374+
[ccache](https://ccache.dev), a tool that wraps your compiler so that it can
375+
cache build objects locally.
376+
377+
#### Linux
378+
379+
You can install it using the package manager, e.g. `sudo apt install ccache`
380+
(Ubuntu) or `sudo dnf install ccache` (RHEL).
381+
382+
#### macOS
383+
384+
You can install it using Homebrew, i.e. `brew install ccache`.
385+
386+
#### Windows
387+
388+
You can install it using Chocolatey, i.e. `choco install ccache`. If you already
389+
have Ccache installed, then `choco upgrade ccache` will update it to the latest
390+
version. However, if you see an error such as:
391+
392+
```
393+
terminate called after throwing an instance of 'std::bad_alloc'
394+
what(): std::bad_alloc
395+
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppCommon.targets(617,5): error MSB6006: "cl.exe" exited with code 3.
396+
```
397+
398+
then please install a specific version of Ccache that we know works, via: `choco
399+
install ccache --version 4.11.3 --allow-downgrade`.
400+
371401
### Build and Test
372402

373403
1. Create a build directory and move into it.
@@ -545,16 +575,10 @@ See [Sanitizers docs](./docs/build/sanitizers.md) for more details.
545575
| `assert` | OFF | Enable assertions. |
546576
| `coverage` | OFF | Prepare the coverage report. |
547577
| `tests` | OFF | Build tests. |
548-
| `unity` | OFF | Configure a unity build. |
549578
| `xrpld` | OFF | Build the xrpld application, and not just the libxrpl library. |
550579
| `werr` | OFF | Treat compilation warnings as errors |
551580
| `wextra` | OFF | Enable additional compilation warnings |
552581

553-
[Unity builds][5] may be faster for the first build
554-
(at the cost of much more memory) since they concatenate sources into fewer
555-
translation units. Non-unity builds may be faster for incremental builds,
556-
and can be helpful for detecting `#include` omissions.
557-
558582
## Troubleshooting
559583

560584
### Conan
@@ -621,7 +645,6 @@ If you want to experiment with a new package, follow these steps:
621645
[1]: https://github.com/conan-io/conan-center-index/issues/13168
622646
[2]: https://en.cppreference.com/w/cpp/compiler_support/20
623647
[3]: https://docs.conan.io/en/latest/getting_started.html
624-
[5]: https://en.wikipedia.org/wiki/Unity_build
625648
[6]: https://github.com/boostorg/beast/issues/2648
626649
[7]: https://github.com/boostorg/beast/issues/2661
627650
[gcovr]: https://gcovr.com/en/stable/getting-started.html

cmake/XrplAddTest.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,5 @@ function (xrpl_add_test name)
99

1010
isolate_headers(${target} "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/tests/${name}" PRIVATE)
1111

12-
# Make sure the test isn't optimized away in unity builds
13-
set_target_properties(${target} PROPERTIES UNITY_BUILD_MODE GROUP UNITY_BUILD_BATCH_SIZE 0) # Adjust as needed
14-
1512
add_test(NAME ${target} COMMAND ${target})
1613
endfunction ()

cmake/XrplCore.cmake

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44

55
include(target_protobuf_sources)
66

7-
# Protocol buffers cannot participate in a unity build,
8-
# because all the generated sources
9-
# define a bunch of `static const` variables with the same names,
10-
# so we just build them as a separate library.
117
add_library(xrpl.libpb)
12-
set_target_properties(xrpl.libpb PROPERTIES UNITY_BUILD OFF)
138
target_protobuf_sources(xrpl.libpb xrpl/proto LANGUAGE cpp IMPORT_DIRS include/xrpl/proto
149
PROTOS include/xrpl/proto/xrpl.proto)
1510

@@ -160,12 +155,4 @@ if (xrpld)
160155
# antithesis_instrumentation.h, which is not exported as INTERFACE
161156
target_include_directories(xrpld PRIVATE ${CMAKE_SOURCE_DIR}/external/antithesis-sdk)
162157
endif ()
163-
164-
# any files that don't play well with unity should be added here
165-
if (tests)
166-
set_source_files_properties(
167-
# these two seem to produce conflicts in beast teardown template methods
168-
src/test/rpc/ValidatorRPC_test.cpp src/test/ledger/Invariants_test.cpp PROPERTIES SKIP_UNITY_BUILD_INCLUSION
169-
TRUE)
170-
endif ()
171158
endif ()

cmake/XrplSettings.cmake

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,6 @@ if (tests)
3030
endif ()
3131
endif ()
3232

33-
option(unity "Creates a build using UNITY support in cmake." OFF)
34-
if (unity)
35-
if (NOT is_ci)
36-
set(CMAKE_UNITY_BUILD_BATCH_SIZE 15 CACHE STRING "")
37-
endif ()
38-
set(CMAKE_UNITY_BUILD ON CACHE BOOL "Do a unity build")
39-
endif ()
40-
4133
if (is_clang AND is_linux)
4234
option(voidstar "Enable Antithesis instrumentation." OFF)
4335
endif ()

conanfile.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ class Xrpl(ConanFile):
2323
"shared": [True, False],
2424
"static": [True, False],
2525
"tests": [True, False],
26-
"unity": [True, False],
2726
"xrpld": [True, False],
2827
}
2928

@@ -55,7 +54,6 @@ class Xrpl(ConanFile):
5554
"shared": False,
5655
"static": True,
5756
"tests": False,
58-
"unity": False,
5957
"xrpld": False,
6058
"date/*:header_only": True,
6159
"ed25519/*:shared": False,
@@ -168,7 +166,6 @@ def generate(self):
168166
tc.variables["rocksdb"] = self.options.rocksdb
169167
tc.variables["BUILD_SHARED_LIBS"] = self.options.shared
170168
tc.variables["static"] = self.options.static
171-
tc.variables["unity"] = self.options.unity
172169
tc.variables["xrpld"] = self.options.xrpld
173170
tc.generate()
174171

include/xrpl/basics/rocksdb.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef XRPL_UNITY_ROCKSDB_H_INCLUDED
2-
#define XRPL_UNITY_ROCKSDB_H_INCLUDED
1+
#ifndef XRPL_BASICS_ROCKSDB_H_INCLUDED
2+
#define XRPL_BASICS_ROCKSDB_H_INCLUDED
33

44
#if XRPL_ROCKSDB_AVAILABLE
55
// #include <rocksdb2/port/port_posix.h>

0 commit comments

Comments
 (0)