Skip to content

Commit 1fbd5ec

Browse files
committed
Simplify pixi through environments
1 parent aee3b0d commit 1fbd5ec

File tree

7 files changed

+1210
-42
lines changed

7 files changed

+1210
-42
lines changed

.github/workflows/cpp.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ jobs:
1616

1717
- name: run build task on all environments
1818
run: |
19-
pixi run -e default build
20-
pixi run -e rerunfindpackage build
19+
pixi run build-fetchcontent
20+
pixi run build-findpackage

.gitignore

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Build directories
2-
build
3-
buildrerunfindpackage
2+
build_*
43

54
# Pixi environment
65
.pixi

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ The easiest way to get started is to install [pixi](https://prefix.dev/docs/pixi
1717

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

2222
If you want to also download rerun C++ SDK via pixi, you can run:
23-
* `pixi run -e rerundfindpackage example`
23+
* `pixi run example-findpackage`
2424

2525
## Without `pixi`
2626
If you choose not to use pixi, you will need to install a few things yourself before you get started.

pixi.lock

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

pixi.toml

+58-35
Original file line numberDiff line numberDiff line change
@@ -21,49 +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/" }
28-
print-env = { cmd = "echo $PATH" }
2946

30-
[target.win-64.tasks]
31-
prepare = "cmake -G 'Visual Studio 17 2022' -B build -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DRERUN_FIND_PACKAGE:BOOL=OFF"
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",
37-
] }
47+
print-env = { cmd = "echo $PATH" }
3848

3949
[target.unix.tasks]
40-
prepare = "cmake -G 'Ninja' -B build -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DRERUN_FIND_PACKAGE:BOOL=OFF"
41-
build = { cmd = "cmake --build build --config RelWithDebInfo --target all", depends_on = [
42-
"prepare",
43-
] }
44-
example = { cmd = "build/rerun_ext_example", depends_on = ["build"] }
50+
# This task only runs propertly Unix systems.
4551
format = { cmd = "clang-format -i src/*" }
4652

47-
[feature.rerunfindpackage.target.win-64.tasks]
48-
prepare = "cmake -G 'Visual Studio 17 2022' -B buildrerunfindpackage -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DRERUN_FIND_PACKAGE:BOOL=ON"
49-
build = { cmd = "cmake --build buildrerunfindpackage --config RelWithDebInfo", depends_on = [
50-
"prepare",
51-
] }
52-
example = { cmd = "buildrerunfindpackage/RelWithDebInfo/rerun_ext_example.exe", depends_on = [
53-
"build",
54-
] }
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"
5561

56-
[feature.rerunfindpackage.target.unix.tasks]
57-
prepare = "cmake -G 'Ninja' -B buildrerunfindpackage -S . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DRERUN_FIND_PACKAGE:BOOL=ON"
58-
build = { cmd = "cmake --build buildrerunfindpackage --config RelWithDebInfo --target all", depends_on = [
59-
"prepare",
62+
build-fetchcontent = { cmd = "cmake --build $BUILD_FOLDER --config RelWithDebInfo", depends_on = [
63+
"prepare-fetchcontent",
6064
] }
61-
example = { cmd = "buildrerunfindpackage/rerun_ext_example", depends_on = [
62-
"build",
65+
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",
6382
] }
64-
format = { cmd = "clang-format -i src/*" }
6583

84+
example-findpackage = { cmd = "$EXE_PATH", depends_on = ["build-findpackage"] }
85+
86+
clean = { cmd = "rm -rf $BUILD_FOLDER bin CMakeFiles/" }
6687

88+
################################################################################
89+
# Dependencies
90+
################################################################################
6791
[dependencies]
6892
# Build tools:
6993
clang-tools = ">=15,<16" # clang-format
@@ -84,11 +108,10 @@ ninja = "1.11.1"
84108
# Build tools:
85109
vs2022_win-64 = "19.37.32822"
86110

87-
[feature.rerunfindpackage.dependencies]
111+
[feature.findpackage.dependencies]
88112
librerun-sdk = "0.17.0.*"
89113

90114
[environments]
91115
default = { solve-group = "defaultgroup" }
92-
rerunfindpackage = { features = [
93-
"rerunfindpackage",
94-
], 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)