Cherry-pick https://github.com/bazelbuild/bazel/commit/a63d8ebb84caba9d1741a9d9fec725a7db52e25e into 6.4.0