diff --git a/TODOS.md b/TODOS.md index 1b0480a..fe2ccd5 100644 --- a/TODOS.md +++ b/TODOS.md @@ -9,6 +9,14 @@ Remember to polish existing features before moving on to new ones. +- [ ] Bake the default `layouts` into the binary at compile time via + `#load_directory` so the binary is self-contained and doesn't read + `DEFAULTS_PATH` from disk at runtime. + - `#load_directory` is NOT recursive and its `name` is the base filename + only, so `defaults/layouts` and `defaults/layouts/partials` must be loaded + separately and mounted into the VFS with `data` set (not `fs_path`). + - Removes the runtime dependency on `THOR_DEFAULTS_PATH` / `#directory` and + the need to ship `defaults/` alongside the binary (see `flake.nix`). - [ ] `build` command alias of default - [ ] `new site` command to set up new project - [ ] Some render errors blank the entire page instead of scoping to the failing tag. diff --git a/defaults.odin b/defaults.odin index 757b79b..3261a74 100644 --- a/defaults.odin +++ b/defaults.odin @@ -2,4 +2,17 @@ package main import "core:os" -DEFAULTS_PATH :: #directory + os.Path_Separator_String + "defaults" +// Path to the built-in default layouts, resolved at runtime. +// +// The default points at the `defaults` directory next to the source tree (via +// `#directory`), which works for local `odin run`/`odin build` from the repo. +// Packaged builds install `defaults/` to a fixed location and override this +// with `-define:THOR_DEFAULTS_PATH=` (see flake.nix). +// +// TODO: bake these into the binary at compile time via `#load_directory` so the +// binary is self-contained and this runtime path goes away entirely. See +// TODOS.md. +DEFAULTS_PATH :: #config( + THOR_DEFAULTS_PATH, + #directory + os.Path_Separator_String + "defaults", +) diff --git a/flake.nix b/flake.nix index b4072e1..5195c5a 100644 --- a/flake.nix +++ b/flake.nix @@ -141,13 +141,20 @@ buildPhase = '' runHook preBuild - odin build . -o:speed -no-bounds-check -out:${pname}-keep + odin build . -o:speed -no-bounds-check \ + -define:THOR_DEFAULTS_PATH=$out/share/thor/defaults \ + -out:${pname}-keep runHook postBuild ''; installPhase = '' runHook preInstall install -Dm755 ${pname}-keep $out/bin/${pname} + # Ship the built-in default layouts alongside the binary. The + # binary reads these at runtime from THOR_DEFAULTS_PATH (baked in + # above). Keep in sync with defaults.odin. + mkdir -p $out/share/thor + cp -r defaults $out/share/thor/defaults runHook postInstall ''; };