Specify a compiler for packages built with `bazel`

Is there an easy way to tell bazel to use a specific compiler for building packages?

Related to

we have bazel packages that are failing with gcc15, but that should work with its previous version.

For example, I was investigating Build failure: protoc-gen-js · Issue #475586 · NixOS/nixpkgs · GitHub .

It seemed to me that a candidate solution would be to pin the compiler to gcc14, but I have a hard time understanding this build system, and even less the nixpkgs abstraction built on top of it…

A solution from protoc-gen-js: fix build by pinning to gcc14 by gepbird · Pull Request #476867 · NixOS/nixpkgs · GitHub by @gepbird ; If there is an standard environment bundling the needed compiler, one can override the stdenv of buildBazelPackage with it:

let
  buildBazelPackage' =
    buildBazelPackage.override {
      stdenv = gcc14Stdenv;
    }
in
buildBazelPackage' rec { ... }