Skip to content

refactor!: amalgamate kernal-api-build into kernal-api as build-resources - #341

Merged
zackees merged 3 commits into
mainfrom
feat/amalgamate-build-resources
Sep 20, 2026
Merged

zackees merged 3 commits into
mainfrom
feat/amalgamate-build-resources

Conversation

@zackees

@zackees zackees commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Summary

This PR merges kernal-api-build into kernal-api, following the one-package design in ARCHITECTURE.md ("Source and package organization"). kernal-api-build was never published: every release's publish step failed, because crates.io trusted publishing can't create a new crate. Nothing outside this repo depends on it.

  • New feature: build-resources = ["dep:embed-resource"]. embed-resource is now optional and pinned to =3.0.11. The feature is outside full and is added to docs.rs.
  • New module: kernal_api::build_resources, gated by #[cfg(feature = "build-resources")]. The API is the same as before, only the path changed: embed_windows_app_resources, WindowsAppResources (new, with_file_description, with_icon) and WindowsResourceError.
  • The compiler is still picked at run time from the build script's environment: CARGO_CFG_TARGET_OS, RC/RC_<target>, rc.exe/llvm-rc. There's no host cfg.

Consumer shape (and why the rename does not work)

[dependencies]
kernal-api = { version = "=0.1.x", features = ["window-icon"] }

[build-dependencies]
kernal-api = { version = "=0.1.x", default-features = false, features = ["build-resources"] }

The plan was a renamed build-dependency (kernal-api-build = { package = "kernal-api", ... }). Cargo 1.95 rejects that: the crate X depends on crate kernal-api multiple times with different names. Cargo checks every declared edge between two packages, whatever the dependency kind. I reproduced this with a two-crate example outside this repo. That leaves the same-name build-dependency above:

  • Features enabled in the [dependencies] entry don't reach the build script, because the edition-2021 resolver keeps build-dependency features separate. The reverse holds too: build-resources never reaches the executable.
  • A kernal-api/<feature> entry in the application's own [features] table does reach the build script, because Cargo applies it to every dependency with that name. This is the problem the separate crate was created to avoid, and a single package can't avoid it. The workaround, which I checked with a repro: forward through a library crate the application owns (viewer = ["dep:app-viewer"]), so the binary's feature table never names kernal-api/....
  • Even without any forwarded features, a build script that uses this compiles kernal-api's mandatory (non-optional) dependencies for the host: running-process, Tokio, BLAKE3 and the platform crates. Only the optional capabilities stay out.

The module docs, README, COMPATIBILITY and the Cargo.toml feature comment all describe this.

Tests

  • tests/build-resources-consumer/: an external fixture with its own [workspace], like the daemon-registration consumers. CI's "Check the external facade consumers" step compiles it.
    • ci/check_compilation_boundary_dependencies.py checks its resolved features: the runtime kernal-api has window-icon and not build-resources; the build-script one has exactly {build-resources}.
    • With --features forwarded, the build dependency does get text-similarity. This pins Cargo's current behaviour so the docs can't quietly go stale.
    • I checked that the check fails when the fixture's build-dependency gains window-icon.
  • New check in the same script that embed-resource stays out of the dependency graph unless build-resources is on.
  • The public-API tests are now in tests/process/windows_app_resources.rs. The tests for the private resource-script rendering stay inline in the module.
  • tests/source_policy/facade_policy.rs: the companion-version test is replaced by build_resources_is_an_opt_in_feature_of_the_one_package.

Removed

  • crates/kernal-api-build/ and the root [workspace] members entry.
  • The companion package step in ci.yml, the package step in release.yml, and the publish step in auto-release.yml.
  • The --package/Spec code in ci/crate_release.py (back to single-package) and the BuildCompanionTests in ci/test_crate_release.py.
  • The kernal-api-build entry in Cargo.lock.

The version is not bumped.

Validation (Linux x86-64, exit codes)

