I'm excited to announce the open-source release of codable-macro, a Swift macro that aims to eliminate the need to write Codable implementations manually.
Features
Exclude certain properties.
Provide default values for properties.
Specify custom coding keys and key paths (supports nested containers).
Customize decoding logic for a property.
Provide additional validation logic for a type.
Fall back to the default value in case of a decoding error.
Skip invalid items when decoding collections (arrays and dictionary values).
The macro has been in use in production apps with hundreds of thousands of active users for more than 6 months.
It depends on a precompiled version of swift-syntax to avoid the impact on indexing and build time (hopefully this won't be needed when Swift 6.1 ships).
I am not familiar with the swift-syntax-xcframeworks dependency. Would this support building legacy versions of swift-syntax from source if a product engineer imports a dependency that requires an earlier version of swift-syntax like 510?
Yes, I think so. swift-syntax-xcframeworks just checks out swift-syntax by tag, builds it, and packages it in an XCFramework (see the build script here). The binary version is not picked up automatically though, the package that needs swift-syntax will have to switch to the binary version. It's a drop-in replacement, but it needs to be done manually.
If a product engineer depends on a package that builds swift-syntax from source and attempts to depend on this new package at the same time… their aggregate build graph includes two different swift-syntax artifacts? Is that correct?
Have you experimented with an option for product engineers to control this behavior? Maybe something like an environment variable that package can switch over to choose swift-syntax or swift-syntax-xcframeworks?
The package was published on SPI this week, and before that it was closed-source, so I'm afraid I don't have an answer to that question But if other macro packages on SPI are any indication, I'd assume the answer would be yes.
Lack of support for older versions (and Linux) definitely makes this package less useful, but we felt that solving the problem with build times was more important.
That can be a legit tradeoff. My advice would then be to explicitly indicate this package is only meant to be built from 6.0 and up. It's currently indicating a toolchain requirement of 5.9… a bulild failure at that point would be confusing to product engineers that expect legacy toolchains to be supported.