Skip to content

feat(cross): add --define CLI override for build-system -D defines#107

Merged
jwinarske merged 1 commit into
mainfrom
jw/cross-define-override
Jul 8, 2026
Merged

feat(cross): add --define CLI override for build-system -D defines#107
jwinarske merged 1 commit into
mainfrom
jw/cross-define-override

Conversation

@jwinarske

Copy link
Copy Markdown
Contributor

What

Adds a repeatable --define/-D KEY=VALUE flag to emb cross that overrides a build-system -D define for the embedder configure. The override wins over every manifest source — cross.defines, any backends entry, and anything an extends chain merged in.

How

  • Parsed up front, so a malformed -D is a usage error before any download.
  • Baked into the CrossTarget via withDefineOverrides, so everything downstream sees the final values: buildKey (the build-dir key differs, so caches never go stale), the backend matrix, the no-backend build, and --dry-run.
  • Rides on the shared defines map, which both the CMake (cmake -S) and Meson (meson setup) paths emit as -Dkey=value — so it is generator-agnostic. cmakeArgs (CMake-only) is deliberately left untouched.

Safety

  • Values reach the build tool only as discrete argv elements (Process.start with runInShell: false) — no shell interpolation.
  • parseDefineOverrides splits on the first = only (a value may contain =), allows an empty value (CMake unset-style), and rejects a missing = or empty key with a FormatException.

Tests

  • Unit coverage for withDefineOverrides / parseDefineOverrides (multiple overrides, verbatim spaces, empty value, generator preserved, no mutation).
  • Builder-level tests proving the override reaches the CMake and Meson configure argv, and every backend, with the replaced manifest value gone.
  • CLI --dry-run cases: Meson embedder, glued -DKEY=VALUE form, empty value, embedded =, and repeated-key last-wins.

Full suite green (549 tests); every new line is covered including both error branches.

Add a repeatable --define/-D KEY=VALUE flag to `emb cross` that
overrides a build-system define for the embedder configure. The
override is parsed up front (usage error before any download) and
baked into the CrossTarget itself via withDefineOverrides, so it
wins over every manifest source — cross.defines, any backends entry,
and anything an extends chain merged in.

Because the target is amended, everything downstream sees the final
values: buildKey (so the build-dir key differs and caches never go
stale), the backend matrix, the no-backend build, and --dry-run.
The override rides on the shared `defines` map, which both the CMake
(`cmake -S`) and Meson (`meson setup`) paths emit as -Dkey=value, so
it is generator-agnostic; cmakeArgs is deliberately left untouched.

Values reach the build tool only as discrete argv elements
(Process.start with runInShell: false), so there is no shell
interpolation. parseDefineOverrides splits on the first = only (a
value may contain =), allows an empty value (CMake unset-style),
and rejects a missing = or empty key with a FormatException.

Tests: unit coverage for withDefineOverrides/parseDefineOverrides,
builder-level tests proving the override reaches the CMake and Meson
configure argv (and every backend), and CLI --dry-run cases for the
glued -DKEY=VALUE form, empty values, embedded =, and last-wins.

Signed-off-by: Joel Winarske <joel.winarske@linux.com>
@jwinarske
jwinarske merged commit 0620b2a into main Jul 8, 2026
39 checks passed
@jwinarske
jwinarske deleted the jw/cross-define-override branch July 8, 2026 00:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant