{"action":"created","comment":{"url":"https://api.github.com/repos/apple/swift-package-manager/pulls/comments/112932403","pull_request_review_id":34282078,"id":112932403,"diff_hunk":"@@ -0,0 +1,128 @@\n+import Foundation\n+import Basic\n+import PackageModel\n+\n+enum DestinationError: Swift.Error {\n+    /// Couldn't find the Xcode installation.\n+    case invalidInstallation(problem: String)\n+\n+    /// Wrong version.\n+    case destinationFileVersionMismatch(problem: String)\n+}\n+\n+extension DestinationError: CustomStringConvertible {\n+    var description: String {\n+        switch self {\n+        case .destinationFileVersionMismatch(let problem):\n+            return problem\n+        case .invalidInstallation(let problem):\n+            return problem\n+        }\n+    }\n+}\n+\n+/// The compilation destination, has information about everything that's required for a certain destination.\n+public struct Destination {\n+\n+    /// The clang/LLVM triple describing the target OS and architecture.\n+    public let target: String\n+\n+    /// The SDK used to compile for the destination.\n+    public let sdk: AbsolutePath\n+\n+    /// The toolchain containing the compilers/linker to be used for the compilation.\n+    public let toolchain: AbsolutePath\n+\n+    /// The file extension for dynamic libraries (eg. `.so` or `.dylib`)\n+    public let dynamicLibraryExtension: String\n+\n+    /// Additional flags to be passed to the C compiler.\n+    public let extraCCFlags: [String]\n+\n+    /// Additional flags to be passed to the Swift compiler.\n+    public let extraSwiftCFlags: [String]\n+\n+    /// Additional flags to be passed when compiling with C++.\n+    public let extraCPPFlags: [String]\n+\n+    /// The destination describing the host OS.\n+    public static func hostDestination() throws -> Destination {\n+        #if os(macOS)\n+            let sdkPath = try Process.checkNonZeroExit(args: \"xcrun\", \"--sdk\", \"macosx\", \"--show-sdk-path\").chomp()\n+            guard !sdkPath.isEmpty else {\n+                throw DestinationError.invalidInstallation(problem: \"could not find default SDK\")\n+            }\n+\n+            let platformPath = try Process.checkNonZeroExit(args: \"xcrun\", \"--sdk\", sdkPath, \"--show-sdk-platform-path\").chomp()\n+            guard !platformPath.isEmpty else {\n+                throw DestinationError.invalidInstallation(problem: \"could not find SDK platform path for SDK \\(sdkPath)\")\n+            }\n+\n+            let sdkPlatformFrameworksPath = AbsolutePath(platformPath).appending(components: \"Developer\", \"Library\", \"Frameworks\")\n+\n+            let devDirPath = try Process.checkNonZeroExit(args: \"xcode-select\", \"-p\").chomp()\n+            let platformFrameworkPath = AbsolutePath(sdkPath).appending(component: \"System\")\n+                                                             .appending(component: \"Library\")\n+                                                             .appending(component: \"Frameworks\").asString","path":"Sources/Build/Destination.swift","position":66,"original_position":66,"commit_id":"67e21fa85315843449cda781fde5ed1920694e7f","original_commit_id":"67e21fa85315843449cda781fde5ed1920694e7f","user":{"login":"aciidb0mb3r","id":4136295,"avatar_url":"https://avatars3.githubusercontent.com/u/4136295?v=3","gravatar_id":"","url":"https://api.github.com/users/aciidb0mb3r","html_url":"https://github.com/aciidb0mb3r","followers_url":"https://api.github.com/users/aciidb0mb3r/followers","following_url":"https://api.github.com/users/aciidb0mb3r/following{/other_user}","gists_url":"https://api.github.com/users/aciidb0mb3r/gists{/gist_id}","starred_url":"https://api.github.com/users/aciidb0mb3r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aciidb0mb3r/subscriptions","organizations_url":"https://api.github.com/users/aciidb0mb3r/orgs","repos_url":"https://api.github.com/users/aciidb0mb3r/repos","events_url":"https://api.github.com/users/aciidb0mb3r/events{/privacy}","received_events_url":"https://api.github.com/users/aciidb0mb3r/received_events","type":"User","site_admin":false},"body":"Do we need this? If yes, please document why.\r\n\r\nAlso, `AbsolutePath(sdkPath).appending(components: \"Developer\", \"Library\", \"Frameworks\").asString`","created_at":"2017-04-24T12:29:05Z","updated_at":"2017-04-24T12:29:05Z","html_url":"https://github.com/apple/swift-package-manager/pull/1098#discussion_r112932403","pull_request_url":"https://api.github.com/repos/apple/swift-package-manager/pulls/1098","_links":{"self":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/comments/112932403"},"html":{"href":"https://github.com/apple/swift-package-manager/pull/1098#discussion_r112932403"},"pull_request":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/1098"}}},"pull_request":{"url":"https://api.github.com/repos/apple/swift-package-manager/pulls/1098","id":116580316,"html_url":"https://github.com/apple/swift-package-manager/pull/1098","diff_url":"https://github.com/apple/swift-package-manager/pull/1098.diff","patch_url":"https://github.com/apple/swift-package-manager/pull/1098.patch","issue_url":"https://api.github.com/repos/apple/swift-package-manager/issues/1098","number":1098,"state":"open","locked":false,"title":"cross compilation support (configurable destinations)","user":{"login":"weissi","id":624238,"avatar_url":"https://avatars1.githubusercontent.com/u/624238?v=3","gravatar_id":"","url":"https://api.github.com/users/weissi","html_url":"https://github.com/weissi","followers_url":"https://api.github.com/users/weissi/followers","following_url":"https://api.github.com/users/weissi/following{/other_user}","gists_url":"https://api.github.com/users/weissi/gists{/gist_id}","starred_url":"https://api.github.com/users/weissi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weissi/subscriptions","organizations_url":"https://api.github.com/users/weissi/orgs","repos_url":"https://api.github.com/users/weissi/repos","events_url":"https://api.github.com/users/weissi/events{/privacy}","received_events_url":"https://api.github.com/users/weissi/received_events","type":"User","site_admin":false},"body":"# General\r\n\r\nThis adds _experimental_ support for cross compilation or more precisely configurable destinations for binaries to SwiftPM. The basic idea is that you hand a JSON file in the format described below to SwiftPM (ie. `swift build --destination my-destination.json`). SwiftPM will then invoke the `swiftc`/`clang` with the appropriate arguments. The `--destination` switch is optional and if omitted SwiftPM will use the destination as appropriate for the host OS as it previously did.\r\n\r\n# `destination.json` File Format\r\n\r\n    {\r\n        \"version\": \"1\",\r\n        \"sdk\": <path to the SDK for the target platform: String>,\r\n        \"toolchain\": <path to the toolchain: String>,\r\n        \"target\": <LLVM target triple: String>,\r\n        \"extra-cc-flags\": <extra C compiler arguments: [String]>,\r\n        \"extra-swiftc-flags\": <extra Swift compiler arguments: [String]>,\r\n        \"dynamic-library-extension\": <extension of dynamic library files: String>,\r\n        \"extra-cpp-flags\": <extra C++ compiler flags: [String]>\r\n    }\r\n\r\n## Example: compile for macOS on macOS\r\n\r\n    {\r\n        \"version\": \"1\",\r\n        \"sdk\": \"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/\",\r\n        \"toolchain\": \"/Library/Developer/Toolchains/swift-3.1-RELEASE.xctoolchain/\",\r\n        \"target\": \"x86_64-apple-macosx10.10\",\r\n        \"extra-cc-flags\": [\r\n            \"-arch\", \"x86_64\",\r\n            \"-mmacosx-version-min=10.10\"\r\n        ],\r\n        \"extra-swiftc-flags\": [],\r\n        \"extra-cpp-flags\": [\"-lc++\"],\r\n        \"dynamic-library-extension\": \"dylib\"\r\n    }\r\n\r\n## Example: compile for Ubuntu Linux on macOS (SDK required)\r\n\r\n    {\r\n        \"version\": \"1\",\r\n        \"sdk\": \"/Users/johannes/cross-toolchain/ubuntu-xenial.sdk\",\r\n        \"toolchain\": \"/Users/johannes/cross-toolchain/swift.xctoolchain\",\r\n        \"target\": \"linux-unknown-x86_64\",\r\n        \"dynamic-library-extension\": \"so\",\r\n        \"extra-cc-flags\": [\r\n            \"-fPIC\"\r\n        ],\r\n        \"extra-swiftc-flags\": [\r\n            \"-use-ld=gold\"\r\n        ],\r\n        \"extra-cpp-flags\": [\"-lstdc++\"]\r\n    }\r\n\r\n# Some Words About Cross Compilation\r\n\r\nTo cross compile a binary, you will need a cross compilation toolchain which consists of the toolchain itself and an SDK. For example compiling an iPhone binary from your Mac will use `/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.3.sdk` or similar. If you want to compile a Swift binary for say Ubuntu Xenial on your Mac, you'll need the following pieces of software\r\n\r\n - a compiler being able to cross compile ✅ (`swiftc` and `clang` are able to do that)\r\n - the basic Swift libraries (like `libswiftCore`) for Ubuntu ✅ (that's part of the Swift distribution for Ubuntu)\r\n - an SDK for Ubuntu Linux ✅ (that can be assembled from the `.deb` packages available from Ubuntu)\r\n - an ELF linker that runs on macOS ✅ (the [gold linker](https://sourceware.org/binutils/) from the GNU binutils can be compiled on macOS)\r\n\r\nIn other words, all the pieces of software are available for free online, they just need to be assembled in the correct way. An example script to do that all for Ubuntu Xenial can be found in a [separate PR](https://github.com/apple/swift-package-manager/pull/1099).","created_at":"2017-04-19T15:46:14Z","updated_at":"2017-04-24T12:29:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2e08efd0cfd36dc2c521a6f59b56798b26a4a93e","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apple/swift-package-manager/pulls/1098/commits","review_comments_url":"https://api.github.com/repos/apple/swift-package-manager/pulls/1098/comments","review_comment_url":"https://api.github.com/repos/apple/swift-package-manager/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apple/swift-package-manager/issues/1098/comments","statuses_url":"https://api.github.com/repos/apple/swift-package-manager/statuses/67e21fa85315843449cda781fde5ed1920694e7f","head":{"label":"weissi:jw-cross-compilation","ref":"jw-cross-compilation","sha":"67e21fa85315843449cda781fde5ed1920694e7f","user":{"login":"weissi","id":624238,"avatar_url":"https://avatars1.githubusercontent.com/u/624238?v=3","gravatar_id":"","url":"https://api.github.com/users/weissi","html_url":"https://github.com/weissi","followers_url":"https://api.github.com/users/weissi/followers","following_url":"https://api.github.com/users/weissi/following{/other_user}","gists_url":"https://api.github.com/users/weissi/gists{/gist_id}","starred_url":"https://api.github.com/users/weissi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weissi/subscriptions","organizations_url":"https://api.github.com/users/weissi/orgs","repos_url":"https://api.github.com/users/weissi/repos","events_url":"https://api.github.com/users/weissi/events{/privacy}","received_events_url":"https://api.github.com/users/weissi/received_events","type":"User","site_admin":false},"repo":{"id":88756927,"name":"swift-package-manager","full_name":"weissi/swift-package-manager","owner":{"login":"weissi","id":624238,"avatar_url":"https://avatars1.githubusercontent.com/u/624238?v=3","gravatar_id":"","url":"https://api.github.com/users/weissi","html_url":"https://github.com/weissi","followers_url":"https://api.github.com/users/weissi/followers","following_url":"https://api.github.com/users/weissi/following{/other_user}","gists_url":"https://api.github.com/users/weissi/gists{/gist_id}","starred_url":"https://api.github.com/users/weissi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/weissi/subscriptions","organizations_url":"https://api.github.com/users/weissi/orgs","repos_url":"https://api.github.com/users/weissi/repos","events_url":"https://api.github.com/users/weissi/events{/privacy}","received_events_url":"https://api.github.com/users/weissi/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/weissi/swift-package-manager","description":"The Package Manager for the Swift Programming Language","fork":true,"url":"https://api.github.com/repos/weissi/swift-package-manager","forks_url":"https://api.github.com/repos/weissi/swift-package-manager/forks","keys_url":"https://api.github.com/repos/weissi/swift-package-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/weissi/swift-package-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/weissi/swift-package-manager/teams","hooks_url":"https://api.github.com/repos/weissi/swift-package-manager/hooks","issue_events_url":"https://api.github.com/repos/weissi/swift-package-manager/issues/events{/number}","events_url":"https://api.github.com/repos/weissi/swift-package-manager/events","assignees_url":"https://api.github.com/repos/weissi/swift-package-manager/assignees{/user}","branches_url":"https://api.github.com/repos/weissi/swift-package-manager/branches{/branch}","tags_url":"https://api.github.com/repos/weissi/swift-package-manager/tags","blobs_url":"https://api.github.com/repos/weissi/swift-package-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/weissi/swift-package-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/weissi/swift-package-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/weissi/swift-package-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/weissi/swift-package-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/weissi/swift-package-manager/languages","stargazers_url":"https://api.github.com/repos/weissi/swift-package-manager/stargazers","contributors_url":"https://api.github.com/repos/weissi/swift-package-manager/contributors","subscribers_url":"https://api.github.com/repos/weissi/swift-package-manager/subscribers","subscription_url":"https://api.github.com/repos/weissi/swift-package-manager/subscription","commits_url":"https://api.github.com/repos/weissi/swift-package-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/weissi/swift-package-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/weissi/swift-package-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/weissi/swift-package-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/weissi/swift-package-manager/contents/{+path}","compare_url":"https://api.github.com/repos/weissi/swift-package-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/weissi/swift-package-manager/merges","archive_url":"https://api.github.com/repos/weissi/swift-package-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/weissi/swift-package-manager/downloads","issues_url":"https://api.github.com/repos/weissi/swift-package-manager/issues{/number}","pulls_url":"https://api.github.com/repos/weissi/swift-package-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/weissi/swift-package-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/weissi/swift-package-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/weissi/swift-package-manager/labels{/name}","releases_url":"https://api.github.com/repos/weissi/swift-package-manager/releases{/id}","deployments_url":"https://api.github.com/repos/weissi/swift-package-manager/deployments","created_at":"2017-04-19T14:50:51Z","updated_at":"2017-04-19T14:50:54Z","pushed_at":"2017-04-24T11:41:52Z","git_url":"git://github.com/weissi/swift-package-manager.git","ssh_url":"git@github.com:weissi/swift-package-manager.git","clone_url":"https://github.com/weissi/swift-package-manager.git","svn_url":"https://github.com/weissi/swift-package-manager","homepage":"","size":5377,"stargazers_count":0,"watchers_count":0,"language":"Swift","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"apple:master","ref":"master","sha":"3d57e636aec90d998510f589e71e37f8c8256d62","user":{"login":"apple","id":10639145,"avatar_url":"https://avatars3.githubusercontent.com/u/10639145?v=3","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"repo":{"id":44840041,"name":"swift-package-manager","full_name":"apple/swift-package-manager","owner":{"login":"apple","id":10639145,"avatar_url":"https://avatars3.githubusercontent.com/u/10639145?v=3","gravatar_id":"","url":"https://api.github.com/users/apple","html_url":"https://github.com/apple","followers_url":"https://api.github.com/users/apple/followers","following_url":"https://api.github.com/users/apple/following{/other_user}","gists_url":"https://api.github.com/users/apple/gists{/gist_id}","starred_url":"https://api.github.com/users/apple/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apple/subscriptions","organizations_url":"https://api.github.com/users/apple/orgs","repos_url":"https://api.github.com/users/apple/repos","events_url":"https://api.github.com/users/apple/events{/privacy}","received_events_url":"https://api.github.com/users/apple/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apple/swift-package-manager","description":"The Package Manager for the Swift Programming Language","fork":false,"url":"https://api.github.com/repos/apple/swift-package-manager","forks_url":"https://api.github.com/repos/apple/swift-package-manager/forks","keys_url":"https://api.github.com/repos/apple/swift-package-manager/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apple/swift-package-manager/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apple/swift-package-manager/teams","hooks_url":"https://api.github.com/repos/apple/swift-package-manager/hooks","issue_events_url":"https://api.github.com/repos/apple/swift-package-manager/issues/events{/number}","events_url":"https://api.github.com/repos/apple/swift-package-manager/events","assignees_url":"https://api.github.com/repos/apple/swift-package-manager/assignees{/user}","branches_url":"https://api.github.com/repos/apple/swift-package-manager/branches{/branch}","tags_url":"https://api.github.com/repos/apple/swift-package-manager/tags","blobs_url":"https://api.github.com/repos/apple/swift-package-manager/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apple/swift-package-manager/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apple/swift-package-manager/git/refs{/sha}","trees_url":"https://api.github.com/repos/apple/swift-package-manager/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apple/swift-package-manager/statuses/{sha}","languages_url":"https://api.github.com/repos/apple/swift-package-manager/languages","stargazers_url":"https://api.github.com/repos/apple/swift-package-manager/stargazers","contributors_url":"https://api.github.com/repos/apple/swift-package-manager/contributors","subscribers_url":"https://api.github.com/repos/apple/swift-package-manager/subscribers","subscription_url":"https://api.github.com/repos/apple/swift-package-manager/subscription","commits_url":"https://api.github.com/repos/apple/swift-package-manager/commits{/sha}","git_commits_url":"https://api.github.com/repos/apple/swift-package-manager/git/commits{/sha}","comments_url":"https://api.github.com/repos/apple/swift-package-manager/comments{/number}","issue_comment_url":"https://api.github.com/repos/apple/swift-package-manager/issues/comments{/number}","contents_url":"https://api.github.com/repos/apple/swift-package-manager/contents/{+path}","compare_url":"https://api.github.com/repos/apple/swift-package-manager/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apple/swift-package-manager/merges","archive_url":"https://api.github.com/repos/apple/swift-package-manager/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apple/swift-package-manager/downloads","issues_url":"https://api.github.com/repos/apple/swift-package-manager/issues{/number}","pulls_url":"https://api.github.com/repos/apple/swift-package-manager/pulls{/number}","milestones_url":"https://api.github.com/repos/apple/swift-package-manager/milestones{/number}","notifications_url":"https://api.github.com/repos/apple/swift-package-manager/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apple/swift-package-manager/labels{/name}","releases_url":"https://api.github.com/repos/apple/swift-package-manager/releases{/id}","deployments_url":"https://api.github.com/repos/apple/swift-package-manager/deployments","created_at":"2015-10-23T21:41:12Z","updated_at":"2017-04-24T12:27:12Z","pushed_at":"2017-04-24T12:16:36Z","git_url":"git://github.com/apple/swift-package-manager.git","ssh_url":"git@github.com:apple/swift-package-manager.git","clone_url":"https://github.com/apple/swift-package-manager.git","svn_url":"https://github.com/apple/swift-package-manager","homepage":"","size":5400,"stargazers_count":5420,"watchers_count":5420,"language":"Swift","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":523,"mirror_url":null,"open_issues_count":3,"forks":523,"open_issues":3,"watchers":5420,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/1098"},"html":{"href":"https://github.com/apple/swift-package-manager/pull/1098"},"issue":{"href":"https://api.github.com/repos/apple/swift-package-manager/issues/1098"},"comments":{"href":"https://api.github.com/repos/apple/swift-package-manager/issues/1098/comments"},"review_comments":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/1098/comments"},"review_comment":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apple/swift-package-manager/pulls/1098/commits"},"statuses":{"href":"https://api.github.com/repos/apple/swift-package-manager/statuses/67e21fa85315843449cda781fde5ed1920694e7f"}}}}
{"actor":{"display_login":"aciidb0mb3r"}}