Initial commit
This commit is contained in:
@@ -0,0 +1,111 @@
|
||||
# siege-deck
|
||||
|
||||
A from-scratch tower defense deck-builder in C++26 on SDL3
|
||||
|
||||
## Getting started
|
||||
|
||||
With direnv:
|
||||
|
||||
```sh
|
||||
direnv allow # loads the devShell on cd
|
||||
cmake --preset debug
|
||||
cmake --build --preset debug
|
||||
./cmake-build-debug/bin/siege_deck
|
||||
```
|
||||
|
||||
Without direnv, prefix commands with `nix develop --command`.
|
||||
|
||||
`siege_deck --frames N` renders N frames and exits, so the smoke test can run
|
||||
unattended from a script or CI.
|
||||
|
||||
## Layout
|
||||
|
||||
| Path | What it is |
|
||||
|---------------------|------------------------------------------------------|
|
||||
| `flake.nix` | devShells: `default` (clang), `gcc` |
|
||||
| `CMakeLists.txt` | dependency pins + the single executable target |
|
||||
| `cmake/Cpm.cmake` | CPM bootstrap — nixpkgs copy, else pinned download |
|
||||
| `cmake/ImGui.cmake` | defines `imgui::imgui` from either nixpkgs or source |
|
||||
| `Source/` | `Common.h` (vocabulary types), `Pch.h`, `Main.cpp` |
|
||||
| `Assets/` | copied next to the executable after each build |
|
||||
|
||||
## How dependencies resolve
|
||||
|
||||
Every dependency is declared once, as a `CPMAddPackage` call, and resolves two
|
||||
different ways depending on where you build:
|
||||
|
||||
- **Inside the devShell** — `CPM_USE_LOCAL_PACKAGES=ON` makes each call try
|
||||
`find_package` first, and all of them hit nixpkgs. Nothing is downloaded and
|
||||
nothing is rebuilt; configure takes under a second.
|
||||
- **Anywhere else** (Windows, CI, a machine without nix) — CPM fetches and
|
||||
builds each one from its pinned tag.
|
||||
|
||||
Both paths are pinned to the *same* version on purpose. A dependency that
|
||||
differs between "on my machine" and "in the nix shell" is the class of bug
|
||||
this arrangement exists to prevent, so bumping one means bumping the other —
|
||||
or waiting for nixpkgs to catch up.
|
||||
|
||||
Two dependencies don't fit the pattern cleanly, and the comments in
|
||||
`CMakeLists.txt` and `cmake/ImGui.cmake` explain why: Boost exposes
|
||||
`Boost::type_index` only in the modular CMake build, so both sides target the
|
||||
header-only aggregate `Boost::headers` instead; and Dear ImGui ships no
|
||||
`CMakeLists.txt` upstream at all, so `cmake/ImGui.cmake` builds it by hand
|
||||
when nixpkgs isn't supplying it.
|
||||
|
||||
## CLion
|
||||
|
||||
CMake reloads need the devShell environment, and CLion has to be told where to
|
||||
get it. Once per machine:
|
||||
|
||||
1. **Settings → Build, Execution, Deployment → Toolchains**: add a System
|
||||
toolchain (e.g. `siege-deck (nix)`), then **Add environment → From file**
|
||||
and choose `cmake/clion-env.sh`. CLion sources that file before every CMake
|
||||
reload, build, run and debug session, so all of them get the flake's
|
||||
compiler, CMake, `CMAKE_PREFIX_PATH` and CPM settings.
|
||||
2. **Settings → Build, Execution, Deployment → CMake**: enable the `debug` and
|
||||
`release` profiles that come from `CMakePresets.json`, set their toolchain
|
||||
to the one from step 1, and delete the plain `Debug` profile CLion creates
|
||||
by itself. That profile shares `cmake-build-debug` with the `debug` preset.
|
||||
|
||||
The file loads the shell through direnv, so run `direnv allow` once in the
|
||||
checkout first.
|
||||
|
||||
The `intellij-direnv` plugin can't stand in for this. It only merges variables
|
||||
into Run/Debug configurations, and a CMake reload isn't one, so with the plugin
|
||||
alone CLion configures with no nix environment at all. It also writes a
|
||||
snapshot of nix store paths into every run configuration, which goes stale on
|
||||
the next `nix flake update`. The toolchain environment already covers runs, so
|
||||
the plugin isn't needed.
|
||||
|
||||
To see what CLion will inherit, sourced the way CLion does it (through your
|
||||
login shell):
|
||||
|
||||
```sh
|
||||
"$SHELL" -l -i -c 'source cmake/clion-env.sh 2>/dev/null; command -v cmake; echo $CXX; echo $CPM_CMAKE_PATH'
|
||||
```
|
||||
|
||||
### Launching from a terminal
|
||||
|
||||
`nix develop --command clion .` also works, but only because two system-level
|
||||
breakages were fixed in `~/homelab/hosts/terra/configuration.nix` — neither is
|
||||
specific to this project, and both made every Toolbox IDE unlaunchable outside
|
||||
the Toolbox GUI:
|
||||
|
||||
- `programs.nix-ld.libraries` was unset, so nix-ld's minimal default applied
|
||||
and carried no X11, freetype, wayland or xkbcommon. The bundled JBR died on
|
||||
`libX11.so.6: cannot open shared object file`.
|
||||
- `services.envfs.enable` now serves `/bin` and `/usr/bin` from the caller's
|
||||
PATH, so the `#!/bin/bash` shebang Toolbox writes into its shims resolves.
|
||||
NixOS ships only `/bin/sh`, so those shims previously failed everywhere.
|
||||
|
||||
Both need a `nixos-rebuild switch` to take effect. This flake deliberately
|
||||
carries no IDE wrapper of its own.
|
||||
|
||||
### clangd
|
||||
|
||||
The shell regenerates `.clangd` on every entry, pinning the compiler's real
|
||||
system include paths. Without it clangd cannot find the standard library on
|
||||
NixOS: those paths are injected by the cc-wrapper through `NIX_CFLAGS_COMPILE`
|
||||
at compile time, and clangd only ever reads `compile_commands.json`, so the
|
||||
build succeeds while every `#include <...>` goes red. The file is generated,
|
||||
gitignored, and rewritten to match whichever shell you entered.
|
||||
Reference in New Issue
Block a user