Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions .github/actions/setup-llvm-mingw/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@ inputs:
outputs:
llvm-path:
description: "The path in which llvm-mingw is installed to"
value: ${{ steps.setup-llvm.outputs.llvm-path }}
value: ${{ ((runner.os == 'Windows') && steps.setup-llvm.outputs.llvm-path) || steps.setup-llvm-linux.outputs.llvm-path }}
runs:
using: "composite"
steps:
- name: Cache llvm-mingw
- name: Cache llvm-mingw (Windows)
id: cache-llvm
if: runner.os == 'Windows'
uses: actions/cache@v3
with:
path: .llvm-mingw
key: llvm-mingw-${{ runner.os }}-${{ inputs.llvm-mingw-version }}-${{ inputs.host-arch }}

- name: Install llvm-mingw ${{ inputs.llvm-mingw-version }} (${{ inputs.host-arch }})
if: steps.cache-llvm.outputs.cache-hit != 'true'
- name: Install llvm-mingw ${{ inputs.llvm-mingw-version }} (Windows ${{ inputs.host-arch }})
if: runner.os == 'Windows' && steps.cache-llvm.outputs.cache-hit != 'true'
shell: pwsh
run: |
$llvm_mingw_version = "${{ inputs.llvm-mingw-version }}"
Expand All @@ -33,8 +34,9 @@ runs:
7z x llvm-mingw.zip -o"$pwd\.llvm-mingw"
rm llvm-mingw.zip

- name: Set up llvm-mingw
- name: Set up llvm-mingw (Windows)
id: setup-llvm
if: runner.os == 'Windows'
shell: pwsh
run: |
$llvm_mingw_version = "${{ inputs.llvm-mingw-version }}"
Expand All @@ -44,3 +46,34 @@ runs:
Add-Content $env:GITHUB_PATH "$pwd\.llvm-mingw\llvm-mingw-${llvm_mingw_version}-ucrt-${llvm_arch}\bin"
# for the ASAN runtime DLL:
Add-Content $env:GITHUB_PATH "$pwd\.llvm-mingw\llvm-mingw-${llvm_mingw_version}-ucrt-${llvm_arch}\${llvm_arch}-w64-mingw32\bin"

- name: Cache llvm-mingw (Linux)
id: cache-llvm-linux
if: runner.os == 'Linux'
uses: actions/cache@v3
with:
path: /opt/llvm-mingw
key: llvm-mingw-${{ runner.os }}-${{ inputs.llvm-mingw-version }}-${{ inputs.host-arch }}

- name: Install llvm-mingw ${{ inputs.llvm-mingw-version }} (Linux ${{ inputs.host-arch }})
if: runner.os == 'Linux' && steps.cache-llvm-linux.outputs.cache-hit != 'true'
shell: bash
run: |
llvm_mingw_version="${{ inputs.llvm-mingw-version }}"
llvm_arch="${{ inputs.host-arch }}"
mkdir -p /opt/llvm-mingw
cd /opt/llvm-mingw
curl -L https://github.com/mstorsjo/llvm-mingw/releases/download/20220906/llvm-mingw-${llvm_mingw_version}-ucrt-ubuntu-18.04-${llvm_arch}.tar.xz | tar xJ --strip-components=1

- name: Set up llvm-mingw (Linux)
id: setup-llvm-linux
if: runner.os == 'Linux'
shell: bash
run: |
cd /opt/llvm-mingw
if [ ! -x bin/clang++ ]; then
echo "$PWD/bin/clang++ not found or not executable!"
exit 1
fi
echo "llvm-path=$PWD/llvm-mingw" >> $GITHUB_OUTPUT
echo "$PWD/bin" >> $GITHUB_PATH
105 changes: 103 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ jobs:
test-llvm-mingw-cppwinrt:
name: 'llvm-mingw: Build and test'
strategy:
fail-fast: false
matrix:
arch: [i686, x86_64]
config: [Debug, Release]
Expand All @@ -262,6 +263,8 @@ jobs:
- id: setup-llvm
name: Set up llvm-mingw
uses: ./.github/actions/setup-llvm-mingw
with:
host-arch: ${{ matrix.arch }}

- name: Build cppwinrt
run: |
Expand Down Expand Up @@ -335,19 +338,117 @@ jobs:
name: 'cross: Test run on Windows'
needs: build-linux-cross-cppwinrt
strategy:
fail-fast: false
matrix:
arch: [i686, x86_64]
runs-on: windows-latest
steps:
- uses: actions/checkout@v3

