From e52562bcc606f5cb5d9232b5933b18ba322e2406 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Fri, 18 Jun 2021 11:11:24 -0500 Subject: [PATCH 1/2] Add Windows MSYS2 ucrt support --- common.js | 12 +++++++++++- dist/index.js | 16 +++++++++++++--- windows.js | 4 ++-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/common.js b/common.js index 9153130c1..c7385cf4e 100644 --- a/common.js +++ b/common.js @@ -149,6 +149,13 @@ 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) { const envPath = windows ? 'Path' : 'PATH' const originalPath = process.env[envPath].split(path.delimiter) @@ -170,8 +177,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 + let 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\\${build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] newPath = [...newPathEntries, ...msys2] } else { newPath = newPathEntries diff --git a/dist/index.js b/dist/index.js index 9cc41f932..4f22874fc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -390,6 +390,13 @@ 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) { const envPath = windows ? 'Path' : 'PATH' const originalPath = process.env[envPath].split(path.delimiter) @@ -411,8 +418,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 + let 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\\${build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] newPath = [...newPathEntries, ...msys2] } else { newPath = newPathEntries @@ -59003,12 +59013,12 @@ 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); } + common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) + return rubyPrefix } diff --git a/windows.js b/windows.js index e88411fd5..d9e978849 100644 --- a/windows.js +++ b/windows.js @@ -50,12 +50,12 @@ 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); } + common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) + return rubyPrefix } From c8ff979fda1f21948f7ec7db3180a7223c212427 Mon Sep 17 00:00:00 2001 From: Lars Kanis Date: Fri, 2 Jul 2021 13:10:55 +0200 Subject: [PATCH 2/2] Windows: Use "ridk enable" equivalent setup and install gcc on UCRT --- common.js | 32 ++++++++++++++++++++++---------- dist/index.js | 39 +++++++++++++++++++++++++++++++-------- windows.js | 10 ++++++++++ 3 files changed, 63 insertions(+), 18 deletions(-) diff --git a/common.js b/common.js index c7385cf4e..42b8b479d 100644 --- a/common.js +++ b/common.js @@ -4,6 +4,7 @@ const fs = require('fs') const util = require('util') const stream = require('stream') const crypto = require('crypto') +const child_process = require('child_process') const core = require('@actions/core') const { performance } = require('perf_hooks') @@ -150,7 +151,7 @@ export function win2nix(path) { } // JRuby is installed after setupPath is called, so folder doesn't exist -function rubyIsUCRT(path) { +export 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$/))) @@ -175,16 +176,27 @@ export function setupPath(newPathEntries) { } // Then add new path entries using core.addPath() - let newPath + let newPath = newPathEntries if (windows) { - // main Ruby dll determines whether mingw or ucrt build - let 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\\${build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] - newPath = [...newPathEntries, ...msys2] - } else { - newPath = newPathEntries + try { + // Use RubyInstaller mechanisms to set various evenironment variables including the PATH to MSYS2 tools + // Same as "ridk enable" on the command line + const envbuf = child_process.execFileSync(`${newPathEntries[0]}\\ruby`, ['-rruby_installer/runtime', '-e', 'puts RubyInstaller::Runtime.msys2_installation.enable_msys_apps_per_cmd']) + const envvars = envbuf.toString().trim().split(/\r?\n/) + + envvars.forEach( (envvar) => { + console.log(`SET ${envvar}`) + const parts = envvar.split("=", 2) + core.exportVariable(parts[0], parts[1]) + }) + } catch (ex) { + // main Ruby dll determines whether mingw or ucrt build + let 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\\${build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] + newPath = [...newPathEntries, ...msys2] + } } console.log(`Entries added to ${envPath} to use selected Ruby:`) for (const entry of newPath) { diff --git a/dist/index.js b/dist/index.js index 4f22874fc..c40206c18 100644 --- a/dist/index.js +++ b/dist/index.js @@ -237,6 +237,7 @@ __nccwpck_require__.r(__webpack_exports__); /* harmony export */ "getToolCacheRubyPrefix": () => (/* binding */ getToolCacheRubyPrefix), /* harmony export */ "createToolCacheCompleteFile": () => (/* binding */ createToolCacheCompleteFile), /* harmony export */ "win2nix": () => (/* binding */ win2nix), +/* harmony export */ "rubyIsUCRT": () => (/* binding */ rubyIsUCRT), /* harmony export */ "setupPath": () => (/* binding */ setupPath) /* harmony export */ }); const os = __nccwpck_require__(2087) @@ -245,6 +246,7 @@ const fs = __nccwpck_require__(5747) const util = __nccwpck_require__(1669) const stream = __nccwpck_require__(2413) const crypto = __nccwpck_require__(6417) +const child_process = __nccwpck_require__(3129) const core = __nccwpck_require__(2186) const { performance } = __nccwpck_require__(630) @@ -416,16 +418,27 @@ function setupPath(newPathEntries) { } // Then add new path entries using core.addPath() - let newPath + let newPath = newPathEntries if (windows) { - // main Ruby dll determines whether mingw or ucrt build - let build_sys = rubyIsUCRT(newPathEntries[0]) ? 'ucrt64' : 'mingw64' + try { + // Use RubyInstaller mechanisms to set various evenironment variables including the PATH to MSYS2 tools + // Same as "ridk enable" on the command line + const envbuf = child_process.execFileSync(`${newPathEntries[0]}\\ruby`, ['-rruby_installer/runtime', '-e', 'puts RubyInstaller::Runtime.msys2_installation.enable_msys_apps_per_cmd']) + const envvars = envbuf.toString().trim().split(/\r?\n/) + + envvars.forEach( (envvar) => { + console.log(`SET ${envvar}`) + const parts = envvar.split("=", 2) + core.exportVariable(parts[0], parts[1]) + }) + } catch (ex) { + // main Ruby dll determines whether mingw or ucrt build + let 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\\${build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] - newPath = [...newPathEntries, ...msys2] - } else { - newPath = newPathEntries + // add MSYS2 in path for all Rubies on Windows, as it provides a better bash shell and a native toolchain + const msys2 = [`C:\\msys64\\${build_sys}\\bin`, 'C:\\msys64\\usr\\bin'] + newPath = [...newPathEntries, ...msys2] + } } console.log(`Entries added to ${envPath} to use selected Ruby:`) for (const entry of newPath) { @@ -59019,6 +59032,10 @@ async function install(platform, engine, version) { common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) + if (common.rubyIsUCRT(`${rubyPrefix}\\bin`)) { + await installUCRT() + } + return rubyPrefix } @@ -59042,6 +59059,12 @@ async function downloadAndExtract(engine, version, url, base, rubyPrefix) { } } +async function installUCRT() { + await common.measure('Installing MSYS2 UCRT build tools', async () => { + cp.execSync(`pacman -S --noconfirm --noprogressbar --needed %MINGW_PACKAGE_PREFIX%-gcc`) + }) +} + async function setupMingw(version) { core.exportVariable('MAKE', 'make.exe') diff --git a/windows.js b/windows.js index d9e978849..76ba760f0 100644 --- a/windows.js +++ b/windows.js @@ -56,6 +56,10 @@ export async function install(platform, engine, version) { common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths]) + if (common.rubyIsUCRT(`${rubyPrefix}\\bin`)) { + await installUCRT() + } + return rubyPrefix } @@ -79,6 +83,12 @@ async function downloadAndExtract(engine, version, url, base, rubyPrefix) { } } +async function installUCRT() { + await common.measure('Installing MSYS2 UCRT build tools', async () => { + cp.execSync(`pacman -S --noconfirm --noprogressbar --needed %MINGW_PACKAGE_PREFIX%-gcc`) + }) +} + async function setupMingw(version) { core.exportVariable('MAKE', 'make.exe')