Skip to content

Commit b48c1c7

Browse files
jleibstraversaroWumpf
authored
Add example of downloading rerun c++ lib via pixi (#30)
* Add example of downloading rerun c++ lib via pixi * Simplify pixi through environments * spell * fix bat file env var substitution --------- Co-authored-by: Silvio Traversaro <[email protected]> Co-authored-by: Andreas Reich <[email protected]>
1 parent 3d087b9 commit b48c1c7

File tree

8 files changed

+2998
-507
lines changed

8 files changed

+2998
-507
lines changed

.github/workflows/cpp.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ jobs:
1414
pixi-version: v0.25.0
1515
cache: true
1616

17-
- run: pixi run build
17+
- name: run build task on all environments
18+
run: |
19+
pixi run build-fetchcontent
20+
pixi run build-findpackage

.gitignore

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Build directory
2-
build
1+
# Build directories
2+
build_*
33

44
# Pixi environment
55
.pixi

README.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@ This is a minimal CMake project that shows how to use [Rerun](https://github.com
1616
The easiest way to get started is to install [pixi](https://prefix.dev/docs/pixi/overview).
1717

1818
The pixi environment described in `pixi.toml` contains all of the dependencies, including the rerun viewer,
19-
allowing you to run the example with a single command:
19+
allowing you to run the example with a single command, while the rerun C++ SDK is downloaded via `FetchContent`
2020
* `pixi run example`
2121

22+
If you want to also download rerun C++ SDK via pixi, you can run:
23+
* `pixi run example-findpackage`
24+
2225
## Without `pixi`
2326
If you choose not to use pixi, you will need to install a few things yourself before you get started.
2427

cspell.json

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"ignoreWords": [
66
"eigen",
77
"Eigen",
8+
"findpackage",
89
"pixi",
910
"srcset"
1011
]

pixi.lock

+2,914-488
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pixi.toml

+67-15
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,73 @@ readme = "README.md"
2121
repository = "https://github.com/rerun-io/cpp-example-opencv-eigen"
2222
version = "0.1.0"
2323

24+
# The following activation scripts make the tasks portable cross-platform.
25+
#
26+
# They define:
27+
# - CMAKE_GENERATOR
28+
# - BUILD_FOLDER
29+
# - EXE_PATH
30+
#
31+
# In particular, BUILD_FOLDER will be set to either:
32+
# - build_fetchcontent
33+
# - build_findpackage
34+
# depending on the feature being used.
35+
[activation]
36+
scripts = ["pixi/env.sh"]
37+
38+
[target.win-64.activation]
39+
scripts = ["pixi/env.bat"]
40+
41+
################################################################################
42+
# Common Tasks
43+
################################################################################
2444

2545
[tasks]
26-
# Note: extra CLI argument after `pixi run TASK` are passed to the task cmd.
27-
clean = { cmd = "rm -rf build bin CMakeFiles/" }
46+
2847
print-env = { cmd = "echo $PATH" }
2948

30-
[target.win-64.tasks]
31-
prepare = "cmake -G 'Visual Studio 17 2022' -B build -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo"
32-
build = { cmd = "cmake --build build --config RelWithDebInfo", depends_on = [
33-
"prepare",
34-
] }
35-
example = { cmd = "build/RelWithDebInfo/rerun_ext_example.exe", depends_on = [
36-
"build",
49+
[target.unix.tasks]
50+
# This task only runs properly Unix systems.
51+
format = { cmd = "clang-format -i src/*" }
52+
53+
################################################################################
54+
# Building against Rerun using the default of FetchContent.
55+
#
56+
# The rerun-cpp source will be downloaded and built as part of the build.
57+
################################################################################
58+
[feature.fetchcontent.tasks]
59+
60+
prepare-fetchcontent = "cmake -B $BUILD_FOLDER -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo"
61+
62+
build-fetchcontent = { cmd = "cmake --build $BUILD_FOLDER --config RelWithDebInfo", depends_on = [
63+
"prepare-fetchcontent",
3764
] }
3865

39-
[target.unix.tasks]
40-
prepare = "cmake -G 'Ninja' -B build -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo"
41-
build = { cmd = "cmake --build build --config RelWithDebInfo --target all", depends_on = [
42-
"prepare",
66+
example = { cmd = "$EXE_PATH", depends_on = ["build-fetchcontent"] }
67+
68+
clean = { cmd = "rm -rf $BUILD_FOLDER bin CMakeFiles/" }
69+
70+
################################################################################
71+
# Alternatively, build by locating Rerun via find_package
72+
#
73+
# In this case rerun is provided by the `librerun-sdk` package in the
74+
# conda environment.
75+
################################################################################
76+
[feature.findpackage.tasks]
77+
78+
prepare-findpackage = "cmake -B $BUILD_FOLDER -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DRERUN_FIND_PACKAGE:BOOL=ON"
79+
80+
build-findpackage = { cmd = "cmake --build $BUILD_FOLDER --config RelWithDebInfo", depends_on = [
81+
"prepare-findpackage",
4382
] }
44-
example = { cmd = "build/rerun_ext_example", depends_on = ["build"] }
45-
format = { cmd = "clang-format -i src/*" }
4683

84+
example-findpackage = { cmd = "$EXE_PATH", depends_on = ["build-findpackage"] }
85+
86+
clean = { cmd = "rm -rf $BUILD_FOLDER bin CMakeFiles/" }
87+
88+
################################################################################
89+
# Dependencies
90+
################################################################################
4791
[dependencies]
4892
# Build tools:
4993
clang-tools = ">=15,<16" # clang-format
@@ -63,3 +107,11 @@ ninja = "1.11.1"
63107
[target.win-64.dependencies]
64108
# Build tools:
65109
vs2022_win-64 = "19.37.32822"
110+
111+
[feature.findpackage.dependencies]
112+
librerun-sdk = "0.17.0.*"
113+
114+
[environments]
115+
default = { solve-group = "defaultgroup" }
116+
fetchcontent = { features = ["fetchcontent"], solve-group = "defaultgroup" }
117+
findpackage = { features = ["findpackage"], solve-group = "defaultgroup" }

pixi/env.bat

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
set CMAKE_GENERATOR="Visual Studio 17 2022"
2+
set BUILD_FOLDER=build_%PIXI_ENVIRONMENT_NAME%
3+
set EXE_PATH=%BUILD_FOLDER%/RelWithDebInfo/rerun_ext_example

pixi/env.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export CMAKE_GENERATOR=Ninja
2+
export BUILD_FOLDER=build_${PIXI_ENVIRONMENT_NAME}
3+
export EXE_PATH=$BUILD_FOLDER/rerun_ext_example

0 commit comments

Comments
 (0)