From 9d7d2ce4b58c6e77aff410413591dbc63d53647f Mon Sep 17 00:00:00 2001 From: abeimler Date: Sun, 20 Nov 2022 05:20:13 +0100 Subject: [PATCH] feat: add mingw CI (#140) * add docker-compose --- .github/workflows/ci.mingw.yml | 67 +++++++++++++++++++++++++++++++ Taskfile.yml | 72 +++++++++++++++------------------- docker-compose.yml | 51 ++++++++++++++++++++++++ docker/Dockerfile | 14 ------- docker/Dockerfile.emscripten | 1 + docker/Dockerfile.mingw | 6 --- src/CrossCompiler.cmake | 7 +++- src/Vcpkg.cmake | 2 +- 8 files changed, 156 insertions(+), 64 deletions(-) create mode 100644 .github/workflows/ci.mingw.yml create mode 100644 docker-compose.yml diff --git a/.github/workflows/ci.mingw.yml b/.github/workflows/ci.mingw.yml new file mode 100644 index 00000000..3fe6c90a --- /dev/null +++ b/.github/workflows/ci.mingw.yml @@ -0,0 +1,67 @@ +name: ci-cross-mingw +on: + pull_request: + push: + branches: + - main + - master + +jobs: + Test: + if: "!contains(github.event.head_commit.message, '[ci skip]')" + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - ubuntu-20.04 + cmake: + - true + include: + - platform: x64 + cross_cc: x86_64-w64-mingw32-gcc + cross_cxx: x86_64-w64-mingw32-g++ + - platform: x86 + cross_cc: i686-w64-mingw32-gcc + cross_cxx: i686-w64-mingw32-g++ + steps: + - uses: actions/checkout@v2 + - name: Cache + uses: actions/cache@v2 + with: + path: | + ~/vcpkg + ./build/vcpkg_installed + ${{ env.HOME }}/.cache/vcpkg/archives + ${{ env.XDG_CACHE_HOME }}/vcpkg/archives + ${{ env.LOCALAPPDATA }}\vcpkg\archives + ${{ env.APPDATA }}\vcpkg\archives + key: ${{ runner.os }}-mingw-${{ matrix.platform }}-${{ env.BUILD_TYPE }}-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('./vcpkg.json')}}-${{ matrix.cmake }} + restore-keys: | + ${{ runner.os }}-${{ env.BUILD_TYPE }}- + + - name: Setup Cpp + uses: aminya/setup-cpp@v1 + with: + cmake: ${{ matrix.cmake }} + ninja: true + vcpkg: true + conan: true + cppcheck: true + clangtidy: true + task: true + doxygen: true + + - name: Setup MinGW + uses: egor-tensin/setup-mingw@v2 + with: + platform: ${{ matrix.cmake }} + + - name: Build + run: | + task build_minimal_mingw + task build_mingw + env: + CMAKE_GENERATOR: ${{ matrix.cmake_generator }} + CROSS_CC: ${{ matrix.cross_cc }} + CROSS_CXX: ${{ matrix.cross_cxx }} diff --git a/Taskfile.yml b/Taskfile.yml index cf0d305f..e21fcf17 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -3,16 +3,15 @@ version: 3 tasks: build: - - cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' + - cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{ .CMAKE_ARGS }} - cmake --build ./test/build --config Debug + build_release: - - cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' + - cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Release -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{ .CMAKE_ARGS }} - cmake --build ./test/build --config Release - build_cross_compile: - - cmake ./test -B ./test/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DENABLE_CROSS_COMPILING:BOOL=ON - - cmake --build ./test/build --config Debug + build_minimal: - - cmake ./test_minimal -B ./test_minimal/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' + - cmake ./test_minimal -B ./test_minimal/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' {{ .CMAKE_ARGS }} - cmake --build ./test_minimal/build --config Debug test: @@ -35,49 +34,40 @@ tasks: sh: git rev-parse --show-toplevel test_docker: - # test gcc compiler - - docker build --build-arg compiler=gcc -f ./docker/Dockerfile --target build -t project_options:build . - #- docker build --build-arg compiler=gcc -f ./docker/Dockerfile --target build-alt -t project_options:build-alt . - - docker build --build-arg compiler=gcc -f ./docker/Dockerfile --target test -t project_options:test . - - docker run --rm -it project_options:build - - docker run --rm -it project_options:test - #- docker run --rm -it project_options:build-alt - - docker rmi project_options:build project_options:test project_options:build-alt - # test llvm compiler - - docker build --build-arg compiler=llvm -f ./docker/Dockerfile --target build -t project_options:build-clang . - #- docker build --build-arg compiler=llvm -f ./docker/Dockerfile --target build-alt -t project_options:build-alt-clang . - - docker build --build-arg compiler=llvm -f ./docker/Dockerfile --target test -t project_options:test-clang . - - docker run --rm -it project_options:build-clang - - docker run --rm -it project_options:test-clang - #- docker run --rm -it project_options:build-alt-clang - - docker rmi project_options:build-clang project_options:test-clang + - docker-compose up --build build-gcc + - docker-compose up --build test-gcc + - docker-compose down build-gcc test-gcc + + test_docker_llvm: + - docker-compose up --build build-llvm + - docker-compose up --build test-llvm + - docker-compose down build-llvm test-llvm + test_docker_mingw: - # test mingw (cross) compiler - - docker build -f ./docker/Dockerfile.mingw --target build -t project_options:build-mingw . - - docker build -f ./docker/Dockerfile.mingw --target build-alt -t project_options:build-alt-mingw . - - docker run --rm -it project_options:build-mingw - #- docker run --rm -it project_options:build-alt-mingw - - docker run --rm -it --env CROSS_CC=i686-w64-mingw32-gcc --env CROSS_CXX=i686-w64-mingw32-gcc project_options:build-mingw - - docker rmi project_options:build-mingw project_options:build-alt-mingw + - docker-compose up --build build-mingw-x64 + - docker-compose up --build build-mingw-x86 + - docker-compose down build-mingw-x64 build-mingw-x86 + test_docker_emscripten: - # test emscripten (cross) compiler - - docker build -f ./docker/Dockerfile.emscripten --target build -t project_options:build-emscripten . - - docker run --rm -it project_options:build-emscripten - - docker rmi project_options:build-emscripten + - docker-compose up --build build-emscripten + - docker-compose down build-emscripten + + build_minimal_mingw: + cmds: + - task: build_minimal + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} build_mingw: cmds: - - task: build_cross_compile - vars: - CC: '{{ .CROSS_CC | default "x86_64-w64-mingw32-gcc" }}' - CXX: '{{ .CROSS_CXX | default "x86_64-w64-mingw32-g++" }}' + - task: build + vars: + CMAKE_ARGS: -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER={{.CROSS_CC | default "x86_64-w64-mingw32-gcc"}} -DCMAKE_CXX_COMPILER={{.CROSS_CXX | default "x86_64-w64-mingw32-g++"}} + build_emscripten: cmds: - - cmake ./test_emscripten -B ./test_emscripten/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DENABLE_CROSS_COMPILING:BOOL=ON + - cmake ./test_emscripten -B ./test_emscripten/build -DCMAKE_BUILD_TYPE:STRING=Debug -G '{{.CMAKE_GENERATOR | default "Ninja Multi-Config"}}' -DENABLE_CROSS_COMPILING:BOOL=ON -DCMAKE_C_COMPILER=emcc -DCMAKE_CXX_COMPILER=em++ - cmake --build ./test_emscripten/build --config Debug - vars: - CC: emcc - CXX: em++ lint: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..0d74904c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,51 @@ +version: "3.9" + +services: + build-gcc: + build: + context: . + dockerfile: ./docker/Dockerfile + args: + compiler: gcc + target: build + test-gcc: + build: + context: . + args: + compiler: gcc + target: test + build-llvm: + build: + context: . + dockerfile: ./docker/Dockerfile + args: + compiler: llvm + target: build + test-llvm: + build: + context: . + dockerfile: ./docker/Dockerfile + args: + compiler: llvm + target: test + build-mingw-x64: + build: + context: . + dockerfile: ./docker/Dockerfile.mingw + target: build + environment: + - CROSS_CC=x86_64-w64-mingw32-gcc + - CROSS_CXX=x86_64-w64-mingw32-g++ + build-mingw-x86: + build: + context: . + dockerfile: ./docker/Dockerfile.mingw + target: build + environment: + - CROSS_CC=i686-w64-mingw32-gcc + - CROSS_CXX=i686-w64-mingw32-g++ + build-emscripten: + build: + context: . + dockerfile: ./docker/Dockerfile.emscripten + target: build \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile index fab96631..8a00a6c0 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -44,17 +44,3 @@ CMD ["/bin/bash", "-c", "task test"] #COPY --from=build_release /home/project_options/test/build/Release/ /home/app/ #WORKDIR /home/app/ #ENTRYPOINT ["./build/main"] - - - - -#FROM setup AS build-alt -#COPY . /home/project_options -#WORKDIR /home/project_options -#CMD ["/home/project_options/docker/build.sh"] - - -#FROM setup AS test-alt -#COPY . /home/project_options -#WORKDIR /home/project_options -#CMD ["/home/project_options/docker/test.sh"] \ No newline at end of file diff --git a/docker/Dockerfile.emscripten b/docker/Dockerfile.emscripten index 6b93be59..90d5a5f5 100644 --- a/docker/Dockerfile.emscripten +++ b/docker/Dockerfile.emscripten @@ -31,6 +31,7 @@ RUN /root/emsdk/emsdk activate latest # Get emscripten repo, for Emscripten.cmake RUN git clone https://github.com/emscripten-core/emscripten /root/emscripten ENV EMSCRIPTEN /root/emscripten +#RUN touch /root/.bash_profile && echo 'source "/root/emsdk/emsdk_env.sh"' >> /root/.bash_profile COPY ./docker/entrypoint.emscripten.sh /docker-entrypoint.sh ENTRYPOINT [ "/docker-entrypoint.sh" ] diff --git a/docker/Dockerfile.mingw b/docker/Dockerfile.mingw index bb93a560..b70f531c 100644 --- a/docker/Dockerfile.mingw +++ b/docker/Dockerfile.mingw @@ -34,9 +34,3 @@ FROM setup AS build COPY . /home/project_options WORKDIR /home/project_options CMD ["/bin/bash", "-c", "task build_mingw"] - - -#FROM setup AS build-alt -#COPY . /home/project_options -#WORKDIR /home/project_options/test_minimal -#CMD ["/home/project_options/docker/build.mingw.sh"] diff --git a/src/CrossCompiler.cmake b/src/CrossCompiler.cmake index c8684732..ab07d938 100644 --- a/src/CrossCompiler.cmake +++ b/src/CrossCompiler.cmake @@ -4,14 +4,17 @@ macro(enable_cross_compiler) include("${ProjectOptions_SRC_DIR}/Utilities.cmake") detect_architecture(_arch) + # detect_compiler() set(_cc ${CMAKE_C_COMPILER}) - if(NOT _cc) + if("${_cc}" STREQUAL "") set(_cc $ENV{CC}) endif() set(_cxx ${CMAKE_CXX_COMPILER}) - if(NOT _cxx) + if("${_cxx}" STREQUAL "") set(_cxx $ENV{CXX}) endif() + set(CMAKE_C_COMPILER ${_cc}) + set(CMAKE_CXX_COMPILER ${_cxx}) if(NOT DEFINED TARGET_ARCHITECTURE) if(_cc MATCHES "x86_64(-w64)?-mingw32-[gc]..?" OR _cxx MATCHES "x86_64(-w64)?-mingw32-[gc]..?") diff --git a/src/Vcpkg.cmake b/src/Vcpkg.cmake index 828ab1c4..9ddbb3f8 100644 --- a/src/Vcpkg.cmake +++ b/src/Vcpkg.cmake @@ -123,7 +123,7 @@ macro(run_vcpkg) if(_toolchain_file) set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE ${_toolchain_file} - CACHE STRING "vcpkg chainload toolchain file" FORCE) + CACHE STRING "vcpkg chainload toolchain file") message(STATUS "Setup cross-compiler for ${VCPKG_TARGET_TRIPLET}") message(STATUS "Use cross-compiler toolchain: ${VCPKG_CHAINLOAD_TOOLCHAIN_FILE}") endif()