Fixes for MinGW cross compilation on Linux to generate Windows binaries (Part 3) and MSVC compatibility - #1504
Fixes for MinGW cross compilation on Linux to generate Windows binaries (Part 3) and MSVC compatibility#1504Nightwalker-87 wants to merge 8 commits into
Conversation
- New subfolder stlink-env for system-specific sources, headers and libraries - System-specific definitions, header files and libraries relocated and condensed in subordinate CMakeLists.txt - Simplified environment-specific compilation of function init_chipids( ) - Corrected system-specific include in map_file.h
- Fixes for cmake build configuration - Removed duplicate libusb build routine - Fix for getopt: compile-time constants - Fixed filepath issue for chipid files - Added missing include guard for win32_socket.h - Fixed includes in trace.h, remote.h, gdb-remote.h - Minor formatting fixes
- Fixed broken Multi-COMMAND-execute_process()-pipe in Findlibusb.cmake, causing race conditions - Updated shell script gen_binaries_win.sh
|
Could someone please review this PR and test the changes in a native Windows environment? |
|
Hey @Nightwalker-87, I can go through the changes and test the compilation on my Windows machine - apart from compiling and running the stlink lib do you have any other tests you'd like me to perform? |
|
@klonyyy Thank you for your help. I have tested the cross-complining intensively on Debian, but my possibilities on running and actively using the toolset is very limited due to VM use. This it would be great to have people there to test it more intensively on a native Windows system. I am aware of that there are quite a few changes to review though... |
|
Waiting for at least a second reviewer here... |
|
@Nightwalker-87, sorry for the delay and my detachment from the project. |
I haven't tested MSVC and focussed on the original approach which was present before this was added. @slyshykO Add the following code block in I need feedback and external testing to address this. |
This didn't work. Along with libusb, we also need the pthread library, so adding only libusb didn't allow us to build the project with MSVC. |
|
Hello all, I can test MSVC support and assist on it, but using the toolset is impossible for me due to lack of devices currently |
Ok, if @a-michelis Thx for popping in. Please assist @slyshykO to allow for independent testing and updating the documentation for MSVC which you contributed earlier. |
|
Proposal:
What remains open/untested (I can't conclusively clarify this without a real MSVC environment):
Could you investigate that? |
this is my fixes - slyshykO@bbbd07b#diff-a883cf46cbd8aa22e92cee2d199e16bf8c02d8d5edbadb9572f806175ca25ad8 |
Fixed MSVC compatibility: Use vcpkg with MSVC
|
As feared cross-compilation is not successful anymore. It now fails for x86-64. |
|
Tested MSVC + vcpkg works. Configuring with On the x86-64 cross-compilation failure at I think the cause is four lines above, at line 98: COMMAND ./configure --host=i686-w64-mingw${ARCH} --prefix=...ARCH is 64 or 32 and is used in only this one place, so it expands to:
The 64-bit triple is x86_64-w64-mingw32. The 32 in mingw32 refers to the Win32 API rather than the word size, so it should stay 32 while the prefix changes from i686 to x86_64. As written, the prefix is never switched. That also explains why make fails rather than configure: with a This predates the MSVC work (git log -L points at 4 MSVC issues at 1. On the two open questions
A few words on the old build-from-source approach of on Win32 there is no standard location for third-party libraries that aren't shipped through a platform mechanism, so build systems targeting Windows usually ship them directly. Anything else pushes the user into manually adding install directories to PATH. This repo already shows both halves of that: the find_path/find_library hints in Findlibusb.cmake invent a To be clear, this is not an argument against vcpkg. vcpkg builds libusb and pthreads from source into the build tree and copies the DLLs next to the binaries, so it is per-project vendoring too - the difference is who curates the recipe, and outsourcing that to vcpkg is a reasonable trade - if we don't mind requiring users to install a separate package manager, essentially. What I would like to keep from the older approach is the property that the shipped artifacts are self-contained. With statically vendored libusb, stlink.dll imported only |
From what I can tell, it just worked again before one started to address the MSVC issue. |
Inability to build due to arch errors is what prompted me to do the previous PR in the first place, - if my memory is intact, the zip archive downloaded by the older approach gave errors depending on the arch (some calculated zip path was off). But maybe I was the one doing something wrong back then! |
|
I have now removed any potential remnants of previous build approaches and restarted a clean build from scratch. Both variants now compile successfully. |
Worth noting though that your log shows the triple is still malformed and is just being papered over: |
This would subsequently result in: and |
Please fix this properly without further complicating or changing the existing routines. Here are my thoughts on this: MSVC support policy
Scope note: the |
Restored cross-compiling for Windows binaries (i686 and x86-64) & major refactoring of
cmakebuild configurationcmakebuild configurationstlink-envfor system-specific sources, headers and librariesCMakeLists.txtinit_chipids( )map_file.hcmakebuild configurationlibusbbuild routinegetopt: compile-time constantswin32_socket.htrace.h,remote.h,gdb-remote.hlibusbcompilation withautotoolsFindlibusb.cmake, causing race conditionsgen_binaries_win.sh(Closes #1472) (Closes #1478) (Closes #1497) (Closes #1501)