Repository navigation
windows: opt-in CRT-free build - #860
Merged
Merged
Conversation
ebraminio
force-pushed
the
crt-free
branch
11 times, most recently
from
November 20, 2026 01:38
3b6c69d to
4f86d3b
Compare
ebraminio
force-pushed
the
crt-free
branch
10 times, most recently
from
November 22, 2026 12:45
ac98609 to
f7156d3
Compare
ebraminio
commented
Nov 22, 2026
ebraminio
force-pushed
the
crt-free
branch
4 times, most recently
from
November 25, 2026 12:11
826b88f to
ddf3e3d
Compare
Youw
reviewed
Nov 25, 2026
Youw
reviewed
Nov 25, 2026
Use one guarded ntdef include for MinGW and Cygwin, parenthesize all compatibility macro arguments consistently, and add the standard license header to both no-CRT probe sources.
Add optional shared-DLL/import-library inputs to the no-CRT probe project, copy the DLL beside the probe, and run an init smoke test in the no-CRT CI job. This covers loader, custom DllMain, and import-library behavior that import-table checks alone miss.
Use one Test-NoCrtDependencies helper for the static probes, shared DLL, and shared probe instead of repeating the dumpbin regex.
ebraminio
commented
Nov 30, 2026
This was referenced Nov 30, 2026
The x86 memory-intrinsic path only recognized MSVC/clang-cl, so GCC fell back to byte loops even though its intrin.h provides __stosb and __movsb as inline asm. Include it for MinGW as well and rename the feature macro to HIDAPI_WINAPI_HAVE_X86_MEM_INTRIN.
Youw
reviewed
Dec 1, 2026
Youw
reviewed
Dec 1, 2026
Youw
left a comment
Member
There was a problem hiding this comment.
Two suggestions for the CRT-free helpers.
Generated by Codex (gpt-6.2-astra).
Youw
reviewed
Dec 1, 2026
Require CMake 3.13 for Windows. Link the MSVC Debug DLL without runtime checks, select the x86 MinGW entry points, and publish private libraries for static pkg-config consumers. Report lifecycle failures from the initialization probe. Assisted-by: Codex:gpt-6.2-astra
It needs to wrap the ending part of the function with a block otherwise it will become an invalid C++ code as -Wjump-misses-init, the alternative solution is to move the variables at the of the function that however decrease readability as widens lifespan of the variables to places they didn't actually touched.
If an allocation failure happens the above list freeing part is bypassed so this makes sure leak won't happen even if "Encode the report descriptor output" part is bypassed by the goto.
Fix Windows CRT-free builds and static consumer linking
The no-CRT fallback shifted a signed long and could overflow. Saturate at LONG_MAX while still advancing endptr, matching wcstol behavior.
Use a size_t-capacity helper so 64-bit callers don't truncate maxlen to int, and always terminate the destination.
Use HIDAPI_SWPRINTF in the CRT path and FormatMessageW with an argument array in the no-CRT path, behind a shared helper.
Build the no-CRT WinAPI error string directly instead of using FormatMessageW's FROM_STRING formatting. FROM_STRING requires a second format language and argument array, and %3 dereferences the detail even when the system lookup returned nothing. The direct formatter preserves the original `%.*ls: (0x%08X) %.*ls` output without changing the shared caller or its trimming behavior.
Youw
reviewed
Dec 1, 2026
Drop hid_internal_format_winapi_error and HIDAPI_SWPRINTF. The CRT and the no-CRT builds now format the error string with one FormatMessageW call in register_winapi_error_to_buffer. The output is unchanged. Assisted-by: claude-code:claude-fable-5-2
pp_data_dump.c uses stdio functions and got <stdio.h> only through hid.c, which no longer includes it. Assisted-by: claude-code:claude-fable-5-2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HIDAPI's Windows backend uses the CRT for allocation, wide-string operations, and error formatting. That is fine for normal desktop builds, but it can matter when HIDAPI is linked into code that does not control the process runtime: ASI/Mod loader plugins, audio/video plugins, game overlays, and similar injected modules, or a native messaging host. Those hosts may build with
/NODEFAULTLIB, supply their own entry point, or pin a runtime, and a library that pulls in CRT imports can be awkward or impossible to fit. This is not a claim that the UCRT is usually missing or that/MTis not a valid alternative; the narrow case is a host that has already chosen a no-CRT or fixed-runtime model. Binary size can improve as a side effect, but it is not the main argument.This is a suggestion for an opt-in
HIDAPI_NO_CRTmode that uses Win32 allocation, string, and memory helpers instead. The normal CRT build remains the default and itsswprintf/wcstol/towupperpaths are untouched; the replacements are compiled only when the option is enabled. Report descriptor reconstruction is covered by the same helpers.A shared HIDAPI DLL still needs CRT startup unless its consumer supplies a custom entry point, so this only removes CRT function imports; the primary target is static embedding.now it supports DLL generation also.If this is accepted, a reasonable follow-up would be to make the internal helpers inline and use them in the default Windows path as well, so the two implementations can converge into one over the time. The
mem*shims are the part that needs care: they exist for compiler-generated calls, not for HIDAPI's own code, and removing them requires either compiler/linker changes or keeping a small shim. I would not expand this PR to change the default path yet; the safer sequence is to let the opt-in path get some use and CI coverage first. To not make things complicated, it doesn't include meson support but can be provided later.If this does not fit HIDAPI's direction or the maintenance cost is not worth it, closing or ignoring it is completely fine.