Skip to content

A child spawned with a relative cwd gets PWD set to the relative string; with get then roots the project at a relative path and CMake refuses the relative compiler path #3166

Closed

Description

@ehartford

Found by tools/facade_coverage.w (#3116): run_to_files_in("out/facade-coverage/zlib", ["with", "get", "c.zlib"], …) from the repo root failed every library with

CMake Error at CMakeLists.txt:3 (project):
  The CMAKE_C_COMPILER:
    out/facade-coverage/zlib/.with/deps/c/zlib/1.3.2/.build/tools/cc
  is not a full path and was not found in the PATH.

and could not write the CMake package config of opengl/system for sdl/3.4.16: no metadata.json for opengl/system under out/facade-coverage/sdl/out/facade-coverage/sdl/.with/deps/c/opengl/system (the root joined onto itself). The same run with an absolute cwd works.

Root cause

posix_run_argv (rt/darwin_aarch64.w, rt/linux_*.w) does chdir(cwd) in the forked child and then setenv("PWD", cwd) with the string it was given. A relative cwd is a correct chdir but a wrong PWD: getcwd says /Users/eric/with/out/facade-coverage/zlib, PWD says out/facade-coverage/zlib. The compiler's runtime_cwd() prefers PWD (#1915), so project_config_find_root(".") absolutizes . against the relative PWD and every path under the project (the dep dir, the .build/tools/cc CMake is told to use) is relative to wherever the child happens to be. The Windows spawner (win_setenv("PWD", cwd) before CreateProcessW, #1082) has the same shape.

Repro:

use std.os
print("cwd=" ++ current_dir() ++ " PWD=" ++ env("PWD"))

run through run_to_files_in("out", ["with", "run", "child.w"], …) prints cwd=/abs/out PWD=out.

Fix

The child's PWD is the directory's real path: getcwd after the chdir on the unix spawners (a stack buffer; the forked child allocates nothing), and the absolutized directory on Windows.

Activity

  1. added
    bug
    on Nov 9, 2026
  2. added a commit that references this issue on Nov 9, 2026
  3. ehartford commented on Nov 9, 2026

    @ehartford
    ContributorAuthor

    Fixed in #3181 (main a46efbc): the unix spawners set PWD from getcwd after the chdir; Windows resolves it with win_realpath. Fixture behav_3166.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions