1

My project is developed in Qt C++ in Windows environment. I want to build on Github actions by using msbuild and windeployqt.

This is my example yml script

name: MSBuild
on:
 push:
 branches: [ "master" ]
 pull_request:
 branches: [ "master" ]
env:
 # Path to the solution file relative to the root of the project.
 SOLUTION_FILE_PATH: ..
 QT_VERSION: 6.4.3
 # Configuration type to build.
 # You can convert this to a build matrix if you need coverage of multiple configuration types.
 # https://docs.github.com/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
 BUILD_CONFIGURATION: Release
permissions:
 contents: read
jobs:
 build:
 runs-on: windows-latest
steps:
- name: (1) Checkout repo
 uses: actions/checkout@v3
- name: (2) Install Qt
 uses: jurplel/install-qt-action@v3
 with:
 version: ${{ env.QT_VERSION }}
 host: windows
 target: desktop
 arch: win64_msvc2019_64
 dir: ${{ runner.temp }}
 setup-python: false 
 
- name: (4) Add MSBuild to PATH
 uses: microsoft/[email protected]
- name: Create build folder
 run: mkdir -p ${{ runner.temp }}\build
- name: (5) Build with msbuild
 working-directory: ${{ runner.temp }}\build
 run: echo "Start building in ${{ runner.temp }}\build"
 cd ${{ runner.temp }}\build
 msbuild /m /p:Configuration=${{ env.BUILD_CONFIGURATION }} ${{ github.workspace }}\xxx.sln
- name: (6) List contents of the build directory
 run: |
 ls -R ${{ runner.temp }}\build
 
#- name: (6) Deploy with windeployqt
# working-directory: ${{ runner.temp }}
# run: |
# mkdir ${{ env.DEPLOY_DIR }}
# windeployqt --dir ${{ env.DEPLOY_DIR }} ${{ env.SOLUTION_FILE_PATH }}/path/to/my/exe

But after step 5 and 6, nothing happened. There's even no any error message that I can check if the source code is built correctly.

Can someone teach me how to build it with MSbuild and windeployqt?

Thanks!

Update: after syntax errors fixed:

- name: (2) Install Qt
 uses: jurplel/install-qt-action@v3
 with:
 version: ${{ env.QT_VERSION }}
 host: windows
 target: desktop
 arch: win64_msvc2019_64
 dir: ${{ runner.temp }}
 setup-python: false 
 
- name: Print Qt version information
 run: |
 qmake -v
 
- name: (3) Add MSBuild to PATH
 uses: microsoft/[email protected]
- name: (4) Create build folder
 run: |
 mkdir -p ${{ runner.temp }}\build
- name: (5) Set Qt Environment Variables
 run: |
 echo "Setting Qt Environment Variables"
 echo "QTDIR=${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/msvc2019_64" >> $GITHUB_ENV
 echo "QtToolsPath=${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/msvc2019_64/bin" >> $GITHUB_ENV
 shell: bash
- name: (6) Build with msbuild
 working-directory: ${{ github.workspace }}
 run: |
 echo "Current directory: $($PWD.Path)"
 msbuild /p:Configuration=${{ env.BUILD_CONFIGURATION }} /p:OutDir=${{ runner.temp }}\build\ "${{ env.SOLUTION_FILE_PATH }}\QtStockV3.sln"

enter image description here

UPDATE 2: Q: How to include path in github action?

In the section below "Set Qt Environment Variables and path", I set several include path which contain my header files.

But according to the error msg, it didn't find the header files there?

I'll provide a complete example here, after I resolve all of this. And thanks for your help!

enter image description here

- name: (5) Install Vcpkg and cURL 
 working-directory: ${{ runner.temp }}
 run: |
 git clone https://github.com/microsoft/vcpkg.git
 cd vcpkg
 .\bootstrap-vcpkg.bat
 .\vcpkg install curl
 curl --version
