From f6dcb727aa7634613dc53a4cdab0a35b09dd4363 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 18 Nov 2026 08:47:01 +0900 Subject: [PATCH 1/2] Point mkmf at the vcpkg packages on mswin The mswin builds from cache.ruby-lang.org keep the build machine's paths out of configure_args, so extconf.rb no longer finds the vcpkg headers and libraries that ruby-loco located through --with-opt-dir. Their RbConfig also has an empty PKG_CONFIG, so mkmf ran the MSYS2 pkg-config on PATH, which pointed fiddle at the MinGW libffi headers and broke the MSVC build. ruby-loco meant to set PKG_CONFIG to the vcpkg pkgconf, but its path missed a variable and pointed nowhere. https://github.com/ruby/setup-ruby/issues/976 Co-Authored-By: Claude Opus 5.5 --- dist/index.js | 19 ++++++++++++++++++- windows.js | 19 ++++++++++++++++++- 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index 84435881b..6cce5be2a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -46314,7 +46314,7 @@ async function installVCPKG(url) { await common.measure('Extracting mswin vcpkg packages', async () => exec.exec('7z', ['x', downloadPath, '-aoa', '-bd', `-o${extractPath}`], { silent: true })) - return await common.measure('Setting up MSVC environment', async () => { + const paths = await common.measure('Setting up MSVC environment', async () => { const cmd = 'vswhere -latest -property installationPath' const vcVarsBat = os.arch() === 'arm64' ? 'vcvarsarm64.bat' : 'vcvars64.bat' const vcVars = `${cp.execSync(cmd).toString().trim()}\\VC\\Auxiliary\\Build\\${vcVarsBat}` @@ -46325,6 +46325,23 @@ async function installVCPKG(url) { return exportCommandEnv(`set "MAKE=nmake" && "${vcVars}"`) }) + + await core.group('Setting up vcpkg', async () => { + // mswin Rubies do not record the vcpkg location in configure_args, so the compiler and linker find it through INCLUDE and LIB + const vcpkgDir = `${extractPath}\\installed\\${os.arch()}-windows` + exportEnv({ + INCLUDE: `${vcpkgDir}\\include;${process.env.INCLUDE}`, + LIB: `${vcpkgDir}\\lib;${process.env.LIB}` + }) + + // Without these, mkmf runs the MSYS2 pkg-config on PATH, whose MinGW flags break MSVC builds, and pkgconf only searches the missing tools\lib\pkgconfig + exportEnv({ + PKG_CONFIG: `${vcpkgDir}\\tools\\pkgconf\\pkgconf.exe`, + PKG_CONFIG_PATH: `${vcpkgDir}\\lib\\pkgconfig` + }) + }) + + return paths } // Run a cmd command, export its environment, and return new paths diff --git a/windows.js b/windows.js index b955c227a..1e9b5cd5d 100644 --- a/windows.js +++ b/windows.js @@ -215,7 +215,7 @@ async function installVCPKG(url) { await common.measure('Extracting mswin vcpkg packages', async () => exec.exec('7z', ['x', downloadPath, '-aoa', '-bd', `-o${extractPath}`], { silent: true })) - return await common.measure('Setting up MSVC environment', async () => { + const paths = await common.measure('Setting up MSVC environment', async () => { const cmd = 'vswhere -latest -property installationPath' const vcVarsBat = os.arch() === 'arm64' ? 'vcvarsarm64.bat' : 'vcvars64.bat' const vcVars = `${cp.execSync(cmd).toString().trim()}\\VC\\Auxiliary\\Build\\${vcVarsBat}` @@ -226,6 +226,23 @@ async function installVCPKG(url) { return exportCommandEnv(`set "MAKE=nmake" && "${vcVars}"`) }) + + await core.group('Setting up vcpkg', async () => { + // mswin Rubies do not record the vcpkg location in configure_args, so the compiler and linker find it through INCLUDE and LIB + const vcpkgDir = `${extractPath}\\installed\\${os.arch()}-windows` + exportEnv({ + INCLUDE: `${vcpkgDir}\\include;${process.env.INCLUDE}`, + LIB: `${vcpkgDir}\\lib;${process.env.LIB}` + }) + + // Without these, mkmf runs the MSYS2 pkg-config on PATH, whose MinGW flags break MSVC builds, and pkgconf only searches the missing tools\lib\pkgconfig + exportEnv({ + PKG_CONFIG: `${vcpkgDir}\\tools\\pkgconf\\pkgconf.exe`, + PKG_CONFIG_PATH: `${vcpkgDir}\\lib\\pkgconfig` + }) + }) + + return paths } // Run a cmd command, export its environment, and return new paths From 30b77fb739f04c653e2a682e469d4f3d9799b607 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Wed, 18 Nov 2026 08:47:08 +0900 Subject: [PATCH 2/2] Build a gem that needs vcpkg libraries on mswin in CI json builds without any external library, so it did not catch mkmf losing track of vcpkg. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 0e78a62f9..06726e02c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -85,6 +85,9 @@ jobs: - run: gem env - name: C extension test run: gem install json -v 2.2.0 + - name: C extension test with vcpkg libraries (mswin) + run: gem install fiddle -v 1.1.8 + if: matrix.ruby == 'mswin' - run: bundle --version # This step is redundant with `bundler-cache: true` but is there to check a redundant `bundle install` still works - run: bundle install