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
46 changes: 46 additions & 0 deletions .github/workflows/build-windows-plugin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Build Windows Plugin

on:
pull_request:
paths:
- "SDK/Plugins/Windows/**/*.cpp"
- "SDK/Plugins/Windows/**/*.h"
- "SDK/Plugins/Windows/CMakeLists.txt"
- "SDK/Plugins/CMakeLists.txt"
- ".github/workflows/build-windows-plugin.yml"
push:
branches: [main]
paths:
- "SDK/Plugins/Windows/**/*.cpp"
- "SDK/Plugins/Windows/**/*.h"
- "SDK/Plugins/Windows/CMakeLists.txt"
- "SDK/Plugins/CMakeLists.txt"
- ".github/workflows/build-windows-plugin.yml"

jobs:
build:
name: Build PrivyWebView.dll
runs-on: windows-latest

steps:
- uses: actions/checkout@v4

- name: Install WebView2 SDK
run: |
nuget install Microsoft.Web.WebView2 -OutputDirectory ${{ runner.temp }}/webview2

- name: Configure CMake
run: |
$wv2 = Get-ChildItem "${{ runner.temp }}/webview2/Microsoft.Web.WebView2.*" | Select-Object -First 1
$wv2Root = "$($wv2.FullName)/build/native"
cmake -S SDK/Plugins -B SDK/Plugins/build -G "Visual Studio 17 2022" -A x64 -D WEBVIEW2_ROOT="$wv2Root"

- name: Build
run: cmake --build SDK/Plugins/build --config Release

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: PrivyWebView-windows-x64
path: SDK/Plugins/Windows/x86_64/Release/PrivyWebView.dll
if-no-files-found: error
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,16 @@ npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Build artifact folders for C Windows plugin
/SDK/Plugins/Windows/**/bin/
/SDK/Plugins/Windows/**/obj/
/SDK/Plugins/Windows/**/Debug/
/SDK/Plugins/Windows/**/Release/*.lib*
/SDK/Plugins/Windows/**/Release/*.exp*
/SDK/Plugins/Build*

# Temporary build/test folders
SampleApp/Test*/

# Environment secrets
.env
6 changes: 6 additions & 0 deletions SDK/Plugins/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cmake_minimum_required(VERSION 3.16)
project(PrivyWebViewPlugins LANGUAGES C CXX)

if(WIN32 OR CMAKE_SYSTEM_NAME STREQUAL "Windows")
add_subdirectory(Windows)
endif()
7 changes: 7 additions & 0 deletions SDK/Plugins/CMakeLists.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions SDK/Plugins/Windows.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

77 changes: 77 additions & 0 deletions SDK/Plugins/Windows/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 3.16)
project(PrivyWebViewWindows LANGUAGES CXX)

set(PLUGIN_OUTPUT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/x86_64")

add_library(PrivyWebView SHARED PrivyWebView.cpp)

# Ensure output is placed in the Unity plugin folder
set_target_properties(PrivyWebView PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${PLUGIN_OUTPUT_DIR}"
LIBRARY_OUTPUT_DIRECTORY "${PLUGIN_OUTPUT_DIR}"
ARCHIVE_OUTPUT_DIRECTORY "${PLUGIN_OUTPUT_DIR}"
)

# WebView2 SDK support
# User can specify WEBVIEW2_ROOT to point to the WebView2 SDK root (contains include/ and lib/)
if(NOT WEBVIEW2_ROOT)
# ProgramFiles(x86) contains parentheses and cannot be referenced directly in CMake variables.
# Use cmd to expand it instead.
execute_process(COMMAND cmd /c "echo %ProgramFiles(x86)%" OUTPUT_VARIABLE _progfiles_x86 OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND cmd /c "echo %ProgramFiles%" OUTPUT_VARIABLE _progfiles OUTPUT_STRIP_TRAILING_WHITESPACE)

if(_progfiles_x86)
set(_webview2_candidate "${_progfiles_x86}/Microsoft WebView2 SDK")
elseif(_progfiles)
set(_webview2_candidate "${_progfiles}/Microsoft WebView2 SDK")
endif()

if(_webview2_candidate)
set(WEBVIEW2_ROOT "${_webview2_candidate}")
endif()
endif()

# Primary (recommended) include path
find_path(WEBVIEW2_INCLUDE_DIR WebView2.h
PATHS
"${WEBVIEW2_ROOT}/include"
"${WEBVIEW2_ROOT}/*/include"
NO_DEFAULT_PATH
)

# Primary lib path
find_library(WEBVIEW2_LIB WebView2LoaderStatic
PATHS
"${WEBVIEW2_ROOT}/x64"
"${WEBVIEW2_ROOT}/x86"
"${WEBVIEW2_ROOT}/*/x64"
"${WEBVIEW2_ROOT}/*/x86"
NO_DEFAULT_PATH
)

# Fallback: if we still don't find it, check the expected folder layout directly.
if(NOT WEBVIEW2_INCLUDE_DIR)
if(EXISTS "${WEBVIEW2_ROOT}/include/WebView2.h")
set(WEBVIEW2_INCLUDE_DIR "${WEBVIEW2_ROOT}/include")
endif()
endif()

if(NOT WEBVIEW2_LIB)
if(EXISTS "${WEBVIEW2_ROOT}/x64/WebView2LoaderStatic.lib")
set(WEBVIEW2_LIB "${WEBVIEW2_ROOT}/x64/WebView2LoaderStatic.lib")
elseif(EXISTS "${WEBVIEW2_ROOT}/x86/WebView2LoaderStatic.lib")
set(WEBVIEW2_LIB "${WEBVIEW2_ROOT}/x86/WebView2LoaderStatic.lib")
endif()
endif()

message(STATUS "WebView2 SDK root candidate: ${WEBVIEW2_ROOT}")
message(STATUS "Searching for WebView2.h under: ${WEBVIEW2_ROOT}/include")

if(WEBVIEW2_INCLUDE_DIR AND WEBVIEW2_LIB)
message(STATUS "Found WebView2 include: ${WEBVIEW2_INCLUDE_DIR}")
message(STATUS "Found WebView2 lib: ${WEBVIEW2_LIB}")
target_include_directories(PrivyWebView PRIVATE "${WEBVIEW2_INCLUDE_DIR}")
target_link_libraries(PrivyWebView PRIVATE "${WEBVIEW2_LIB}")
else()
message(FATAL_ERROR "WebView2 SDK not found. Please install WebView2 SDK (https://developer.microsoft.com/microsoft-edge/webview2/) and ensure WebView2.h and WebView2.lib are available. You can also set WEBVIEW2_ROOT to the SDK root folder.")
endif()
7 changes: 7 additions & 0 deletions SDK/Plugins/Windows/CMakeLists.txt.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading