Skip to content

Commit

Permalink
feat: add mingw CI (aminya#140)
Browse files Browse the repository at this point in the history
* add docker-compose
  • Loading branch information
abeimler committed Nov 20, 2022
1 parent 9fca801 commit 9d7d2ce
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 64 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/ci.mingw.yml
Original file line number Diff line number Diff line change
@@ -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 }}
72 changes: 31 additions & 41 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
51 changes: 51 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 0 additions & 14 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
1 change: 1 addition & 0 deletions docker/Dockerfile.emscripten
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
6 changes: 0 additions & 6 deletions docker/Dockerfile.mingw
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
7 changes: 5 additions & 2 deletions src/CrossCompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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]..?")
Expand Down
2 changes: 1 addition & 1 deletion src/Vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 9d7d2ce

Please sign in to comment.