Ensure build deps are installed for deps with inherited options

Fixes #28144.