SPM Build Time Metrics

Hello, I am trying to improve the build time of a project but I am having trouble with getting the SPM build information.
The project is an iOS app defined within a Workspace with dependencies booth as Pods, and as SPM libraries. Yes, it's not a great setup, I know.
Besides third party SPM libraries, we have a SPM Package inside the workspace where we have been developing most of the app.
I have found this article to be pretty helpful, and I decided to use XCLogParser to have a better visualisation.
The problem is that those -Xfrontend flags seem to be ignored by our SPM part of the project, Xcode does not show the time for type checking expressions and the function body for those files. The rest of the files have the data reported as expected.
Is there anyway of making those commands work? Or is there an alternative command for using with the package? We are moving most of our project source code to the package, so that's where we need the diagnostics the most.
Any help would be appreciated.

2 Likes

Packages don't inherit flags from Xcode projects, so setting any flags there won't affect how packages build. I don't really have a good solution for you. You could build the package in isolation and pass those flags via the unsafeFlags API.

1 Like

Hum... Interesting, but you said to build the package in isolation, just adding them to the Package would not make it work when building trough Xcode? Or Xcode ignores the Package flags too?

Note that "in isolation" doesn't mean outside of Xcode, but just not as a dependency. The unsafeFlags API is explicitly disallowed for package dependencies in Xcode, so an app with dependencies that uses that API would simply fail to build.

The package manifest is Swift code, though, so you could make the use of unsafeFlags conditional (e.g. based on an environment variable) and enable them only when building the package in isolation to get build timings.

I see, I didn't know about the unsafeFlags API, when I read I thought it meant that would not build if it was a "external" dependency, but now that I think about it it does not make a lot of sense
hahha
I will try that, thank you.

It worked, thank you :smile:
I really thought it was not gonna be possible.

For anyone else that finds this thread.
You can just select the Package schema for the build itself (I tought I would have to open it outside of the Workspace).
And remember that -Xfrontend is a separate flag. So for me it ended up like this:

swiftSettings: [.unsafeFlags([
                "-driver-time-compilation",
                "-Xfrontend",
                "-debug-time-compilation",
                "-Xfrontend",
                "-debug-time-function-bodies",
                "-Xfrontend",
                "-debug-time-expression-type-checking",
                "-Xfrontend",
                "-warn-long-function-bodies=100",
                "-Xfrontend",
                "-warn-long-expression-type-checking=100"
            ])]
7 Likes