SwiftGen / SwiftGenPlugin

SwiftGen plugin for SPM
MIT License
90 stars 54 forks source link

High Xcode CPU usage #2

Open aregler opened 1 year ago

aregler commented 1 year ago

Hey! First of all I wanted to thank you for providing an official plugin 🤗 When I add the plugin via the remote dependency,

dependencies: [
    .package(url: "https://github.com/SwiftGen/SwiftGenPlugin", from: "6.6.0")
 ]

the CPU usage of Xcode rises constantly to 100%+. In contrast, when I add the package locally all is fine.

I created a minimal example to show the problem. SwiftgenSPM.zip

Do you have any ideas where the problem could lie? Thanks for everything, have a nice day,

Arsatius

djbe commented 1 year ago

I'm not sure TBH, what Xcode does is a bit of a black box. I also can't open that project file, I assume because it's made using the Xcode beta (which I don't have yet).

What I did notice is that your swiftgen.yml file seems to be in a weird place? Make sure to read the docs for the plugin, you must place the file in the root of your project, or in the folder for a module. Not sure how that works with this though, as your Package.swift is also in a subfolder… Shouldn't that also be in the root of your project?

Another note: your swiftgen config looks wrong as well, those paths, such as Strings/Base.lproj don't exist? Does your config work with normal SwiftGen?

Edit: what do you mean with "add the package locally"?

aregler commented 1 year ago

Hi! Thank you for your reply. Yeah my bad for uploading a Xcode beta project and for the wrong path in the SwiftGen config. Sorry. Here is a sample using the current stable Xcode version: SwiftGenSPM.zip

I think the place of my swiftgen.yml should be ok (no?) as it should be placed on the root level or at the module level:

image

By "add the package locally" I mean to remove the remote dependency .package(url: "https://github.com/SwiftGen/SwiftGenPlugin", from: "6.6.0"), download the SwiftGenPlugin project and drop it into the Xcode project and just add the dependency as .package("SwiftGenPlugin).

Thank you for your time and help!

iwt-dahlborn commented 1 year ago

I have a similar problem with Xcode having high cpu usage when I add the package as a dependency. My guess is that it might be an issue with the artifactbundle (or an Xcode bug), because when I unfold the plugin in the package dependencies in the navigator the downloaded artifactbundle blinks in and out of existance as if it is repeatedly getting deleted and redownloaded. When selecting the package.swift file the organizer is also blinking.

This also happens when using another plugin https://github.com/lukepistrol/SwiftLintPlugin who also uses a remote artifactbundle, so it might very well be an Xcode issue. I tested it with Xcode 13.4, Xcode 13.4.1 and Xcode 14.0 beta 5.

mtzaquia commented 1 year ago

I am also experiencing this issue, which seems to clearly an issue with Xcode itself. Adding the plugin will immediately set CPU usage at 130%. Tested on Xcode 13.x and Xcode 14 betas.

iwt-dahlborn commented 1 year ago

Adding the artifactbundle to the package and referencing it locally "solves" the issue. But of course that would not be as elegant as having a remote dependency.

pchmelar commented 1 year ago

If anyone is using the temporary workaround from https://github.com/DroidKaigi/conference-app-2022/pull/88, please note that in Xcode 14 you have to add .filter { FileManager.default.fileExists(atPath: $0.string) } 🙂

weakfl commented 1 year ago

Looks like this has been resolved in Xcode 14.1

markltownsend commented 1 year ago

I just created a Swift Package with SwiftGenPlugin as a dependency and build plugin. I am still getting the high cpu in Xcode 14.2, but that is only when I first open the project. Xcode shows a beachball cursor for about 10 secs before being done with whatever it's doing. My guess is that it's compiling the xcasset catalog and running SwiftGen. Not ideal, but I don't think there is anything that this project can do about it. I think it's a requirement to have the build plugins works better in the background when it's setup as a pre-build Swift Package plugin.