"Found Code Connect Swift package" step finding incorrect location with Swift Package Manager
Hi,
When running figma connect commands in my Xcode project root directory, I get the following:
Using "swift" parser as a file matching *.xcodeproj or Package.swift was found in /Users/jordikitto/Repos/ios-jupiter. If this is incorrect, please check you are running Code Connect from your project root, or add a `parser` key to your config file. See https://github.com/figma/code-connect for more information.
Fetching component information from Figma...
Parsing response
Generating Code Connect files...
Found Code Connect Swift package at /Users/jordikitto/Repos/<project>/build/../../SourcePackages/checkouts/code-connect, building parser binary. This may take a few minutes if this is the first time you've run Code Connect.
Failed to create: Parser exited with code 1
It fails because code-connect is not checked out to this location. I am using Swift Package Manager (SPM) and the actual location is:
/Users/jordikitto/Library/Developer/Xcode/DerivedData/<app>-aujmsoebpvanokfwonszghsvtqth/SourcePackages/checkouts/code-connect
Looking at your implementation, I see the following steps are occurring:
xcodeProjFileis being defined viagetFileIfExists(cwd, '*.xcodeproj')xcodebuild -project ${xcodeProjFile} -showBuildSettingsis being run to determine:
- If the Code Connect Swift package has been added (it has been)
- Whether the package is local (it isn't)
- What the
BUILD_DIRis (/Users/jordikitto/Repos/<project>/build)
- The final path is then being constructed as
/Users/jordikitto/Repos/<project>/build/../../SourcePackages/checkouts/code-connect
Again, unfortunately, this path is not the correct location. The correct location is in the DerivedData folder located above.
From my understanding, this is because of Swift Package Manager checking out the repo? Does Code Connect support SPM installation? If not, what is the correct way to use Code Connect with Xcode projects/workspaces?
Happy to provide any further details.
--
I did manage to get Code Connect to work with a hack symbolic link, for reference:
ln -s /Users/jordikitto/Library/Developer/Xcode/DerivedData/<app>-aujmsoebpvanokfwonszghsvtqth/SourcePackages/checkouts/code-connect /Users/jordikitto/Repos/SourcePackages/checkouts/code-connect
Please provide:
- Code Connect CLI version:
1.0.6 - Operating system: macOS Sonoma 14.6.1
Hi @jordikitto, thanks for bringing this to our attention -- Looks like there's some cases that finding the checkout of code-connect doesn't cover completely.
Would you be willing to share what the output of running xcodebuild -project
Workaround wise, as you've identified you can add a symlink in order to trick the parser to finding the right location. Another option is to create a dummy Package.swift file somewhere that adds a dependency to code-connect and then configure the configuration file with the relevant include glob paths (And then run code connect from that directory).
Hi @jyyang0
Here is the output of xcodebuild -project .xcodeproj -showBuildSettings -> xcodebuild-output.txt
As for the project structure, it looks like such:
/<REPO_NAME>/
<PROJECT_NAME>.xcodeproj <-- Code Connect package added here
<PROJECT_NAME>.xcworkspace
/<PROJECT_NAME>/
/LOCAL_PACKAGE_1/
/LOCAL_PACKAGE_2/
/LOCAL_PACKAGE_3/
/LOCAL_PACKAGE_DESIGN_SYSTEM/
Package.swift <-- Code Connect package added here as well
The package is added to the project like so:
- Select Project
- Select "Package Dependencies"
- Click "+"
- Search for Code Connect via GitHub URL, add to project
- Click "Add package"
- Add
FigmaLibrary to app target, and don't addfigma-swiftexecutable to target (Left asnone, this caused build errors if added)
The package is added to the LOCAL_PACKAGE_DESIGN_SYSTEM package as per the installation instructions
In Package.swift:
- Add package dependency to
dependencies - Add product dependencies to package targets dependencies
This all builds successfully, with a FigmaConnection file in LOCAL_PACKAGE_DESIGN_SYSTEM package publishing successfully to Code Connect.
If it makes any difference, I open the "project" via the xcworkspace when developing. I'm also using Xcode 16 Beta 6.
Hey @jyyang0, any updates on this one? Would be really great if we could integrate this into our CI for our large project but this is making it quite difficult :(
Sorry about the delay -- Looking at your setup it seems like our current system is making some assumptions about xcodeproj based workspaces. which is failing -- In the next release that's coming out (1.0.7) we've added the ability to specify a swiftPackagePath which you can use to refer to the Package.swift file. Another option here is to run figma connect ... in your LOCAL_PACKAGE_DESIGN_SYSTEM (so there's no ambiguity about whether theres an xcodeproj or SPM managed project) which should also unblock you.
This isn't a perfect solution and we're still iterating on how we can make the system more robust as a whole to support a variety of xcode project configurations, but this feedback is really helpful!
Hello @jyyang0 I am experiencing the same issue on CLI 1.1.4
- Add Figma through SPM in Xcode under "Package Dependencies"
- Run CLI command from the project root folder
It cannot locate the checkout of code-connect in derived data folder.
That's because it uses BUILD_DIR.
xcodebuild -project .xcodeproj -showBuildSettings returns the project folder,
BUILD_DIR is (/Users/raph/Developer/<project>/build)
not the derived data folder.
BUILD_DIR only returns the correct derived folder path when building.
@jyyang0 what's the correct way to install it, I've followed instructions on https://github.com/figma/code-connect/blob/main/docs/swiftui.md ?
@raphschwander are you using local packages like myself? Or just single project?
@jordikitto just a single project.
Hey @raphschwander, sorry to hear you're continuing to have issues here. It feels like a good workaround for now might be for us to provide a way to override the checkout location manually, would that work?
hello @tomduncalf-figma , thanks for getting back to me. In the meantime, I used a hacky workaround as jyygang0 suggested to make it work. I only wanted to test the tool. Yes, that would be a workaround, but not very convenient, as finding the checkout location is not straightforward and AFAIK it can change (for instance after cleaning the derived data folder)
+1 that I'm also experiencing this issue while not using a Package.swift file and instead adding the dependency directly in the project. The symbolic link workaround worked for me as well but this blocks our CI from doing the same thing.
@tomduncalf-figma
It feels like a good workaround for now might be for us to provide a way to override the checkout location manually
We're also hitting issues with this and would appreciate the ability to manually set the checkout location.
FYI we're using Tuist for project generation and the location of the checkouts end up being something like {ProjectDir}/Tuist/.build/checkouts in our project.