Skip to content

Run the vcpkg pkgconf and load vcpkg DLLs on mswin - #978

Merged
hsbt merged 3 commits into
masterfrom
mswin-vcpkg-pkgconf-dlls
Nov 18, 2026
Merged

hsbt merged 3 commits into
masterfrom
mswin-vcpkg-pkgconf-dlls

Conversation

@hsbt

@hsbt hsbt commented Nov 18, 2026

Copy link
Copy Markdown
Member

After #977, mkmf on mswin still never runs the vcpkg pkgconf. It skips an absolute PKG_CONFIG that File.expand_path would rewrite, and setup-ruby writes it with backslashes, so extensions build only through their have_header fallbacks. A zlib extension built against vcpkg also links libz.dll, which the Ruby package does not ship, so require "zlib" fails with LoadError and breaks RubyGems in that gem home.

This writes PKG_CONFIG with forward slashes and appends the vcpkg bin to PATH. Ruby's own bin still comes first, so the other DLLs keep resolving to the copies shipped with Ruby.

Generated with Claude Code

hsbt and others added 3 commits November 18, 2026 10:43
mkmf skips an absolute PKG_CONFIG that File.expand_path would rewrite, so the backslashed path never ran pkgconf and extensions built only through their header and library fallbacks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The mswin Ruby ships z.dll, not the libz.dll that vcpkg's libz.lib imports, so a zlib extension built against vcpkg failed to load and then broke RubyGems in that gem home. The other vcpkg DLLs still resolve to the copies in Ruby's own bin first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Building fiddle succeeded even while a zlib extension linked to libz.dll could not be loaded. The step activates the installed zlib explicitly, because Ruby also ships a default zlib built against its own z.dll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread windows.js
// Otherwise mkmf runs the MSYS2 pkg-config, whose MinGW flags break MSVC builds. mkmf accepts an absolute PKG_CONFIG only with forward slashes, and pkgconf alone searches just the missing tools\lib\pkgconfig
exportEnv({
PKG_CONFIG: `${vcpkgDir}\\tools\\pkgconf\\pkgconf.exe`,
PKG_CONFIG: `${vcpkgDir}\\tools\\pkgconf\\pkgconf.exe`.replaceAll('\\', '/'),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should mkmf support either forward slash or backward slash?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should. I'm working on making native builds on mswin work properly, and I'll use this case, where mkmf silently ignores a backslashed absolute PKG_CONFIG, as material to improve mkmf there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fixed in ruby/ruby#19970, so mkmf now accepts a backslashed absolute PKG_CONFIG on master. Released versions still need the forward slashes here.

@hsbt
hsbt merged commit 20eb24b into master Nov 18, 2026
474 checks passed
@hsbt
hsbt deleted the mswin-vcpkg-pkgconf-dlls branch November 18, 2026 03:02
hsbt added a commit to ruby/ruby that referenced this pull request Nov 18, 2026
`find_executable0` treated a path as absolute only when `File.expand_path` returned it unchanged, so a Windows path written with backslashes, such as a `PKG_CONFIG` pointing at vcpkg's pkgconf, was looked up in `PATH` and never found. Use `File.absolute_path?` instead, which also accepts absolute paths containing `..` or `.` on every platform.

ruby/setup-ruby#978

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants