Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: add types for the public functions #78

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ inputs:
description: Windows SDK number to build for
spectre:
description: Enable Specre mitigations
default: "false"
toolset:
description: VC++ compiler toolset version
uwp:
description: Build for Universal Windows Platform
default: "false"
vsversion:
description: The Visual Studio version to use. This can be the version number (e.g. 16.0 for 2019) or the year (e.g. "2019").
runs:
Expand Down
46 changes: 46 additions & 0 deletions lib.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Convert the vs version (e.g. 2022) or year (e.g. 17.0) to the version number (e.g. 17.0)
* @param {string | undefined} vsversion the year (e.g. 2022) or version number (e.g. 17.0)
* @returns {string | undefined} the version number (e.g. 17.0)
*/
export function vsversion_to_versionnumber(version: string | undefined): string | undefined

/**
* Convert the vs version (e.g. 17.0) or year (e.g. 2022) to the year (e.g. 2022)
* @param {string} vsversion the version number (e.g. 17.0) or year (e.g. 2022)
* @returns {string} the year (e.g. 2022)
*/
export function vsversion_to_year(version: string): string

/**
* Find MSVC tools with vswhere
* @param {string} pattern the pattern to search for
* @param {string} version_pattern the version pattern to search for
* @returns {string | null} the path to the found MSVC tools
*/
export function findWithVswhere(version: string, version_pattern: string): string | null

/**
* Find the vcvarsall.bat file for the given Visual Studio version
* @param {string | undefined} vsversion the version of Visual Studio to find (year or version number)
* @returns {string} the path to the vcvarsall.bat file
*/
export function findVcvarsall(version: string): string

/**
* Setup MSVC Developer Command Prompt
* @param {string} arch - Target architecture
* @param {string | undefined} sdk - Windows SDK number to build for
* @param {string | undefined} toolset - VC++ compiler toolset version
* @param {boolean | 'true' | 'false' | undefined} uwp - Build for Universal Windows Platform
* @param {boolean | 'true' | 'false' | undefined} spectre - Enable Spectre mitigations
* @param {string | undefined} vsversion - The Visual Studio version to use. This can be the version number (e.g. 16.0 for 2019) or the year (e.g. "2019").
*/
export function setupMSVCDevCmd(
arch: string,
sdk?: string,
toolset?: string,
uwp?: boolean | 'true' | 'false',
spectre?: boolean | 'true' | 'false',
vsversion?: string,
)
36 changes: 33 additions & 3 deletions lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ const VsYearVersion = {
'2013': '12.0',
}

/**
* Convert the vs version (e.g. 2022) or year (e.g. 17.0) to the version number (e.g. 17.0)
* @param {string | undefined} vsversion the year (e.g. 2022) or version number (e.g. 17.0)
* @returns {string | undefined} the version number (e.g. 17.0)
*/
function vsversion_to_versionnumber(vsversion) {
if (Object.values(VsYearVersion).includes(vsversion)) {
return vsversion
Expand All @@ -31,6 +36,11 @@ function vsversion_to_versionnumber(vsversion) {
}
exports.vsversion_to_versionnumber = vsversion_to_versionnumber

/**
* Convert the vs version (e.g. 17.0) or year (e.g. 2022) to the year (e.g. 2022)
* @param {string} vsversion the version number (e.g. 17.0) or year (e.g. 2022)
* @returns {string} the year (e.g. 2022)
*/
function vsversion_to_year(vsversion) {
if (Object.keys(VsYearVersion).includes(vsversion)) {
return vsversion
Expand All @@ -47,6 +57,12 @@ exports.vsversion_to_year = vsversion_to_year

const VSWHERE_PATH = `${PROGRAM_FILES_X86}\\Microsoft Visual Studio\\Installer`

/**
* Find MSVC tools with vswhere
* @param {string} pattern the pattern to search for
* @param {string} version_pattern the version pattern to search for
* @returns {string | null} the path to the found MSVC tools
*/
function findWithVswhere(pattern, version_pattern) {
try {
let installationPath = child_process.execSync(`vswhere -products * ${version_pattern} -prerelease -property installationPath`).toString().trim()
Expand All @@ -58,6 +74,11 @@ function findWithVswhere(pattern, version_pattern) {
}
exports.findWithVswhere = findWithVswhere

/**
* Find the vcvarsall.bat file for the given Visual Studio version
* @param {string | undefined} vsversion the version of Visual Studio to find (year or version number)
* @returns {string} the path to the vcvarsall.bat file
*/
function findVcvarsall(vsversion) {
const vsversion_number = vsversion_to_versionnumber(vsversion)
let version_pattern
Expand Down Expand Up @@ -120,7 +141,15 @@ function filterPathValue(path) {
return paths.filter(unique).join(';')
}

/** See https://github.com/ilammy/msvc-dev-cmd#inputs */
/**
* Setup MSVC Developer Command Prompt
* @param {string} arch - Target architecture
* @param {string | undefined} sdk - Windows SDK number to build for
* @param {string | undefined} toolset - VC++ compiler toolset version
* @param {boolean | 'true' | 'false' | undefined} uwp - Build for Universal Windows Platform
* @param {boolean | 'true' | 'false' | undefined} spectre - Enable Spectre mitigations
* @param {string | undefined} vsversion - The Visual Studio version to use. This can be the version number (e.g. 16.0 for 2019) or the year (e.g. "2019").
*/
function setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre, vsversion) {
if (process.platform != 'win32') {
core.info('This is not a Windows virtual environment, bye!')
Expand All @@ -147,7 +176,8 @@ function setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre, vsversion) {
// Call the configuration batch file and then output *all* the environment variables.

var args = [arch]
if (uwp == 'true') {

if (uwp && JSON.parse(uwp) === true) {
args.push('uwp')
}
if (sdk) {
Expand All @@ -156,7 +186,7 @@ function setupMSVCDevCmd(arch, sdk, toolset, uwp, spectre, vsversion) {
if (toolset) {
args.push(`-vcvars_ver=${toolset}`)
}
if (spectre == 'true') {
if (spectre && JSON.parse(spectre) === true) {
args.push('-vcvars_spectre_libs=spectre')
}

Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"version": "1.13.0-dev",
"description": "GitHub Action to setup Developer Command Prompt for Microsoft Visual C++",
"main": "index.js",
"types": "./lib.d.ts",
"type": "commonjs",
"scripts": {
"lint": "eslint index.js"
},
Expand Down