Skip to content

Commit 409e6b9

Browse files
authored
Use different C++ build directories for debug/release and roundtrips (#4282)
### What It got too annoying to rebuild libarrow whenever switching between roundtrips, tests and benchmarks. This PR puts each of those into a different build folder. ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested [demo.rerun.io](https://demo.rerun.io/pr/4282) (if applicable) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4282) - [Docs preview](https://rerun.io/preview/3849601eb18e8cf179ab83db0252ac8d7d2517da/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/3849601eb18e8cf179ab83db0252ac8d7d2517da/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
1 parent b5918ff commit 409e6b9

File tree

5 files changed

+127
-147
lines changed

5 files changed

+127
-147
lines changed

docs/code-examples/roundtrips.py

+5-70
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import argparse
88
import multiprocessing
99
import os
10-
import subprocess
1110
import sys
1211
import time
1312
from os import listdir
1413
from os.path import isfile, join
1514

15+
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../../scripts/")
16+
from roundtrip_utils import cmake_build, cmake_configure, cpp_build_dir, roundtrip_env, run, run_comparison # noqa
17+
1618
# fmt: off
1719

1820
# These entries won't run at all.
@@ -57,16 +59,6 @@
5759
# fmt: on
5860

5961

60-
def run(
61-
args: list[str], *, env: dict[str, str] | None = None, timeout: int | None = None, cwd: str | None = None
62-
) -> None:
63-
print(f"> {subprocess.list2cmdline(args)}")
64-
result = subprocess.run(args, env=env, cwd=cwd, timeout=timeout, check=False, capture_output=True, text=True)
65-
assert (
66-
result.returncode == 0
67-
), f"{subprocess.list2cmdline(args)} failed with exit-code {result.returncode}. Output:\n{result.stdout}\n{result.stderr}"
68-
69-
7062
def main() -> None:
7163
parser = argparse.ArgumentParser(description="Run end-to-end cross-language roundtrip tests for all API examples")
7264
parser.add_argument("--no-py", action="store_true", help="Skip Python tests")
@@ -115,16 +107,7 @@ def main() -> None:
115107
print("----------------------------------------------------------")
116108
print("Build rerun_c & rerun_cpp…")
117109
start_time = time.time()
118-
os.makedirs("build", exist_ok=True)
119-
build_type = "Debug"
120-
if args.release:
121-
build_type = "Release"
122-
configure_args = ["cmake", f"-DCMAKE_BUILD_TYPE={build_type}", "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON", ".."]
123-
run(
124-
configure_args,
125-
env=build_env,
126-
cwd="build",
127-
)
110+
cmake_configure(args.release, build_env)
128111
cmake_build("rerun_sdk", args.release)
129112
elapsed = time.time() - start_time
130113
print(f"rerun-sdk for C++ built in {elapsed:.1f} seconds")
@@ -218,26 +201,6 @@ def run_example(example: str, language: str, args: argparse.Namespace) -> None:
218201
assert False, f"Unknown language: {language}"
219202

220203

221-
def roundtrip_env(*, save_path: str | None = None) -> dict[str, str]:
222-
env = os.environ.copy()
223-
224-
# NOTE: Make sure to disable batching, otherwise the Arrow concatenation logic within
225-
# the batcher will happily insert uninitialized padding bytes as needed!
226-
env["RERUN_FLUSH_NUM_ROWS"] = "0"
227-
228-
# Turn on strict mode to catch errors early
229-
env["RERUN_STRICT"] = "1"
230-
231-
# Treat any warning as panics
232-
env["RERUN_PANIC_ON_WARN"] = "1"
233-
234-
if save_path:
235-
# NOTE: Force the recording stream to write to disk!
236-
env["_RERUN_TEST_FORCE_SAVE"] = save_path
237-
238-
return env
239-
240-
241204
def run_roundtrip_python(example: str) -> str:
242205
main_path = f"docs/code-examples/{example}.py"
243206
output_path = f"docs/code-examples/{example}_py.rrd"
@@ -284,41 +247,13 @@ def run_roundtrip_cpp(example: str, release: bool) -> str:
284247

285248
cmake_build(target_name, release)
286249

287-
cmd = [f"./build/docs/code-examples/{example}"] + (extra_args.get(example) or [])
250+
cmd = [f"{cpp_build_dir}/docs/code-examples/{example}"] + (extra_args.get(example) or [])
288251
env = roundtrip_env(save_path=output_path)
289252
run(cmd, env=env, timeout=12000)
290253

291254
return output_path
292255

293256

294-
def cmake_build(target: str, release: bool) -> None:
295-
config = "Debug"
296-
if release:
297-
config = "Release"
298-
299-
build_process_args = [
300-
"cmake",
301-
"--build",
302-
".",
303-
"--config",
304-
config,
305-
"--target",
306-
target,
307-
"--parallel",
308-
str(multiprocessing.cpu_count()),
309-
]
310-
run(build_process_args, cwd="build")
311-
312-
313-
def run_comparison(rrd0_path: str, rrd1_path: str, full_dump: bool) -> None:
314-
cmd = ["rerun", "compare"]
315-
if full_dump:
316-
cmd += ["--full-dump"]
317-
cmd += [rrd0_path, rrd1_path]
318-
319-
run(cmd, env=roundtrip_env(), timeout=30)
320-
321-
322257
def check_non_empty_rrd(path: str) -> None:
323258
from pathlib import Path
324259

pixi.toml

+10-10
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,31 @@ py-test = { cmd = "python -m pytest -vv rerun_py/tests/unit", depends_on = [
4848
] }
4949

5050
# All the cpp-* tasks can be configured with environment variables, e.g.: RERUN_WERROR=ON CXX=clang++
51-
cpp-prepare-release = "cmake -G 'Ninja' -B build -S . -DCMAKE_BUILD_TYPE=Release"
52-
cpp-prepare = "cmake -G 'Ninja' -B build -S . -DCMAKE_BUILD_TYPE=Debug"
53-
cpp-build-all = { cmd = "cmake --build build --config Debug --target all", depends_on = [
51+
cpp-prepare-release = "cmake -G 'Ninja' -B build/release -S . -DCMAKE_BUILD_TYPE=Release"
52+
cpp-prepare = "cmake -G 'Ninja' -B build/debug -S . -DCMAKE_BUILD_TYPE=Debug"
53+
cpp-build-all = { cmd = "cmake --build build/debug --config Debug --target all", depends_on = [
5454
"cpp-prepare",
5555
] }
5656
cpp-clean = "rm -rf build CMakeCache.txt CMakeFiles"
57-
cpp-build-tests = { cmd = "cmake --build build --config Debug --target rerun_sdk_tests", depends_on = [
57+
cpp-build-tests = { cmd = "cmake --build build/debug --config Debug --target rerun_sdk_tests", depends_on = [
5858
"cpp-prepare",
5959
] }
60-
cpp-build-roundtrips = { cmd = "cmake --build build --config Debug --target roundtrips", depends_on = [
60+
cpp-build-roundtrips = { cmd = "cmake --build build/debug --config Debug --target roundtrips", depends_on = [
6161
"cpp-prepare",
6262
] }
63-
cpp-build-examples = { cmd = "cmake --build build --config Debug --target examples", depends_on = [
63+
cpp-build-examples = { cmd = "cmake --build build/debug --config Debug --target examples", depends_on = [
6464
"cpp-prepare",
6565
] }
66-
cpp-build-doc-examples = { cmd = "cmake --build build --config Debug --target doc_examples", depends_on = [
66+
cpp-build-doc-examples = { cmd = "cmake --build build/debug --config Debug --target doc_examples", depends_on = [
6767
"cpp-prepare",
6868
] }
69-
cpp-build-log-benchmark = { cmd = "cmake --build build --config Release --target log_benchmark", depends_on = [
69+
cpp-build-log-benchmark = { cmd = "cmake --build build/release --config Release --target log_benchmark", depends_on = [
7070
"cpp-prepare-release",
7171
] }
72-
cpp-test = { cmd = "export RERUN_STRICT=1 && ./build/rerun_cpp/tests/rerun_sdk_tests", depends_on = [
72+
cpp-test = { cmd = "export RERUN_STRICT=1 && ./build/debug/rerun_cpp/tests/rerun_sdk_tests", depends_on = [
7373
"cpp-build-tests",
7474
] }
75-
cpp-log-benchmark = { cmd = "export RERUN_STRICT=1 && ./build/tests/cpp/log_benchmark/log_benchmark", depends_on = [
75+
cpp-log-benchmark = { cmd = "export RERUN_STRICT=1 && ./build/release/tests/cpp/log_benchmark/log_benchmark", depends_on = [
7676
"cpp-build-log-benchmark",
7777
] }
7878
cpp-build-and-test-all = { depends_on = ["cpp-build-all", "cpp-test"] }

scripts/roundtrip_utils.py

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/usr/bin/env python3
2+
3+
"""Shared functionality for roundtrip tests."""
4+
5+
from __future__ import annotations
6+
7+
import multiprocessing
8+
import os
9+
import subprocess
10+
11+
cpp_build_dir = "./build/roundtrips"
12+
repo_root = None
13+
14+
15+
def get_repo_root() -> str:
16+
global repo_root
17+
if repo_root is not None:
18+
return repo_root
19+
else:
20+
get_rev_parse = subprocess.run(["git", "rev-parse", "--show-toplevel"], capture_output=True)
21+
assert get_rev_parse.returncode == 0
22+
repo_root = get_rev_parse.stdout.decode("utf-8").strip()
23+
print("Repository root:", repo_root)
24+
return repo_root
25+
26+
27+
def run(
28+
args: list[str], *, env: dict[str, str] | None = None, timeout: int | None = None, cwd: str | None = None
29+
) -> None:
30+
# Run from the repo root if not specify otherwise.
31+
if cwd is None:
32+
cwd = get_repo_root()
33+
34+
print(f"> {subprocess.list2cmdline(args)}")
35+
result = subprocess.run(args, env=env, cwd=cwd, timeout=timeout, check=False, capture_output=True, text=True)
36+
assert (
37+
result.returncode == 0
38+
), f"{subprocess.list2cmdline(args)} failed with exit-code {result.returncode}. Output:\n{result.stdout}\n{result.stderr}"
39+
40+
41+
def roundtrip_env(*, save_path: str | None = None) -> dict[str, str]:
42+
env = os.environ.copy()
43+
44+
# NOTE: Make sure to disable batching, otherwise the Arrow concatenation logic within
45+
# the batcher will happily insert uninitialized padding bytes as needed!
46+
env["RERUN_FLUSH_NUM_ROWS"] = "0"
47+
48+
# Turn on strict mode to catch errors early
49+
env["RERUN_STRICT"] = "1"
50+
51+
# Treat any warning as panics
52+
env["RERUN_PANIC_ON_WARN"] = "1"
53+
54+
if save_path:
55+
# NOTE: Force the recording stream to write to disk!
56+
env["_RERUN_TEST_FORCE_SAVE"] = save_path
57+
58+
return env
59+
60+
61+
def cmake_configure(release: bool, env: dict[str, str]) -> None:
62+
os.makedirs(cpp_build_dir, exist_ok=True)
63+
build_type = "Debug"
64+
if release:
65+
build_type = "Release"
66+
# TODO(andreas): We should pixi for the prepare so we can ensure we have build tooling ready
67+
configure_args = [
68+
"cmake",
69+
"-B",
70+
cpp_build_dir,
71+
f"-DCMAKE_BUILD_TYPE={build_type}",
72+
"-DCMAKE_COMPILE_WARNING_AS_ERROR=ON",
73+
".",
74+
]
75+
run(
76+
configure_args,
77+
env=env,
78+
)
79+
80+
81+
def cmake_build(target: str, release: bool) -> None:
82+
config = "Debug"
83+
if release:
84+
config = "Release"
85+
86+
build_process_args = [
87+
"cmake",
88+
"--build",
89+
cpp_build_dir,
90+
"--config",
91+
config,
92+
"--target",
93+
target,
94+
"--parallel",
95+
str(multiprocessing.cpu_count()),
96+
]
97+
run(build_process_args)
98+
99+
100+
def run_comparison(rrd0_path: str, rrd1_path: str, full_dump: bool) -> None:
101+
cmd = ["rerun", "compare"]
102+
if full_dump:
103+
cmd += ["--full-dump"]
104+
cmd += [rrd0_path, rrd1_path]
105+
106+
run(cmd, env=roundtrip_env(), timeout=30)

tests/cpp/log_benchmark/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// For better whole-executable timing capture you can also first build the executable and then run:
2626
// ```
2727
// pixi run cpp-build-log-benchmark
28-
// ./build/tests/cpp/log_benchmark/log_benchmark
28+
// ./build/release/tests/cpp/log_benchmark/log_benchmark
2929
// ```
3030
//
3131

tests/roundtrips.py

+5-66
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
import argparse
1313
import multiprocessing
1414
import os
15-
import subprocess
1615
import sys
1716
import time
1817
from os import listdir
1918
from os.path import isfile, join
2019

20+
sys.path.append(os.path.dirname(os.path.realpath(__file__)) + "/../scripts/")
21+
from roundtrip_utils import cmake_build, cmake_configure, cpp_build_dir, roundtrip_env, run, run_comparison # noqa
22+
2123
ARCHETYPES_PATH = "crates/re_types/definitions/rerun/archetypes"
2224

2325
opt_out = {
@@ -29,16 +31,6 @@
2931
}
3032

3133

32-
def run(
33-
args: list[str], *, env: dict[str, str] | None = None, timeout: int | None = None, cwd: str | None = None
34-
) -> None:
35-
print(f"> {subprocess.list2cmdline(args)}")
36-
result = subprocess.run(args, env=env, cwd=cwd, timeout=timeout, check=False, capture_output=True, text=True)
37-
assert (
38-
result.returncode == 0
39-
), f"{subprocess.list2cmdline(args)} failed with exit-code {result.returncode}. Output:\n{result.stdout}\n{result.stderr}"
40-
41-
4234
def main() -> None:
4335
parser = argparse.ArgumentParser(description="Run our end-to-end cross-language roundtrip tests for all SDK")
4436
parser.add_argument("--no-py-build", action="store_true", help="Skip building rerun-sdk for Python")
@@ -80,16 +72,7 @@ def main() -> None:
8072
print("----------------------------------------------------------")
8173
print("Build rerun_c & rerun_cpp…")
8274
start_time = time.time()
83-
os.makedirs("build", exist_ok=True)
84-
build_type = "Debug"
85-
if args.release:
86-
build_type = "Release"
87-
configure_args = ["cmake", f"-DCMAKE_BUILD_TYPE={build_type}", "-DCMAKE_COMPILE_WARNING_AS_ERROR=ON", ".."]
88-
run(
89-
configure_args,
90-
env=build_env,
91-
cwd="build",
92-
)
75+
cmake_configure(args.release, build_env)
9376
cmake_build("rerun_sdk", args.release)
9477
elapsed = time.time() - start_time
9578
print(f"rerun-sdk for C++ built in {elapsed:.1f} seconds")
@@ -155,22 +138,6 @@ def main() -> None:
155138
print("All tests passed!")
156139

157140

158-
def roundtrip_env() -> dict[str, str]:
159-
env = os.environ.copy()
160-
161-
# NOTE: Make sure to disable batching, otherwise the Arrow concatenation logic within
162-
# the batcher will happily insert uninitialized padding bytes as needed!
163-
env["RERUN_FLUSH_NUM_ROWS"] = "0"
164-
165-
# Turn on strict mode to catch errors early
166-
env["RERUN_STRICT"] = "1"
167-
168-
# Treat any warning as panics
169-
env["RERUN_PANIC_ON_WARN"] = "1"
170-
171-
return env
172-
173-
174141
def build(arch: str, language: str, args: argparse.Namespace) -> None:
175142
if language == "cpp":
176143
run_roundtrip_cpp(arch, args.release)
@@ -226,39 +193,11 @@ def run_roundtrip_cpp(arch: str, release: bool) -> str:
226193

227194
cmake_build(target_name, release)
228195

229-
cmd = [f"./build/tests/cpp/roundtrips/{target_name}", output_path]
196+
cmd = [f"{cpp_build_dir}/tests/cpp/roundtrips/{target_name}", output_path]
230197
run(cmd, env=roundtrip_env(), timeout=12000)
231198

232199
return output_path
233200

234201

235-
def cmake_build(target: str, release: bool) -> None:
236-
config = "Debug"
237-
if release:
238-
config = "Release"
239-
240-
build_process_args = [
241-
"cmake",
242-
"--build",
243-
".",
244-
"--config",
245-
config,
246-
"--target",
247-
target,
248-
"--parallel",
249-
str(multiprocessing.cpu_count()),
250-
]
251-
run(build_process_args, cwd="build")
252-
253-
254-
def run_comparison(rrd0_path: str, rrd1_path: str, full_dump: bool) -> None:
255-
cmd = ["rerun", "compare"]
256-
if full_dump:
257-
cmd += ["--full-dump"]
258-
cmd += [rrd0_path, rrd1_path]
259-
260-
run(cmd, env=roundtrip_env(), timeout=30)
261-
262-
263202
if __name__ == "__main__":
264203
main()

0 commit comments

Comments
 (0)