Skip to content

Commit

Permalink
Add Windows MSYS2 ucrt support
Browse files Browse the repository at this point in the history
  • Loading branch information
MSP-Greg committed Jun 28, 2021
1 parent a783f95 commit e52562b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
12 changes: 11 additions & 1 deletion common.js
Expand Up @@ -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)
Expand All @@ -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
Expand Down
16 changes: 13 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions windows.js
Expand Up @@ -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
}

Expand Down

0 comments on commit e52562b

Please sign in to comment.