Repository navigation
Build with MSVC and add an MSVC CI job - #458
Merged
Merged
Conversation
- Add kickcat/packed.h with KICKCAT_PACKED_BEGIN/END: #pragma pack for MSVC, __attribute__((__packed__)) for all other compilers. Convert the packed structures and add static_asserts for their sizes. - Rename FoE::opcode::ERROR to FoE::opcode::ERR: ERROR is a macro of the Windows API (wingdi.h), so the header did not compile after <windows.h>. Same naming as mailbox::ERR. The value (0x05) is unchanged. - Rename the parameter "interface" to "ifname": "interface" is a macro of the Windows API as well. - CoE/OD.h: undefine the DOMAIN macro of the MSVC <math.h>. - OS/Windows/Time.cc: sleep() uses std::this_thread::sleep_for with MSVC, which has no clock_nanosleep(). No functional change for GCC and Clang.
- cmake/Config.cmake: MSVC gets /W4 instead of the GCC warning options, which cl rejects (D8021 on /Wextra). GCC and Clang keep their options. - lib/CMakeLists.txt: with MSVC the library is compiled with /permissive- (the code uses the alternative operator tokens and, or, not) and with NOMINMAX (<windows.h> defines min and max as macros otherwise). Both are PUBLIC because the headers need them as well. - Mutex and ConditionVariable: MSVC has no pthread. Add an implementation on the native primitives (SRWLOCK, CONDITION_VARIABLE) in OS/Windows, used with MSVC only. MinGW keeps the pthread sources. As with MinGW, the primitives are not shareable between processes and there is no priority inheritance. - types.h, helpers.cc: select the Windows headers with MSVC too. No change for GCC, Clang and MinGW.
- bus-t.cc, gateway-t.cc: declare the packed structures with KICKCAT_PACKED_BEGIN/END instead of __attribute__((__packed__)). - kickcat-t.cc: include <array>, which the other standard libraries provided indirectly. - unit/CMakeLists.txt: -static-libgcc and -static-libstdc++ are options of the GNU toolchain, do not pass them to the MSVC linker (LNK4044). The 801 tests of the Windows build pass with MSVC.
- Master examples: declare the packed structures with KICKCAT_PACKED_BEGIN/END instead of __attribute__((packed)). - marvin.cc: define _USE_MATH_DEFINES before the first standard header, <iostream> already includes <cmath> with MSVC. - debugUseCase.cc, eeprom.cc: select the Windows socket with MSVC too. - od_generator, hw_test_bench, esi_validate, esi_boot: require C++17. These targets relied on the default standard of the compiler, which is C++14 with MSVC. With this, a build with the default options succeeds with MSVC.
Add a second windows-latest entry to the build_x86 matrix that builds with MSVC. It installs the dependencies with the new conan/profile_windows_msvc_x86_64.txt and lets CMake use the installed Visual Studio. It builds the default options and runs the unit tests, like the MinGW entry. The profile names the compiler of the current windows-latest image (Visual Studio 2026, compiler.version=195). For Visual Studio 2022 pass -s compiler.version=194. ctest gets the configuration (-C): the Visual Studio generators are multi-config and ctest finds no test without it. Single-config generators ignore the option.
Same change as for AbstractSocket and the Windows Socket: "interface" is a macro of the Windows API. It is only hidden as long as <windows.h> is included with WIN32_LEAN_AND_MEAN.
The include was added to undefine the DOMAIN macro of the MSVC <math.h>. Other C libraries do not need it, and it breaks the NuttX builds whose board configuration has no math library (arduino-due, freedom-k64f: "'acos' has not been declared in 'std'").
|
Minimum allowed coverage is Generated by 🐒 cobertura-action against 39bc1c0 |
leducp
approved these changes
Nov 13, 2026
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.
Second pull request announced in #456.
What
KickCAT builds with MSVC through its own CMake with the default options, and
the unit tests pass. A CI job keeps it that way.
The commits are meant to be read one by one:
KICKCAT_PACKED_BEGIN/END(
kickcat/packed.h) instead of__attribute__((__packed__)), withstatic_asserts on the structure sizes;FoE::opcode::ERRORrenamed toFoE::opcode::ERRand the parameterinterfacerenamed toifname(bothare macros of the Windows API, see Introduction: Nanotec is using KickCAT in a fork, and would like to contribute #456);
DOMAINof the MSVC<math.h>./W4for MSVC instead of the GCC warning options,/permissive-andNOMINMAX, andMutex/ConditionVariableon thenative primitives (
SRWLOCK,CONDITION_VARIABLE), because MSVC has nopthread. MinGW keeps the pthread sources.
linker options only for MinGW.
on the compiler default.
windows-latestentry in thebuild_x86matrix that buildswith MSVC, with a conan profile for it.
TapSocket: theinterfaceparameter that commit 1 missed.Notes for the review
/permissive-andNOMINMAXare PUBLIC on thekickcattarget, becausethe headers need them too.
Mutexhas no priority inheritance and is notshareable between processes.
/W4reports warnings in existing code (mostly conversions and formatspecifiers), none in the new files. They do not fail the build.
-Cto ctest for all entries: the Visual Studiogenerators are multi-config, single-config generators ignore it.
windows-latest, like the MinGW entry. Its conan profilenames the compiler of that image (Visual Studio 2026); for Visual Studio
2022 pass
-s compiler.version=194.locally on a clean export: conan install, configure, build, ctest.
Testing
options: 830 tests pass.