- name: Fetch cppwinrt executable
uses: actions/download-artifact@v3
with:
name: cross-build-${{ matrix.arch }}-bin
path: ./
path: ./.test

- name: Run cppwinrt to build projection
run: |
.\cppwinrt.exe -in local -out .\ -verbose
.\.test\cppwinrt.exe -in local -out .\.test\out -verbose

- id: setup-llvm
name: Set up llvm-mingw
uses: ./.github/actions/setup-llvm-mingw
with:
host-arch: ${{ matrix.arch }}

- name: Build cppwinrt tests
run: |
mkdir build
cd build
cmake ../test -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Debug `
-DCPPWINRT_PROJECTION_INCLUDE_DIR="../.test/out" `
-DDOWNLOAD_WINDOWSNUMERICS=TRUE
cmake --build . -j2

- name: Run tests
run: |
cd build
ctest --verbose

build-linux-native-cppwinrt:
name: 'linux: GCC native build + llvm-mingw cross-build tests'
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3

- name: Build cppwinrt
run: |
cmake -S . -B build/native/ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_INSTALL_PREFIX=$PWD/install/
cmake --build build/native/ --target install -j2

- name: Test run (cppwinrt -?)
run: |
install/bin/cppwinrt -?

- name: Test run (build projection using Windows.winmd)
run: |
curl -o Windows.winmd -L https://github.com/microsoft/windows-rs/raw/master/crates/libs/metadata/default/Windows.winmd
install/bin/cppwinrt -in Windows.winmd -out /tmp/cppwinrt -verbose

- id: setup-llvm
name: Set up llvm-mingw
uses: ./.github/actions/setup-llvm-mingw

- name: Cross-build tests using projection
run: |
cmake -S test -B build/cross-tests --toolchain "$PWD/cross-mingw-toolchain.cmake" \
-DCMAKE_SYSTEM_PROCESSOR=x86_64 \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_FLAGS="-static" \
-DCPPWINRT_PROJECTION_INCLUDE_DIR=/tmp/cppwinrt \
-DDOWNLOAD_WINDOWSNUMERICS=TRUE
cmake --build build/cross-tests -j2

- name: Upload built tests
uses: actions/upload-artifact@v3
with:
name: linux-native-cppwinrt-cross-build-tests-x86_64-bin
path: build/cross-tests/*.exe

test-linux-native-cppwinrt-cross-tests:
name: 'linux: Run llvm-mingw cross-build tests'
needs: build-linux-native-cppwinrt
strategy:
matrix:
arch: [x86_64]
runs-on: windows-latest
steps:
- uses: actions/checkout@v3

- name: Fetch test executables
uses: actions/download-artifact@v3
with:
name: linux-native-cppwinrt-cross-build-tests-${{ matrix.arch }}-bin
path: ./

- name: Run tests
run: |
$test_exes = ls *.exe -Name
$has_failed_tests = 0
foreach ($test_exe in $test_exes) {
echo "::group::Run '$test_exe'"
& .\$test_exe
echo "::endgroup::"
if ($LastExitCode -ne 0) {
echo "::error::Test '$test_exe' failed!"
$has_failed_tests = 1
}
}
if ($has_failed_tests -ne 0) {
exit 1
}

build-msvc-natvis:
name: 'Build natvis'
Expand Down
68 changes: 40 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# This CMake build file is intended for use with the llvm-mingw toolchain:
# https://github.com/mstorsjo/llvm-mingw
#
# It also works for building natively on Linux, or cross-building from Linux
# for running on Windows with a mingw-w64 toolchain.
#
# It most probably doesn't work with MSVC.

cmake_minimum_required(VERSION 3.16)
Expand All @@ -16,8 +19,10 @@ if(CPPWINRT_BUILD_VERSION STREQUAL "2.3.4.5" OR CPPWINRT_BUILD_VERSION STREQUAL
endif()
message(STATUS "Using version string: ${CPPWINRT_BUILD_VERSION}")

# WinMD uses CreateFile2 which requires Windows 8.
add_compile_definitions(_WIN32_WINNT=0x0602)
if(WIN32)
# WinMD uses CreateFile2 which requires Windows 8.
add_compile_definitions(_WIN32_WINNT=0x0602)
endif()


# === prebuild: Generator tool for strings.cpp, strings.h, version.rc ===
Expand Down Expand Up @@ -77,32 +82,37 @@ set(CPPWINRT_HEADERS
cppwinrt/type_writers.h
)

add_custom_command(
OUTPUT
"${PROJECT_BINARY_DIR}/app.manifest"
COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/cppwinrt/app.manifest" "${PROJECT_BINARY_DIR}/app.manifest"
DEPENDS "${PROJECT_SOURCE_DIR}/cppwinrt/app.manifest"
VERBATIM
)
# Do the configure_file dance so that app.manifest.rc don't get modified every
# single time the project is reconfigured and trigger a rebuild.
file(WRITE "${PROJECT_BINARY_DIR}/app.manifest.rc.in" "1 24 \"app.manifest\"\n")
configure_file(
"${PROJECT_BINARY_DIR}/app.manifest.rc.in"
"${PROJECT_BINARY_DIR}/app.manifest.rc"
COPYONLY
)
if(WIN32)
add_custom_command(
OUTPUT
"${PROJECT_BINARY_DIR}/app.manifest"
COMMAND ${CMAKE_COMMAND} -E copy "${PROJECT_SOURCE_DIR}/cppwinrt/app.manifest" "${PROJECT_BINARY_DIR}/app.manifest"
DEPENDS "${PROJECT_SOURCE_DIR}/cppwinrt/app.manifest"
VERBATIM
)
# Do the configure_file dance so that app.manifest.rc don't get modified every
# single time the project is reconfigured and trigger a rebuild.
file(WRITE "${PROJECT_BINARY_DIR}/app.manifest.rc.in" "1 24 \"app.manifest\"\n")
configure_file(
"${PROJECT_BINARY_DIR}/app.manifest.rc.in"
"${PROJECT_BINARY_DIR}/app.manifest.rc"
COPYONLY
)

set(CPPWINRT_RESOURCES
"${PROJECT_BINARY_DIR}/app.manifest"
"${PROJECT_BINARY_DIR}/app.manifest.rc"
"${PROJECT_BINARY_DIR}/version.rc"
)
set(CPPWINRT_RESOURCES
"${PROJECT_BINARY_DIR}/app.manifest"
"${PROJECT_BINARY_DIR}/app.manifest.rc"
"${PROJECT_BINARY_DIR}/version.rc"
)
endif()

add_executable(cppwinrt ${CPPWINRT_SRCS} ${CPPWINRT_RESOURCES} ${CPPWINRT_HEADERS})
target_compile_definitions(cppwinrt PRIVATE CPPWINRT_VERSION_STRING="${CPPWINRT_BUILD_VERSION}")
target_include_directories(cppwinrt PRIVATE ${PROJECT_BINARY_DIR})
target_link_libraries(cppwinrt shlwapi)

if(WIN32)
target_link_libraries(cppwinrt shlwapi)
endif()

install(TARGETS cppwinrt)

Expand Down Expand Up @@ -158,26 +168,28 @@ int main() {}
add_dependencies(cppwinrt gen-libxmllite)
endif()
endif()
target_link_libraries(cppwinrt "${XMLLITE_LIBRARY}")
if(WIN32)
target_link_libraries(cppwinrt "${XMLLITE_LIBRARY}")
endif()


# === winmd: External header-only library for reading winmd files ===

include(ExternalProject)
ExternalProject_Add(winmd
URL https://github.com/microsoft/winmd/releases/download/1.0.210629.2/Microsoft.Windows.WinMD.1.0.210629.2.nupkg
URL_HASH SHA256=4c5f29d948f5b3d724d229664c8f8e4823250d3c9f23ad8067b732fc7076d8c7
GIT_REPOSITORY https://github.com/microsoft/winmd.git
GIT_TAG 0f1eae3bfa63fa2ba3c2912cbfe72a01db94cc5a
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)
add_dependencies(cppwinrt winmd)
ExternalProject_Get_Property(winmd SOURCE_DIR)
set(winmd_SOURCE_DIR "${SOURCE_DIR}")
target_include_directories(cppwinrt PRIVATE "${winmd_SOURCE_DIR}")
target_include_directories(cppwinrt PRIVATE "${winmd_SOURCE_DIR}/src")


if(NOT CMAKE_CROSSCOMPILING)
if(WIN32 AND NOT CMAKE_CROSSCOMPILING)
include(CTest)
if(BUILD_TESTING)
add_subdirectory(test)
Expand Down
Loading