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 }