Repository navigation
Conversation
3b6c69d to
4f86d3b
Compare
ac98609 to
f7156d3
Compare
826b88f to
ddf3e3d
Compare
| if ($compiler -eq 'gcc') { | ||
| gcc -c -DHID_API_NO_EXPORT_DEFINE -Ihidapisrc\hidapi hidapisrc\windows\test\no_crt_probe.c -o no_crt_probe.o | ||
| if ($LASTEXITCODE -ne 0) { $ok = $false; continue } | ||
| gcc -nostdlib "-Wl,--entry=mainCRTStartup" "-Wl,--subsystem,console" ` | ||
| -o no_crt_probe.exe no_crt_probe.o "$($lib.FullName)" -lkernel32 -luser32 -lshlwapi -lgcc | ||
| if ($LASTEXITCODE -ne 0) { $ok = $false; continue } | ||
|
|
||
| gcc -c -DHIDAPI_NO_CRT -DHIDAPI_TEST_MEM_FUNCTIONS -DHID_API_NO_EXPORT_DEFINE -Ihidapisrc\hidapi hidapisrc\windows\test\no_crt_probe.c -o no_crt_probe_amalgamated.o | ||
| if ($LASTEXITCODE -ne 0) { $ok = $false; continue } | ||
| gcc -nostdlib "-Wl,--entry=mainCRTStartup" "-Wl,--subsystem,console" ` | ||
| -o no_crt_probe_amalgamated.exe no_crt_probe_amalgamated.o -lkernel32 -luser32 -lshlwapi -lgcc | ||
| if ($LASTEXITCODE -ne 0) { $ok = $false; continue } | ||
| } else { | ||
| & $compiler /nologo /c /GS- /Gs9999999 /DHID_API_NO_EXPORT_DEFINE /Ihidapisrc\hidapi hidapisrc\windows\test\no_crt_probe.c /Fo:no_crt_probe.obj | ||
| if ($LASTEXITCODE -ne 0) { $ok = $false; continue } | ||
| link /nologo /NODEFAULTLIB /ENTRY:mainCRTStartup /SUBSYSTEM:CONSOLE ` | ||
| /OUT:no_crt_probe.exe no_crt_probe.obj "$($lib.FullName)" kernel32.lib user32.lib shlwapi.lib | ||
| if ($LASTEXITCODE -ne 0) { $ok = $false; continue } | ||
|
|
||
| & $compiler /nologo /c /GS- /Gs9999999 /DHIDAPI_NO_CRT /DHIDAPI_TEST_MEM_FUNCTIONS /DHID_API_NO_EXPORT_DEFINE /Ihidapisrc\hidapi hidapisrc\windows\test\no_crt_probe.c /Fo:no_crt_probe_amalgamated.obj | ||
| if ($LASTEXITCODE -ne 0) { $ok = $false; continue } | ||
| link /nologo /NODEFAULTLIB /ENTRY:mainCRTStartup /SUBSYSTEM:CONSOLE ` | ||
| /OUT:no_crt_probe_amalgamated.exe no_crt_probe_amalgamated.obj kernel32.lib user32.lib shlwapi.lib | ||
| if ($LASTEXITCODE -ne 0) { $ok = $false; continue } | ||
| } |
There was a problem hiding this comment.
make a small CMake or Make/GMake/NMake script instead of direct compiler/linker invocation, this looks too verbose for a CI script
There was a problem hiding this comment.
Replaced the direct compiler/linker invocations with windows/test/no_crt/CMakeLists.txt. CI now configures/builds both probe targets through CMake for cl, clang-cl, and gcc.
|
|
|
I’ve addressed the review items in ad715f4 and resolved the threads:
The fundamental tradeoff is still real: |
7d92615 to
5720761
Compare
|
Unrelated to this patch please consider registering hidapi in https://github.com/anthropics/oss-scanner it catches interesting bugs and only the maintainers can do the registration (no need to reply if that's not interesting to you). And sorry for the repeated amends, will try to lower them from now on. |
cd82e22 to
7a8e7f2
Compare
Add HIDAPI_NO_CRT to replace CRT allocation, string, memory and formatting helpers with Win32 equivalents while leaving CRT builds unchanged. Route the implementation through HIDAPI_* aliases and use the volatile byte-loop fallback for clang instead of its CRT-lowered intrinsics. Avoid compiler-generated memset calls in the descriptor reconstruction and device-detection initialization so the library exports no standard memory symbols. Add MSVC, clang-cl and MinGW no-CRT CI that builds the library, links regular and amalgamated probes without the CRT, checks imports, and runs the memory helpers at runtime. Assisted-by: deepseek-harness:deepseek-flash
Move the two 8x256 descriptor lookup arrays off the stack so the no-CRT build no longer needs stack-probe suppression. Keep /GS- because the security cookie is still required for local SDK structs. Assisted-by: deepseek-harness:deepseek-flash
Add a custom DllMain and no-default-lib link options for shared HIDAPI_NO_CRT builds, and check the DLL imports/exports in CI. Reproduced the official hidapi-0.16.0 x64 release from tag 750c87a using windows/hidapi.vcxproj (MSBuild Release|x64, /MT static CRT, LTCG): 169,472 bytes, importing only KERNEL32.dll. x64 DLL sizes before/after: Official release (/MT static CRT, LTCG): 169,472 bytes this no-CRT build: MSVC LTCG: 42,496 bytes (-75%) MSVC: 39,424 bytes (-77%) clang-cl: 43,520 bytes (-74%) MinGW: 56,057 bytes (-67%) The regular MSVC /MD build is 42,496 bytes but imports VCRUNTIME140 and the UCRT API sets; the no-CRT builds import only system DLLs. Exact sizes depend on compiler/linker versions and release packaging. Assisted-by: deepseek-harness:deepseek-flash
|
Added shared-DLL support for Shared no-CRT builds now use a custom
CI now also builds the shared DLL for For size context, I reproduced the official Size comparison (x64, same backend): The normal MSVC |
|
One open design question I’d like your input on before settling the patch: Meson option The Meson wrapper delegates the actual build to a CMake subproject, so a parent Meson project cannot pass I’m unsure whether that belongs in hidapi. A Windows-only, opt-in build mode is fairly specialized, and adding a generic Meson option for it may be more surface area than it’s worth. The alternative is to leave CRT-free builds CMake-only and document that Meson subprojects cannot select it. Longer term, if CRT-free support becomes part of the normal Windows path rather than an opt-in mode, the option would become obsolete anyway. Would you prefer:
Naming Two names feel slightly off to me:
I’m happy to follow whichever naming and integration direction you prefer; I don’t want to be proactive about these until there’s a maintainer preference. |
Keep it CMake-only for now, no Meson-specific documentation is required.
|
Rename the CRT/WinAPI compatibility header to hidapi_winapi_crt_compat.h and the optional CRT-free DLL entry source to hidapi_winapi_dllmain.c. Keep the CRT-free Meson integration out of this patch; it remains CMake-only for now.
KERNEL32.dll 26 symbols files, heaps, events, overlapped I/O, code pages, lstrlenW, lstrcpynW, FormatMessageW, etc. SHLWAPI.dll 2 symbols wnsprintfW, StrStrW USER32.dll 1 symbol CharUpperW This does not change behavior; it makes the link declaration reflect which system DLL provides the bulk of the backend's Win32 surface.
Apply the shared no-CRT link flags to Cygwin. Without those flags Cygwin's GCC still pulls in the Cygwin runtime. The main advantage is that the CRT-free Cygwin DLL no longer depends on cygwin1.dll: the CMake build is about 57 KB instead of 96 KB and imports only kernel32, shlwapi, and user32. Verified normal and no-CRT builds with Cygwin CMake, MSVC, and MinGW.
Applied Also added the Cygwin support in 34308a0 usually Cygwin generated artifacts are Just to note |
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.
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.