-
Notifications
You must be signed in to change notification settings - Fork 258
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
Incremental swift compilation #21
Comments
Bazel in general does not support this. Each build gets a clean sandbox, so keeping previous object files is not possible. Changing the way bazel works is a much harder problem, sadly. That said, we currently use WMO on debug builds to speed up compilation. You can put "-wmo" into copts of a swift_library target to do that. |
Since our project is entirely written in Swift, even wmo builds take minutes, where incremental builds take < 10 seconds normally. Because of that I think it would never be feasible for us to use a tool that didn't support Swift incremental compilation. I'm surprised to hear that bazel has no support for this for any language? But I guess since this isn't really feasible to change we can close this. Thanks for the context! |
+1 Here in case the discussion continues...I understand Swift's compilation model presents unique challenges :) Same with @keith, we have a fairly large Swift application, and for development, incremental builds are the only way we could be productive. We plan on adopting bazel for all the other dependencies, and relying on Xcode for Swift. |
I'm going to reöpen this issue because I think it highlights an important area where we (that is, Bazel) could do better, even if we don't have any immediate clean solutions yet. I'll give it an appropriately low priority. FWIW, sandboxing can be disabled for individual actions (set @dmishe likely has more info or possible workarounds. |
Right, one way to achieve this is to make swift_library output intermediary files into a location outside of bazel tree, say, /tmp. This way bazel will only cleanup the final products, but swiftc will see previously built objects and use that. You will also need to add a global dependency map output (see https://github.com/apple/swift/blob/master/docs/Driver.md#output-file-maps) to make this work. The other, more sophisticated but also not hermetic, approach is to use a relatively new Bazel feature called persistent workers. This is in fact something we wanted to use in the long run. Let's keep this issue open to track this. |
First off, kudos to getting swift compiling under bazel 👍 I'm using swift for some small projects - my builds are running exclusively through Xcode, where I had a minute to look at the swift rules this morning, based on my ( weak ) understanding of bazel, I think it may work nicely with swifts compilation model. Have you considered:
I think a design similar to this could leverage bazel's hermaticness, caching, and incremental build abilities. This is just speculation: I haven't had a chance to implement this yet. Tangentially related, I was looking at some of the work the Swift team has done for Swift PM. They have been implementing a quite nice build system, lower level build system, which should also do incremental builds. I wonder how |
Is there a misunderstanding here? According to the user manual, incremental builds are a "primary goal" of Bazel: https://docs.bazel.build/versions/master/user-manual.html#correctness I made a small |
I believe dmishe was referring more about bazel's model being different enough to Swift's model to make incremental builds for Swift incompatible. |
Are there any related issues elsewhere about supporting the Swift-style incremental compilation model? It sounds like kotlin and rust might also benefit from support for this in bazel, although I'm not 100% sure they use exactly the same model. |
Since the |
Through some cursory tests to integrate bazel into our all swift project, we noticed that bazel doesn't currently support incremental swift compilation.
We've taken a stab at adding this by adding the
-incremental
and-emit-dependencies
compiler flags and adding the dependency information to theoutput_file_map.json
.If I then run the commands that are being ran by bazel manually, I get incremental compilation, but running from bazel, it does not work incrementally. It seems as though bazel is removing the previously generated files after each change.
Is there a reason the initial Swift support didn't support incremental compilation? Also are there any plans to add this? I would be happy to submit a PR for the changes we've made if you can point me in the right direction on the problems we've ran in to.
Thanks!
(This was copied over from bazelbuild/bazel#2781)
The text was updated successfully, but these errors were encountered: