[Pitch #2] Expression macros

I am considering using macros to embed binaries into Swift source code.

EXAMPLE:

let data = #embed("images/icon.png")

// ^ This macro will generate the code below.
let data = Data([0x4d, 0x49, 0x54, ..., 0x65, 0x6e, 0x73])

Similar to the #embed macro in C23.

This would be useful for applications that do not have bundles, such as command-line tools.

To make this work, I need to access the file system from the macro processor.

Macro implementations will be executed in a sandbox like other SwiftPM plugins, preventing file system and network access.

The proposal says that the macro runs in a sandbox and does not have a file system or network access, but is there a mechanism planned to access read-only files or get permissions explicitly, like SwiftPM's command plugin?

9 Likes