Skip to content

Commit 8bd3834

Browse files
committed
Support out-of-tree builds
1 parent ef4639c commit 8bd3834

13 files changed

Lines changed: 73 additions & 40 deletions

File tree

ci-build.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ NPROCS=$(getconf _NPROCESSORS_ONLN)
5858
echo "Found $NPROCS processors"
5959
date
6060

61+
mkdir -p "build-${CC}-${PROTOCOL}"
62+
cd "build-${CC}-${PROTOCOL}"
63+
6164
# Try to ensure we're using the real g++ and clang++ versions we want
6265
mkdir -p bin
6366

@@ -101,7 +104,7 @@ export ASAN_OPTIONS="quarantine_size_mb=100:malloc_context_size=4:detect_leaks=0
101104
echo "config_flags = $config_flags"
102105

103106
#### ccache config
104-
export CCACHE_DIR=$HOME/.ccache
107+
export CCACHE_DIR=$(pwd)/.ccache
105108
export CCACHE_COMPRESS=true
106109
export CCACHE_COMPRESSLEVEL=9
107110
# cache size should be large enough for a full build
@@ -117,11 +120,10 @@ if [ -d "$CCACHE_DIR" ] ; then
117120
fi
118121

119122
ccache -p
120-
121123
ccache -s
122124
date
123-
time ./autogen.sh
124-
time ./configure $config_flags
125+
time (cd .. && ./autogen.sh)
126+
time ../configure $config_flags
125127
if [ -z "${SKIP_FORMAT_CHECK}" ]; then
126128
make format
127129
d=`git diff | wc -l`
@@ -145,9 +147,8 @@ date
145147
time make -j$(($NPROCS - 1))
146148

147149
ccache -s
148-
### incrementally purge old content from cargo source cache and target directory
149-
cargo cache trim --limit 100M
150-
cargo sweep --maxsize 500MB
150+
### incrementally purge old content from target directory
151+
(cd .. && CARGO_TARGET_DIR="build-${CC}-${PROTOCOL}/target" cargo sweep --maxsize 800MB)
151152

152153
if [ $WITH_TESTS -eq 0 ] ; then
153154
echo "Build done, skipping tests"

src/Makefile.am

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ endif # !BUILD_TESTS
6565
if ENABLE_NEXT_PROTOCOL_VERSION_UNSAFE_FOR_PRODUCTION
6666
CARGO_FEATURE_NEXT = --features next
6767
main/XDRFilesSha256.cpp: $(SRC_X_FILES) Makefile $(top_srcdir)/hash-xdrs.sh
68-
$(top_srcdir)/hash-xdrs.sh protocol-next >$@
68+
$(top_srcdir)/hash-xdrs.sh $(top_srcdir)/src/protocol-next >$@
6969
else
7070
CARGO_FEATURE_NEXT =
7171
main/XDRFilesSha256.cpp: $(SRC_X_FILES) Makefile $(top_srcdir)/hash-xdrs.sh
72-
$(top_srcdir)/hash-xdrs.sh protocol-curr >$@
72+
$(top_srcdir)/hash-xdrs.sh $(top_srcdir)/src/protocol-curr >$@
7373
endif
7474

7575
stellar_core_LDADD = $(soci_LIBS) $(libmedida_LIBS) \
@@ -89,6 +89,7 @@ BUILT_SOURCES = $(SRC_X_FILES:.x=.h) main/StellarCoreVersion.cpp main/XDRFilesSh
8989
$(SRC_X_FILES:.x=.h): $(XDRC)
9090
SUFFIXES = .x .h .rs
9191
.x.h:
92+
mkdir -p $(@D)
9293
$(XDRC) -hh -pedantic -o $@ $<
9394

