Skip to content

[Explicit Module Builds][Target Variant] Refactor build planning to allow for a second, separate emit-module task for the target variant #1856

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

Merged
merged 4 commits into from
Jun 24, 2025

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented Mar 28, 2025

This change allows builds that specify a variant triple and which must emit a target variant module to do so from within a single swiftc invocation when using Explicit Module Builds.

This is an extensive refactor of the build planning procedure with respect to Explicit Module Builds:

  • Remove ExplicitDependencyBuildPlanner global state from the Driver instance
  • Instantiate a ExplicitDependencyBuildPlanner instance at the beginning if build planning and propagate/thread this instance to all the required compilation task creation routines, all the way to addCommonFrontendOptions
  • For -target-variant builds which emit a variant triple module, instantiate a whole separate explicit build planner, including performing a secondary dependency scan using the variant triple. Using this information:
    • Schedule variant triple module pre-compile dependency tasks
    • Schedule a variant triple PCH compilation task, if necessary
    • Schedule the variant emit-module task
    • Schedule the variant textual module verification task, if necessary

@artemcm
Copy link
Contributor Author

artemcm commented Mar 28, 2025

@swift-ci test

@artemcm artemcm force-pushed the VariantEmitModule branch from 6d351de to 95c6c6d Compare April 1, 2025 21:12
@artemcm
Copy link
Contributor Author

artemcm commented Apr 1, 2025

@swift-ci test

@artemcm artemcm force-pushed the VariantEmitModule branch from 95c6c6d to e1c9db6 Compare April 1, 2025 22:21
@artemcm
Copy link
Contributor Author

artemcm commented Apr 1, 2025

@swift-ci test

@artemcm artemcm force-pushed the VariantEmitModule branch from e1c9db6 to 16688ae Compare April 1, 2025 22:38
@artemcm
Copy link
Contributor Author

artemcm commented Apr 1, 2025

@swift-ci test

@artemcm
Copy link
Contributor Author

artemcm commented Apr 1, 2025

@swift-ci test Windows platform

1 similar comment
@artemcm
Copy link
Contributor Author

artemcm commented Apr 2, 2025

@swift-ci test Windows platform

@artemcm artemcm force-pushed the VariantEmitModule branch 2 times, most recently from 80d34fb to 5d7f59a Compare April 16, 2025 22:51
@artemcm
Copy link
Contributor Author

artemcm commented Apr 16, 2025

@swift-ci test

@artemcm
Copy link
Contributor Author

artemcm commented Apr 16, 2025

@swift-ci test Windows platform

1 similar comment
@artemcm
Copy link
Contributor Author

artemcm commented Apr 16, 2025

@swift-ci test Windows platform

@artemcm artemcm force-pushed the VariantEmitModule branch from 5d7f59a to 94c621f Compare April 17, 2025 16:06
@artemcm
Copy link
Contributor Author

artemcm commented Apr 17, 2025

@swift-ci test

@artemcm
Copy link
Contributor Author

artemcm commented Apr 18, 2025

@swift-ci test Windows platform

@artemcm artemcm force-pushed the VariantEmitModule branch from 94c621f to e47991f Compare April 18, 2025 22:40
@artemcm
Copy link
Contributor Author

artemcm commented Apr 18, 2025

@swift-ci test

@artemcm artemcm marked this pull request as ready for review April 18, 2025 22:41
@artemcm artemcm requested a review from etcwilde April 18, 2025 22:41
@artemcm
Copy link
Contributor Author

artemcm commented Apr 18, 2025

@swift-ci test Windows platform

@artemcm artemcm force-pushed the VariantEmitModule branch from e47991f to 6010b76 Compare April 22, 2025 17:49
@artemcm
Copy link
Contributor Author

artemcm commented Apr 22, 2025

@swift-ci test

@artemcm
Copy link
Contributor Author

artemcm commented Apr 22, 2025

@swift-ci test Windows platform

@artemcm artemcm force-pushed the VariantEmitModule branch from 6010b76 to bdf0ec6 Compare April 22, 2025 18:25
@artemcm
Copy link
Contributor Author

artemcm commented Apr 22, 2025

@swift-ci test
@swift-ci test Windows platform

@artemcm
Copy link
Contributor Author

artemcm commented Apr 22, 2025

@swift-ci test Windows platform

@artemcm
Copy link
Contributor Author

artemcm commented Apr 22, 2025

@swift-ci test

artemcm added 3 commits June 12, 2025 06:28
…llow for a second, separte emit-module task for the target variant

This change allows builds that specify a variant triple and which must emit a target variant module to do so from within a single `swiftc` invocation when using Explicit Module Builds.

