diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6bd2c9f02..e47e95c65 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -15,12 +15,14 @@ jobs: strategy: fail-fast: false matrix: - os: [ ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11.0, windows-2016, windows-2019 ] + os: [ ubuntu-18.04, ubuntu-20.04, macos-10.15, macos-11.0, windows-2016, windows-2019, windows-2022 ] ruby: [ 1.9, '2.0', 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, '3.0', 3.1, ruby-head, jruby, jruby-head, truffleruby, truffleruby-head, truffleruby+graalvm, truffleruby+graalvm-head ] include: - { os: windows-2016, ruby: mingw } - { os: windows-2019, ruby: mingw } - { os: windows-2019, ruby: mswin } + - { os: windows-2022, ruby: mingw } + - { os: windows-2022, ruby: ucrt } exclude: - { os: windows-2016, ruby: 1.9 } - { os: windows-2016, ruby: debug } @@ -34,6 +36,12 @@ jobs: - { os: windows-2019, ruby: truffleruby-head } - { os: windows-2019, ruby: truffleruby+graalvm } - { os: windows-2019, ruby: truffleruby+graalvm-head } + - { os: windows-2022, ruby: 1.9 } + - { os: windows-2022, ruby: debug } + - { os: windows-2022, ruby: truffleruby } + - { os: windows-2022, ruby: truffleruby-head } + - { os: windows-2022, ruby: truffleruby+graalvm } + - { os: windows-2022, ruby: truffleruby+graalvm-head } name: ${{ matrix.os }} ${{ matrix.ruby }} runs-on: ${{ matrix.os }} diff --git a/common.js b/common.js index d505d0a0f..8520a0a86 100644 --- a/common.js +++ b/common.js @@ -48,7 +48,7 @@ export async function measure(name, block) { } export function isHeadVersion(rubyVersion) { - return rubyVersion === 'head' || rubyVersion === 'debug' || rubyVersion === 'mingw' || rubyVersion === 'mswin' + return ['head', 'debug', 'mingw', 'mswin', 'ucrt'].includes(rubyVersion) } export function isStableVersion(rubyVersion) { @@ -155,7 +155,15 @@ export function win2nix(path) { return path.replace(/\\/g, '/').replace(/ /g, '\\ ') } +// JRuby is installed after setupPath is called, so folder doesn't exist +function rubyIsUCRT(path) { + return !!(fs.existsSync(path) && + fs.readdirSync(path, { withFileTypes: true }).find(dirent => + dirent.isFile() && dirent.name.match(/^x64-ucrt-ruby\d{3}\.dll$/))) +} + export function setupPath(newPathEntries) { + let win_build_sys = null const envPath = windows ? 'Path' : 'PATH' const originalPath = process.env[envPath].split(path.delimiter) let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry)) @@ -176,8 +184,11 @@ export function setupPath(newPathEntries) { // Then add new path entries using core.addPath() let newPath if (windows) { + // main Ruby dll determines whether mingw or ucrt build + win_build_sys = rubyIsUCRT(newPathEntries[0]) ? 'ucrt64' : 'mingw64' + // add MSYS2 in path for all Rubies on Windows, as it provides a better bash shell and a native toolchain - const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin'] + const msys2 = [`C:\\msys64\\${win_build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] newPath = [...newPathEntries, ...msys2] } else { newPath = newPathEntries @@ -189,4 +200,5 @@ export function setupPath(newPathEntries) { core.endGroup() core.addPath(newPath.join(path.delimiter)) + return win_build_sys } diff --git a/dist/index.js b/dist/index.js index 5b11c2c4c..2aa50e835 100644 --- a/dist/index.js +++ b/dist/index.js @@ -296,7 +296,7 @@ async function measure(name, block) { } function isHeadVersion(rubyVersion) { - return rubyVersion === 'head' || rubyVersion === 'debug' || rubyVersion === 'mingw' || rubyVersion === 'mswin' + return ['head', 'debug', 'mingw', 'mswin', 'ucrt'].includes(rubyVersion) } function isStableVersion(rubyVersion) { @@ -403,7 +403,15 @@ function win2nix(path) { return path.replace(/\\/g, '/').replace(/ /g, '\\ ') } +// JRuby is installed after setupPath is called, so folder doesn't exist +function rubyIsUCRT(path) { + return !!(fs.existsSync(path) && + fs.readdirSync(path, { withFileTypes: true }).find(dirent => + dirent.isFile() && dirent.name.match(/^x64-ucrt-ruby\d{3}\.dll$/))) +} + function setupPath(newPathEntries) { + let win_build_sys = null const envPath = windows ? 'Path' : 'PATH' const originalPath = process.env[envPath].split(path.delimiter) let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry)) @@ -424,8 +432,11 @@ function setupPath(newPathEntries) { // Then add new path entries using core.addPath() let newPath if (windows) { + // main Ruby dll determines whether mingw or ucrt build + win_build_sys = rubyIsUCRT(newPathEntries[0]) ? 'ucrt64' : 'mingw64' + // add MSYS2 in path for all Rubies on Windows, as it provides a better bash shell and a native toolchain - const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin'] + const msys2 = [`C:\\msys64\\${win_build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] newPath = [...newPathEntries, ...msys2] } else { newPath = newPathEntries @@ -437,6 +448,7 @@ function setupPath(newPathEntries) { core.endGroup() core.addPath(newPath.join(path.delimiter)) + return win_build_sys } @@ -58907,7 +58919,7 @@ async function downloadAndExtract(platform, engine, version, rubyPrefix) { return await tc.downloadTool(url) }) - await common.measure('Extracting Ruby', async () => { + await common.measure('Extracting Ruby', async () => { if (windows) { // Windows 2016 doesn't have system tar, use MSYS2's, it needs unix style paths await exec.exec('tar', ['-xz', '-C', common.win2nix(parentDir), '-f', common.win2nix(downloadPath)]) @@ -58997,7 +59009,8 @@ const versions = { "3.1.0": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-3.1.0-1/rubyinstaller-3.1.0-1-x64.7z", "head": "https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-head-x64.7z", "mingw": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mingw.7z", - "mswin": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mswin.7z" + "mswin": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mswin.7z", + "ucrt": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-ucrt.7z" } @@ -59011,6 +59024,7 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ __nccwpck_require__.d(__webpack_exports__, { /* harmony export */ "getAvailableVersions": () => (/* binding */ getAvailableVersions), /* harmony export */ "install": () => (/* binding */ install), +/* harmony export */ "installJRubyTools": () => (/* binding */ installJRubyTools), /* harmony export */ "addVCVARSEnv": () => (/* binding */ addVCVARSEnv) /* harmony export */ }); // Most of this logic is from @@ -59028,6 +59042,8 @@ const rubyInstallerVersions = __nccwpck_require__(7223)/* .versions */ .d const drive = common.drive +const msys2BasePath = 'C:\\msys64' + // needed for 2.0-2.3, and mswin, cert file used by Git for Windows const certFile = 'C:\\Program Files\\Git\\mingw64\\ssl\\cert.pem' @@ -59035,6 +59051,8 @@ const certFile = 'C:\\Program Files\\Git\\mingw64\\ssl\\cert.pem' const msys = `${drive}:\\DevKit64` const msysPathEntries = [`${msys}\\mingw\\x86_64-w64-mingw32\\bin`, `${msys}\\mingw\\bin`, `${msys}\\bin`] +const virtualEnv = common.getVirtualEnvironmentName() + function getAvailableVersions(platform, engine) { if (engine === 'ruby') { return Object.keys(rubyInstallerVersions) @@ -59046,6 +59064,10 @@ function getAvailableVersions(platform, engine) { async function install(platform, engine, version) { const url = rubyInstallerVersions[version] + // The windows-2016 and windows-2019 images have MSYS2 build tools (C:/msys64/usr) + // and MinGW build tools installed. The windows-2022 image has neither. + const hasMSYS2PreInstalled = ['windows-2019', 'windows-2016'].includes(virtualEnv) + if (!url.endsWith('.7z')) { throw new Error(`URL should end in .7z: ${url}`) } @@ -59065,15 +59087,72 @@ async function install(platform, engine, version) { let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version) - common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) - if (!inToolCache) { await downloadAndExtract(engine, version, url, base, rubyPrefix); } + const winMSYS2Type = common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) + + // install msys2 tools for all Ruby versions, only install mingw or ucrt for Rubies >= 2.4 + + if (!hasMSYS2PreInstalled) { + await installMSYS2Tools() + } + + // windows 2016 and 2019 need ucrt64 installed, 2022 and future images need + // ucrt64 or mingw64 installed, depending on Ruby version + if (((winMSYS2Type === 'ucrt64') || !hasMSYS2PreInstalled) && + (common.floatVersion(version) >= 2.4)) { + await installGCCTools(winMSYS2Type) + } + + const ridk = `${rubyPrefix}\\bin\\ridk.cmd` + if (fs.existsSync(ridk)) { + await common.measure('Adding ridk env variables', async () => addRidkEnv(ridk)) + } + return rubyPrefix } +// Actions windows-2022 image does not contain any mingw or ucrt build tools. Install tools for it, +// and also install ucrt tools on earlier versions, which have msys2 and mingw tools preinstalled. +async function installGCCTools(type) { + const downloadPath = await common.measure(`Downloading ${type} build tools`, async () => { + let url = `https://github.com/MSP-Greg/setup-msys2-gcc/releases/download/msys2-gcc-pkgs/${type}.7z` + console.log(url) + return await tc.downloadTool(url) + }) + + await common.measure(`Extracting ${type} build tools`, async () => + // -aoa overwrite existing, -bd disable progress indicator + exec.exec('7z', ['x', downloadPath, '-aoa', '-bd', `-o${msys2BasePath}`], { silent: true })) +} + +// Actions windows-2022 image does not contain any MSYS2 build tools. Install tools for it. +// A subset of the MSYS2 base-devel group +async function installMSYS2Tools() { + const downloadPath = await common.measure(`Downloading msys2 build tools`, async () => { + let url = `https://github.com/MSP-Greg/setup-msys2-gcc/releases/download/msys2-gcc-pkgs/msys2.7z` + console.log(url) + return await tc.downloadTool(url) + }) + + // need to remove all directories, since they may indicate old packages are installed, + // otherwise, error of "error: duplicated database entry" + fs.rmdirSync(`${msys2BasePath}\\var\\lib\\pacman\\local`, { recursive: true, force: true }) + + await common.measure(`Extracting msys2 build tools`, async () => + // -aoa overwrite existing, -bd disable progress indicator + exec.exec('7z', ['x', downloadPath, '-aoa', '-bd', `-o${msys2BasePath}`], { silent: true })) +} + +// Windows JRuby can install gems that require compile tools, only needed for +// windows-2022 and later images +async function installJRubyTools() { + await installMSYS2Tools() + await installGCCTools('mingw64') +} + async function downloadAndExtract(engine, version, url, base, rubyPrefix) { const parentDir = path.dirname(rubyPrefix) @@ -59082,8 +59161,9 @@ async function downloadAndExtract(engine, version, url, base, rubyPrefix) { return await tc.downloadTool(url) }) - await common.measure('Extracting Ruby', async () => - exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true })) + await common.measure('Extracting Ruby', async () => + // -bd disable progress indicator, -xr extract but exclude share\doc files + exec.exec('7z', ['x', downloadPath, '-bd', `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true })) if (base !== path.basename(rubyPrefix)) { await io.mv(path.join(parentDir, base), rubyPrefix) @@ -59097,6 +59177,11 @@ async function downloadAndExtract(engine, version, url, base, rubyPrefix) { async function setupMingw(version) { core.exportVariable('MAKE', 'make.exe') + // rename these to avoid confusion when Ruby is using OpenSSL 1.0.2 + // most current extconf files look for 1.1.x dll files first, which is the + // version of the renamed files + if (common.floatVersion(version) <= 2.4) { renameSystem32Dlls() } + if (common.floatVersion(version) <= 2.3) { core.exportVariable('SSL_CERT_FILE', certFile) await common.measure('Installing MSYS', async () => installMSYS(version)) @@ -59141,9 +59226,22 @@ async function setupMSWin() { /* Sets MSVC environment for use in Actions * allows steps to run without running vcvars*.bat, also for PowerShell * adds a convenience VCVARS environment variable - * this assumes a single Visual Studio version being available in the windows-latest image */ + * this assumes a single Visual Studio version being available in the Windows images */ function addVCVARSEnv() { - const vcVars = '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"' + let vcVars = '' + switch (virtualEnv) { + case 'windows-2016': + vcVars = '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"' + break + case 'windows-2019': + vcVars = '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"' + break + case 'windows-2022': + vcVars = '"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"' + break + default: + throw new Error(`Unknown Windows Image: ${virtualEnv}`) + } core.exportVariable('VCVARS', vcVars) let newEnv = new Map() @@ -59169,6 +59267,39 @@ function addVCVARSEnv() { return newPathEntries } +// ssl files cause issues with non RI2 Rubies (<2.4) and ruby/ruby's CI from +// build folder due to dll resolution +function renameSystem32Dlls() { + const sys32 = 'C:\\Windows\\System32\\' + const badFiles = ['libcrypto-1_1-x64.dll', 'libssl-1_1-x64.dll'] + badFiles.forEach( (bad) => { + let fn = `${sys32}${bad}` + if (fs.existsSync(fn)) { fs.renameSync(fn, `${fn}_`) } + }) +} + +// Sets MSYS2 ENV variables set from running `ridk enable` +// +function addRidkEnv(ridk) { + let newEnv = new Map() + let cmd = `cmd.exe /c "${ridk} enable && set"` + let newSet = cp.execSync(cmd).toString().trim().split(/\r?\n/) + newSet = newSet.filter(line => /^\S+=\S+/.test(line)) + newSet.forEach(s => { + let [k,v] = common.partition(s, '=') + newEnv.set(k,v) + }) + + for (let [k, v] of newEnv) { + if (process.env[k] !== v) { + if (!/^Path$/i.test(k)) { + console.log(`${k}=${v}`) + core.exportVariable(k, v) + } + } + } +} + /***/ }), @@ -59200,7 +59331,7 @@ module.exports = JSON.parse('["ac","com.ac","edu.ac","gov.ac","net.ac","mil.ac", /***/ ((module) => { "use strict"; -module.exports = require("assert");; +module.exports = require("assert"); /***/ }), @@ -59208,7 +59339,7 @@ module.exports = require("assert");; /***/ ((module) => { "use strict"; -module.exports = require("buffer");; +module.exports = require("buffer"); /***/ }), @@ -59216,7 +59347,7 @@ module.exports = require("buffer");; /***/ ((module) => { "use strict"; -module.exports = require("child_process");; +module.exports = require("child_process"); /***/ }), @@ -59224,7 +59355,7 @@ module.exports = require("child_process");; /***/ ((module) => { "use strict"; -module.exports = require("crypto");; +module.exports = require("crypto"); /***/ }), @@ -59232,7 +59363,7 @@ module.exports = require("crypto");; /***/ ((module) => { "use strict"; -module.exports = require("events");; +module.exports = require("events"); /***/ }), @@ -59240,7 +59371,7 @@ module.exports = require("events");; /***/ ((module) => { "use strict"; -module.exports = require("fs");; +module.exports = require("fs"); /***/ }), @@ -59248,7 +59379,7 @@ module.exports = require("fs");; /***/ ((module) => { "use strict"; -module.exports = require("http");; +module.exports = require("http"); /***/ }), @@ -59256,7 +59387,7 @@ module.exports = require("http");; /***/ ((module) => { "use strict"; -module.exports = require("https");; +module.exports = require("https"); /***/ }), @@ -59264,7 +59395,7 @@ module.exports = require("https");; /***/ ((module) => { "use strict"; -module.exports = require("net");; +module.exports = require("net"); /***/ }), @@ -59272,7 +59403,7 @@ module.exports = require("net");; /***/ ((module) => { "use strict"; -module.exports = require("os");; +module.exports = require("os"); /***/ }), @@ -59280,7 +59411,7 @@ module.exports = require("os");; /***/ ((module) => { "use strict"; -module.exports = require("path");; +module.exports = require("path"); /***/ }), @@ -59288,7 +59419,7 @@ module.exports = require("path");; /***/ ((module) => { "use strict"; -module.exports = require("perf_hooks");; +module.exports = require("perf_hooks"); /***/ }), @@ -59296,7 +59427,7 @@ module.exports = require("perf_hooks");; /***/ ((module) => { "use strict"; -module.exports = require("punycode");; +module.exports = require("punycode"); /***/ }), @@ -59304,7 +59435,7 @@ module.exports = require("punycode");; /***/ ((module) => { "use strict"; -module.exports = require("stream");; +module.exports = require("stream"); /***/ }), @@ -59312,7 +59443,7 @@ module.exports = require("stream");; /***/ ((module) => { "use strict"; -module.exports = require("string_decoder");; +module.exports = require("string_decoder"); /***/ }), @@ -59320,7 +59451,7 @@ module.exports = require("string_decoder");; /***/ ((module) => { "use strict"; -module.exports = require("timers");; +module.exports = require("timers"); /***/ }), @@ -59328,7 +59459,7 @@ module.exports = require("timers");; /***/ ((module) => { "use strict"; -module.exports = require("tls");; +module.exports = require("tls"); /***/ }), @@ -59336,7 +59467,7 @@ module.exports = require("tls");; /***/ ((module) => { "use strict"; -module.exports = require("url");; +module.exports = require("url"); /***/ }), @@ -59344,7 +59475,7 @@ module.exports = require("url");; /***/ ((module) => { "use strict"; -module.exports = require("util");; +module.exports = require("util"); /***/ }), @@ -59352,7 +59483,7 @@ module.exports = require("util");; /***/ ((module) => { "use strict"; -module.exports = require("zlib");; +module.exports = require("zlib"); /***/ }) @@ -59419,7 +59550,9 @@ module.exports = require("zlib");; /******/ /******/ /* webpack/runtime/compat */ /******/ -/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/ +/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; +/******/ +/************************************************************************/ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { @@ -59482,6 +59615,13 @@ async function setupRuby(options = {}) { createGemRC(engine, version) envPreInstall() + // JRuby can use compiled extension code, so make sure gcc exists. + // As of Jan-2022, JRuby compiles against msvcrt. + if (platform.startsWith('windows') && (engine === 'jruby') && + !fs.existsSync('C:\\msys64\\mingw64\\bin\\gcc.exe')) { + await __nccwpck_require__(3216).installJRubyTools() + } + const rubyPrefix = await installer.install(platform, engine, version) // When setup-ruby is used by other actions, this allows code in them to run diff --git a/generate-windows-versions.rb b/generate-windows-versions.rb index d0b9cd245..3bafd1285 100644 --- a/generate-windows-versions.rb +++ b/generate-windows-versions.rb @@ -28,6 +28,7 @@ versions['head'] = 'https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-head-x64.7z' versions['mingw'] = 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mingw.7z' versions['mswin'] = 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mswin.7z' +versions['ucrt'] = 'https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-ucrt.7z' js = "export const versions = #{JSON.pretty_generate(versions)}\n" File.binwrite 'windows-versions.js', js diff --git a/index.js b/index.js index 7a1b0c8b5..a94fa3c58 100644 --- a/index.js +++ b/index.js @@ -51,6 +51,13 @@ export async function setupRuby(options = {}) { createGemRC(engine, version) envPreInstall() + // JRuby can use compiled extension code, so make sure gcc exists. + // As of Jan-2022, JRuby compiles against msvcrt. + if (platform.startsWith('windows') && (engine === 'jruby') && + !fs.existsSync('C:\\msys64\\mingw64\\bin\\gcc.exe')) { + await require('./windows').installJRubyTools() + } + const rubyPrefix = await installer.install(platform, engine, version) // When setup-ruby is used by other actions, this allows code in them to run diff --git a/package.json b/package.json index 67fc84753..915464c23 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,6 @@ "@actions/tool-cache": "^1.7.1" }, "devDependencies": { - "@vercel/ncc": "^0.28.6" + "@vercel/ncc": "^0.31.1" } } diff --git a/ruby-builder.js b/ruby-builder.js index e8ee9a2f6..ed8dedbe6 100644 --- a/ruby-builder.js +++ b/ruby-builder.js @@ -79,7 +79,7 @@ async function downloadAndExtract(platform, engine, version, rubyPrefix) { return await tc.downloadTool(url) }) - await common.measure('Extracting Ruby', async () => { + await common.measure('Extracting Ruby', async () => { if (windows) { // Windows 2016 doesn't have system tar, use MSYS2's, it needs unix style paths await exec.exec('tar', ['-xz', '-C', common.win2nix(parentDir), '-f', common.win2nix(downloadPath)]) diff --git a/windows-versions.js b/windows-versions.js index 7a746b675..d2011eaac 100644 --- a/windows-versions.js +++ b/windows-versions.js @@ -45,5 +45,6 @@ export const versions = { "3.1.0": "https://github.com/oneclick/rubyinstaller2/releases/download/RubyInstaller-3.1.0-1/rubyinstaller-3.1.0-1-x64.7z", "head": "https://github.com/oneclick/rubyinstaller2/releases/download/rubyinstaller-head/rubyinstaller-head-x64.7z", "mingw": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mingw.7z", - "mswin": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mswin.7z" + "mswin": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-mswin.7z", + "ucrt": "https://github.com/MSP-Greg/ruby-loco/releases/download/ruby-master/ruby-ucrt.7z" } diff --git a/windows.js b/windows.js index b987dc4cd..abbc41bdf 100644 --- a/windows.js +++ b/windows.js @@ -13,6 +13,8 @@ const rubyInstallerVersions = require('./windows-versions').versions const drive = common.drive +const msys2BasePath = 'C:\\msys64' + // needed for 2.0-2.3, and mswin, cert file used by Git for Windows const certFile = 'C:\\Program Files\\Git\\mingw64\\ssl\\cert.pem' @@ -20,6 +22,8 @@ const certFile = 'C:\\Program Files\\Git\\mingw64\\ssl\\cert.pem' const msys = `${drive}:\\DevKit64` const msysPathEntries = [`${msys}\\mingw\\x86_64-w64-mingw32\\bin`, `${msys}\\mingw\\bin`, `${msys}\\bin`] +const virtualEnv = common.getVirtualEnvironmentName() + export function getAvailableVersions(platform, engine) { if (engine === 'ruby') { return Object.keys(rubyInstallerVersions) @@ -31,6 +35,10 @@ export function getAvailableVersions(platform, engine) { export async function install(platform, engine, version) { const url = rubyInstallerVersions[version] + // The windows-2016 and windows-2019 images have MSYS2 build tools (C:/msys64/usr) + // and MinGW build tools installed. The windows-2022 image has neither. + const hasMSYS2PreInstalled = ['windows-2019', 'windows-2016'].includes(virtualEnv) + if (!url.endsWith('.7z')) { throw new Error(`URL should end in .7z: ${url}`) } @@ -50,15 +58,72 @@ export async function install(platform, engine, version) { let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version) - common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) - if (!inToolCache) { await downloadAndExtract(engine, version, url, base, rubyPrefix); } + const winMSYS2Type = common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) + + // install msys2 tools for all Ruby versions, only install mingw or ucrt for Rubies >= 2.4 + + if (!hasMSYS2PreInstalled) { + await installMSYS2Tools() + } + + // windows 2016 and 2019 need ucrt64 installed, 2022 and future images need + // ucrt64 or mingw64 installed, depending on Ruby version + if (((winMSYS2Type === 'ucrt64') || !hasMSYS2PreInstalled) && + (common.floatVersion(version) >= 2.4)) { + await installGCCTools(winMSYS2Type) + } + + const ridk = `${rubyPrefix}\\bin\\ridk.cmd` + if (fs.existsSync(ridk)) { + await common.measure('Adding ridk env variables', async () => addRidkEnv(ridk)) + } + return rubyPrefix } +// Actions windows-2022 image does not contain any mingw or ucrt build tools. Install tools for it, +// and also install ucrt tools on earlier versions, which have msys2 and mingw tools preinstalled. +async function installGCCTools(type) { + const downloadPath = await common.measure(`Downloading ${type} build tools`, async () => { + let url = `https://github.com/MSP-Greg/setup-msys2-gcc/releases/download/msys2-gcc-pkgs/${type}.7z` + console.log(url) + return await tc.downloadTool(url) + }) + + await common.measure(`Extracting ${type} build tools`, async () => + // -aoa overwrite existing, -bd disable progress indicator + exec.exec('7z', ['x', downloadPath, '-aoa', '-bd', `-o${msys2BasePath}`], { silent: true })) +} + +// Actions windows-2022 image does not contain any MSYS2 build tools. Install tools for it. +// A subset of the MSYS2 base-devel group +async function installMSYS2Tools() { + const downloadPath = await common.measure(`Downloading msys2 build tools`, async () => { + let url = `https://github.com/MSP-Greg/setup-msys2-gcc/releases/download/msys2-gcc-pkgs/msys2.7z` + console.log(url) + return await tc.downloadTool(url) + }) + + // need to remove all directories, since they may indicate old packages are installed, + // otherwise, error of "error: duplicated database entry" + fs.rmdirSync(`${msys2BasePath}\\var\\lib\\pacman\\local`, { recursive: true, force: true }) + + await common.measure(`Extracting msys2 build tools`, async () => + // -aoa overwrite existing, -bd disable progress indicator + exec.exec('7z', ['x', downloadPath, '-aoa', '-bd', `-o${msys2BasePath}`], { silent: true })) +} + +// Windows JRuby can install gems that require compile tools, only needed for +// windows-2022 and later images +export async function installJRubyTools() { + await installMSYS2Tools() + await installGCCTools('mingw64') +} + async function downloadAndExtract(engine, version, url, base, rubyPrefix) { const parentDir = path.dirname(rubyPrefix) @@ -67,8 +132,9 @@ async function downloadAndExtract(engine, version, url, base, rubyPrefix) { return await tc.downloadTool(url) }) - await common.measure('Extracting Ruby', async () => - exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true })) + await common.measure('Extracting Ruby', async () => + // -bd disable progress indicator, -xr extract but exclude share\doc files + exec.exec('7z', ['x', downloadPath, '-bd', `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true })) if (base !== path.basename(rubyPrefix)) { await io.mv(path.join(parentDir, base), rubyPrefix) @@ -82,6 +148,11 @@ async function downloadAndExtract(engine, version, url, base, rubyPrefix) { async function setupMingw(version) { core.exportVariable('MAKE', 'make.exe') + // rename these to avoid confusion when Ruby is using OpenSSL 1.0.2 + // most current extconf files look for 1.1.x dll files first, which is the + // version of the renamed files + if (common.floatVersion(version) <= 2.4) { renameSystem32Dlls() } + if (common.floatVersion(version) <= 2.3) { core.exportVariable('SSL_CERT_FILE', certFile) await common.measure('Installing MSYS', async () => installMSYS(version)) @@ -126,9 +197,22 @@ async function setupMSWin() { /* Sets MSVC environment for use in Actions * allows steps to run without running vcvars*.bat, also for PowerShell * adds a convenience VCVARS environment variable - * this assumes a single Visual Studio version being available in the windows-latest image */ + * this assumes a single Visual Studio version being available in the Windows images */ export function addVCVARSEnv() { - const vcVars = '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"' + let vcVars = '' + switch (virtualEnv) { + case 'windows-2016': + vcVars = '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"' + break + case 'windows-2019': + vcVars = '"C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"' + break + case 'windows-2022': + vcVars = '"C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\VC\\Auxiliary\\Build\\vcvars64.bat"' + break + default: + throw new Error(`Unknown Windows Image: ${virtualEnv}`) + } core.exportVariable('VCVARS', vcVars) let newEnv = new Map() @@ -153,3 +237,36 @@ export function addVCVARSEnv() { } return newPathEntries } + +// ssl files cause issues with non RI2 Rubies (<2.4) and ruby/ruby's CI from +// build folder due to dll resolution +function renameSystem32Dlls() { + const sys32 = 'C:\\Windows\\System32\\' + const badFiles = ['libcrypto-1_1-x64.dll', 'libssl-1_1-x64.dll'] + badFiles.forEach( (bad) => { + let fn = `${sys32}${bad}` + if (fs.existsSync(fn)) { fs.renameSync(fn, `${fn}_`) } + }) +} + +// Sets MSYS2 ENV variables set from running `ridk enable` +// +function addRidkEnv(ridk) { + let newEnv = new Map() + let cmd = `cmd.exe /c "${ridk} enable && set"` + let newSet = cp.execSync(cmd).toString().trim().split(/\r?\n/) + newSet = newSet.filter(line => /^\S+=\S+/.test(line)) + newSet.forEach(s => { + let [k,v] = common.partition(s, '=') + newEnv.set(k,v) + }) + + for (let [k, v] of newEnv) { + if (process.env[k] !== v) { + if (!/^Path$/i.test(k)) { + console.log(`${k}=${v}`) + core.exportVariable(k, v) + } + } + } +} diff --git a/yarn.lock b/yarn.lock index e973aa19f..6a777f68b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -195,10 +195,10 @@ dependencies: "@types/node" "*" -"@vercel/ncc@^0.28.6": - version "0.28.6" - resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.28.6.tgz#073c0ce8e0269210c0a9f180fb0bf949eecc20e0" - integrity sha512-t4BoSSuyK8BZaUE0gV18V6bkFs4st7baumtFGa50dv1tMu2GDBEBF8sUZaKBdKiL6DzJ2D2+XVCwYWWDcQOYdQ== +"@vercel/ncc@^0.31.1": + version "0.31.1" + resolved "https://registry.yarnpkg.com/@vercel/ncc/-/ncc-0.31.1.tgz#9346c7e59326f5eeac75c0286e47df94c2d6d8f7" + integrity sha512-g0FAxwdViI6UzsiVz5HssIHqjcPa1EHL6h+2dcJD893SoCJaGdqqgUF09xnMW6goWnnhbLvgiKlgJWrJa+7qYA== abort-controller@^3.0.0: version "3.0.0"