Skip to content

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

Closed

Description

@zackees

Context

reld uses host #[cfg] like C++ preprocessor macros — #[cfg(target_os = "linux")], #[cfg(unix)], #[cfg(windows)], #[cfg(target_os = "wasi")], #[cfg(target_os = "illumos")] — scattered across production sources. This is the same problem soldr (#2493, #2498) and zccache (#1365, #1366) already fixed by centralizing host-platform mechanics behind a crate::platform facade and enforcing the boundary with a Dylint.

This issue adapts that fix for reld.

Inventory (host cfg today)

  • crates/reld-core/src/fs.rs — ~20 sites (Linux/macOS/unix/wasi file mechanics: mmap, fallocate, preallocation, …)
  • crates/reld-core/src/bridge.rs — 4 (unix signals, windows EXE suffix + path separator)
  • crates/reld-core/src/save_dir.rs — 3 (unix/windows/wasi symlink)
  • crates/reld-core/src/args/elf.rs — 1 (target_os = "illumos" driver flag)

Important reld nuance vs soldr

soldr treats target_arch as host selection. reld must not: #[cfg(target_arch = "x86_64" | "aarch64" | …)] in args/elf.rs selects the linker target architecture (reld is a cross-target linker; it defaults to the host arch), which is a different concept from host OS mechanics. The boundary lint must forbid host-OS/family selectors (target_os, target_family, unix, windows, …) but must allow target_arch/target_endian target selection.

Plan

  1. Bootstrap crates/reld-core/src/platforms/ with a cfg_select! selector and concrete trees (platform_linux.rs, platform_macos.rs, platform_win.rs, plus platform_wasi.rs/platform_illumos.rs as needed), a neutral platform.rs facade, and crate::platform::fs / crate::platform::process / crate::platform::path capability namespaces.
  2. Bootstrap a dylints/ workspace (excluded from the main workspace, discovered by a lint script, formatted/tested in CI) with ban_platform_cfg_outside_boundary — a pre-expansion Dylint that denies host-platform #[cfg], #[cfg_attr], and cfg!() outside the platforms/ boundary, mirroring soldr's lint.
  3. Migrate the ~28 host-cfg sites behind the facade, shrinking a ratcheting baseline to zero.
  4. Wire CI: run the Dylint (+ its UI tests) in the existing hygiene/lint path.

Acceptance

  • Dylint denies host-OS cfg outside crates/reld-core/src/platforms/.
  • target_arch/target_endian target selection is accepted.
  • All host-platform mechanics live behind crate::platform::*.
  • Zero baseline; no whole-file/whole-directory exemptions outside the concrete trees.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions