Skip to content

Build-action environment inputs: diagnostics, default effects, and docs #649

Closed

Description

@ehartford

Summary

Build actions can read declared environment inputs through
BuildCtx.env_input and ActionCtx.env_input. The original blocker was already
implemented when this issue was filed. Remaining work is diagnostics and
effect enforcement for raw environment reads, documentation, and removal of a
stale build comment.

Current state (revalidated 2026-07-15)

The blessed path works end to end:

let enabled = ctx.env_input("WITH_TEST_NETWORK")

The value is recorded as a build input, and changing it invalidates the cached
action.

Three gaps remain:

  1. A natural raw call wrapped in unsafe { ... } reaches
    NK_UNSAFE_BLOCK, which the comptime evaluator does not handle, and produces
    the generic “expression kind 70 is not comptime-evaluable yet” error instead
    of steering the user to ctx.env_input.
  2. A direct raw with_getenv_str call gets the useful undeclared-input
    diagnostic under strict effects, but default mode currently permits the
    ambient read without recording it. That violates the declared-input model
    unless the evaluator records it as a discovered input.
  3. §17.1b describes environment capabilities but the public env_input APIs are
    not documented in repository docs.

build/selfhost.w also still says a raw-getenv opt-in is unavailable beside the
disabled zlib case. The raw form should remain discouraged, but the comment
must point at env_input rather than claiming no API exists.

Work

  • Evaluate unsafe block structure far enough to emit the targeted declared-
    input diagnostic, or reject the block directly with that guidance.
  • In ordinary mode, never silently consume an unrecorded raw environment value:
    require ctx.env_input or explicitly record a discovered input according to
    §17.1a/§17.1b.
  • Document BuildCtx.env_input and ActionCtx.env_input with examples and cache
    invalidation semantics.
  • Update the stale Restore hermetic with-get gate coverage and add a content-addressed cache #624 comment in build/selfhost.w.

Acceptance criteria

  • Declared env_input reads work in graph construction and action execution.
  • Changing a declared variable invalidates the correct cached node.
  • Raw direct and unsafe-wrapped environment reads cannot silently affect build
    output; diagnostics name ctx.env_input.
  • Default and strict-effects behavior are explicitly specified and tested.
  • The API and its declared-input semantics are documented.
  • Full build, fixpoint, and test gates pass.

Traceability

  • Specification §17.1a, Declared vs discovered inputs
  • Specification §17.1b, Capability-bearing comptime

Activity

  1. changed the title [-]comptime evaluation can't read env vars (extern getenv) — build actions can't gate on the environment[/-] [+]Build-action environment inputs: diagnostics, default effects, and docs[/+] on Jul 15, 2026
  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): still reproduces, and the first gap's diagnostic is now worse than the issue records. A raw getenv in a build file reports a return-type error instead of steering to ctx.env_input:

    use std.build
    pub fn build(ctx: BuildCtx) -> Build:
        let v = unsafe { with_getenv_str("HOME") }
        print(v)
        Build.new()
    
    $ with build
    error: return type does not implement Default
     --> build.w:3:5
    

    pre-release: a misleading diagnostic in the build file every project writes; the fix is a targeted refusal naming ctx.env_input.

  3. ehartford commented on Oct 26, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 21c4a21 (#2727), merged through stack 9 whose seed-driven battery was green on its top (gate, uat and survey all green). Regression test: test/behavior/behav_649_build_env_read_names_env_input.w.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions