Congratulations for this very interesting finding ! I think the Unity il2cpp dev team should read this.
Your workaround can certainly be automated. PROJECT_DIR is the directory where the .xcodeproj directory itself is. And SRCROOT is the directory where your project sources are. Conveniently on Unity projects they're the same. More info here: https://help.apple.com/xcode/mac/8.3/#/itcaec37c2a6
:: @Pierre-Marie Baty added on 10 Sep ’23 · 15:03
P.S. Use "pbxprojparse -query" to have the toolchain resolve these variables for you :-)