Skip to content

[SR-13235] libSwiftPM should vend a ClangTarget's module map generation information to clients #2838

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

Conversation

abertelrud
Copy link
Contributor

@abertelrud abertelrud commented Jul 30, 2020

This also modifies module map generation to use the unified logic for determining the module map type, and cleans up diagnostics reporting.

With detection of module map type (based on a target's header layout) separate from generation of a module map, the existing ModuleMapGenerator API of having a struct that gets initialized only to perform the one operation (either determining module map type of generating a module map) is a bit clunky. We may want to refine that to make these standalone functions, but I think that can be done as a separate PR.

Vending the target's module map layout information provides more semantic information to the client than just vending the raw contents of the generated module map. This semantic information can then (for example) be shown in the user interface of an IDE, etc.

rdar://65678318

@abertelrud abertelrud force-pushed the eng/SR-13235-libswiftpm-should-vend-modulemap-type branch from 6bb68a8 to 16ac7cc Compare July 30, 2020 04:09
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@@ -71,6 +71,49 @@ public struct ModuleMapGenerator {
self.diagnostics = diagnostics
}

/// Determine the type of module map that applies to the specifed public-headers directory.
public static func determineModuleMapType(includeDir: AbsolutePath, moduleName: String, fileSystem: FileSystem) -> ModuleMapType {
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about refactoring and moving the type computation logic from generateModuleMap so we don't have two implementations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Absolutely. This was always the plan, and was noted in the PR description. But the intent was to do it in two phases so that one could be more safely pulled back to 5.3, with the switch for SwiftPM to use the module type being for the next release. But I think it's probably too late to nominate for 5.3 in any case, so I've converted this back to a draft PR until I've put the second part in place.

But to be clear, it was never the intent to leave both implementations in the long run. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the PR to do this.

@@ -356,6 +356,9 @@ public class ClangTarget: Target {

/// The path to include directory.
public let includeDir: AbsolutePath

/// The target's module map type; determined by the file system layout, and controls whether the build system will use a custom module map, generate a module map, etc.
public let moduleMapType: ModuleMapType
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not really sure that it makes sense to encode the module map type in the target. Clients which need to find out the module map type can directly call ModuleMapGenerator API, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it makes sense to separate the decision from the generator, so clients could provide their own generator if desired, but could still use the type as determined by libSwiftPM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right, the longer-term goal here is to have the information vended by libSwiftPM include all the semantic information that's relevant about the target. One of those is the disposition of its headers. It still makes sense to have a module map generation facility in SwiftPM (at least while it has its own custom build system), but I expect that many clients that can already generate module maps would want to use their own facility and just needs to know the decisions that SwiftPM made. This can also include things like showing this information to users in some form, e.g. when inspecting a package-defined target to find out how SwiftPM interpreted it. The plan is also to add this to the describe command.

As I mentioned in the previous response, this PR has the minimal support that could be pulled back to 5.3, but as it is probably too late for that kind of change in 5.3, I've converted this to a draft PR will I fill in the rest of the changes to complete the picture here. I'll probably still keep them as separate independently testable commits, for clarity.

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks great, this is pretty much exactly what I was envisioning w.r.t 50872333 👍

@abertelrud abertelrud marked this pull request as draft July 31, 2020 00:07
@abertelrud
Copy link
Contributor Author

Since this is not going into 5.3 anyway at this point, I will rework this so that we use the same module map implementation all around (ideally also for the XCBuild support).

@abertelrud abertelrud force-pushed the eng/SR-13235-libswiftpm-should-vend-modulemap-type branch from 16ac7cc to 18da011 Compare September 7, 2020 23:31
…on info

This also modifies module map generation to use the unified logic for determining the module map type, and cleans up diagnostics reporting.

With detection of module map type (based on a target's header layout) separate from generation of a module map, the existing ModuleMapGenerator API of having a struct that gets initialized only to perform the one operation (either determining module map type of generating a module map) is a bit clunky.  We may want to refine that to make these standalone functions.

Vending the target's module map layout information provides more semantic information to the client than just vending the raw contents of the generated module map.  This semantic information can then (for example) be shown in the user interface of an IDE, etc.

rdar://65678318
@abertelrud abertelrud force-pushed the eng/SR-13235-libswiftpm-should-vend-modulemap-type branch from 18da011 to ee1ab4c Compare September 8, 2020 16:14
@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test

@abertelrud
Copy link
Contributor Author

Not sure if the Linux failure is related, but it might well be. Looking into it.

<unknown>:0: error: module file \'/home/buildnode/jenkins/workspace/swift-package-manager-Linux-smoke-test/branch-master/build/buildbot_incremental/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/release/3F0X9RIPKZK85/SwiftShims-1H53JKTOZRM74.pcm\' is out of date and needs to be rebuilt: signature mismatch\n<unknown>:0: note: imported by module \'SwiftOverlayShims\' in \'/home/buildnode/jenkins/workspace/swift-package-manager-Linux-smoke-test/branch-master/build/buildbot_incremental/swiftpm-linux-x86_64/x86_64-unknown-linux-gnu/release/3F0X9RIPKZK85/SwiftOverlayShims-1H53JKTOZRM74.pcm\'\n/home/buildnode/jenkins/workspace/swift-package-manager-Linux-smoke-test/branch-master/tmp/DependencyResolution_External_Complex.v8JwwI/app/.build/checkouts/FisherYates/src/Fisher-Yates_Shuffle.swift:4:8: error: missing required module \'SwiftOverlayShims\'\nimport Glibc\n ^\n

@abertelrud
Copy link
Contributor Author

The same test passed in the self-hosted test, however. Also, the failure is in one of the overlay shims modules, not affected by whether or not a particular Clang target exports module a from its headers.

@abertelrud
Copy link
Contributor Author

@swift-ci please smoke test linux

@abertelrud abertelrud marked this pull request as ready for review September 8, 2020 22:09
@abertelrud abertelrud self-assigned this Sep 8, 2020
@abertelrud abertelrud merged commit 60ffec7 into swiftlang:master Sep 10, 2020
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.

4 participants