Split from #36808.
This PR fixes includes in some files in the src/ directory, as needed for #36808. Its scope is intentionally limited to minimize potential merge conflicts.
The changes outside src/ add headers that were previously included transitively.