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 27, 2021
1 parent a783f95 commit 6969723
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
13 changes: 12 additions & 1 deletion common.js
@@ -1,6 +1,7 @@
const os = require('os')
const path = require('path')
const fs = require('fs')
const cp = require('child_process')
const util = require('util')
const stream = require('stream')
const crypto = require('crypto')
Expand Down Expand Up @@ -149,6 +150,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 +178,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
17 changes: 14 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 6969723

Please sign in to comment.