- name: Set Qt Environment Variables and path
 run: |
 echo "QTDIR=${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/msvc2019_64" >> $GITHUB_ENV
 echo "QtToolsPath=${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/msvc2019_64/bin" >> $GITHUB_ENV
 echo "INCLUDE_PATH_1=${{ github.workspace }}/${{ env.PROJ_NAME }}/src/header" >> $GITHUB_PATH
 echo "INCLUDE_PATH_2=${{ github.workspace }}/${{ env.PROJ_NAME }}/src/parser" >> $GITHUB_PATH
 echo "INCLUDE_PATH_3=${{ github.workspace }}/${{ env.PROJ_NAME }}/src/cc" >> $GITHUB_PATH
 echo "INCLUDE_PATH_VCPKG=${{ runner.temp }}/vcpkg/installed/x64-windows/include" >> $GITHUB_PATH
 ls ${INCLUDE_PATH_1}
 ls ${INCLUDE_PATH_2}
 ls ${INCLUDE_PATH_3}
 shell: bash
 
- name: (7) Build with msbuild
 working-directory: ${{ github.workspace }}
 run: |
 echo "Current directory: $($PWD.Path)"
 msbuild /p:Configuration=${{ env.BUILD_CONFIGURATION }} /p:OutDir=${{ runner.temp }}\build\ "${{ env.SOLUTION_FILE_PATH }}\QtStockV3.sln"

enter image description here

Update 3 The way I use $GITHUB_PATH and $GITHUB_ENV seems not work. I installed json in the same way I installed in local.

The pkg was installed properly but still see the error msg in log.

- name: Install nlohmann JSON
 working-directory: ${{ runner.temp }}
 run: |
 git clone https://github.com//json.git
 cd json
 echo "${{ runner.temp }}\json\include" >> $GITHUB_ENV
 ls "${{ runner.temp }}\json\include"

enter image description here

enter image description here

Update 4: I installed json with vcpkg, then the errors left are related to header files path.

To simplified the including path, I move all of my headers to the same folder with .cc

update: I noticed that the path to my header file was not included in the list. But how to do this? To modify the vcxproj file locally? enter image description here

enter image description here

asked Nov 18, 2023 at 10:15
26
  • 1
    You may use lint your workflow with rhysd.github.io/actionlint to fix the typos. Commented Nov 18, 2023 at 10:23
  • 1
    You need to configure charts with modules i.e. modules: qcharts. Also, configure cache i.e. cache: true. Commented Nov 18, 2023 at 18:49
  • 1
    Typo in my above comment: qcharts => qtcharts Commented Nov 18, 2023 at 19:07
  • 1
    Apparently, missing vcpkg integrate install. See vcpkg.io/en/getting-started.html. Commented Nov 19, 2023 at 13:03
  • 1
    The path in your cl.exe command for JSON lib is C:\Installation\json\include which is not what nlohmann::json path you're using with #include directive. You need to fix these inclusions. Commented Nov 19, 2023 at 17:08

1 Answer 1

1

IIRC, you need to set QTDIR and QtToolsPath env vars before your build step. You may use QT_ROOT_DIR to set these in a separate step (see example below with Bash):

- name: Set QTDIR and QtToolsPath
 shell: bash
 run: |
 echo "QTDIR=$QT_ROOT_DIR" >> "$GITHUB_ENV"
 echo "QtToolsPath=$QT_ROOT_DIR/bin" >> "$GITHUB_ENV"
- name: Build
 run: ...

where, QT_ROOT_DIR represents the Qt installation directory.

See jurplel/install-qt-action's dir input parameter for more details on QT_ROOT_DIR.


Depending on your application, you may need to configure modules input parameter to install Qt modules which are not installed by default.

Apart from that, you might want to enable caching to speed up your workflow runs i.e. cache: true. See cache input parameter for more details.

answered Nov 19, 2023 at 6:17
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.