Skip to content

refactor: centralize host-platform cfg behind reld_core::platforms - #150

Merged
zackees merged 1 commit into
mainfrom
refactor/137-host-platform-boundary
Sep 17, 2026
Merged

zackees merged 1 commit into
mainfrom
refactor/137-host-platform-boundary

Conversation

@zackees

@zackees zackees commented Sep 17, 2026

Copy link
Copy Markdown
Collaborator

Closes #137.

Summary

  • One host-selection site. crates/reld-core/src/platforms/mod.rs holds the only cfg_select! on the host OS; it picks one concrete tree (platform_linux, platform_macos, platform_illumos, platform_other_unix, platform_win, platform_wasi, with shared unix code in platform_unix). Every other file calls the neutral facade reld_core::platforms::{fs, host, linker_plugin, path, process}.
  • Zero-baseline Dylint. ban_platform_cfg_outside_boundary now exempts only the selector and the concrete trees (facade leaves are scanned), matches selectors on identifier boundaries, detects host cfg_select! arms, and bans std::os::fd/std::os::wasi too. It covers every workspace crate and target: reld-core, reld bins, integration tests, reld-testkit, reld-diff.
  • Lint tests and CI. Adds unit tests and UI tests, a new dylint CI job (lint fmt, lint tests, workspace lint with default and --no-default-features), dylints/README.md, and an AGENTS.md rule. It also tracks the lint's .cargo/config.toml (linker=dylint-link), which the bootstrap had gitignored, so the UI tests could not run before.

Design decisions

  • Facade name. The facade is reld_core::platforms, not crate::platform. crate::platform is wild upstream's linker-format trait (ELF vs Mach-O, 42 files). Renaming it would be churn and would make upstream syncs painful, and it has nothing to do with the host.
  • target_arch/target_endian stay allowed. reld is a cross-target linker, so these select the linker target.
  • Linker plugins. The ~40 all(feature = "plugins", unix) gates became feature = "plugins" plus a runtime linker_plugins::ENABLED (= platforms::linker_plugin::SUPPORTED). On hosts without plugin support, LinkerPlugin::from_args returns Ok(None) up front, exactly like the old disabled stub. As a result, linker_plugins.rs now compiles on Windows.
  • reld-testkit and reld-diff can't depend on reld-core. A new dependency edge needs approval, so these crates use std's neutral constants (EXE_SUFFIX, ExitStatus::default()) and ask the C compiler for its target (cc -dumpmachine). That is target detection, and it is correct under cross-compilation. reld-bench keeps exactly three explicit routes (Windows/Apple/Linux) and errors on any other compiler target; the existing Python guard was updated to enforce that.
  • Tests no longer compile out per host. Tests previously removed by host cfg now compile everywhere and skip at runtime with a printed reason, based on host facts or capabilities (HostOs, KILLS_PROCESS_TREES, GNU objdump present, HAS_TEMP_DIR).

Intended behavior changes (everything else is preserved)

  • PlatformKind::host() used a cfg_select! without a fallback, so reld-core did not compile on FreeBSD, illumos, Android or WASI. Those hosts now default to ELF, and reld-core type-checks and passes clippy for all four.
  • reld-testkit output names on non-Windows hosts are a/p instead of a.out/p.out. The tools also require a compiler that answers -dumpmachine.
  • The unused unix libc dev-dependency of reld is removed, along with its baseline entry (removal only).

Validation (local, Linux host)

  • cargo fmt --check and cargo clippy --workspace --all-targets -D warnings pass with default features, --no-default-features, and plugins-only.
  • Cross type-check and clippy:
    • x86_64-pc-windows-msvc (no default features) and aarch64-apple-darwin: pass.
    • Full default-features Windows build of reld/reld-core, all targets, via soldr: pass.
    • FreeBSD, illumos, Android and WASI (reld-core): pass.
  • Dylint: fmt passes; unit tests 12/12 and UI tests 4/4 pass. The workspace lint is clean for default and --no-default-features.
  • RED check for the Dylint: I injected host cfg or libc:: into reld-core, reld-testkit and an integration test. The lint failed on each, and the probes were removed afterwards.
  • CI's Linux native test commands all pass: reld-core lib 202, testkit/diff/layout-schema, reld bins, acceptance-policy, external-runner 3/3 (really executed, no skips) and nix-rpath 3/3.
  • Python ci/tests: 258 passed. ci/check_dependencies.py passes, and the baseline matches the manifests exactly.
  • Host LTO/plugin acceptance tests: 11/12 pass. lto-whole-archive-shared/default fails identically on unmodified main in this environment (missing local tool), so CI's full toolchain is the authority for that one.

🤖 Generated with Claude Code

…eld#137)

Host-OS selection was scattered through the workspace as #[cfg(unix)],
cfg!(windows), cfg_select! on target_os, and direct libc/std::os calls.
It now lives in exactly one place: the cfg_select! in
crates/reld-core/src/platforms/mod.rs picks one concrete tree
(platform_linux/macos/illumos/other_unix/win/wasi, with shared unix
building blocks in platform_unix), and everything else calls the neutral
facade reld_core::platforms::{fs, host, linker_plugin, path, process}.
crate::platform (wild's linker-format trait) is untouched.

The ban_platform_cfg_outside_boundary Dylint now enforces this with zero
baseline across every workspace crate and target: only the selector and
the concrete trees are exempt (the facade leaves are scanned), selectors
match on identifier boundaries, cfg_select! host arms are detected, and
std::os::fd/wasi are banned. The lint gains unit and UI tests, a tracked
.cargo/config.toml (dylint-link was never configured), and a CI job that
lints the workspace with default and no-default features.

Behavior is preserved per host and feature set:
- plugins gating is feature = "plugins" plus a runtime
  linker_plugins::ENABLED; unsupported hosts return early exactly like the
  old disabled stub, so linker_plugins.rs now also compiles on Windows.
- Output-writing policy is host-neutral over FilesystemKind; Android keeps
  its Btrfs/vfat-only policy.
- Tests that were compiled out by host cfg now compile everywhere and skip
  at runtime on host facts or capabilities.
- reld-testkit/reld-diff cannot reach reld-core, so they use std's neutral
  constants and the C compiler's target triple (-dumpmachine) instead;
  reld-bench keeps explicit Windows/Apple/Linux routes and errors on any
  other target.
- PlatformKind::host() no longer hard-fails compilation on non
  Linux/macOS/Windows hosts; reld-core now type-checks for FreeBSD,
  illumos, Android and WASI.

Removes the now-unused unix libc dev-dependency of reld (and its baseline
entry).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@zackees
zackees merged commit fcecfdb into main Sep 17, 2026
27 checks passed
@zackees
zackees deleted the refactor/137-host-platform-boundary branch September 17, 2026 17:40
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.

refactor: centralize host-platform cfg behind crate::platform + cfg_select!, enforced by Dylint

1 participant