Skip to content

Match the linkage of rb_digest_wrap_metadata on MSVC - #152

Merged
hsbt merged 1 commit into
masterfrom
wrap-metadata-linkage
Sep 8, 2026
Merged

Match the linkage of rb_digest_wrap_metadata on MSVC#152
hsbt merged 1 commit into
masterfrom
wrap-metadata-linkage

Conversation

@hsbt

@hsbt hsbt commented Sep 8, 2026

Copy link
Copy Markdown
Member

A ruby built with --with-static-linked-ext on MSVC cannot compile this extension.

ext/digest/digest.c(547): error C2375: 'rb_digest_wrap_metadata': redefinition; different linkage
ext/digest/digest.h(82): note: see declaration of 'rb_digest_wrap_metadata'

digest.h declares the function plain under EXTSTATIC while digest.c defines it as RUBY_FUNC_EXPORTED, and cl.exe refuses a __declspec(dllexport) definition of a function that was already declared without it. Dropping the attribute is not an option because win32/mkexports.rb builds the export list from $(LIBRUBY_A), which holds no extension archives, so the attribute is the only thing that puts the symbol in libruby for extensions compiled later. Both sites now go through one macro that digest.c overrides.

Verified on VS BuildTools 2026 (x64-mswin64_140). A static-ext ruby builds, btest and the digest tests pass, rb_digest_wrap_metadata is still exported from the libruby DLL, and rake compile, rake build, rake test and rake check pass. On Linux gcc 13 accepts both branches of the header.

Generated with Claude Code

digest.h declared it plain while digest.c defines it as
RUBY_FUNC_EXPORTED, which cl.exe rejects, so a build with
--with-static-linked-ext failed:

    ext/digest/digest.c(547): error C2375: 'rb_digest_wrap_metadata': redefinition; different linkage

Keeping the attribute on the definition is what exports the symbol from
libruby when extensions are linked statically.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@hsbt
hsbt requested a review from knu as a code owner September 8, 2026 11:23
@hsbt
hsbt merged commit fc1ed53 into master Sep 8, 2026
88 checks passed
@hsbt
hsbt deleted the wrap-metadata-linkage branch September 8, 2026 23:56
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.

1 participant