Incorporate R.swift to Bazel.

Muhammad Muizzsuddin
1 min readSep 11, 2020


Well, this is neither easy nor difficult. Just between the two. How to say it in English? Average?

Hello. I just have production experience with Bazel and I can’t wait to share it so everyone can benefit from it.

R.swift is a library to help us minimise stringy reference to resources. That’s my own word. Please check it out at

To incorporate the workflow of generate R.generated.swift, we should have an xcodeproj where R.swift will parse and put the script in Build Phase.

Until now, I can’t find a solution built right inside bazel to invoke the script in a correct way. Besides, the rswift is an unforgiving tool that demands us to give it a lot of environment variables derived from xcodebuild which in turns, it should be invoked from xcodeproj.

The solution is quite simple.

Meet our friendly XcodeGen. This tool will help us generate an xcodeproj from a spec which we will write as follows,

Then we can build using this code,

xcodebuild -t rswift

Thanks me later.


Easy. Peasy. Happy.

Thanks XcodeGen!!