Skip to content

Commit

Permalink
Add new option autoUpdateTriplet, add new commands setTargetTriplet/s…
Browse files Browse the repository at this point in the history
…etHostTriplet
  • Loading branch information
jyu49 committed Nov 15, 2023
1 parent 21244f7 commit 44bff98
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 13 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ Note: please only enable/disable in `workspace`!
2. Search vcpkg.
3. Select `vcpkg: Use dynamic library`.

### Set target triplet

1. Ctrl(⌘) + Shift + P
2. Search vcpkg.
3. Select `vcpkg: Set target triplet`.
4. Enter your target triplet

### Set host triplet

1. Ctrl(⌘) + Shift + P
2. Search vcpkg.
3. Select `vcpkg: Set host triplet`.
4. Enter your host triplet

### Enable/Disable automatically update host/target triplet

1. Open `Preferences` - `Settings` - `Extensions`(in `workspace`) - `Vcpkg`.
2. Select/Unselect `Vcpkg › General: Auto Update Triplet`.

### Set vcpkg additional install options

1. Open `Preferences` - `Settings` - `Extensions`(in `workspace`) - `Vcpkg`.
Expand Down
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"icon": "images/vcpkg-logo.png",
"publisher": "JackBoosY",
"license": "MIT",
"version": "2.0.5",
"version": "2.0.6",
"engines": {
"vscode": "^1.76.0"
},
Expand Down Expand Up @@ -61,6 +61,16 @@
"title": "Get current host triplet",
"category": "vcpkg"
},
{
"command": "vcpkg-integration.set_target_triplet",
"title": "Set target triplet",
"category": "vcpkg"
},
{
"command": "vcpkg-integration.set_host_triplet",
"title": "Set host triplet",
"category": "vcpkg"
},
{
"command": "vcpkg-integration.enable_manifest",
"title": "Enable manifest",
Expand Down Expand Up @@ -110,6 +120,12 @@
"description": "Use binary cache",
"scope": "resource"
},
"vcpkg.general.autoUpdateTriplet": {
"type": "boolean",
"default": false,
"description": "Automatically update triplet",
"scope": "resource"
},
"vcpkg.target.useManifest": {
"type": "boolean",
"default": false,
Expand Down
127 changes: 117 additions & 10 deletions src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ConfigurationManager implements vscode.Disposable
private _vcpkgPathConfig = 'general.vcpkgPath';
private _vcpkgAssetSourceConfig = 'general.assetSource';
private _vcpkgBinaryCacheConfig = 'general.binaryCaching';
private _autoUpdateTriplet = 'general.autoUpdateTriplet';
private _useManifestConfig = 'target.useManifest';
private _installDependenciesConfig = 'target.installDependencies';
private _preferSystemLibsConfig = 'target.preferSystemLibs';
Expand Down Expand Up @@ -52,6 +53,40 @@ export class ConfigurationManager implements vscode.Disposable
{
this._versionMgr.setVcpkgRoot(vcpkgPath);
}

// Update vcpkg target triplet
let automaticUpdateTriplet = workspace.getConfiguration('vcpkg').get<Boolean>(this._autoUpdateTriplet);
if (automaticUpdateTriplet && this.isVcpkgEnabled())
{
this.getCurrentTriplet().then((currentTriplet) => {
const currentArch = this.getArch();
if (currentTriplet !== undefined && this.combineTriplet(currentArch) !== currentTriplet)
{
let triplet = this.separateTriplet(currentTriplet);
if (currentArch.os !== triplet.os)
{
let newTriplet = this.combineTriplet({arch: triplet.arch, os: currentArch.os});
this.updateVcpkgSetting(this._targetTripletConfig, newTriplet);
this.logInfo('Automatically update target triplet to: ' + newTriplet);
vscode.window.showInformationMessage('Automatically update target triplet to: ' + newTriplet);
}
}
});
this.getCurrentHostTriplet().then((currentHostTriplet) => {
const currentArch = this.getArch();
if (currentHostTriplet !== undefined && this.combineTriplet(currentArch) !== currentHostTriplet)
{
let triplet = this.separateTriplet(currentHostTriplet);
if (triplet.os !== currentArch.os)
{
let newTriplet = this.combineTriplet({arch: triplet.arch, os: currentArch.os});
this.updateVcpkgSetting(this._hostTripletConfig, newTriplet);
this.logInfo('Automatically update host triplet to: ' + newTriplet);
vscode.window.showInformationMessage('Automatically update host triplet to: ' + newTriplet);
}
}
});
}
}

