Is there a way to get the path to the root of the project that is calling the macro?

Hi. I have decided to try writing custom macros that will need access to the file system at the project root. However, I realised that the macro is not executed from the root of the calling code project. Is there a way to get a path to the project root?


I was told that macros are sandboxed, and don't have access to the file system.

See: Use LLDB to debug a Swift macro?

It is a bit disappointing to find this out because the build plugins can access the filesystem of the triggering project.

To be honest, this seems like a missed opportunity to me. For example, F# has type providers than can read databases or make a web requests during the compilation.

I went with a gyb script to get what I needed. I'd love to see a Swift version of that, though that'd just be to reduce the need for external tools.

There's an interesting problem with dependency rebuild need detection. Mine just builds every time, which could be considered a waste, since it only needs to run when a new file is added to a particular directory. I can see how to solve that, it'd get more fun with a database.