Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jordikitto opened this issue Aug 23, 2024 · 4 comments

Comments

@jordikitto
Copy link

jordikitto commented Aug 23, 2024

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
@jyyang0
Copy link

jyyang0 commented Aug 27, 2024

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

@jordikitto
Copy link
Author

jordikitto commented Aug 28, 2024

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
Copy link
Author

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

@jyyang0
Copy link

jyyang0 commented Sep 5, 2024

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants