-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Auto generate module map file for C libs #219
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
1bf031e
to
28e7caa
Compare
public func generateModuleMap() throws { | ||
|
||
//Return if module map is already present | ||
guard !moduleMapPath.isFile else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens when a new header file is added and the modulemap file is checked in? Won't that not generate a new modulemap and thus not make the new header file available?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah there are two problems currently...
- module maps should probably be generated in build dir
- incremental map generation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I did not realize we were not generating them to the build directory. We should be doing that if we are going to generate at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will move the generation to build dir
28e7caa
to
d6efcea
Compare
@mxcl review/CI |
Maybe it should error if there is no I'm mainly thinking of the packaging graph. We don't want broken packages in the wild. OTOH maybe this is tedious. |
should I change it to not emit empty module and error out? |
I think this would be more consistent considering:
|
We definitely should be generating this stuff into a side directory in the build dir. I would prefer it not be an error to not have includes for a lib, just because that is useful when starting development. In general, I prefer it not to be an error for things that are "well formed" even if they aren't totally usable |
Maybe instead of:
We do:
Which then flows nicely with the existing:
|
Sounds good to me! |
d6efcea
to
1866db0
Compare
|
||
protocol Buildable { | ||
var targetName: String { get } | ||
var isTest: Bool { get } | ||
} | ||
|
||
extension CModule { | ||
func workingDirectory(prefix: String) -> String { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we get a documentation comment explaining what this function is?
Also, I think "workingDirectory" isn't the best name, something like "buildDirectory" would be closer to the intent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
ff84d87
to
b0057e3
Compare
@ddunbar addressed the comments re-review |
@swift-ci please test |
let package = Package( | ||
name: "ModuleMapGenerationCases", | ||
targets: [ | ||
Target(name: "Baz", dependencies: ["Foo", "Bar", "Jaz"])] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend renaming the subdirs here to match what the intent they are trying to test is. Otherwise, when someone comes back to this test they won't necessarily know why each case exists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@swift-ci please test |
return ["-Xcc", "-fmodule-map-file=\(module.moduleMapPath)"] | ||
} | ||
let genModuleMap = Path.join(module.buildDirectory(prefix), module.moduleMap) | ||
return ["-Xcc", "-fmodule-map-file=\(genModuleMap)"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this is obvious, but I am not seeing how this doesn't fail for non-library C language targets?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think it is unfortunate that we are more or less recomputing state here which is independently computed by generateModuleMap
. I don't think this is fixable in the current SwiftPM architecture, but it would be good to include a comment which points out that the behavior here is tied to that of the other function (and vice versa), so that if someone updates one they know to look at the other.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
they wont really be in dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding comment, but will push once CI returns
|
||
///There are three possible cases for which we will generate modulemaps: | ||
///Flat includes dir with only header files, in that case we generate | ||
/// `umbrella "path/to/includes/"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should generate umbrella header "foo.h"
even for the flat layout, if "foo.h" exists.
be1ff65
to
0b8e728
Compare
@ddunbar updated the generation logic to :
|
@swift-ci please test |
LGTM! A nice follow on would be to have more explanation in the "invalid layout" cases about exactly what failed, e.g.: |
Yay! Cool. I'll try to improve the error messages in another PR |
these are the updated cases for generating modulemaps: 1. Look for include/foo/foo.h, if so, use umbrella header and error if there are any other dirs or headers outside of there 2. Look for include/foo.h, if so, use umbrella header and error if there are any other dirs outside of there 3. All other cases, just use umbrella dir and don't bother to diagnose anything else
d6450e6
to
c47c6b8
Compare
Fixed the linux error, @ddunbar re run CI please |
@swift-ci please test |
osx tests keep failing due to some watch kit thingy |
@swift-ci please test and merge |
@swift-ci please test |
Thanks! |
Implemented a build manifest generator to help stress test llbuild.
This generates modulemap files according to the C proposal https://github.com/apple/swift-evolution/blob/master/proposals/0038-swiftpm-c-language-targets.md
Additionally if there is no
include
dir then it will emit an empty modulemap file with a warning.