-
Notifications
You must be signed in to change notification settings - Fork 79
Add quick switcher between iOS and macOS targets #381
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,15 @@ interface SwiftTargetInfo { | |
[name: string]: string | object | undefined; | ||
} | ||
|
||
/** | ||
* A Swift compilation target that can be compiled to | ||
* from macOS. These are similar to XCode's target list. | ||
*/ | ||
export enum DarwinCompatibleTarget { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we want to support building for the simulator as well as device. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure about how to expose the simulator, hence why I didn't add it to start. Do you think it should be (in the switcher UI), labeled something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can give this a miss just now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I'm not familiar with that phrase 😓. Does "give this a miss" (here and other instances in this PR) mean to not worry about it for now? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "give this a miss" means "lets not bother" |
||
iOS, | ||
macOS, | ||
} | ||
|
||
export class SwiftToolchain { | ||
constructor( | ||
public swiftFolderPath: string, | ||
|
@@ -195,8 +204,8 @@ export class SwiftToolchain { | |
if (process.env.SDKROOT) { | ||
return process.env.SDKROOT; | ||
} | ||
const { stdout } = await execFile("xcrun", ["--sdk", "macosx", "--show-sdk-path"]); | ||
return path.join(stdout.trimEnd()); | ||
|
||
return this.getSdkForTarget(DarwinCompatibleTarget.macOS); | ||
} | ||
case "win32": { | ||
return process.env.SDKROOT; | ||
|
@@ -205,6 +214,30 @@ export class SwiftToolchain { | |
return undefined; | ||
} | ||
|
||
/** | ||
* @param target Target to obtain the SDK path for | ||
* @returns path to the SDK for the target | ||
*/ | ||
public static async getSdkForTarget( | ||
target: DarwinCompatibleTarget | ||
): Promise<string | undefined> { | ||
let sdkType: string; | ||
switch (target) { | ||
case DarwinCompatibleTarget.macOS: | ||
sdkType = "macosx"; | ||
break; | ||
case DarwinCompatibleTarget.iOS: | ||
sdkType = "iphoneos"; | ||
break; | ||
} | ||
|
||
// Include custom variables so that non-standard XCode installs can be better supported. | ||
const { stdout } = await execFile("xcrun", ["--sdk", sdkType, "--show-sdk-path"], { | ||
env: { ...process.env, ...configuration.swiftEnvironmentVariables }, | ||
}); | ||
return path.join(stdout.trimEnd()); | ||
} | ||
|
||
/** | ||
* @returns path to custom SDK | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the VSCode Swift open source project | ||
// | ||
// Copyright (c) 2022 the VSCode Swift project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of VSCode Swift project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import * as vscode from "vscode"; | ||
|
||
/** | ||
* Displays a QuickPick UI with the parameters and passes the result | ||
* to the provided closure. | ||
*/ | ||
export async function withQuickPick<T extends vscode.QuickPickItem>( | ||
placeholder: string, | ||
options: T[], | ||
onSelect: (picked: T) => Promise<void> | ||
) { | ||
const picker = vscode.window.createQuickPick<T>(); | ||
|
||
picker.placeholder = placeholder; | ||
picker.items = options; | ||
|
||
picker.show(); | ||
|
||
const pickedItem = await new Promise<T | undefined>(resolve => { | ||
picker.onDidAccept(() => resolve(picker.selectedItems[0])); | ||
picker.onDidHide(() => resolve(undefined)); | ||
}); | ||
|
||
picker.busy = true; | ||
|
||
if (pickedItem) { | ||
await onSelect(pickedItem); | ||
picker.busy = false; | ||
} | ||
|
||
picker.dispose(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,6 +251,36 @@ export function swiftDriverSDKFlags(indirect = false): string[] { | |
return indirect ? args.flatMap(arg => ["-Xswiftc", arg]) : args; | ||
} | ||
|
||
/** | ||
* Get target flags for swiftc | ||
* | ||
* @param indirect whether to pass the flags by -Xswiftc | ||
*/ | ||
export function swiftDriverTargetFlags(indirect = false): string[] { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure about setting the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that this is a bit fragile, but I wasn't sure of another way to do this without exposing SDK versioning information to the user as well, something that wouldn't necessary 95% of the time because XCode's SDK uses symlinks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What do you think about adding/removing the target parameter from the build arguments setting when you choose the platform? It would be clearer to the user what is happening. The current version is adding hidden arguments which might confuse the user. I don't have an issue with exposing the underlying details to the user EDIT: forget this. It's just as clunky There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we move to using destination files that'll make this a lot simpler |
||
const IPHONE_SDK_KIND = "iPhoneOS"; | ||
|
||
let args: string[] = []; | ||
|
||
if (configuration.sdk === "") { | ||
return args; | ||
} | ||
|
||
const sdkKindParts = configuration.sdk.split("/"); | ||
const sdkKind = sdkKindParts[sdkKindParts.length - 1]; | ||
if (sdkKind.includes(IPHONE_SDK_KIND)) { | ||
// Obtain the iOS version of the SDK. | ||
const version = sdkKind.substring( | ||
// Trim the prefix | ||
sdkKind.length - IPHONE_SDK_KIND.length, | ||
// Trim the `.sdk` suffix | ||
sdkKind.length - 4 | ||
); | ||
args = ["-target", `arm64-apple-ios${version}`]; | ||
} | ||
|
||
return indirect ? args.flatMap(arg => ["-Xswiftc", arg]) : args; | ||
} | ||
|
||
/** | ||
* Get the file name of executable | ||
* | ||
|
Uh oh!
There was an error while loading. Please reload this page.