9495
BISON=bison
@@ -124,9 +125,11 @@ RUST_TOOLCHAIN_CHANNEL=$(shell sed -n 's/channel *= *"\([^"]*\)"/\1/p' $(RUST_TO
124125
endif
125126
CARGO=cargo +$(RUST_TOOLCHAIN_CHANNEL)
126127

127-
# we pass RUST_TOOLCHAIN_CHANNEL by environment variable
128+
# we pass some configuration by environment variable
128129
# to tests since they can't take command-line arguments.
129130
export RUST_TOOLCHAIN_CHANNEL
131+
export top_srcdir
132+
export top_builddir
130133

131134
RUST_BUILD_DIR=$(top_builddir)/src/rust
132135
RUST_BIN_DIR=$(RUST_BUILD_DIR)/bin
@@ -233,11 +236,12 @@ rust/RustBridge.cpp: rust/src/bridge.rs $(SRC_RUST_FILES) Makefile $(RUST_CXXBRI
233236

234237
$(RUST_DEP_TREE_STAMP): $(wildcard rust/soroban/*/Cargo.*) Makefile $(RUST_TOOLCHAIN_FILE)
235238
rm -f $@
239+
mkdir -p $(RUST_BUILD_DIR)/src/dep-trees
236240
for proto in $(ALL_SOROBAN_PROTOCOLS); \
237241
do \
238-
$(CARGO) tree --manifest-path rust/soroban/$${proto}/Cargo.toml --locked --package soroban-env-host --edges no-dev --target all \
242+
$(CARGO) tree --manifest-path $(top_srcdir)/src/rust/soroban/$${proto}/Cargo.toml --locked --package soroban-env-host --edges no-dev --target all \
239243
| sed -e "s@$(abspath $(top_srcdir))/@@g" > $(RUST_BUILD_DIR)/src/dep-trees/$${proto}-actual.txt ; \
240-
if ! diff -u rust/src/dep-trees/$${proto}-expect.txt $(RUST_BUILD_DIR)/src/dep-trees/$${proto}-actual.txt; \
244+
if ! diff -u $(top_srcdir)/src/rust/src/dep-trees/$${proto}-expect.txt $(RUST_BUILD_DIR)/src/dep-trees/$${proto}-actual.txt; \
241245
then \
242246
echo "dep trees differ, please update $${proto}-expect.txt or roll back submodule"; \
243247
exit 1; \
@@ -346,9 +350,11 @@ $(SOROBAN_LIBS_STAMP): $(wildcard rust/soroban/p*/Cargo.lock) Makefile $(RUST_DE
346350
FEATURE_FLAGS="$(CARGO_FEATURE_TRACY)" \
347351
;; \
348352
esac ; \
349-
cd $(abspath $(RUST_BUILD_DIR))/soroban/$$proto && \
353+
mkdir -p $(SOROBAN_BUILD_DIR)/$$proto/target && \
354+
cd $(abspath $(top_srcdir))/src/rust/soroban/$$proto && \
350355
CC="$(CC)" CXX="$(CXX)" LD="$(LD)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CXXSTDLIB="$(CXXSTDLIB)" LDFLAGS="$(LDFLAGS)" \
351356
RUSTFLAGS="-Cmetadata=$$proto" \
357+
CARGO_TARGET_DIR=$(SOROBAN_BUILD_DIR)/$$proto/target \
352358
CARGO_NET_GIT_FETCH_WITH_CLI=true \
353359
$(CARGO) build \
354360
--package soroban-env-host \

src/herder/test/TxSetTests.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2260,11 +2260,10 @@ TEST_CASE("txset nomination", "[txset]")
22602260
{
22612261
runIteration();
22622262
}
2263-
namespace fs = std::filesystem;
2264-
fs::path resultsPath = "testdata/txset/" + testName;
2265-
fs::create_directories(resultsPath.parent_path());
2263+
auto resultsPath = getSrcTestDataPath("txset/" + testName);
22662264
if (getenv("GENERATE_TEST_TXSETS"))
22672265
{
2266+
std::filesystem::create_directories(resultsPath.parent_path());
22682267
std::ofstream resultsStream(resultsPath);
22692268
for (auto const& result : testResults)
22702269
{

src/history/test/SerializeTests.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "history/HistoryArchive.h"
66
#include "test/Catch2.h"
7+
#include "test/test.h"
78

89
#include <fstream>
910
#include <string>
@@ -19,9 +20,8 @@ TEST_CASE("Serialization round trip", "[history]")
1920
"stellar-history.testnet.6714239.networkPassphrase.v2.json"};
2021
for (size_t i = 0; i < testFiles.size(); i++)
2122
{
22-
std::string fnPath = "testdata/";
23-
std::string testFilePath = fnPath + testFiles[i];
24-
SECTION("Serialize " + testFilePath)
23+
auto testFilePath = getBuildTestDataPath(testFiles[i]);
24+
SECTION("Serialize " + testFilePath.string())
2525
{
2626
std::ifstream in(testFilePath);
2727
REQUIRE(in);

src/ledger/test/LedgerCloseMetaStreamTests.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,11 @@ TEST_CASE_VERSIONS("meta stream contains reasonable meta", "[ledgerclosemeta]")
515515

516516
if (ledgerSeq == targetSeq)
517517
{
518-
std::string refJsonPath;
519-
refJsonPath = fmt::format(
520-
FMT_STRING(
521-
"testdata/ledger-close-meta{}-v{}-protocol-{}{}.json"),
518+
auto refJsonPath = getSrcTestDataPath(fmt::format(
519+
FMT_STRING("ledger-close-meta{}-v{}-protocol-{}{}.json"),
522520
enableClassicEvents ? "-enable-classic-events" : "",
523521
lcm.v(), cfg.TESTING_UPGRADE_LEDGER_PROTOCOL_VERSION,
524-
isSoroban ? "-soroban" : "");
522+
isSoroban ? "-soroban" : ""));
525523
normalizeMeta(lcm);
526524
std::string have = xdrToCerealString(lcm, "LedgerCloseMeta");
527525
if (getenv("GENERATE_TEST_LEDGER_CLOSE_META"))

src/main/test/ApplicationUtilsTests.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -173,18 +173,18 @@ TEST_CASE("application major version numbers", "[applicationutils]")
173173
TEST_CASE("standalone quorum intersection check", "[applicationutils]")
174174
{
175175
Config cfg = getTestConfig();
176-
const std::string JSON_ROOT = "testdata/check-quorum-intersection-json/";
176+
auto JSON_ROOT = getSrcTestDataPath("check-quorum-intersection-json");
177177

178178
SECTION("enjoys quorum intersection")
179179
{
180180
REQUIRE(checkQuorumIntersectionFromJson(
181-
JSON_ROOT + "enjoys-intersection.json", cfg));
181+
JSON_ROOT / "enjoys-intersection.json", cfg));
182182
}
183183

184184
SECTION("does not enjoy quorum intersection")
185185
{
186186
REQUIRE(!checkQuorumIntersectionFromJson(
187-
JSON_ROOT + "no-intersection.json", cfg));
187+
JSON_ROOT / "no-intersection.json", cfg));
188188
}
189189

190190
SECTION("malformed JSON")
@@ -193,17 +193,17 @@ TEST_CASE("standalone quorum intersection check", "[applicationutils]")
193193

194194
// Malformed key
195195
REQUIRE_THROWS_AS(
196-
checkQuorumIntersectionFromJson(JSON_ROOT + "bad-key.json", cfg),
196+
checkQuorumIntersectionFromJson(JSON_ROOT / "bad-key.json", cfg),
197197
KeyUtils::InvalidStrKey);
198198

199199
// Wrong datatype
200200
REQUIRE_THROWS_AS(checkQuorumIntersectionFromJson(
201-
JSON_ROOT + "bad-threshold-type.json", cfg),
201+
JSON_ROOT / "bad-threshold-type.json", cfg),
202202
std::runtime_error);
203203

204204
// No such file
205205
REQUIRE_THROWS_AS(
206-
checkQuorumIntersectionFromJson(JSON_ROOT + "no-file.json", cfg),
206+
checkQuorumIntersectionFromJson(JSON_ROOT / "no-file.json", cfg),
207207
std::runtime_error);
208208
}
209-
}
209+
}

src/main/test/ConfigTests.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ TEST_CASE("resolve node id", "[config]")
147147
TEST_CASE("load validators config", "[config]")
148148
{
149149
Config c;
150-
c.load("testdata/stellar-core_example_validators.cfg");
150+
c.load(getBuildTestDataPath("stellar-core_example_validators.cfg"));
151151
auto actualS = c.toString(c.QUORUM_SET);
152152
std::string expected = R"({
153153
"t" : 4,
@@ -456,9 +456,8 @@ TEST_CASE("load example configs", "[config]")
456456
"stellar-core_testnet_validator.cfg"};
457457
for (auto const& fn : testFiles)
458458
{
459-
std::string fnPath = "testdata/";
460-
fnPath += fn;
461-
SECTION("load config " + fnPath)
459+
auto fnPath = getBuildTestDataPath(fn);
460+
SECTION("load config " + fnPath.string())
462461
{
463462
c.load(fnPath);
464463
}
@@ -628,4 +627,4 @@ PUBLIC_KEY="GBVZFVEARURUJTN5ABZPKW36FHKVJK2GHXEVY2SZCCNU5I3CQMTZ3OES"
628627
)";
629628
std::stringstream ss(configStr);
630629
c.load(ss);
631-
}
630+
}

