Skip to content
Open
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
97 changes: 97 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

jobs:
build-linux-cross-cswinrt:
name: 'cross: Cross-build from Linux'
strategy:
matrix:
arch: [i686, x86_64]
runs-on: ubuntu-22.04
env:
CMAKE_COLOR_DIAGNOSTICS: 1
CLICOLOR_FORCE: 1
steps:
- uses: actions/checkout@v6

- name: Install cross compiler
run: |
arch=${{ matrix.arch }}
sudo apt-get install g++-mingw-w64-${arch/_/-}
sudo update-alternatives --set "${{ matrix.arch }}-w64-mingw32-gcc" "/usr/bin/${{ matrix.arch }}-w64-mingw32-gcc-posix"
sudo update-alternatives --set "${{ matrix.arch }}-w64-mingw32-g++" "/usr/bin/${{ matrix.arch }}-w64-mingw32-g++-posix"

- name: Cross-build cswinrt
run: |
cmake -S src/cswinrt/ -B build/cross/ --toolchain cross-mingw-toolchain.cmake \
-DCMAKE_SYSTEM_PROCESSOR=${{ matrix.arch }} \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_CXX_FLAGS="-static" \
-DCMAKE_INSTALL_PREFIX=$PWD/install/
cmake --build build/cross/ --target install -j2

- name: Upload cswinrt.exe
uses: actions/upload-artifact@v6
with:
name: cross-build-${{ matrix.arch }}-bin
path: install/bin/cswinrt.exe

build-linux-native-cswinrt:
name: 'native: Build cswinrt for Linux'
runs-on: ubuntu-22.04
env:
CMAKE_COLOR_DIAGNOSTICS: 1
CLICOLOR_FORCE: 1
steps:
- uses: actions/checkout@v6

- name: Build cswinrt (native Linux)
run: |
cmake -S src/cswinrt/ -B build/linux_native/ \
-DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build/linux_native/ -j2

- name: Smoke test
run: |
file build/linux_native/cswinrt
build/linux_native/cswinrt 2>&1 | head -3 || true

- name: Upload cswinrt
uses: actions/upload-artifact@v6
with:
name: native-linux-x64-bin
path: build/linux_native/cswinrt

build-linux-dotnet-tools:
name: 'dotnet: Build IIDOptimizer & CsWinMD on Linux'
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v6

- name: Setup .NET 8
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Build IIDOptimizer
run: |
dotnet build src/Perf/IIDOptimizer/IIDOptimizer.csproj \
-p:IsDotnetBuild=true -c Release

- name: Smoke test IIDOptimizer
run: dotnet src/Perf/IIDOptimizer/bin/Release/net8.0/IIDOptimizer.dll 2>&1 || true

- name: Build CsWinMD
run: |
dotnet build src/Authoring/cswinmd/CsWinMD.csproj \
-p:IsDotnetBuild=true \
-p:SolutionDir=${{ github.workspace }}/src/ \
-c Release

- name: Smoke test CsWinMD
run: dotnet src/Authoring/cswinmd/bin/Release/net8.0/CsWinMD.dll 2>&1 || true
41 changes: 41 additions & 0 deletions cross-mingw-toolchain.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# This is a cmake-toolchain(5) file that can be used to cross-build
# cswinrt.exe from Linux or other operating systems using a mingw-w64 cross
# toolchain. This should work with both GCC-based and llvm-mingw toolchains.
#
# Example usage with toolchain installed system-wide:
#
# $ cmake -S src/cswinrt/ -B build/cross_x64/ \
# --toolchain cross-mingw-toolchain.cmake \
# -DCMAKE_BUILD_TYPE=RelWithDebInfo \
# -DCMAKE_CXX_FLAGS="-static" \
# -DCMAKE_INSTALL_PREFIX=$PWD/install/
#
# Example usage with external toolchain:
#
# $ cmake -S src/cswinrt/ -B build/cross_x64/ \
# --toolchain cross-mingw-toolchain.cmake \
# -DMINGW_BIN_PATH=/opt/llvm-mingw/bin \
# -DCMAKE_BUILD_TYPE=RelWithDebInfo \
# -DCMAKE_INSTALL_PREFIX=$PWD/install/