This is an extensive refactor of the build planning procedure with respect to Explicit Module Builds:
- Remove 'ExplicitDependencyBuildPlanner' global state from the 'Driver' instance
- Instantiate a 'ExplicitDependencyBuildPlanner' instance at the beginning if build planning and propagate/thread this instance to all the required compilation task creation routines, all the way to 'addCommonFrontendOptions'
- For '-target-variant' builds which emit a variant triple module, instantiate a whole separate explicit build planner, including performing a secondary dependency scan using the variant triple. Using this information:
  - Schedule variant triple module pre-compile dependency tasks
  - Schedule a variant triple PCH compilation task, if necessary
  - Schedule the variant emit-module task
  - Schedule the variant textual module verification task, if necessary
…th known contents

Similarly to a 'temporaryWithKnownContents', but at an explicitly-determined-by-the-driver 'AbsolutePath'. This is useful for when the driver is able to determine that build planning will produce an input to compilation which must be placed in a specific location. For example, the chained bridging header content and output path are determined during build planning (specifically, dependency scanning) and must be fed into compilation tasks as inputs. This new file type will allow the driver to compute the new file and its contents and then have them get written to disk when resolving input paths to said compilation tasks.
@artemcm artemcm force-pushed the VariantEmitModule branch from 91811bb to 4b8f064 Compare June 12, 2025 13:28
@artemcm
Copy link
Contributor Author

artemcm commented Jun 12, 2025

@swift-ci test

@artemcm
Copy link
Contributor Author

artemcm commented Jun 13, 2025

@swift-ci test Windows platform

@artemcm
Copy link
Contributor Author

artemcm commented Jun 13, 2025

Ping for code review.

@artemcm
Copy link
Contributor Author

artemcm commented Jun 16, 2025

@swift-ci test Windows platform

1 similar comment
@artemcm
Copy link
Contributor Author

artemcm commented Jun 23, 2025

@swift-ci test Windows platform

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the changes look good.

Trying it out, do we want to drop the -target-variant when generating the module/interface for the target triple since it shows up as part of the module interface flags?

e.g. the target has

// swift-module-flags: -target x86_64-apple-macosx15 -target-variant x86_64-apple-ios18-macabi -enable-objc-interop -module-name hello

while the target variant interface has

// swift-module-flags: -target x86_64-apple-ios18-macabi -enable-objc-interop -module-name hello

Otherwise, I think it looks good to me. Thank you for taking care of this.

@artemcm
Copy link
Contributor Author

artemcm commented Jun 24, 2025

I think the changes look good.

Trying it out, do we want to drop the -target-variant when generating the module/interface for the target triple since it shows up as part of the module interface flags?

e.g. the target has

// swift-module-flags: -target x86_64-apple-macosx15 -target-variant x86_64-apple-ios18-macabi -enable-objc-interop -module-name hello

while the target variant interface has

// swift-module-flags: -target x86_64-apple-ios18-macabi -enable-objc-interop -module-name hello

Otherwise, I think it looks good to me. Thank you for taking care of this.

This behavior seems to be how we have been emitting flags into textual interfaces all along in the presence of a variant triple, so I'm not inclined to change it here. It would have to be done in the compiler anyways.

Copy link
Member

@etcwilde etcwilde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, it looks like it's included in the generated interfaces in the SDK today.
Carry on. LGTM

@artemcm artemcm merged commit 6750873 into swiftlang:main Jun 24, 2025
3 checks passed
@artemcm artemcm deleted the VariantEmitModule branch June 24, 2025 17:44
artemcm added a commit to artemcm/swift that referenced this pull request Jun 26, 2025
…t from a single driver invocation

This flag will be used to control opting into behavior introduced in swiftlang/swift-driver#1856
edymtt added a commit to edymtt/swift that referenced this pull request Jun 27, 2025
This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
edymtt added a commit to edymtt/swift that referenced this pull request Jun 27, 2025
This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
edymtt added a commit to edymtt/swift that referenced this pull request Jun 27, 2025
This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
edymtt added a commit to edymtt/swift that referenced this pull request Jun 27, 2025
… 4.1

This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
edymtt added a commit to edymtt/swift that referenced this pull request Jun 27, 2025
This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
edymtt added a commit to edymtt/swift that referenced this pull request Jun 27, 2025
This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
edymtt added a commit to edymtt/swift that referenced this pull request Jun 27, 2025
… 4.1

This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
edymtt added a commit to edymtt/swift that referenced this pull request Jun 30, 2025
This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
edymtt added a commit to edymtt/swift that referenced this pull request Jun 30, 2025
… 4.1

This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
susmonteiro pushed a commit to susmonteiro/swift that referenced this pull request Jul 2, 2025
…t from a single driver invocation

This flag will be used to control opting into behavior introduced in swiftlang/swift-driver#1856
susmonteiro pushed a commit to susmonteiro/swift that referenced this pull request Jul 2, 2025
This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
susmonteiro pushed a commit to susmonteiro/swift that referenced this pull request Jul 2, 2025
This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
susmonteiro pushed a commit to susmonteiro/swift that referenced this pull request Jul 2, 2025
… 4.1

This is needed in order to build target variants properly with a
SwiftDriver that has swiftlang/swift-driver#1856

Addresses rdar://154410676
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants