Skip to content

WinSDK: explicitly re-export ucrt #35337

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 1 commit into from
Jan 12, 2021
Merged

Conversation

egorzhdan
Copy link
Contributor

@egorzhdan egorzhdan commented Jan 9, 2021

ucrt symbols are already implicitly available after an import WinSDK statement, however, WinSDK generated Swift interface does not indicate that.

Besides, WinSDK Swift overlay uses time_t in its public interface, which is declared in ucrt, but there is no corresponding import statement.

This change adds the import statement, to make the dependencies & exports more clear for the users, and to help with IDE integration.
The generated Swift interface for WinSDK after this change contains an import ucrt statement.

@egorzhdan egorzhdan requested a review from compnerd January 9, 2021 13:32
@compnerd
Copy link
Member

compnerd commented Jan 9, 2021

Im not sure how I feel about this. This is roughly similar to say UIKit exporting Darwin.C. How does this improve the usage scenarios for WinSDK?

@egorzhdan
Copy link
Contributor Author

This is mostly to make sure the generated Swift interface for WinSDK reflects what symbols are already being exported from it – ucrt contents were exported before this change, but the generated interface didn't indicate that. Exporting CRT rather than ucrt seemed like a good idea to me, but I can narrow it down to just ucrt if you disagree. That would fully solve the issue as well.

In practice this means that, for example, code referencing __crt_bool (or anything else declared in ucrt) without import ucrt statement would unexpectedly compile without errors given that import WinSDK is present, however, IDEs or static analysis tools would likely choke up on the usage of an undeclared symbol (this was my main motivation behind this PR).

This is roughly similar to say UIKit exporting Darwin.C

There's a difference though: UIKit has a Swiftified interface & is supposed to be used directly, while WinSDK would more likely be used via Swifty wrappers rather than directly, due to lots of rough edges caused by automatic C-to-Swift conversion, especially around pointers & strings.

@compnerd
Copy link
Member

compnerd commented Jan 9, 2021

ucrt is part of WInSDK, the thing is that CRT also exposes visualc which is technically more than just the WinSDK aspect. ucrt actually even resides in WinSDK (ucrt.modulemap is copied into Windows Kits\10\Include\...\ucrt), so I think I could be convinced that this is not too terrible. I wonder if we can adjust the WinSDK module in some other way to not conflate the C library with the Windows SDK.

There's a difference though: UIKit has a Swiftified interface & is supposed to be used directly, while WinSDK would more likely be used via Swifty wrappers rather than directly, due to lots of rough edges caused by automatic C-to-Swift conversion, especially around pointers & strings.

If there are simple things that can be done to improve the ergonomics of the WinSDK module, I think that we should consider adding them to the module. The raison d'être of the WinSDK (Swift) module is to ease the use of the clang module, otherwise we wouldn't need the module at all. I just haven't figured out a nice simple adjustment for the interfaces that eases the access.

ucrt symbols are already implicitly available after an `import WinSDK` statement, however, WinSDK generated Swift interface does not indicate that.

Besides, WinSDK Swift overlay uses `time_t` in its public interface, which is declared in ucrt, but there is no corresponding import statement.

This change adds the import statement, to make the dependencies & exports more clear for the users, and to help with IDE integration.
@egorzhdan egorzhdan changed the title WinSDK: explicitly re-export CRT WinSDK: explicitly re-export ucrt Jan 10, 2021
@egorzhdan
Copy link
Contributor Author

CRT also exposes visualc

Oh that's a fair point, I didn't realize that. Switched the import to just ucrt instead of CRT.

I wonder if we can adjust the WinSDK module in some other way to not conflate the C library with the Windows SDK.

I'm not sure it's possible to avoid exporting ucrt from WinSDK – it seems to be caused by the include-directive-to-module transformation, not by Swift-specific logic.

@compnerd
Copy link
Member

compnerd commented Jan 10, 2021

I wonder if we can adjust the WinSDK module in some other way to not conflate the C library with the Windows SDK.

I'm not sure it's possible to avoid exporting ucrt from WinSDK – it seems to be caused by the include-directive-to-module transformation, not by Swift-specific logic.

The include should convert to an import, of the module, which is a dependency of course. This changes the module to re-export the the dependent module.

My concern with this is just that the WinSDK module should not be vending the C library is all.

@compnerd
Copy link
Member

@swift-ci please smoke test

@compnerd compnerd merged commit cc45a70 into swiftlang:main Jan 12, 2021
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.

2 participants