Skip to content
Draft

UWP #527

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
230 changes: 230 additions & 0 deletions .github/workflows/build-uwp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
name: UWP builds

on:
workflow_dispatch:
workflow_call:
push:
branches:
- main
paths:
- CMakeLists.txt
- cmake/**
- src/**
- vendor/**
- .github/workflows/build-uwp.yml
pull_request:
paths:
- CMakeLists.txt
- cmake/**
- src/**
- vendor/**
- .github/workflows/build-uwp.yml

jobs:
build-uwp:
name: Build UWP (${{ matrix.arch }})
runs-on: windows-2022

strategy:
fail-fast: false
matrix:
include:
- arch: x64
cmake_arch: x64
triplet: x64-uwp
- arch: arm64
cmake_arch: ARM64
triplet: arm64-uwp

env:
VCPKG_ROOT: ${{ github.workspace }}\vcpkg

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Checkout SDL2
uses: actions/checkout@v4
with:
repository: libsdl-org/SDL
ref: release-2.32.10
path: vendor/sdl2

- name: Build and install SDL2 for UWP
shell: pwsh
run: |
$sdlRoot = Join-Path $env:GITHUB_WORKSPACE 'sdl2-uwp'
$sdlBuild = Join-Path $env:GITHUB_WORKSPACE 'vendor\sdl2\build'

if (Test-Path $sdlRoot) {
Remove-Item $sdlRoot -Recurse -Force
}

cmake -S "$env:GITHUB_WORKSPACE\vendor\sdl2" -B $sdlBuild `
-G "Visual Studio 17 2022" `
-A ${{ matrix.cmake_arch }} `
-DCMAKE_SYSTEM_NAME=WindowsStore `
-DCMAKE_SYSTEM_VERSION=10.0 `
-DCMAKE_BUILD_TYPE=Release `
-DCMAKE_INSTALL_PREFIX="$sdlRoot" `
-DSDL_SHARED=OFF `
-DSDL_STATIC=ON `
-DSDL_TESTS=OFF `
-DSDL_STATIC_PIC=OFF

cmake --build $sdlBuild --config Release --parallel
cmake --install $sdlBuild --config Release

- name: Configure UWP build
shell: pwsh
run: |
$sdkRoot = "$env:ProgramFiles(x86)\Microsoft Visual Studio\2022\Enterprise"
if (-not (Test-Path $sdkRoot)) {
$sdkRoot = "$env:ProgramFiles(x86)\Microsoft Visual Studio\2022\BuildTools"
}
if (-not (Test-Path $sdkRoot)) {
$sdkRoot = "$env:ProgramFiles(x86)\Microsoft Visual Studio\2022\Community"
}

$sdlRoot = Join-Path $env:GITHUB_WORKSPACE 'sdl2-uwp'

cmake -S . -B build-uwp `
-G "Visual Studio 17 2022" `
-A ${{ matrix.cmake_arch }} `
-DCMAKE_SYSTEM_NAME=WindowsStore `
-DCMAKE_SYSTEM_VERSION=10.0 `
-DCMAKE_PREFIX_PATH="$sdlRoot" `
-DPLATFORM=uwp `
-DBACKEND=sdl2 `
-DCMAKE_BUILD_TYPE=Release `
-DWERROR=ON

- name: Build
shell: pwsh
run: |
cmake --build build-uwp --config Release --parallel

- name: Package Appx
shell: pwsh
run: |
$appRoot = Join-Path $env:GITHUB_WORKSPACE "build-uwp\package-${{ matrix.arch }}"
$assetsDir = Join-Path $appRoot 'Assets'
$packagePath = Join-Path $env:GITHUB_WORKSPACE "butterscotch-uwp-${{ matrix.arch }}.appx"
$manifestPath = Join-Path $appRoot 'AppxManifest.xml'
$exePath = Join-Path $env:GITHUB_WORKSPACE "build-uwp\Release\butterscotch.exe"
$sdlDll = Join-Path $env:GITHUB_WORKSPACE "sdl2-uwp\bin\SDL2.dll"

New-Item -ItemType Directory -Force -Path $appRoot, $assetsDir | Out-Null

Copy-Item $exePath (Join-Path $appRoot 'butterscotch.exe') -Force
if (Test-Path $sdlDll) {
Copy-Item $sdlDll (Join-Path $appRoot 'SDL2.dll') -Force
} else {
Write-Host 'No SDL2 DLL found in the install tree; assuming static linkage.'
}
Copy-Item "$env:GITHUB_WORKSPACE\vendor\gamecontrollerdb.txt" (Join-Path $appRoot 'gamecontrollerdb.txt') -Force

if (-not (Test-Path "$env:GITHUB_WORKSPACE\data.win")) {
New-Item -ItemType File -Force -Path (Join-Path $appRoot 'data.win') | Out-Null
} else {
Copy-Item "$env:GITHUB_WORKSPACE\data.win" (Join-Path $appRoot 'data.win') -Force
}

Add-Type -AssemblyName System.Drawing
foreach ($spec in @(
@{ Name = 'Square150x150Logo.png'; Width = 150; Height = 150 },
@{ Name = 'Square44x44Logo.png'; Width = 44; Height = 44 },
@{ Name = 'StoreLogo.png'; Width = 50; Height = 50 }
)) {
$bmp = New-Object System.Drawing.Bitmap($spec.Width, $spec.Height)
$g = [System.Drawing.Graphics]::FromImage($bmp)
$g.Clear([System.Drawing.Color]::FromArgb(255, 33, 33, 33))
$pen = New-Object System.Drawing.Pen([System.Drawing.Color]::FromArgb(255, 255, 255, 255)), 2
$g.DrawRectangle($pen, 1, 1, $spec.Width - 3, $spec.Height - 3)
$g.DrawLine($pen, 0, 0, $spec.Width, $spec.Height)
$g.DrawLine($pen, $spec.Width, 0, 0, $spec.Height)
$g.Dispose()
$bmp.Save((Join-Path $assetsDir $spec.Name), [System.Drawing.Imaging.ImageFormat]::Png)
$bmp.Dispose()
}

$manifest = @'
<?xml version="1.0" encoding="utf-8"?>
<Package xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap rescap">
<Identity Name="Butterscotch.UWP" Publisher="CN=ButterscotchDev" Version="1.0.0.0" />
<Properties>
<DisplayName>Butterscotch</DisplayName>
<PublisherDisplayName>Butterscotch</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.19041.0" MaxVersionTested="10.0.26100.0" />
</Dependencies>
<Resources>
<Resource Language="en-US" />
</Resources>
<Capabilities>
<rescap:Capability Name="runFullTrust" />
</Capabilities>
<Applications>
<Application Id="App" Executable="butterscotch.exe" EntryPoint="Windows.FullTrustApplication">
<uap:VisualElements
DisplayName="Butterscotch"
Description="Butterscotch"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
BackgroundColor="transparent" />
</Application>
</Applications>
</Package>
'@
$manifest | Set-Content -Path $manifestPath -Encoding UTF8

$makeAppx = Get-ChildItem 'C:\Program Files (x86)\Windows Kits\10\bin' -Recurse -Filter makeappx.exe -ErrorAction SilentlyContinue |
Sort-Object FullName -Descending |
Select-Object -First 1
if (-not $makeAppx) {
throw 'makeappx.exe not found in the Windows SDK.'
}

if (Test-Path $packagePath) {
Remove-Item $packagePath -Force
}

& $makeAppx.FullName pack /d $appRoot /p $packagePath /nc /o
if ($LASTEXITCODE -ne 0) {
throw 'makeappx failed.'
}

$cert = New-SelfSignedCertificate -CertStoreLocation Cert:\CurrentUser\My -Type Custom `
-Subject 'CN=ButterscotchDev' -KeySpec Signature -KeyExportPolicy Exportable `
-KeyAlgorithm RSA -KeyLength 2048 -HashAlgorithm SHA256 `
-Provider 'Microsoft Enhanced RSA and AES Cryptographic Provider'

$pfxPath = Join-Path $env:GITHUB_WORKSPACE "butterscotch-uwp-${{ matrix.arch }}.pfx"
Export-PfxCertificate -Cert $cert -FilePath $pfxPath -Password (ConvertTo-SecureString -String 'Butterscotch123!' -Force -AsPlainText) | Out-Null

$signtool = Get-ChildItem 'C:\Program Files (x86)\Windows Kits\10\bin' -Recurse -Filter signtool.exe -ErrorAction SilentlyContinue |
Sort-Object FullName -Descending |
Select-Object -First 1
if (-not $signtool) {
throw 'signtool.exe not found in the Windows SDK.'
}

& $signtool.FullName sign /fd SHA256 /f $pfxPath /p 'Butterscotch123!' $packagePath
if ($LASTEXITCODE -ne 0) {
throw 'signtool failed.'
}

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: butterscotch-uwp-${{ matrix.arch }}
path: |
butterscotch-uwp-${{ matrix.arch }}.appx
butterscotch-uwp-${{ matrix.arch }}.pfx
build-uwp/Release/butterscotch.exe
build-uwp/Release/butterscotch.pdb
5 changes: 4 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ jobs:
uses: ./.github/workflows/build-other.yml

Compilers:
uses: ./.github/workflows/build-old-compilers.yml
uses: ./.github/workflows/build-old-compilers.yml

UWP:
uses: ./.github/workflows/build-uwp.yml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ CMakeUserPresets.json
compat/config.mk
/.vs
*.log
Packaging/ManualAppx/
83 changes: 71 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ set(PLATFORM "cli" CACHE STRING "Platform backend")
set(BACKEND "" CACHE STRING "Desktop platform backend")
set(AUDIO_BACKEND "" CACHE STRING "Audio backend")

if(PLATFORM STREQUAL "uwp")
if(BACKEND STREQUAL "" OR BACKEND STREQUAL "uwp" OR BACKEND STREQUAL "winrt")
set(BACKEND "sdl3" CACHE STRING "UWP uses SDL3-UWP backend" FORCE)
endif()
endif()

if(PLATFORM STREQUAL "cli" AND BACKEND STREQUAL "")
message(FATAL_ERROR "You need to set a BACKEND!")
endif()
Expand Down Expand Up @@ -260,7 +266,7 @@ if(ENABLE_VM_EXCEPTIONS_LOGS)
add_compile_definitions(ENABLE_VM_EXCEPTIONS_LOGS)
endif()

if(PLATFORM STREQUAL "cli" OR PLATFORM STREQUAL "vita" OR PLATFORM STREQUAL "switch")
if(PLATFORM STREQUAL "cli" OR PLATFORM STREQUAL "vita" OR PLATFORM STREQUAL "switch" OR PLATFORM STREQUAL "uwp")
if(PLATFORM STREQUAL "vita")
# Normally, __VITA__ should already be defined, but for some reason,
# in my case, this didn't really work... so just in case, when we're
Expand All @@ -279,6 +285,13 @@ if(PLATFORM STREQUAL "cli" OR PLATFORM STREQUAL "vita" OR PLATFORM STREQUAL "swi
set(VM_TRACING_DEFAULT OFF)
set(VM_OPCODE_PROFILER_DEFAULT OFF)
set(VM_STUB_LOGS_DEFAULT OFF)
elseif(PLATFORM STREQUAL "uwp")
add_compile_definitions(PLATFORM_UWP)

set(VM_GML_PROFILER_DEFAULT ON)
set(VM_TRACING_DEFAULT ON)
set(VM_OPCODE_PROFILER_DEFAULT ON)
set(VM_STUB_LOGS_DEFAULT ON)
else()
set(VM_GML_PROFILER_DEFAULT ON)
set(VM_TRACING_DEFAULT ON)
Expand All @@ -305,6 +318,7 @@ if(PLATFORM STREQUAL "cli" OR PLATFORM STREQUAL "vita" OR PLATFORM STREQUAL "swi
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/src/image)
if (MSVC)
target_include_directories(butterscotch PRIVATE ${CMAKE_SOURCE_DIR}/compat/getopt)
add_compile_definitions(NO_STRINGS_H)
add_compile_definitions(NO_STRTOK_R)
add_compile_definitions(NO_STRCASECMP)
endif()
Expand Down Expand Up @@ -341,7 +355,9 @@ if(PLATFORM STREQUAL "cli" OR PLATFORM STREQUAL "vita" OR PLATFORM STREQUAL "swi
# GLAD
add_library(glad STATIC vendor/glad/src/glad.c)
target_include_directories(glad PUBLIC vendor/glad/include)
target_compile_options(glad PRIVATE -Wno-unused-but-set-variable)
if(NOT MSVC)
target_compile_options(glad PRIVATE -Wno-unused-but-set-variable)
endif()
set(PLATFORM_LIBRARIES ${PLATFORM_LIBRARIES} glad)
endif()
if(NOT MSVC)
Expand Down Expand Up @@ -392,19 +408,62 @@ if(PLATFORM STREQUAL "cli" OR PLATFORM STREQUAL "vita" OR PLATFORM STREQUAL "swi
elseif(BACKEND STREQUAL "sdl2")
add_compile_definitions(USE_SDL2)

find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
target_include_directories(butterscotch PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_directories(butterscotch PRIVATE ${SDL2_LIBRARY_DIRS})
set(BACKEND_LIBRARIES ${SDL2_LIBRARIES})
if(MSVC)
if(PLATFORM STREQUAL "uwp")
set(SDL2_UWP_ROOT "$ENV{SDL2_UWP_ROOT}" CACHE PATH "Path to the installed SDL2-UWP distribution")
if(EXISTS "${SDL2_UWP_ROOT}")
list(APPEND CMAKE_PREFIX_PATH "${SDL2_UWP_ROOT}")
endif()

find_package(SDL2 CONFIG REQUIRED
HINTS
"${SDL2_UWP_ROOT}"
"C:/SDL2-UWP"
PATH_SUFFIXES
lib/cmake/SDL2
cmake
)
else()
find_package(SDL2 CONFIG REQUIRED)
endif()
set(BACKEND_LIBRARIES SDL2::SDL2)
else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
target_include_directories(butterscotch PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_directories(butterscotch PRIVATE ${SDL2_LIBRARY_DIRS})
set(BACKEND_LIBRARIES ${SDL2_LIBRARIES})
endif()
elseif(BACKEND STREQUAL "sdl3")
add_compile_definitions(USE_SDL3)

find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL3 REQUIRED sdl3)
target_include_directories(butterscotch PRIVATE ${SDL3_INCLUDE_DIRS})
target_link_directories(butterscotch PRIVATE ${SDL3_LIBRARY_DIRS})
set(BACKEND_LIBRARIES ${SDL3_LIBRARIES})
if(PLATFORM STREQUAL "uwp")
set(SDL3_UWP_ROOT "C:/SDL-UWP" CACHE PATH "Path to the installed SDL-UWP distribution")
if(EXISTS "${SDL3_UWP_ROOT}")
list(APPEND CMAKE_PREFIX_PATH "${SDL3_UWP_ROOT}")
endif()

find_package(SDL3 CONFIG REQUIRED
HINTS
"${SDL3_UWP_ROOT}"
"C:/SDL-UWP"
PATH_SUFFIXES
lib/cmake/SDL3
cmake
)
set(BACKEND_LIBRARIES SDL3::SDL3)

elseif(MSVC)
find_package(SDL3 CONFIG REQUIRED)
set(BACKEND_LIBRARIES SDL3::SDL3)

else()
find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL3 REQUIRED sdl3)
target_include_directories(butterscotch PRIVATE ${SDL3_INCLUDE_DIRS})
target_link_directories(butterscotch PRIVATE ${SDL3_LIBRARY_DIRS})
set(BACKEND_LIBRARIES ${SDL3_LIBRARIES})
endif()
elseif(BACKEND STREQUAL "appkit")
add_compile_definitions(USE_APPKIT)
target_compile_definitions(butterscotch PRIVATE GL_SILENCE_DEPRECATION)
Expand Down
Binary file added Packaging/Assets/Square150x150Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Packaging/Assets/Square44x44Logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Packaging/Assets/StoreLogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading