It might be possible with BuildKit frontend syntax. Though, I have never used it and as such have no experience that I could share. Judged by the documentation, something like might do the trick:
The scope of the mount will be limited to the RUN instruction. You would need to use it on each RUN instruction that should use the mount.
Please open and read the link from above, as there are different types of --mount=type available and you propbably might need to add another parameter or even require a different type than used above.