set(CMAKE_SYSTEM_NAME Windows)
if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
set(CMAKE_SYSTEM_PROCESSOR x86_64)
endif()

set(TOOLCHAIN_PREFIX ${CMAKE_SYSTEM_PROCESSOR}-w64-mingw32)

if(DEFINED MINGW_BIN_PATH)
set(TOOLCHAIN_PREFIX "${MINGW_BIN_PATH}/${TOOLCHAIN_PREFIX}")
endif()

set(CMAKE_C_COMPILER "${TOOLCHAIN_PREFIX}-gcc")
set(CMAKE_CXX_COMPILER "${TOOLCHAIN_PREFIX}-g++")
set(CMAKE_RC_COMPILER "${TOOLCHAIN_PREFIX}-windres")

set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)

unset(TOOLCHAIN_PREFIX)
13 changes: 10 additions & 3 deletions src/Authoring/cswinmd/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static void Main(string[] args)
var i = new List<string>();
string? o = null;
string? sdkVersion = null;
string? windowsWinmd = null;
bool? verbose = false;
bool? nologo = false;
string? a = null;
Expand All @@ -70,6 +71,11 @@ public static void Main(string[] args)
idx++;
sdkVersion = args[idx];
}
else if (args[idx] == "-windowsWinmd")
{
idx++;
windowsWinmd = args[idx];
}
else if (args[idx] == "-verbose")
{
verbose = true;
Expand All @@ -80,7 +86,7 @@ public static void Main(string[] args)
}
}

DoMain(i.ToArray(), o!, a!, sdkVersion, verbose, nologo);
DoMain(i.ToArray(), o!, a!, sdkVersion, windowsWinmd, verbose, nologo);
}

/// <summary>
Expand All @@ -90,10 +96,11 @@ public static void Main(string[] args)
/// <param name="o">Output directory</param>
/// <param name="a">Assembly name</param>
/// <param name="sdkVersion">Optional sdk version</param>
/// <param name="windowsWinmd">Direct path to Windows.winmd (bypasses registry lookup, required on non-Windows)</param>
/// <param name="verbose">Verbose logging</param>
/// <param name="nologo">Don't print logo</param>
/// Uses System.CommandLine.Dragonfruit
public static void DoMain(string[] i, string o, string a, string? sdkVersion, bool? verbose, bool? nologo)
public static void DoMain(string[] i, string o, string a, string? sdkVersion, string? windowsWinmd, bool? verbose, bool? nologo)
{
if (!nologo.HasValue || !nologo.Value)
{
Expand Down Expand Up @@ -125,7 +132,7 @@ public static void DoMain(string[] i, string o, string a, string? sdkVersion, bo

var assemblyName = a;

var windows_winmd = GetWindowsWinMdPath(sdkVersion);
var windows_winmd = !string.IsNullOrEmpty(windowsWinmd) ? windowsWinmd : GetWindowsWinMdPath(sdkVersion);
var compilation = CSharpCompilation.Create(
assemblyName: assemblyName,
syntaxTrees: new[] { CSharpSyntaxTree.ParseText(inputText, new CSharpParseOptions(LanguageVersion.Preview), inputFile) },
Expand Down
1 change: 0 additions & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
</ResourceCompile>
</ItemDefinitionGroup>

<Import Project="Strings.props" />

<Import Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(SimulateCsWinRTNugetReference)' == 'true'" Project="..\nuget\Microsoft.Windows.CsWinRT.props" />

Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

<Target Name="CopyEmbeddedSymbols"
AfterTargets="Build"
Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(TargetFramework)' != ''"
Condition="'$(MSBuildProjectExtension)' == '.csproj' and '$(TargetFramework)' != '' and '$([MSBuild]::IsOSPlatform(Windows))' == 'true'"
Inputs="$(TargetPath)"
Outputs="$(OutputPath)$(AssemblyName).pdb">
<PropertyGroup>
Expand Down
Loading