Cherry-pick https://github.com/bazelbuild/bazel/commit/a63d8ebb84caba9d1741a9d9fec725a7db52e25e into 6.3.1 Context: https://github.com/bazelbuild/bazel/pull/19038