{"action":"created","issue":{"url":"https://api.github.com/repos/apple/swift/issues/2912","repository_url":"https://api.github.com/repos/apple/swift","labels_url":"https://api.github.com/repos/apple/swift/issues/2912/labels{/name}","comments_url":"https://api.github.com/repos/apple/swift/issues/2912/comments","events_url":"https://api.github.com/repos/apple/swift/issues/2912/events","html_url":"https://github.com/apple/swift/pull/2912","id":158595180,"number":2912,"title":"Added -toolchain option to swiftc","user":{"login":"karwa","id":5254025,"avatar_url":"https://avatars.githubusercontent.com/u/5254025?v=3","gravatar_id":"","url":"https://api.github.com/users/karwa","html_url":"https://github.com/karwa","followers_url":"https://api.github.com/users/karwa/followers","following_url":"https://api.github.com/users/karwa/following{/other_user}","gists_url":"https://api.github.com/users/karwa/gists{/gist_id}","starred_url":"https://api.github.com/users/karwa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karwa/subscriptions","organizations_url":"https://api.github.com/users/karwa/orgs","repos_url":"https://api.github.com/users/karwa/repos","events_url":"https://api.github.com/users/karwa/events{/privacy}","received_events_url":"https://api.github.com/users/karwa/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":16,"created_at":"2016-06-06T03:34:40Z","updated_at":"2016-06-21T05:21:26Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/apple/swift/pulls/2912","html_url":"https://github.com/apple/swift/pull/2912","diff_url":"https://github.com/apple/swift/pull/2912.diff","patch_url":"https://github.com/apple/swift/pull/2912.patch"},"body":"<!-- Please complete this template before creating pull request. -->\r\n#### What's in this pull request?\r\n\r\nAdded a `-toolchain` swiftc option. This works like clang/gcc's `-B` flag (which allows specifying an alternate toolchain location).  We need to be able to cross-compile executables in order to cross-compile the LLDB swift REPL. Since I believe it's _only_ relevant for cross-compilers, I've made it a `swiftc`-only option (are there any use-cases for running the interpreter with an alternate toolchain?)\r\n\r\nCurrently, you can cross-compile with swift (assuming you've got a copy of the standard library compiled for the target), like so:\r\n```\r\nswiftc -target armv7-unknown-linux-gnueabihf -sdk ${sysroot} -resource-dir ${sdk-location} main.swift\r\n```\r\n\r\nHowever, this only works for modules (swiftmodules), not for executables. The host swift generates a link command to the system clang++ with `-fuse-ld=gold` (or whatever is the correct linker for the target platform), but there is currently no way to tell it where to find the cross-linker. Normally, you would put this information behind the `-B` switch, so we provide the same kind of functionality here. \r\n\r\nAdding `-toolchain ${gcc-toolchain-path}` to the above command allows swift to cross-compile an executable.\r\n\r\nThis was previously suggested as `-Blinker` (#2483) and I thought it was resolved by the update to clang accepting absolute linker paths, however there are two reasons why that isn't true:\r\n1. Swift's link commands go through the system clang, which might not support absolute linker paths\r\n2. You might not know which linker to use. We recently switched all Linux targets to use gold. Maybe there are different options for different hosts. The Swift compiler already knows which linker to search for in the toolchain, so it's convenient not to have to say this again.\r\n\r\nSo in short a `toolchain` flag is more flexible, and more compatible.\r\n\r\n#### Resolved bug number: ([SR-](https://bugs.swift.org/browse/SR-))\r\n<!-- If this pull request resolves any bugs from Swift bug tracker -->\r\n\r\n* * * *\r\n\r\n<!-- This selection should only be completed by Swift admin -->\r\nBefore merging this pull request to apple/swift repository:\r\n- [ ] Test pull request on Swift continuous integration.\r\n\r\n<details>\r\n  <summary>Triggering Swift CI</summary>\r\n\r\nThe swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:\r\n\r\n**Smoke Testing**\r\n\r\n        Platform     | Comment\r\n        ------------ | -------------\r\n        All supported platforms     | @swift-ci Please smoke test\r\n        All supported platforms     | @swift-ci Please smoke test and merge\r\n        OS X platform               | @swift-ci Please smoke test OS X platform\r\n        Linux platform              | @swift-ci Please smoke test Linux platform\r\n\r\n**Validation Testing**\r\n\r\n        Platform     | Comment\r\n        ------------ | -------------\r\n        All supported platforms     | @swift-ci Please test\r\n        All supported platforms     | @swift-ci Please test and merge\r\n        OS X platform               | @swift-ci Please test OS X platform\r\n        OS X platform               | @swift-ci Please benchmark\r\n        Linux platform              | @swift-ci Please test Linux platform\r\n\r\n\r\n**Lint Testing**\r\n\r\n        Language     | Comment\r\n        ------------ | -------------\r\n        Python       | @swift-ci Please Python lint\r\n\r\nNote: Only members of the Apple organization can trigger swift-ci.\r\n</details>\r\n<!-- Thank you for your contribution to Swift! -->\r\n"},"comment":{"url":"https://api.github.com/repos/apple/swift/issues/comments/227343275","html_url":"https://github.com/apple/swift/pull/2912#issuecomment-227343275","issue_url":"https://api.github.com/repos/apple/swift/issues/2912","id":227343275,"user":{"login":"lattner","id":15152540,"avatar_url":"https://avatars.githubusercontent.com/u/15152540?v=3","gravatar_id":"","url":"https://api.github.com/users/lattner","html_url":"https://github.com/lattner","followers_url":"https://api.github.com/users/lattner/followers","following_url":"https://api.github.com/users/lattner/following{/other_user}","gists_url":"https://api.github.com/users/lattner/gists{/gist_id}","starred_url":"https://api.github.com/users/lattner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lattner/subscriptions","organizations_url":"https://api.github.com/users/lattner/orgs","repos_url":"https://api.github.com/users/lattner/repos","events_url":"https://api.github.com/users/lattner/events{/privacy}","received_events_url":"https://api.github.com/users/lattner/received_events","type":"User","site_admin":false},"created_at":"2016-06-21T05:21:26Z","updated_at":"2016-06-21T05:21:26Z","body":"For example, I think it could be cool to be able to use something like:\r\nswiftc --toolchain beagleboard ....\r\n\r\nand have the compiler look for \"beagleboard.toolchain\" in a directory next to the swift executable (or some system location), then in your home directory, etc.  Of course an absolute path to a toolchain file should also work.  The toolchain file could have paths to all of the components that make up the toolchain as well as specify configuration options to specify the \"kind\" of component each is.\r\n\r\n+ @ddunbar since he probably also has thoughts on this from the SwiftPM / llbuild perspective.\r\n"}}
{"actor":{"display_login":"lattner"}}