logInfo(content: string)
Expand Down Expand Up @@ -82,36 +117,59 @@ export class ConfigurationManager implements vscode.Disposable
{
if (process.arch === 'x64')
{
return "x64-windows";
return {arch: "x64", os: "windows"};
}
else if (process.arch === 'x86')
{
return "x86-windows";
return {arch: "x86", os: "windows"};
}
else if (process.arch.toLowerCase() === 'arm')
{
return "arm-windows";
return {arch: "arm", os: "windows"};
}
else if (process.arch.toLowerCase() === 'arm64')
{
return "arm64-windows";
return {arch: "arm64", os: "windows"};
}
else
{
return {arch: "x86", os: "windows"};
}
}
else if (process.platform === "darwin")
{
if (process.arch.toLowerCase() === 'arm64')
{
return "arm64-osx";
return {arch: "arm64", os: "osx"};
}
else
{
return "x64-osx";
return {arch: "x64", os: "osx"};
}
}
else if (process.platform === "linux")
{
return "x64-linux";
return {arch: "x64", os: "linux"};
}
else
{
vscode.window.showWarningMessage('Warning! Could NOT detect current triplet! Please set triplet manually.');
return {arch: "undefined", os: "undefined"};
}
}

private combineTriplet(triplet: {arch: string, os: string})
{
return triplet.arch + "-" + triplet.os;
}

private separateTriplet(triplet: string)
{
let sep = triplet.indexOf('-');
let arch = triplet.substring(0, sep);
let os = triplet.substring(sep + 1, triplet.length);

return {arch: arch, os: os};
}

private generateVcpkgFullPath(path: string)
Expand Down Expand Up @@ -359,7 +417,7 @@ export class ConfigurationManager implements vscode.Disposable
{
this.updateVcpkgSetting(this._vcpkgPathConfig, vcpkgPath, true);

let currArch = this.getArch();
let currArch = this.combineTriplet(this.getArch());

this.logInfo('current arch is: ' + currArch);

Expand Down Expand Up @@ -570,15 +628,64 @@ export class ConfigurationManager implements vscode.Disposable
this.logInfo('cmake options: ' + newConfigs.toString());
await this.updateCMakeSetting(this._cmakeOptionConfig, newConfigs);
}
async showCurrentTriplet()
{
vscode.window.showInformationMessage('Current triplet is: ' + this.getCurrentTriplet());
}

async setTargetTriplet()
{
vscode.window.showInputBox().then(async result => {
if (result?.length)
{
// the correct triplet name is "<arch>-<os>"
if (result.match(".+\-.+") !== null)
{
this.updateVcpkgSetting(this._targetTripletConfig, result);
this.logInfo('update target triplet to: ' + result);
vscode.window.showInformationMessage('Update target triplet to: ' + result);
}
else
{
vscode.window.showErrorMessage('Invalide triplet name.');
}
}
});
}

async setHostTriplet()
{
vscode.window.showInputBox().then(async result => {
if (result?.length)
{
// the correct triplet name is "<arch>-<os>"
if (result.match(".+\-.+") !== null)
{
this.updateVcpkgSetting(this._hostTripletConfig, result);
this.logInfo('update host triplet to: ' + result);
vscode.window.showInformationMessage('Update host triplet to: ' + result);
}
else
{
vscode.window.showErrorMessage('Invalide triplet name.');
}
}
});
}

async getCurrentTriplet()
{
vscode.window.showInformationMessage('Current triplet is: ' + workspace.getConfiguration('vcpkg').get<string>(this._targetTripletConfig));
return workspace.getConfiguration('vcpkg').get<string>(this._targetTripletConfig);
}

async showCurrentHostTriplet()
{
vscode.window.showInformationMessage('Current host triplet is: ' + this.getCurrentHostTriplet());
}

async getCurrentHostTriplet()
{
vscode.window.showInformationMessage('Current host triplet is: ' + workspace.getConfiguration('vcpkg').get<string>(this._hostTripletConfig));
return workspace.getConfiguration('vcpkg').get<string>(this._hostTripletConfig);
}

async useLibType(staticLib: boolean)
Expand Down
10 changes: 8 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ export function activate(context: vscode.ExtensionContext) {
disposables.push(vscode.commands.registerCommand('vcpkg-integration.disable_manifest', async() => await configMgr.disableManifest()));

// get current triplet
disposables.push(vscode.commands.registerCommand('vcpkg-integration.current_triplet', async() => await configMgr.getCurrentTriplet()));
disposables.push(vscode.commands.registerCommand('vcpkg-integration.current_triplet', async() => await configMgr.showCurrentTriplet()));

// get host triplet
disposables.push(vscode.commands.registerCommand('vcpkg-integration.current_host_triplet', async() => await configMgr.getCurrentHostTriplet()));
disposables.push(vscode.commands.registerCommand('vcpkg-integration.current_host_triplet', async() => await configMgr.showCurrentHostTriplet()));

// set current triplet
disposables.push(vscode.commands.registerCommand('vcpkg-integration.set_target_triplet', async() => await configMgr.setTargetTriplet()));

// set host triplet
disposables.push(vscode.commands.registerCommand('vcpkg-integration.set_host_triplet', async() => await configMgr.setHostTriplet()));

// use static lib
disposables.push(vscode.commands.registerCommand('vcpkg-integration.use_static_lib', async() => await configMgr.useLibType(true)));
Expand Down

0 comments on commit 44bff98

Please sign in to comment.