Skip to content
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

[SR-327] Add --outdir argument to swiftc #42949

Open
swift-ci opened this issue Dec 20, 2015 · 10 comments
Open

[SR-327] Add --outdir argument to swiftc #42949

swift-ci opened this issue Dec 20, 2015 · 10 comments
Assignees
Labels
compiler The Swift compiler itself feature A feature request or implementation legacy driver Area → compiler: the integrated C++ legacy driver. Succeeded by the swift-driver project

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-327
Radar None
Original Reporter jpakkane (JIRA User)
Type New Feature
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels New Feature, Driver
Assignee @modocache
Priority Medium

md5: ffc5d47714bb694b2a42adb551584a44

relates to:

  • SR-7704 swiftc -emit-module -c, driver documentation and diagnostics
  • SR-6079 Incremental compilation should not require an output file map
  • SR-6271 Unable to emit assembly from swift compiler to multiple files

Issue Description:

Currently swiftc writes all its output to current working directory. Please consider adding a --outdir argument so you can instruct swiftc to write its output to a different directory.

This makes it easier to integrate swiftc with other build systems. For example on Ninja you need to write all paths relative to the top level Ninja file directory. This leads to the weird situation that you need to manually cd into the output directory and invoke swiftc with paths that are different to what the Ninja file has.

As an example suppose you have a swift project with sources in Sources and you want to build in a directory called build and place the temporary files in a directory called build/tmpdir then you Ninja dependency looks [roughly] like this

executable [depends on] ../Sources/myexe.swift

but the compilation command is this:

cd tmpdir; swiftc -c ../../Sources/myexe.swift; cd ..

Note the extra '..' in the source file. This makes integration work needlessly complicated. With --outdir the command would look like this:

swiftc --outdir=tmpdir -c ../Sources/myexe.swift

@belkadan
Copy link
Contributor

We'd need something like this if we want to have incremental builds without having to write out a whole output file map. I'm not quite sure it's the right name because it's the directory used for intermediate files, not outputs, when swiftc is responsible for producing the output binary as well.

@swift-ci
Copy link
Contributor Author

swift-ci commented Feb 8, 2017

Comment by Raphael (JIRA)

Yes, please!

@belkadan The we probably need one parameter for tmps and one for outputs?

@belkadan
Copy link
Contributor

belkadan commented Feb 8, 2017

Interesting. I'm not sure there are many temporaries that don't make sense to persist in an incremental build, but I suppose we could support a separate directory for those.

@modocache
Copy link
Mannequin

modocache mannequin commented Oct 8, 2017

I'm interested in trying my hand at this task, if that's alright. I have a few questions:

  1. The task description mentions integrating swiftc with build systems such as Ninja. Is there another tool that integrates well with Ninja by providing something similar to this --outdir option? Does Clang provide something like this? I'd like to copy prior art if you have something in mind.

  2. Based on the way --outdir behaves in the task description above, to me it sounds similar to git -C <dir>, ninja -C <dir>, and make -C <dir>. That is, an option that switches to the directory <dir> before the tool does anything else. Is that the feature that's being described here?

@modocache
Copy link
Mannequin

modocache mannequin commented Oct 9, 2017

Thanks to z (JIRA User), who informed me that there's a clang -working-directory option. My understanding is that something similar should be implemented in Swift. I like the name of that option just fine, so I'll begin working on a swift -working-directory option.

@belkadan
Copy link
Contributor

belkadan commented Oct 9, 2017

No, this is completely different from -working-directory. That sets PWD; this is providing a place to put object files and other outputs without an output file map. We actually don't want to change PWD because search paths can be relative.

@belkadan
Copy link
Contributor

belkadan commented Oct 9, 2017

The only thing this should affect is calculating the paths of output files.

@modocache
Copy link
Mannequin

modocache mannequin commented Oct 9, 2017

OK, I think I understand. For my own clarification, though: is it possible that the original task was describing something like -working-directory? Because, as far as I've researched so far, the output file map doesn't effect input source file paths, but the original task description describes passing an input file tmp/myexe.swift as just myexe.swift. But output file maps are only used to specify paths to object files and other build products, not source files, right?

@belkadan
Copy link
Contributor

belkadan commented Oct 9, 2017

I don't think so. Note that in the original description ../Sources/myexe.swift is still supposed to be resolved relative to the (shell's) current directory, not the output directory.

@modocache
Copy link
Mannequin

modocache mannequin commented Oct 10, 2017

Oooh, I see! Yes, thanks, I think I was misreading it.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added feature A feature request or implementation and removed new feature labels Nov 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler itself feature A feature request or implementation legacy driver Area → compiler: the integrated C++ legacy driver. Succeeded by the swift-driver project
Projects
None yet
Development

No branches or pull requests

3 participants