Skip to content

Fix -pch-output-dir, -o -, and -dump-ast-format under explicit module builds - #2254

Draft
artemcm wants to merge 3 commits into
swiftlang:mainfrom
artemcm:DefaultEBM-Part3-ExplicitBuildFixes
Draft

artemcm wants to merge 3 commits into
swiftlang:mainfrom
artemcm:DefaultEBM-Part3-ExplicitBuildFixes

Conversation

@artemcm

@artemcm artemcm commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Fix three issues exposed when running swiftc invocations under -explicit-module-build:

  • Create the -pch-output-dir directory before running PCH jobs: An implicit build passes -pch-output-dir to the frontend, which creates the directory itself. An explicit build resolves the PCH file path and passes it via -o, which the frontend opens without creating parent directories. Create the parent directory in performTheBuild before executing jobs so planning remains side-effect-free.

  • Relay standard-output job products (-o -) to stdout: A single-job invocation runs in-place and writes directly to standard output, but an explicit build adds module precompile jobs and runs the compile job as a child process through ToolExecutionDelegate. Send the raw output bytes of jobs with a - output to stdoutStream instead of decoding them as UTF-8 and forwarding them to stderrStream.

  • Forward -dump-ast-format only to compile jobs: swift-frontend -scan-dependencies rejects -dump-ast-format, causing -dump-ast -dump-ast-format json to fail during dependency scanning.

An implicit build passes -pch-output-dir to the frontend, which creates the directory. An explicit build names the PCH itself and passes it with -o, and the frontend opens that path without creating its directory, so a build whose -pch-output-dir does not exist yet failed to emit the bridging PCH.

Create the directory just before the jobs run, so planning alone still leaves the file system untouched.
With `-o -` the compile job writes its product to standard output. A lone job runs in place of the driver and writes there directly, but the module jobs of an explicit build make the compile a child of the driver, which sent its output to standard error, and dropped it when it was not valid UTF-8. Pass the product's bytes through to standard output unchanged.
The dependency scanner rejects `-dump-ast-format`, so with explicit module builds on by default, `-dump-ast -dump-ast-format json` failed in the scan. Only the job that dumps the AST takes the flag.
@artemcm

artemcm commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci test

@artemcm

artemcm commented Nov 8, 2026

Copy link
Copy Markdown
Contributor Author

@swift-ci test Windows

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