code-connect icon indicating copy to clipboard operation
code-connect copied to clipboard

"Found Code Connect Swift package" step finding incorrect location with Swift Package Manager

Open jordikitto opened this issue 1 year ago • 11 comments

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:

  1. xcodeProjFile is being defined via getFileIfExists(cwd, '*.xcodeproj')
  2. xcodebuild -project ${xcodeProjFile} -showBuildSettings is 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_DIR is (/Users/jordikitto/Repos/<project>/build)
  1. 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

jordikitto avatar Aug 23 '24 07:08 jordikitto

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 .xcodeproj -showBuildSettings locally is for you, and how you're adding the package to your project? That would help to determine a proper solution.

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).

jyyang0 avatar Aug 27 '24 15:08 jyyang0

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:

  1. Select Project
  2. Select "Package Dependencies"
  3. Click "+"
  4. Search for Code Connect via GitHub URL, add to project
  5. Click "Add package"
  6. Add Figma Library to app target, and don't add figma-swift executable to target (Left as none, 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:

  1. Add package dependency to dependencies
  2. 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.

jordikitto avatar Aug 28 '24 00:08 jordikitto

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 :(

jordikitto avatar Sep 04 '24 23:09 jordikitto

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!

jyyang0 avatar Sep 05 '24 13:09 jyyang0

Hello @jyyang0 I am experiencing the same issue on CLI 1.1.4

  1. Add Figma through SPM in Xcode under "Package Dependencies"
  2. 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 avatar Oct 01 '24 07:10 raphschwander

@raphschwander are you using local packages like myself? Or just single project?

jordikitto avatar Oct 10 '24 23:10 jordikitto

@jordikitto just a single project.

raphschwander avatar Oct 15 '24 10:10 raphschwander

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?

tomduncalf-figma avatar Oct 22 '24 09:10 tomduncalf-figma

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)

raphschwander avatar Oct 25 '24 08:10 raphschwander

+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.

tylerjdoyle avatar Nov 29 '24 14:11 tylerjdoyle

@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.

robmaceachern avatar Jun 27 '25 15:06 robmaceachern