# Error embedding file data with a macro

**URL:** <https://forums.swift.org/t/error-embedding-file-data-with-a-macro/81448>\
**Category:** Using Swift\
**Tags:** macros\
**Created:** [August 2, 2025, 3:40am UTC](https://forums.swift.org/t/error-embedding-file-data-with-a-macro/81448 "2025-08-02T03:40:42Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![Max\_Desiatov](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/max_desiatov/32/20654_2.png) [@Max\_Desiatov](https://forums.swift.org/u/Max_Desiatov)\
**Post date:** [August 26, 2025, 1:54pm UTC](https://forums.swift.org/t/error-embedding-file-data-with-a-macro/81448/8 "2025-08-26T13:54:06Z")

</div>

> [@awwright](#):
>
> Why ought it be the case that macros not have side effects? Or I/O more specifically, I don’t see how reading from the filesystem is a problem, as it’s obviously necessary for the compile step.

That was explained in my original message: source code placed on the file system is tracked by the build system, as source code file paths are known to the build system. Arbitrary side effects within Swift macros are opaque and unknown to the build system, breaking determinism and assumptions built on top of that determinism.

> [@awwright](#):
>
> That is, why does C get to have macros with filesystem read access but not Swift?

For the same reason that C gets to have unrestricted memory access and data races, but Swift does not thanks to its memory safety and strict concurrency. In the same way, macros in Swift are supposed to be free from side effects (partially enforced only on some platforms for now) to prevent build system errors and incorrect incremental builds.

> [@awwright](#):
>
> And granting that macros don’t get filesystem access, is there a way I can build a Swift-compatible object file from some source data, bypassing the Swift compiler and going directly to an LLVM frontend?

You could embed data from a module written in C or C++, but do that at your own risk as Swift build system would have no way to ensure correctness of the build.

---

_[View the full topic](https://forums.swift.org/t/error-embedding-file-data-with-a-macro/81448)._
