Open darrarski opened 6 months ago
I made some progress. It's nowhere close to a proper solution, but I made it work with some manual hacking, so I guess it's worth sharing. Here are the steps I take to use the XCFramework generated from the Composable Architecture package, along with contained Swift Macros:
CasePathsMacros
ComposableArchitectureMacros
DependenciesMacrosPlugin
PerceptionMacros
cp "path/to/some/directory/*Macros" "$BUILD_DIR/Debug$EFFECTIVE_PLATFORM_NAME/"
-load-plugin-executable $BUILD_DIR/Debug$EFFECTIVE_PLATFORM_NAME/ComposableArchitectureMacros#ComposableArchitectureMacros -load-plugin-executable $BUILD_DIR/Debug$EFFECTIVE_PLATFORM_NAME/DependenciesMacrosPlugin#DependenciesMacrosPlugin -load-plugin-executable $BUILD_DIR/Debug$EFFECTIVE_PLATFORM_NAME/PerceptionMacros#PerceptionMacros -load-plugin-executable $BUILD_DIR/Debug$EFFECTIVE_PLATFORM_NAME/CasePathsMacros#CasePathsMacros
Now, I'm able to use Composable Architecture XCFramework and use Swift Macros like @Reducer
when running my app in iOS Simulator.
The only issue I found so far, is that when I use the macros in my code, Xcode previews are no longer working - fail to build due to the following error:
external macro implementation type 'ComposableArchitectureMacros.ReducerMacro' could not be found for macro 'Reducer()'
The broken previews need investigation, it may be a matter of telling Xcode where to find the macro binaries when building for previews.
I'm not sure if the above process could be fully automated with Scipio. It may require some manual work when integrating generated XCFramework with an Xcode project (like adding a build phase and updating swift compiler flags manually). I think that at least some parts of the process could be automated, like extracting the included macro binaries when generating XCFramework.
Hi. Thank you for opening this issue.
As you said, I've noticed the problem that Scipio couldn't build the package it requires a macro.
Adding -load-plugin-executable
options will help us. I'm planning the following steps.
-load-plugin-executable
as OTHER_LINKER_FLAGS
Scipio uses PIF; the format to represent the Xcode project generated by SwiftPM. We have to investigate the behavior to build such packages with Xcode build.
swift build --build-system xcode
I'm going to support the Swift Macro. I'll use TCA to test the feature.
I did some research and put my findings into a repository. It contains a simple bash script that uses Scipio to build TCA and output XCFrameworks with Swift Macros binaries. There's also an example swift package where I try to integrate the generated frameworks and macros. It mostly works, but there are some issues. I may be missing some steps when building the frameworks, or when integrating with the example swift package.
I'm trying to use Scipio to make XCFramework for Composable Architecture. At first, it seemed to be working fine, as I was able to use the generated XCFramework in Xcode project. However, I can't use Swift Macros that Composable Architecture exposes. When trying to do so, I get the following error:
I'm unsure how to debug the issue, but I found that Tuist does some extra work when creating Xcode targets from swift packages. It adds an additional build phase for each swift package that contains macros. The build scheme looks like this:
I think the above build phase is crucial for the Swift Macros to work, when integrated in a different way than through SPM.
It would be great to use Scipio for generating XCFrameworks, and being able to use Swift Macros. I'm happy to help with further investigation and research possible solutions, but I'm not even sure where to start at the moment.