Skip to content

Commit 226c4cc

Browse files
MSP-Gregeregon
authored andcommitted
Add Windows MSYS2 ucrt and Windows-2022 support
1 parent 4726835 commit 226c4cc

File tree

2 files changed

+54
-4
lines changed

2 files changed

+54
-4
lines changed

common.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,15 @@ export function win2nix(path) {
155155
return path.replace(/\\/g, '/').replace(/ /g, '\\ ')
156156
}
157157

158+
// JRuby is installed after setupPath is called, so folder doesn't exist
159+
function rubyIsUCRT(path) {
160+
return !!(fs.existsSync(path) &&
161+
fs.readdirSync(path, { withFileTypes: true }).find(dirent =>
162+
dirent.isFile() && dirent.name.match(/^x64-ucrt-ruby\d{3}\.dll$/)))
163+
}
164+
158165
export function setupPath(newPathEntries) {
166+
let win_build_sys = null
159167
const envPath = windows ? 'Path' : 'PATH'
160168
const originalPath = process.env[envPath].split(path.delimiter)
161169
let cleanPath = originalPath.filter(entry => !/\bruby\b/i.test(entry))
@@ -176,8 +184,11 @@ export function setupPath(newPathEntries) {
176184
// Then add new path entries using core.addPath()
177185
let newPath
178186
if (windows) {
187+
// main Ruby dll determines whether mingw or ucrt build
188+
win_build_sys = rubyIsUCRT(newPathEntries[0]) ? 'ucrt64' : 'mingw64'
189+
179190
// add MSYS2 in path for all Rubies on Windows, as it provides a better bash shell and a native toolchain
180-
const msys2 = ['C:\\msys64\\mingw64\\bin', 'C:\\msys64\\usr\\bin']
191+
const msys2 = [`C:\\msys64\\${win_build_sys}\\bin`, 'C:\\msys64\\usr\\bin']
181192
newPath = [...newPathEntries, ...msys2]
182193
} else {
183194
newPath = newPathEntries
@@ -189,4 +200,5 @@ export function setupPath(newPathEntries) {
189200
core.endGroup()
190201

191202
core.addPath(newPath.join(path.delimiter))
203+
return win_build_sys
192204
}

windows.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,53 @@ export async function install(platform, engine, version) {
5050

5151
let toolchainPaths = (version === 'mswin') ? await setupMSWin() : await setupMingw(version)
5252

53-
common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths])
54-
5553
if (!inToolCache) {
5654
await downloadAndExtract(engine, version, url, base, rubyPrefix);
5755
}
5856

57+
const winMSYS2Type = common.setupPath([`${rubyPrefix}\\bin`, ...toolchainPaths])
58+
59+
const virtualEnv = common.getVirtualEnvironmentName()
60+
61+
if (( winMSYS2Type === 'ucrt64') || !['windows-2019', 'windows-2016'].includes(virtualEnv)) {
62+
await installGCCTools(winMSYS2Type)
63+
64+
if (!['windows-2019', 'windows-2016'].includes(virtualEnv)) {
65+
await installMSY2Tools()
66+
}
67+
}
68+
5969
return rubyPrefix
6070
}
6171

72+
// Actions windows-2022 image does not contain any mingw or ucrt build tools. Install tools for it,
73+
// and also install ucrt tools on earlier versions, which have msys2 and mingw tools preinstalled.
74+
async function installGCCTools(type) {
75+
const downloadPath = await common.measure(`Download ${type} build tools`, async () => {
76+
let url = `https://github.com/MSP-Greg/setup-msys2-gcc/releases/download/msys2-gcc-pkgs/${type}.7z`
77+
console.log(url)
78+
return await tc.downloadTool(url)
79+
})
80+
81+
await common.measure(`Extracting ${type} build tools`, async () =>
82+
// -aoa overwrite existing, -bd disable progress indicator
83+
exec.exec('7z', ['x', downloadPath, '-aoa', '-bd', '-oC:\\msys64'], { silent: true }))
84+
}
85+
86+
// Actions windows-2022 image does not contain any MSYS2 build tools. Install tools for it.
87+
// A subset of the MSYS2 base-devel group
88+
async function installMSY2Tools() {
89+
const downloadPath = await common.measure(`Download msys2 build tools`, async () => {
90+
let url = `https://github.com/MSP-Greg/setup-msys2-gcc/releases/download/msys2-gcc-pkgs/msys2.7z`
91+
console.log(url)
92+
return await tc.downloadTool(url)
93+
})
94+
95+
await common.measure(`Extracting msys2 build tools`, async () =>
96+
// -aoa overwrite existing, -bd disable progress indicator
97+
exec.exec('7z', ['x', downloadPath, '-aoa', '-bd', '-oC:\\msys64'], { silent: true }))
98+
}
99+
62100
async function downloadAndExtract(engine, version, url, base, rubyPrefix) {
63101
const parentDir = path.dirname(rubyPrefix)
64102

@@ -68,7 +106,7 @@ async function downloadAndExtract(engine, version, url, base, rubyPrefix) {
68106
})
69107

70108
await common.measure('Extracting Ruby', async () =>
71-
exec.exec('7z', ['x', downloadPath, `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true }))
109+
exec.exec('7z', ['x', downloadPath, '-bd', `-xr!${base}\\share\\doc`, `-o${parentDir}`], { silent: true }))
72110

73111
if (base !== path.basename(rubyPrefix)) {
74112
await io.mv(path.join(parentDir, base), rubyPrefix)

0 commit comments

Comments
 (0)