Check Exit
soldr cargo fmt --all --check (and the fixture) 0
clippy --all-targets --all-features -D warnings 0
clippy --lib --test process --test source_policy --no-default-features --features build-resources 0
same, --target x86_64-pc-windows-msvc 0
clippy --lib --no-default-features 0
fixture cargo check --locked native / --target x86_64-pc-windows-msvc (the build script really ran llvm-rc: kernal-api-app.lib produced) 0 / 0
cargo test --features build-resources: lib unit, process::windows_app_resources, source_policy, doctests 0
cargo test --all-features --test source_policy (32 passed) 0
ci/check_compilation_boundary_dependencies.py 0
ci/test_crate_release.py, test_auto_release.py, test_release_package_features.py, unittest guards (native_proof, native_proof_jobs, macos_x64_guest, nextest_config, deny_warnings) 0
soldr cargo dylint --all --workspace -- --all-features --all-targets 0

clippy --all-targets --no-default-features fails in the wasm test target, which can't find wasmparser. It fails the same way with no features at all, so it isn't caused by this PR. CI's per-feature isolation runs cargo check on the lib, not --all-targets.

🤖 Generated with Claude Code

…urces`

kernal-api is one package (ARCHITECTURE.md, "Source and package
organization"). The build-script companion `kernal-api-build` was never
published -- every release's publish step failed because crates.io trusted
publishing cannot create a new crate -- and nothing outside this repository
depends on it. Its code becomes the feature-gated module
`kernal_api::build_resources` behind `build-resources = ["dep:embed-resource"]`,
with embed-resource an optional, exact-pinned dependency. Public API is
unchanged apart from the path.

The companion existed because a `kernal-api/<feature>` entry in an
application's feature table applies to every dependency named `kernal-api`,
build-dependencies included. Renaming the build-dependency does not work:
Cargo 1.95 rejects one package depending on another under two names
("depends on crate ... multiple times with different names"), regardless of
dependency kind. The documented shape is therefore a second, same-name
build-dependency. Features set in `[dependencies]` stay out of the build
script (edition-2021 resolver); forwarded `kernal-api/<feature>` entries do
reach it, with an application-owned library crate as the workaround. The
build script also compiles kernal-api's mandatory dependencies for the host.

- tests/build-resources-consumer: external fixture; CI compiles it and
  ci/check_compilation_boundary_dependencies.py asserts its resolved
  features (runtime: window-icon only; build script: build-resources only;
  forwarded feature reaches the build script, pinning the documented rule).
- embed-resource RED/GREEN case; feature in CI isolation list and docs.rs.
- Public-API tests moved to tests/process/windows_app_resources.rs; the
  private resource-script rendering tests stay inline.
- Removed: crates/kernal-api-build, the workspace member, the companion
  package/publish steps in ci.yml, release.yml and auto-release.yml,
  crate_release.py's --package/Spec plumbing and its companion tests, and
  the companion-version source-policy test (replaced by a build-resources
  policy test).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
The Windows `Build` lanes failed to link kernal-api's own test binaries:
`lld-link: error: undefined symbol: vswhom_find_visual_studio_and_windows_sdk`.
`build-resources` pulls embed-resource, which depends on vswhom-sys for
Windows; that crate's C++ archive is produced only on a Windows host, so a
Linux-hosted cross link for `*-pc-windows-msvc` cannot resolve its symbols.
Before the amalgamation embed-resource was only ever compiled for a build
script's host, and `--all-features` in the per-target matrix put it in a
target graph for the first time.

`build-resources` is a host-only build-script facility, so a graph linked for
another target must not include it. ci/target_features.py derives the target
graph from Cargo.toml's `[features]` -- everything but `default` and the
host-only set -- so new features are still covered; the `build` job exports it
as KERNAL_TARGET_FEATURES for its clippy, `cargo test --no-run`, `nextest
archive` and webview smoke steps, and ci/native_proof.py's `all` graph reads
the same variable so it still shares the archive's graph (`--all-features` in
`linux`, where host == target).

Coverage for `build-resources` is unchanged in substance and now runs it the
way applications do: the per-feature isolation check, the native
tests/build-resources-consumer check in `linux`, and a new step in each
Windows lane that runs that fixture's build script for the Windows target --
which is what actually proves resource compilation cross-compiles.

Linux-hosted `--all-features` jobs are unaffected and stay as they were:
`linux` (clippy, nextest), `dylints`, release.yml's
`soldr cargo test --locked --all-features`, and ci/crate_release.py packaging.

ci/test_target_features.py is new (and added to the CI guards step): the list
equals `--all-features` minus the host-only set, every optional dependency is
named by a `dep:` entry so there are no implicit features, and the `build` job
uses the variable in all four places instead of `--all-features`.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zackees

zackees commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up: the per-target build graph excludes host-only features

The first CI run failed in the Windows Build lanes:

lld-link: error: undefined symbol: vswhom_find_visual_studio_and_windows_sdk
lld-link: error: undefined symbol: vswhom_free_resources

while linking kernal-api (lib test) and test "process" for x86_64-pc-windows-msvc and aarch64-pc-windows-msvc (the macOS lanes were cancelled by fail-fast).

build-resources pulls embed-resource, which depends on vswhom-sys for Windows, and that crate's C++ archive is only produced on a Windows host. Before the amalgamation embed-resource was only ever compiled for a build script's host; --all-features in the per-target matrix put it in a graph linked for a target for the first time.

build-resources is a host-only build-script facility, so a target graph must not contain it:

  • ci/target_features.py derives the target graph from Cargo.toml's [features] -- everything but default and the host-only set -- so a new feature is still covered automatically. There are no implicit optional-dependency features (every optional dependency is named by a dep: entry), so the list is exactly --all-features minus that set, and a test asserts this.
  • The build job exports it once as KERNAL_TARGET_FEATURES and uses it for clippy, cargo test --no-run, nextest archive and the webview smoke build. ci/native_proof.py's all graph reads the same variable, so it still shares whatever graph the job already built (--all-features in linux, where host == target).
  • build-resources coverage is now closer to how applications use it: the per-feature isolation check, the native tests/build-resources-consumer check in linux, and a new step in each Windows lane that runs that fixture's build script for the Windows target -- which is what actually proves cross-target resource compilation works.

Unaffected, all Linux-hosted and left as they were: linux (clippy, nextest), both dylints jobs, release.yml's soldr cargo test --locked --all-features, and ci/crate_release.py packaging.

New ci/test_target_features.py (added to the CI guards step) asserts the derived list, the absence of implicit features, and that the build job uses the variable in all four places instead of --all-features.

The new Windows-lane step failed with
`embed-resource: compilation not attempted: missing compiler: llvm-rc`.
embed-resource invokes `llvm-rc` by plain name for an MSVC target, and the
Linux cross builder carries only versioned LLVM binaries. Resolve one --
PATH, then `/usr/lib/llvm-*/bin/llvm-rc` or `llvm-rc-*`, then `apt-get
install llvm` -- and pass it through embed-resource's documented
`RC_<target>` override. A host with no llvm-rc at all is an error, not a
skip: compiling resources for the target is the point of the step.

Verified locally for both aarch64- and x86_64-pc-windows-msvc, including that
the override is what selects the compiler (a bogus RC_<target> fails naming
that path) and that the build script produces kernal-api-app.lib.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees merged commit a0837e8 into main Sep 20, 2026
25 of 26 checks passed
@zackees
zackees deleted the feat/amalgamate-build-resources branch September 20, 2026 01:23
zackees added a commit that referenced this pull request Sep 20, 2026
First release with the amalgamated single crate (#341): the Windows
executable-resources helper ships as `kernal_api::build_resources` behind the
`build-resources` feature, and kernal-api-build is gone.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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