Platform Integration and Deployment
Get SDK and Demo
- SDK Download: PC SDK Download Page
- Demo Project: GitHub - UnityMiniHost/PCDemo
1. Windows Platform
1.1 Development Environment
Required Tools:
- Visual Studio 2019 or higher
- Windows 10 SDK
- CMake 3.15+
Dependencies:
ws2_32.lib- Windows Sockets APIwinhttp.lib- Windows HTTP Services
1.2 CMake Configuration
cmake_minimum_required(VERSION 3.15)
project(webglhost_native_demo VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
add_executable(demo demo.cpp)
target_include_directories(demo PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include)
if(WIN32)
target_link_libraries(demo PRIVATE ws2_32 winhttp)
if(MSVC)
target_compile_options(demo PRIVATE /W3 /MP)
endif()
endif()
1.3 Build and Run
One-click build and run:
cd PCDemo_cpp
scripts\build-and-run.bat
Step-by-step operations:
scripts\build.bat # Build (auto-extracts SDK)
scripts\run.bat # Run
scripts\clean.bat # Clean
Manual build:
mkdir build && cd build
cmake .. -G "Visual Studio 16 2019" -A x64
cmake --build . --config Release
1.4 Deployment Structure
YourApp/
├── YourApp.exe
├── host/
│ └── webglhost_export.dll
└── runtime/
├── webglhost-runtime.exe
├── icudtl.dat
├── v8_context_snapshot.bin
├── *.pak
└── locales/
Packaging Recommendation: Use NSIS or Inno Setup to create an installer, including Visual C++ Redistributable components.
2. macOS Platform
2.1 Development Environment
Required Tools:
- Xcode Command Line Tools
- CMake 3.15+
System Libraries (built-in):
libcurl- HTTP requestslibdl- Dynamic library loading
2.2 CMake Configuration
elseif(APPLE)
find_package(CURL REQUIRED)
target_include_directories(demo PRIVATE ${CURL_INCLUDE_DIRS})
target_link_libraries(demo PRIVATE ${CURL_LIBRARIES})
target_compile_options(demo PRIVATE -Wall -Wextra)
set_target_properties(demo PROPERTIES
BUILD_RPATH "@executable_path"
INSTALL_RPATH "@executable_path"
)
endif()
2.3 Build and Run
One-click build and run:
cd PCDemo_cpp
chmod +x scripts/*.sh
./scripts/build-and-run.sh
Step-by-step operations:
./scripts/build.sh # Build (auto-extracts SDK)
./scripts/run.sh # Run
./scripts/clean.sh # Clean
Architecture options:
./scripts/build.sh --arch arm64 # ARM64
./scripts/build.sh --arch x64 # x64
Manual build:
# Extract runtime
cd native_sdk/mac
cat runtime-arm64.tar.gz.* | tar -xzf - -C ../../runtime/
cd ../..
# Build
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make
2.4 Deployment Structure
YourApp.app/
└── Contents/
├── MacOS/
│ └── YourApp
├── Resources/
│ ├── host/
│ │ └── libwebglhost_export.dylib
│ └── runtime/
│ └── webglhost-runtime.app/
└── Info.plist
Code Signing:
codesign --force --sign "Developer ID Application: Your Name" YourApp.app
codesign --verify --verbose YourApp.app
3. Cross-Platform Code
3.1 Platform Detection
#ifdef _WIN32
#define PLATFORM_WINDOWS
#include <windows.h>
#include <winhttp.h>
#elif defined(__APPLE__)
#define PLATFORM_MACOS
#include <dlfcn.h>
#include <curl/curl.h>
#endif
3.2 Library Loading Abstraction
#ifdef _WIN32
typedef HMODULE LibHandle;
#else
typedef void* LibHandle;
#endif
class LibraryLoader {
public:
static LibHandle LoadLib(const char* path) {
#ifdef _WIN32
return LoadLibraryA(path);
#else
return dlopen(path, RTLD_NOW | RTLD_LOCAL);
#endif
}
static void* GetFunction(LibHandle lib, const char* name) {
#ifdef _WIN32
return (void*)GetProcAddress(lib, name);
#else
return dlsym(lib, name);
#endif
}
static void UnloadLib(LibHandle lib) {
#ifdef _WIN32
FreeLibrary(lib);
#else
dlclose(lib);
#endif
}
};
3.3 Runtime Path
#ifdef _WIN32
const char* runtimePath = "runtime\\webglhost-runtime.exe";
#else
const char* runtimePath = "runtime/webglhost-runtime.app/Contents/MacOS/webglhost-runtime";
#endif
service->InitializeBrowsingCore(config, runtimePath, &handler);
4. SDK File Organization
SDK files are stored as split archives, and build scripts will automatically extract them.
Windows (native_sdk/windows/):
host.zip # SDK DLL
runtime.z01/z02/z03 # Runtime split archives
version.json
macOS (native_sdk/mac/):
runtime-arm64.tar.gz.01/02/03 # ARM64 runtime
runtime-x64.tar.gz.01/02/03 # x64 runtime
version.json
5. Troubleshooting
5.1 Build Issues
| Issue | Solution |
|---|---|
| CMake not found | Windows: Download from cmake.org; macOS: brew install cmake |
| VS version mismatch | Modify generator: cmake -G "Visual Studio 17 2022" -A x64 .. |
| libcurl not found | macOS: brew install curl |
5.2 Runtime Issues
Windows:
- DLL load failed: Check if
host/webglhost_export.dllexists - Runtime not found: Confirm
runtime/directory is complete - Use
dumpbin /DEPENDENTS demo.exeto check dependencies
macOS:
- dylib load failed: Use
otool -Lto check dependencies - Architecture mismatch: Use
file demoto check architecture - Permission issues: Check file permissions and code signing
5.3 Extraction Issues
Windows:
# Manual extraction
7z x native_sdk\windows\runtime.z01
macOS:
# Manual merge and extract
cat native_sdk/mac/runtime-arm64.tar.gz.* | tar -xzf - -C runtime/