diff --git a/action.yml b/action.yml index b20fad3..ef1f492 100644 --- a/action.yml +++ b/action.yml @@ -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: diff --git a/lib.d.ts b/lib.d.ts new file mode 100644 index 0000000..88b4e83 --- /dev/null +++ b/lib.d.ts @@ -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, +) diff --git a/lib.js b/lib.js index e1774d8..03762e1 100644 --- a/lib.js +++ b/lib.js @@ -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 @@ -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 @@ -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() @@ -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 @@ -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!') @@ -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) { @@ -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') } diff --git a/package.json b/package.json index 1b35f6e..d7028f7 100644 --- a/package.json +++ b/package.json @@ -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" },