Bug 400716 - Build issues on Windows
Summary: Build issues on Windows
Status: RESOLVED FIXED
Alias: None
Product: rust-qt-binding-generator
Classification: Unmaintained
Component: demo (other bugs)
Version First Reported In: unspecified
Platform: Other Other
: NOR normal
Target Milestone: ---
Assignee: Jos van den Oever
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-05 19:55 UTC by Svend Tofte
Modified: 2018-11-20 20:59 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Svend Tofte 2018-11-05 19:55:34 UTC
SUMMARY
The shipped CMakeLists.txt in the example directory has some issues on Windows. Using Qt 5.11.2 and VS2017

STEPS TO REPRODUCE
1. cmake -G "Visual Studio 15 2017 Win64" -DCMAKE_PREFIX_PATH=C:\Qt\5.11.2\msvc2017_64\lib\cmake
2. Open "Developer Prompt for VS2017", navigate to the todos example directory
3. msbuild ALL_BUILD.vcxproj

OBSERVED RESULT
LINK : fatal error LNK1104: cannot open file 'rust\target\release\\librust.a' [C:\src\rustqt3\examples\todos\todos.vcxproj]

EXPECTED RESULT
Build success.

SOFTWARE VERSIONS
(available in About System)
KDE Plasma Version: N/A
KDE Frameworks Version: N/A
Qt Version: 5.11.2

ADDITIONAL INFORMATION

The first error is pretty easy to workaround by modifying the CMakeList.txt to use "rust.lib" instead of "librust.a". Presumably a Windows convention issue. Once you do (and rerun cmake) you're met by a wall of linking errors https://gist.github.com/stofte/15f7cdfe0882b855f5082553ee020076.

I assume rust is linking these symbols somehow? Eitherway, these are found in WS2_32.LIB and Userenv.lib. Adding these on eg line 64, makes the build complete successfully on Windows:

list(APPEND Libs Qt5::Core Qt5::Quick Threads::Threads ${CMAKE_DL_LIBS} WS2_32.LIB Userenv.lib)

Also want to add this is an awesome project, thanks for putting this together!

I did a small writeup for myself here: https://gist.github.com/stofte/91942f124dfebb875038ad2131fe25e7
Comment 1 Jos van den Oever 2018-11-05 20:41:04 UTC
Nice to hear you got it working on windows.

Would these changes work for you?