src/test/check-sorobans

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ SKIP_TESTS="host::declared_size::test::test_expected_size"
2828
set -e
2929
set -x
3030

31-
cd rust/soroban
31+
cd "${top_srcdir}/src/rust/soroban"
3232
for i in p??; do
3333
cd $i
34+
CARGO_TARGET_DIR="${top_builddir}/src/rust/soroban/${i}/target" \
3435
RUSTFLAGS="-Cmetadata=${i}" cargo +${RUST_TOOLCHAIN_CHANNEL} \
3536
test \
3637
--locked \

src/test/selftest-nopg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# under the Apache License, Version 2.0. See the COPYING file at the root
55
# of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
66

7-
exec ./test/selftest-parallel ./test/run-selftest-nopg
7+
exec "${top_srcdir}/src/test/selftest-parallel" "${top_srcdir}/src/test/run-selftest-nopg"

src/test/selftest-parallel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,5 @@ for i in $RUN_PARTITIONS; do
8989
cat $TEST_PARTITIONS_DIR/test-partition-$i.txt >> $TESTS
9090
done
9191

92-
cat $TESTS | parallel -j $nparts -n $BATCHSIZE --line-buffer --tag-string '{%}' --progress --halt-on-error 2 runpart '{%}' "{}"
92+
cat $TESTS | parallel -j $nparts -n $BATCHSIZE --line-buffer --tag-string '{%}' --halt-on-error 2 runpart '{%}' "{}"
9393

0 commit comments

Comments
 (0)