Skip to content

[docs] Add an external description of the swiftc driver. #4992

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
Sep 27, 2016

Conversation

jrose-apple
Copy link
Contributor

Aimed at people writing build systems who won't be satisfied with "just use xcodebuild" or "just use SwiftPM", mostly because they'll go ahead doing what they're doing anyway and it'll be incorrect.

@jrose-apple
Copy link
Contributor Author

@modocache, @abertelrud, @rballard, @ddunbar, @gribozavr, anyone else: thoughts / suggestions?

Copy link
Contributor

@modocache modocache left a comment

Choose a reason for hiding this comment

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

Wow, this is so so great! Thanks for the write-up! ❤️

be part of the same module. Doing anything else is unsupported.

- The _driver_ is the program that's run when you invoke `swift` or `swiftc`
directly. This doesn't actually compile anything itself; instead it invokes
Copy link
Contributor

Choose a reason for hiding this comment

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

I found "directly" vague here. I understand the driver to be the program that's run when you invoke these executables without using the -frontend flag. The driver generates a series of commands that, for the most part, simply invoke swift -frontend.

"Directly" to me is unintuitive because when I invoke swift MyFile.swift, my understanding is that that's a pretty "direct" invocation. An "indirect" invocation would be when I invoke xcodebuild or something.

So, perhaps change the wording here a bit?

mode, executes it via a JIT).

The frontend is an implementation detail. No aspects of its command-line
interface are considered stable. Even its existence isn't guaranteed.
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow, good to know!


(It *would* be nice to have a way to get reasonable default behavior by
pointing `-o` at a directory, or by adding an `-intermediate-directory`
argument or something. Patches welcome.)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do these niceties come with Swift JIRA tasks? Linking to those would make it (a) easy for contributors to start that work, and (b) easy to understand when this blurb can be deleted from this doc.

Threaded mode is controlled by the `-num-threads` command-line option rather
than `-j` used to control the number of jobs (simultaneous subprocesses spawned
by the driver). Why? Well, they're not quite setting the same thing...but it's
unclear whether that difference is buying us anything.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate? As a reader, I would have expected the next paragraph to go into detail on why you thought the difference didn't have any benefits. As is, on the other hand, I just have unanswered questions lingering in my brain.

Perhaps pare this down to just:

Threaded mode is controlled by the -num-threads command-line option rather than -j, which is used to control the number of jobs (simultaneous subprocesses spawned by the driver).

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 actually can't remember the reasoning but I think I talked it through with @eeckstein at the time and it made sense. Erik, do you remember?

Copy link
Contributor

Choose a reason for hiding this comment

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

The reason is that applying -num-threads changes the generated code (even with an argument of 1). In theory it should not be performance relevant, but still, the code is different.
One would assume that -j has no influence on the generated code.

them they can be omitted.

The output file map accepts other entries, but they should not be considered
stable. Please stick to what's shown here.
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 we should document the "dependencies" key too, since you shouldn't be trying to do incremental compilation without also tracking the Clang module header deps.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good point.

"swift-dependencies": "/path/to/build/bar.swiftdeps",
"diagnostics": "/path/to/build/bar.dia",
},
"": {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe clarify this record doesn't map to anything?

Whole-module builds actually have two modes: threaded and non-threaded. The
default is non-threaded, which produces a single object file for the entire
compilation unit (.o). If you're just producing object files, you can use the
usual `-o` option with `-c` to control where the single output goes.
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably document the location of this in the object file map mode is controlled by the "object" entry of the "master" (i.e. "" entry).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we prefer that over -o/-c? In this guide, you shouldn't care about where intermediates go.

@ddunbar
Copy link
Contributor

ddunbar commented Sep 25, 2016

Looks great, and kudos for taking the time to write it up!

@jrose-apple
Copy link
Contributor Author

Addressed review feedback.

@swift-ci Please smoke test

"diagnostics": "/path/to/build/foo.dia",
},
"/path/to/src/bar.swift": {
"object": "/path/to/build/bar.o"
Copy link
Member

Choose a reason for hiding this comment

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

nitpick: missing comma.

Also, trailing comma ( e.g. ... .dia", }) are accepted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops, too used to YAML. Will fix.

Aimed at people writing build systems who won't be satisfied with
"just use xcodebuild" or "just use SwiftPM", mostly because they'll
go ahead doing what they're doing anyway and it'll be incorrect.
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test Linux platform

@jrose-apple jrose-apple merged commit 33228c6 into swiftlang:master Sep 27, 2016
@jrose-apple jrose-apple deleted the Driver.md branch September 27, 2016 19:01
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.

5 participants