diff --git a/examples/todos/CMakeLists.txt b/examples/todos/CMakeLists.txt
index 9a940af..8400542 100644
--- a/examples/todos/CMakeLists.txt
+++ b/examples/todos/CMakeLists.txt
@@ -37,7 +37,11 @@ feature_summary(WHAT ALL INCLUDE_QUIET_PACKAGES FATAL_ON_MISSING_REQUIRED_PACKAG
 ### build commands ###
 
 SET(RUST_DIR "${CMAKE_CURRENT_SOURCE_DIR}/rust")
-SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/librust.a")
+if (MSVC)
+  SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/rust.lib")
+else()
+  SET(RUST_LIB "${RUST_DIR}/${RUST_TARGET_DIR}/librust.a")
+endif()
 
 # generate c++ and rust code from bindings.json
 add_custom_command(
@@ -61,6 +65,9 @@ add_custom_command(
 add_custom_target(rust_target DEPENDS "${RUST_LIB}")
 
 list(APPEND Libs "${RUST_LIB}")
+if (MSVC)
+  list(APPEND Libs WS2_32.LIB Userenv.lib)
+endif()
 list(APPEND Libs Qt5::Core Qt5::Quick Threads::Threads ${CMAKE_DL_LIBS})
 set(SRCS src/main.cpp src/Bindings.cpp "qml.qrc")
 add_executable(todos ${SRCS})
Comment 2 Svend Tofte 2018-11-06 08:54:39 UTC
Applying the patch fixes my build issues yes :)
Comment 3 Jos van den Oever 2018-11-11 15:03:52 UTC
Git commit f678d441e9fe31d6d933f6c27b884b807438fcad by Jos van den Oever.
Committed on 11/11/2018 at 15:03.
Pushed by vandenoever into branch 'master'.

Fix building with MSVC

M  +10   -3    demo/CMakeLists.txt
M  +8    -1    examples/todos/CMakeLists.txt
M  +5    -1    templates/qt_quick/CMakeLists.txt
M  +5    -1    templates/qt_widgets/CMakeLists.txt
M  +8    -3    tests/CMakeLists.txt

https://commits.kde.org/rust-qt-binding-generator/f678d441e9fe31d6d933f6c27b884b807438fcad
Comment 4 Jos van den Oever 2018-11-11 15:05:18 UTC
The patch also fixes the 'test' and 'demo' targets. I'm curious if the demo application works on windows.
Comment 5 Svend Tofte 2018-11-19 09:19:23 UTC
Hello Jos, I'm not able to build the demo app (using cmake and the same approach as used for the todo sample). It breaks on the usage of a "build" command, which is not found.

Looking at the generated msbuild files (specificallly "rust_target.vcxproj", which is generated in both cases). In todos, the build steps look like this:

<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Generating rust/target/release/rust.lib</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">setlocal
cd C:\src\rust-qt-binding-generator\examples\todos\rust
if %errorlevel% neq 0 goto :cmEnd
C:
if %errorlevel% neq 0 goto :cmEnd
C:\Users\svto\.cargo\bin\cargo.exe build --release
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal &amp; call :cmErrorLevel %errorlevel% &amp; goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>

The same section for the demo project looks like this:

<Message Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Generating rust/rust.lib</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|x64'">setlocal
cd C:\src\rust-qt-binding-generator\demo\rust
if %errorlevel% neq 0 goto :cmEnd
C:
if %errorlevel% neq 0 goto :cmEnd
build
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal &amp; call :cmErrorLevel %errorlevel% &amp; goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>

The bare "build" line causes the issue. Might be as simple as quotes missing? I will try to investigate during the week and see if I can learn anything.
Comment 6 Svend Tofte 2018-11-19 21:04:59 UTC
Here's the cmake output btw: https://gist.github.com/stofte/4cbe0e8afcc38dca3a718b2738a25708
cmake output from building todo also included at the bottom, for comparison.

When I look at the cmakelist.txt it looks fairly different from the one in the todo dir. In the todo dir, there's also a cmake subdir, which has stuff like FindCargo.cmake, which I guess cmake is auto including, the bare "build" line I mention seems to be the attempt to run "cargo build" on line 23. There's also no find_package commands in the demo cmake?
Comment 7 Svend Tofte 2018-11-19 21:09:18 UTC
Sorry for spamming, but I can't edit this in, but my cmake version is 3.12.2
Comment 8 Jos van den Oever 2018-11-19 22:34:56 UTC
The demo application takes information from the parent directory CMakeLists.txt. The example and template applications are stand-alone.

You can run cmake and build in example/todo/, but not in demo/. For demo you run cmake for the parent and then 'make Demo'.
Comment 9 Svend Tofte 2018-11-20 15:15:23 UTC
Ok, that helped alot. It still fails on "ECM", which I guess is this repo https://github.com/KDE/extra-cmake-modules 

I ran cmake in ecm cloned folder, and it didn't complain too much (a doc generation tool was missing, no problem). In the following, I've used "set ECM_DIR=C:\src\extra-cmake-modules" to indicate the path, and when I run cmake, I get the following:

https://gist.github.com/stofte/238c20d2a2788f53749e9be23ad3e3e2
Comment 10 Jos van den Oever 2018-11-20 20:09:20 UTC
Have you tried running 'make install' on the ECM in Windows?

Or you might be able to change the demo CMakeLists.txt with some IF statement so that missing ECM is not a problem. KDE parts are optional and just for the use with Kirigami.
Comment 11 Svend Tofte 2018-11-20 20:59:59 UTC
cmake -P cmake_install.cmake worked for installing ecm, and then commenting out these two lines, and cmake generated the project:

L:39 find_library(DL_LIBRARY ${CMAKE_DL_LIBS})
L:46 message(FATAL_ERROR "No runtime information library (-ldl or -lexecinfo)")

Even so, I should have simply tried the rust code to start with because it doesn't build :(

https://gist.github.com/stofte/0dd1b6bee4502f32c3076a0b6419312b

Seems pid_t is unsupported on windows https://github.com/rust-lang/libc/pull/833