diff --git a/.gitmodules b/.gitmodules index 03b27fbd..82ef814b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -14,3 +14,6 @@ [submodule "Documentation~/doxygen-awesome-css"] path = Documentation~/doxygen-awesome-css url = https://github.com/jothepro/doxygen-awesome-css.git +[submodule "native~/extern/blend2d"] + path = native~/extern/blend2d + url = https://github.com/blend2d/blend2d diff --git a/Build~/Package.cs b/Build~/Package.cs index 2225001b..bbd0adc3 100644 --- a/Build~/Package.cs +++ b/Build~/Package.cs @@ -227,6 +227,22 @@ public void Run() Console.WriteLine("**** Adding generated files (for the Android Player) to the package"); AddGeneratedFiles("!UNITY_EDITOR && UNITY_ANDROID", generatedRuntimePath, Path.Combine(outputPackagePath, "Runtime", "generated")); + + Console.WriteLine("**** Compiling for Web Player"); + unity.Run(new[] + { + "-batchmode", + "-nographics", + "-projectPath", + Utility.ProjectRoot, + "-buildTarget", + "WebGL", + "-executeMethod", + "CesiumForUnity.BuildCesiumForUnity.CompileForWebAndExit" + }); + + Console.WriteLine("**** Adding generated files (for the Android Player) to the package"); + AddGeneratedFiles("!UNITY_EDITOR && UNITY_ANDROID", generatedRuntimePath, Path.Combine(outputPackagePath, "Runtime", "generated")); } else if (OperatingSystem.IsMacOS()) { diff --git a/Editor/BuildCesiumForUnity.cs b/Editor/BuildCesiumForUnity.cs index 5b75633a..690bb4f9 100644 --- a/Editor/BuildCesiumForUnity.cs +++ b/Editor/BuildCesiumForUnity.cs @@ -46,6 +46,25 @@ public static void CompileForAndroidAndExit() EditorApplication.Exit(0); } + public static void CompileForWebAndExit() + { + CompileCesiumForUnityNative.ExitAfterCompile = true; + + string buildPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + Directory.CreateDirectory(buildPath); + try + { + PlayerSettings.SetScriptingBackend(BuildTargetGroup.WebGL, ScriptingImplementation.IL2CPP); + PlayerSettings.WebGL.threadsSupport = true; + BuildPlayer(BuildTargetGroup.WebGL, BuildTarget.WebGL, Path.Combine(buildPath, "WebGL")); + } + finally + { + Directory.Delete(buildPath, true); + } + EditorApplication.Exit(0); + } + public static void CompileForUWPAndExit() { CompileCesiumForUnityNative.ExitAfterCompile = true; diff --git a/Editor/CompileCesiumForUnityNative.cs b/Editor/CompileCesiumForUnityNative.cs index 1b8657ab..1ff9e588 100644 --- a/Editor/CompileCesiumForUnityNative.cs +++ b/Editor/CompileCesiumForUnityNative.cs @@ -4,6 +4,7 @@ using UnityEditor.Build.Reporting; using System.Diagnostics; using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; using System.IO; using System.Text; using System; @@ -122,6 +123,8 @@ private static string GetSharedLibraryFilename(string baseName, BuildTarget targ return $"lib{baseName}.a"; case BuildTarget.StandaloneOSX: return $"lib{baseName}.dylib"; + case BuildTarget.WebGL: + return $"lib{baseName}.a"; default: // Assume Linux-ish return $"lib{baseName}.so"; @@ -432,8 +435,103 @@ private static string GetInstallDirectoryForPlatform(PlatformToBuild platform, s return Path.Combine(packagePath, "Plugins", GetDirectoryNameForPlatform(platform)); } + // Web builds use static libraries (.a files) that need to be marked as only + // compatible with WebGL. This is normally done in OnPostprocessAllAssets, but + // that only includes the main libCesiumForUnityNative.a library, not the other + // static libraries. + private static void SetWebGLStaticLibrariesPlatform(string webglPluginsPath) + { + if (!Directory.Exists(webglPluginsPath)) + return; + + // Find all static library files (.a) in the directory and its subdirectories. + string[] libraryFiles = Directory.GetFiles(webglPluginsPath, "*.a", SearchOption.AllDirectories); + if (libraryFiles.Length == 0) + return; + + AssetDatabase.StartAssetEditing(); + + foreach (string filePath in libraryFiles) + { + // Application.datapath is the /Assets folder. We need to strip off that + // part and prepend "Packages" to get the correct asset path. + string assetPath = "Packages" + filePath.Substring(Application.dataPath.Length + 2); + + // Get the importer for the asset. + PluginImporter importer = AssetImporter.GetAtPath(assetPath) as PluginImporter; + + if (importer != null) + { + // Disable "Any Platform" to enable platform-specific settings. + importer.SetCompatibleWithAnyPlatform(false); + + // Exclude from all platforms before enabling the desired one. + // This ensures the library is ONLY active on WebGL. + importer.SetCompatibleWithPlatform(BuildTarget.Android, false); + importer.SetCompatibleWithPlatform(BuildTarget.iOS, false); + importer.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows, false); + importer.SetCompatibleWithPlatform(BuildTarget.StandaloneWindows64, false); + importer.SetCompatibleWithPlatform(BuildTarget.StandaloneOSX, false); + importer.SetCompatibleWithPlatform(BuildTarget.StandaloneLinux64, false); + importer.SetCompatibleWithEditor(false); + + // We need to exclude libastcenc-none-static.a as it's being installed, but conflicts with + // Unity's symbols. + bool supportsWebGL = !assetPath.EndsWith("libastcenc-none-static.a"); + + importer.SetCompatibleWithPlatform(BuildTarget.WebGL, supportsWebGL); + + importer.SaveAndReimport(); + } + } + + AssetDatabase.StopAssetEditing(); + } + internal static void BuildNativeLibrary(LibraryToBuild library) { + var emscriptenDir = ""; + var deleteTemporaryEmscriptenDir = false; + + if (library.Platform == BuildTarget.WebGL) + { + // Find the Emscripten that ships with the Unity WebGL platform + var editorDir = EditorApplication.applicationContentsPath; + emscriptenDir = Path.Combine(editorDir, "PlaybackEngines", "WebGLSupport", "BuildTools", "Emscripten"); + if (!Directory.Exists(emscriptenDir)) + { + // Check for editor built from source + editorDir = new FileInfo(Path.Combine(editorDir, "..", "..", "..", "..")).FullName; + emscriptenDir = Path.Combine(editorDir, "WebGLSupport", "BuildTools", "Emscripten"); + if (!Directory.Exists(emscriptenDir)) + { + // Check for editor built from source on mac + editorDir = new FileInfo(Path.Combine(editorDir, "..")).FullName; + emscriptenDir = Path.Combine(editorDir, "WebGLSupport", "BuildTools", "Emscripten"); + if (!Directory.Exists(emscriptenDir)) + { + UnityEngine.Debug.LogError($"Emscripten directory does not exist at: {emscriptenDir}. Cannot build Web version of CesiumForUnityNative."); + return; + } + } + } + + if (emscriptenDir.Contains(' ')) + { + // Some ezvcpkg libraries like openssl fail to build if the path to compilation tools contains spaces. + // The default Unity install path on Windows does contain spaces as it's put into "Program Files". + // Use subst to map the Emscripten directory to a drive letter, eliminating the space. + // When the process finishes, we will delete the mapping. + char driveLetter = 'M'; + if (!Directory.Exists(driveLetter + ":\\")) + { + Process.Start("subst", driveLetter + ": \"" + emscriptenDir + "\"").WaitForExit(); + deleteTemporaryEmscriptenDir = true; + } + emscriptenDir = driveLetter + ":\\"; + } + } + if (library.CleanBuild && library.BuildDirectory.Length > 2 && Directory.Exists(library.BuildDirectory)) Directory.Delete(library.BuildDirectory, true); Directory.CreateDirectory(library.BuildDirectory); @@ -454,6 +552,13 @@ internal static void BuildNativeLibrary(LibraryToBuild library) { startInfo.FileName = File.Exists("/Applications/CMake.app/Contents/bin/cmake") ? "/Applications/CMake.app/Contents/bin/cmake" : "cmake"; } + else if (library.Platform == BuildTarget.WebGL) + { + if (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows) + startInfo.FileName = $"{emscriptenDir}/emscripten/emcmake.bat"; + else + startInfo.FileName = $"{emscriptenDir}/emscripten/emcmake"; + } else { startInfo.FileName = "cmake"; @@ -464,6 +569,30 @@ internal static void BuildNativeLibrary(LibraryToBuild library) startInfo.RedirectStandardOutput = true; ConfigureEnvironmentVariables(startInfo.Environment, library); + var EM_CONFIG = ""; + if (library.Platform == BuildTarget.WebGL) + { + startInfo.EnvironmentVariables["EMSDK"] = emscriptenDir; + startInfo.EnvironmentVariables["EMCC_SKIP_SANITY_CHECK"] = "1"; + startInfo.EnvironmentVariables["EM_FROZEN_CACHE"] = "1"; + startInfo.EnvironmentVariables["EM_WORKAROUND_PYTHON_BUG_34780"] = "1"; + startInfo.EnvironmentVariables["EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG"] = "1"; + startInfo.EnvironmentVariables["PYTHONUTF8"] = "1"; + + EM_CONFIG = Path.Combine(emscriptenDir, ".emscripten"); + startInfo.EnvironmentVariables["EM_CONFIG"] = EM_CONFIG; + startInfo.EnvironmentVariables["EM_PYTHON"] = Path.Combine(emscriptenDir, "python", + (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Linux) ? "python3" : + (SystemInfo.operatingSystemFamily == OperatingSystemFamily.Windows) ? Path.Combine("python.exe") : + (SystemInfo.operatingSystemFamily == OperatingSystemFamily.MacOSX) ? Path.Combine("bin", "python3") : + "python"); + + var path = startInfo.EnvironmentVariables.ContainsKey("PATH") ? startInfo.EnvironmentVariables["PATH"] : ""; + if (path == "") + path = Environment.GetEnvironmentVariable("Path"); + startInfo.EnvironmentVariables["PATH"] = $"{emscriptenDir}/emscripten;{emscriptenDir}/node;{emscriptenDir}/python;{emscriptenDir}/python/bin;{path}"; + } + List args = new List() { "-B", @@ -475,6 +604,16 @@ internal static void BuildNativeLibrary(LibraryToBuild library) $"-DCMAKE_INSTALL_PREFIX=\"{library.InstallDirectory}\"", $"-DREINTEROP_GENERATED_DIRECTORY={library.GeneratedDirectoryName}", }; + + if (library.Platform == BuildTarget.WebGL) + { + args.Insert(0, "cmake"); + args.Add("-DBUILD_SHARED_LIB=OFF"); + args.Add("-DCESIUM_ENABLE_CLANG_TIDY=OFF"); + var generatedInclude = Path.Combine(library.SourceDirectory, "Runtime", library.GeneratedDirectoryName, "include"); + args.Add($"-DCMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES=\"{generatedInclude}\""); + } + args.AddRange(library.ExtraConfigureArgs); if (library.Toolchain != null) @@ -484,6 +623,9 @@ internal static void BuildNativeLibrary(LibraryToBuild library) RunAndLog(startInfo, log, logFilename); + if (library.Platform == BuildTarget.WebGL) + startInfo.FileName = "cmake"; + args = new List() { "--build", @@ -499,13 +641,32 @@ internal static void BuildNativeLibrary(LibraryToBuild library) startInfo.Arguments = string.Join(' ', args); RunAndLog(startInfo, log, logFilename); - if (library.Platform == BuildTarget.iOS) + // Refresh the asset database for platforms that use static linking so the Unity + // builder can find the libraries. + if (library.Platform == BuildTarget.iOS || library.Platform == BuildTarget.WebGL) AssetDatabase.Refresh(); + + if (library.Platform == BuildTarget.WebGL) + SetWebGLStaticLibrariesPlatform(library.InstallDirectory); } } finally { EditorUtility.ClearProgressBar(); + if (deleteTemporaryEmscriptenDir) + { + try + { + var driveLetter = emscriptenDir[0]; + UnityEngine.Debug.Log("Deleting temporary Emscripten drive mapping: " + driveLetter + ":"); + Process.Start("subst", driveLetter + ": /D").WaitForExit(); + } + catch (Exception) + { + // Ignore any errors here. + UnityEngine.Debug.LogWarning("Failed to delete temporary Emscripten drive mapping: " + emscriptenDir); + } + } } } diff --git a/Editor/ConfigureReinterop.cs b/Editor/ConfigureReinterop.cs index a1228d4d..9c65e873 100644 --- a/Editor/ConfigureReinterop.cs +++ b/Editor/ConfigureReinterop.cs @@ -26,6 +26,8 @@ internal partial class ConfigureReinterop public const string CppOutputPath = "../native~/Runtime/generated-WSA"; #elif UNITY_64 public const string CppOutputPath = "../native~/Editor/generated-Standalone"; +#elif UNITY_WEBGL + public const string CppOutputPath = "../native~/Editor/generated-WebGL"; #else public const string CppOutputPath = "../native~/Editor/generated-Unknown"; #endif diff --git a/Runtime/CesiumRuntime.asmdef b/Runtime/CesiumRuntime.asmdef index e735c00e..225d4b8d 100644 --- a/Runtime/CesiumRuntime.asmdef +++ b/Runtime/CesiumRuntime.asmdef @@ -12,7 +12,8 @@ "iOS", "macOSStandalone", "WSA", - "WindowsStandalone64" + "WindowsStandalone64", + "WebGL" ], "excludePlatforms": [], "allowUnsafeCode": true, diff --git a/Runtime/ConfigureReinterop.cs b/Runtime/ConfigureReinterop.cs index e3b19a26..612c6c10 100644 --- a/Runtime/ConfigureReinterop.cs +++ b/Runtime/ConfigureReinterop.cs @@ -35,6 +35,8 @@ internal partial class ConfigureReinterop public const string CppOutputPath = "../native~/Runtime/generated-WSA"; #elif UNITY_64 public const string CppOutputPath = "../native~/Runtime/generated-Standalone"; +#elif UNITY_WEBGL + public const string CppOutputPath = "../native~/Runtime/generated-WebGL"; #else public const string CppOutputPath = "../native~/Runtime/generated-Unknown"; #endif @@ -45,7 +47,7 @@ internal partial class ConfigureReinterop public const string BaseNamespace = "DotNet"; // The name of the DLL or SO containing the C++ code. -#if UNITY_IOS && !UNITY_EDITOR +#if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR public const string NativeLibraryName = "__Internal"; #else public const string NativeLibraryName = "CesiumForUnityNative-Runtime"; diff --git a/native~/CMakeLists.txt b/native~/CMakeLists.txt index 29b91a7d..b25ca0a2 100644 --- a/native~/CMakeLists.txt +++ b/native~/CMakeLists.txt @@ -6,6 +6,40 @@ project(CesiumForUnityNative LANGUAGES CXX C ) +get_filename_component(toolchainFile "${CMAKE_TOOLCHAIN_FILE}" NAME) +if(toolchainFile STREQUAL "Emscripten.cmake") + set(CESIUM_TARGET_WASM ON) + # Include the toolchain directly as ezvcpkg will overwrite the + # toolchain before it's loaded + include(${CMAKE_TOOLCHAIN_FILE}) +endif() + +option(CESIUM_WASM64 "Enable 64-bit WebAssembly target" OFF) + +if(CESIUM_TARGET_WASM) + # vcpkg will attempt to second-guess our CMAKE_C_COMPILER setting, choosing to go with the value of CC instead. + # While normally this is the correct value to go with, for wasm we need to be using emcc and em++. + # So we set CC and CXX to emcc and em++ here so vcpkg will pick them up properly. + # Does this make sense? No. Does it work? Somehow. ¯\_(ツ)_/¯ + set(ENV{CC} ${CMAKE_C_COMPILER}) + set(ENV{CXX} ${CMAKE_CXX_COMPILER}) + + set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE BOTH) + set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) + + # Make sure all files are compiled with -pthread and other required flags. + # HAS_FUTIME is for tidy-html5 to keep it from using , which is not available with Emscripten. + if(CESIUM_WASM64) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -sMEMORY64=1 -fwasm-exceptions -mbulk-memory -mnontrapping-fptoint -sSUPPORT_LONGJMP=wasm -pthread -DHAS_FUTIME=0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -sMEMORY64=1 -fwasm-exceptions -mbulk-memory -mnontrapping-fptoint -sSUPPORT_LONGJMP=wasm -pthread -DHAS_FUTIME=0") + else() + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fwasm-exceptions -mbulk-memory -mnontrapping-fptoint -sSUPPORT_LONGJMP=wasm -pthread -DHAS_FUTIME=0") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fwasm-exceptions -mbulk-memory -mnontrapping-fptoint -sSUPPORT_LONGJMP=wasm -pthread -DHAS_FUTIME=0") + endif() +endif() + # By default, vcpkg (or is it cmake?) will try to link against the Debug version # of the vcpkg libraries when we build the RelWithDebInfo configuration. Tell it # to prefer Release instead. vcpkg Release builds DO have debug symbols, just like @@ -19,6 +53,10 @@ if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../Editor" CACHE PATH "Installed to the Editor directory." FORCE) endif() +if (CESIUM_TARGET_WASM) + set(CMAKE_INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../Plugins/WebGL") +endif() + option(CESIUM_TRACING_ENABLED "Whether to enable the Cesium performance tracing framework (CESIUM_TRACE_* macros)." OFF) option(EDITOR "Whether to build with Editor support." ON) set(REINTEROP_GENERATED_DIRECTORY "generated-Editor" CACHE STRING "The subdirectory of each native library in which the Reinterop-generated code is found.") @@ -80,16 +118,39 @@ if (NOT VCPKG_TRIPLET) endif() endif() +if(CESIUM_TARGET_WASM) + if(CESIUM_WASM64) + # vcpkg will attempt to make this wasm32-emscripten if we don't declare it + set(VCPKG_TARGET_TRIPLET wasm64-emscripten-unity) + else() + # vcpkg will attempt to make this wasm32-emscripten if we don't declare it + set(VCPKG_TARGET_TRIPLET wasm32-emscripten-unity) + endif() +endif() + # We never need any of cesium-native's header files to be installed. set(CESIUM_INSTALL_HEADERS OFF) -# We only need cesium-native's static lib files to be installed on iOS. -if (NOT IOS) +# We only need cesium-native's static lib files to be installed on iOS and Wasm. +if (NOT IOS AND NOT CESIUM_TARGET_WASM) set(CESIUM_INSTALL_STATIC_LIBS OFF) endif() +if (CESIUM_TARGET_WASM) + list(APPEND CESIUM_EXCLUDE_INSTALL_STATIC_LIBS "libjpeg-turbo") # This conflicts with Unity symbols +endif() + add_subdirectory(extern/swl-variant) +if(CESIUM_TARGET_WASM AND EXISTS extern/blend2d) + # fix blend2d not working from vcpkg install + set(BLEND2D_EXTERNAL_ASMJIT OFF) + set(BLEND2D_STATIC ON) + add_subdirectory(extern/blend2d) + install(TARGETS blend2d) # TODO: just install static lib, not headers + set_target_properties(blend2d PROPERTIES EXCLUDE_FROM_ALL 0 EXCLUDE_FROM_DEFAULT_BUILD 0) +endif() + set(CESIUM_DISABLE_CURL ON) add_subdirectory(extern/cesium-native) @@ -106,10 +167,14 @@ if (EDITOR) add_subdirectory(Editor) endif() -set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) +if (CESIUM_TARGET_WASM) + set(LIB_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}") +else() + set(LIB_INSTALL_DIR ${CMAKE_INSTALL_LIBDIR}) +endif() # Specify all targets that need to compile bitcode -if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS") - install(TARGETS tidy-static) - set_target_properties(tidy-static PROPERTIES EXCLUDE_FROM_ALL 0 EXCLUDE_FROM_DEFAULT_BUILD 0) +if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS" OR CESIUM_TARGET_WASM) + install(TARGETS tidy-static) + set_target_properties(tidy-static PROPERTIES EXCLUDE_FROM_ALL 0 EXCLUDE_FROM_DEFAULT_BUILD 0) endif() diff --git a/native~/Editor/src/CesiumIonSessionImpl.cpp b/native~/Editor/src/CesiumIonSessionImpl.cpp index dad75514..bbab92af 100644 --- a/native~/Editor/src/CesiumIonSessionImpl.cpp +++ b/native~/Editor/src/CesiumIonSessionImpl.cpp @@ -17,6 +17,8 @@ #include #include +#include + using namespace DotNet; namespace { diff --git a/native~/Runtime/CMakeLists.txt b/native~/Runtime/CMakeLists.txt index 62fa2768..8e491e7e 100644 --- a/native~/Runtime/CMakeLists.txt +++ b/native~/Runtime/CMakeLists.txt @@ -6,10 +6,15 @@ project(CesiumForUnityNative LANGUAGES CXX C ) +get_filename_component(toolchainFile "${CMAKE_TOOLCHAIN_FILE}" NAME) +if(toolchainFile STREQUAL "Emscripten.cmake") + set(CESIUM_TARGET_WASM ON) +endif() + file(GLOB_RECURSE CESIUMFORUNITYNATIVE_SOURCES CONFIGURE_DEPENDS src/*.cpp ../Shared/src/*.cpp ${REINTEROP_GENERATED_DIRECTORY}/src/*.cpp) file(GLOB_RECURSE CESIUMFORUNITYNATIVE_HEADERS CONFIGURE_DEPENDS src/*.h ${REINTEROP_GENERATED_DIRECTORY}/src/*.h) -if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS") +if (${CMAKE_SYSTEM_NAME} STREQUAL "iOS" OR CESIUM_TARGET_WASM) add_library(CesiumForUnityNative-Runtime STATIC) else() add_library(CesiumForUnityNative-Runtime SHARED) diff --git a/native~/Runtime/src/UnityPrepareRendererResources.cpp b/native~/Runtime/src/UnityPrepareRendererResources.cpp index dbeff78c..7efe023a 100644 --- a/native~/Runtime/src/UnityPrepareRendererResources.cpp +++ b/native~/Runtime/src/UnityPrepareRendererResources.cpp @@ -913,7 +913,12 @@ UnityPrepareRendererResources::prepareInLoadThread( // Unfortunately, this must be done on the main thread. return UnityEngine::Mesh::AllocateWritableMeshData(numberOfPrimitives); }) +#ifndef __EMSCRIPTEN__ .thenInWorkerThread( +#else + // Unity Wasm can only access managed code from the main thread. + .thenInMainThread( +#endif [tileLoadResult = std::move(tileLoadResult), rendererOptions]( UnityEngine::MeshDataArray&& meshDataArray) mutable { MeshDataResult meshDataResult{std::move(meshDataArray), {}}; @@ -1014,7 +1019,12 @@ UnityPrepareRendererResources::prepareInLoadThread( } if (instanceIDs.size() > 0) { +#ifndef __EMSCRIPTEN__ return asyncSystem.runInWorkerThread( +#else + // Unity Wasm can only access managed code from the main thread. + return asyncSystem.runInMainThread( +#endif [workerResult = std::move(workerResult), instanceIDs = std::move(instanceIDs), meshes = std::move(meshes)]() mutable { diff --git a/native~/Shared/src/UnityAssetAccessor.cpp b/native~/Shared/src/UnityAssetAccessor.cpp index 5ca59294..3e048e23 100644 --- a/native~/Shared/src/UnityAssetAccessor.cpp +++ b/native~/Shared/src/UnityAssetAccessor.cpp @@ -28,11 +28,36 @@ #include #include +#include using namespace CesiumAsync; using namespace CesiumUtility; using namespace DotNet; +#ifdef __EMSCRIPTEN__ +struct RequestMetaDataLengths { + RequestMetaDataLengths() + : headerLength(0u) + , responseUrlLength(0u) + {} + + uint32_t headerLength; + uint32_t responseUrlLength; +}; +typedef void (*OnResponseCallback)(void* instance, int statusCode, void* data, uint32_t size, char* error, int webError); +typedef void (*OnProgressCallback)(void* instance, int statusCode, uint32_t bytes, uint32_t total, void* data, uint32_t size); + +extern "C" { +extern uint32_t JS_WebRequest_Create(const char* url, const char* method); +extern void JS_WebRequest_SetRequestHeader(uint32_t request, const char* header, const char* value); +extern void JS_WebRequest_Send(uint32_t request, void *ptr, uint32_t length, void *ref, OnResponseCallback onresponse, OnProgressCallback onprogress); +extern void JS_WebRequest_GetResponseMetaDataLengths(uint32_t request, RequestMetaDataLengths* buffer); +extern void JS_WebRequest_GetResponseMetaData(uint32_t request, char* headerBuffer, uint32_t headerSize, char* responseUrlBuffer, uint32_t responseUrlSize); +extern void JS_WebRequest_Abort(uint32_t request); +extern void JS_WebRequest_Release(uint32_t request); +} // extern "C" +#endif // __EMSCRIPTEN__ + namespace { class UnityAssetResponse : public IAssetResponse { @@ -113,6 +138,75 @@ std::string replaceInvalidChars(const std::string& input) { return result; } +#ifdef __EMSCRIPTEN__ +class JSAssetResponse : public IAssetResponse { +public: + JSAssetResponse(const HttpHeaders& headers, int statusCode, void* data, uint32_t size) + : _headers(headers) + , _statusCode(statusCode) + , _data(size) { + memcpy(_data.data(), data, size); + } + + virtual uint16_t statusCode() const override { return _statusCode; } + + virtual std::string contentType() const override { + auto find = this->_headers.find("content-type"); + if (find != this->_headers.end()) { + return find->second; + } + return ""; + } + + virtual const HttpHeaders& headers() const override { return _headers; } + + virtual std::span data() const override { return _data; } + +private: + HttpHeaders _headers; + int _statusCode; + std::vector _data; + std::vector _headerBuffer; + std::vector _responseUrlBuffer; +}; + +class JSAssetRequest : public IAssetRequest { +public: + JSAssetRequest(const std::string& method, + const std::string& url, + const HttpHeaders& headers, + IAssetResponse* response) + : _method(method) + , _url(url) + , _headers(headers) + , _response(response) {} + + virtual ~JSAssetRequest() { + delete this->_response; + } + + virtual const std::string& method() const override { return _method; } + virtual const std::string& url() const override { return _url; } + virtual const HttpHeaders& headers() const override { return _headers; } + virtual const IAssetResponse* response() const override { return _response; } + +private: + std::string _method; + std::string _url; + HttpHeaders _headers; + IAssetResponse* _response; +}; +#endif // __EMSCRIPTEN__ + +struct ResponseData { + uint32_t request; + std::string url; + HttpHeaders requestHeaders; + HttpHeaders responseHeaders; + Promise> promise; + std::vector data; +}; + } // namespace namespace CesiumForUnityNative { @@ -129,12 +223,129 @@ UnityAssetAccessor::UnityAssetAccessor() : _cesiumRequestHeaders() { std::string osVersion = System::Environment::OSVersion().VersionString().ToStlString(); +#ifndef __EMSCRIPTEN__ this->_cesiumRequestHeaders.insert({"X-Cesium-Client", "Cesium For Unity"}); this->_cesiumRequestHeaders.insert({"X-Cesium-Client-Version", version}); this->_cesiumRequestHeaders.insert({"X-Cesium-Client-Project", projectName}); this->_cesiumRequestHeaders.insert({"X-Cesium-Client-Engine", engine}); this->_cesiumRequestHeaders.insert({"X-Cesium-Client-OS", osVersion}); +#endif // __EMSCRIPTEN__ +} + +#ifdef __EMSCRIPTEN__ +static bool IsSpace(char c) { + return c == ' ' || c == '\t' || c == '\r' || c == '\n'; +} + +static void SetUnvalidated(std::string_view name, std::string_view value, bool replace, HttpHeaders& headers) { + // Insert or replace header + std::string nameStr(name.data(), name.size()); + HttpHeaders::iterator it = headers.find(nameStr); + if (it != headers.end()) { + if (replace) { + it->second = value; + } else { + it->second.reserve(it->second.size() + 1 + value.size()); + it->second.append(","); + it->second.append(value); + } + } else { + headers.insert({std::string(name), std::string(value)}); + } +} + +static void ParseAndSetAllHeaders(const char* buf, size_t length, HttpHeaders& headers) { + while (length > 0) { + // Find : character delimiting the key from the value + const char* delim = buf; + while ((delim - buf) < length && *delim != ':') { + ++delim; + + // If we hit a new line and did not find a delimiter character, skip this line. + if (*delim == '\r' || *delim == '\n') { + length -= (delim - buf); + buf = delim; + } + } + + // skip leading newline characters + while (*buf == '\r' || *buf == '\n') { + length--; + buf++; + } + + if ((delim - buf) >= length) + break; + + const char* end = delim; + while ((end - buf) < length && *end != '\r' && *end != '\n') { + ++end; + } + + // If we found a delimiter, parse it into headers + size_t keyLen = delim - buf; + // skip ':' + delim++; + + // Skip starting spaces in value + while (delim < end && IsSpace(*delim)) { + delim++; + } + + std::string_view key(buf, keyLen); + + if (delim < end) { + // Value was not all spaces + std::string_view value(delim, end - delim); + SetUnvalidated(key, value, true, headers); + } else { + SetUnvalidated(key, "", true, headers); + } + + while ((end - buf) < length && (*end == '\r' || *end == '\n')) { + ++end; + } + + length -= (end - buf); + buf = end; + } +} + +static void _OnProgress(void* _instance, int statusCode, uint32_t bytes, uint32_t total, void* data, uint32_t size) { + ResponseData* responseData = static_cast(_instance); + if (size > 0) { + size_t endPosition = responseData->data.size(); + responseData->data.resize(responseData->data.size() + size); + memcpy(responseData->data.data() + endPosition, data, size); + } + + RequestMetaDataLengths lengths; + JS_WebRequest_GetResponseMetaDataLengths(responseData->request, &lengths); + std::string headers((size_t)lengths.headerLength + 1, 0); + std::string responseUrl((size_t)lengths.responseUrlLength + 1, 0); + JS_WebRequest_GetResponseMetaData(responseData->request, (char *)headers.data(), headers.size(), (char *)responseUrl.data(), responseUrl.size()); + headers.resize(headers.size() - 1); // strip null terminator + responseUrl.resize(responseUrl.size() - 1); // strip null terminator + ParseAndSetAllHeaders(headers.c_str(), headers.size(), responseData->responseHeaders); +} + +static void _OnResponse(void* _instance, int statusCode, void* data, uint32_t size, char* error, int webError) { + ResponseData* responseData = static_cast(_instance); + auto& promise = responseData->promise; + if (webError == 0) { + // Success + promise.resolve(std::make_shared("GET", responseData->url, responseData->requestHeaders, + new JSAssetResponse(responseData->responseHeaders, statusCode, responseData->data.data(), responseData->data.size()))); + } else { + // Error + promise.reject(std::runtime_error(fmt::format( + "Request for `{}` failed: {}", + responseData->url, + error))); + } + delete responseData; } +#endif // __EMSCRIPTEN__ CesiumAsync::Future> UnityAssetAccessor::get( @@ -146,8 +357,27 @@ UnityAssetAccessor::get( return asyncSystem.runInMainThread([asyncSystem, url, headers, - &cesiumRequestHeaders = - this->_cesiumRequestHeaders]() { + &cesiumRequestHeaders = this->_cesiumRequestHeaders]() { + +#ifdef __EMSCRIPTEN__ + auto promise = asyncSystem.createPromise>(); + + auto future = promise.getFuture(); + + uint32_t request = JS_WebRequest_Create(url.c_str(), "GET"); + HttpHeaders requestHeaders = cesiumRequestHeaders; + for (const auto& header : headers) { + requestHeaders.insert(header); + } + for (const auto& header : requestHeaders) { + JS_WebRequest_SetRequestHeader(request, header.first.c_str(), header.second.c_str()); + } + + ResponseData* responseData = new ResponseData{request, url, std::move(requestHeaders), {}, std::move(promise)}; + JS_WebRequest_Send(request, nullptr, 0, responseData, _OnResponse, _OnProgress); + + return future; +#else UnityEngine::Networking::UnityWebRequest request = UnityEngine::Networking::UnityWebRequest::Get(System::String(url)); @@ -164,9 +394,7 @@ UnityAssetAccessor::get( System::String(header.second)); } - auto promise = - asyncSystem - .createPromise>(); + auto promise = asyncSystem.createPromise>(); auto future = promise.getFuture(); @@ -191,8 +419,8 @@ UnityAssetAccessor::get( request.error().ToStlString()))); } })); - return future; +#endif // __EMSCRIPTEN__ }); } diff --git a/native~/Shared/src/UnityLoggerSink.cpp b/native~/Shared/src/UnityLoggerSink.cpp index d46f8b88..5919fe38 100644 --- a/native~/Shared/src/UnityLoggerSink.cpp +++ b/native~/Shared/src/UnityLoggerSink.cpp @@ -1,4 +1,5 @@ #include "UnityLoggerSink.h" +#include #include #include diff --git a/native~/Shared/src/UnityTaskProcessor.cpp b/native~/Shared/src/UnityTaskProcessor.cpp index 1c6668b9..22ef04f4 100644 --- a/native~/Shared/src/UnityTaskProcessor.cpp +++ b/native~/Shared/src/UnityTaskProcessor.cpp @@ -1,14 +1,113 @@ #include "UnityTaskProcessor.h" +#ifndef __EMSCRIPTEN__ #include #include +#endif // __EMSCRIPTEN__ -using namespace DotNet; +#include +#include +#include +#include +#include namespace CesiumForUnityNative { +#ifdef __EMSCRIPTEN__ +// Unity Wasm can't use C# System/Threads, so we need to implement our own thread pool. + +// How many threads to use in the pool. This is somewhat arbitrary; we +// just don't want to create a new thread for every task, to keep the number +// of threads under the Emscripten limit. +static const int UNITY_THREAD_POOL_SIZE = 4; + +class UnityThreadPool { +public: + UnityThreadPool(size_t threads); + + ~UnityThreadPool(); + + void enqueue(std::function f); + +private: + std::vector workers; + std::queue> tasks; + std::mutex queue_mutex; + std::condition_variable condition; + bool stop; +}; + +UnityThreadPool::UnityThreadPool(size_t threads) + : stop(false) { + for(size_t i = 0; i < threads; ++i) { + workers.emplace_back([this] { + while (true) { + std::function task; + + { + std::unique_lock lock(this->queue_mutex); + + this->condition.wait(lock, [this] { + return this->stop || !this->tasks.empty(); + }); + + if (this->stop && this->tasks.empty()) { + return; + } + + task = std::move(this->tasks.front()); + this->tasks.pop(); + } + + task(); + } + }); + } +} + +void UnityThreadPool::enqueue(std::function task) { + { + std::unique_lock lock(queue_mutex); + if (stop) { + return; + } + tasks.emplace(task); + } + condition.notify_one(); +} + +UnityThreadPool::~UnityThreadPool() { + { + std::unique_lock lock(queue_mutex); + stop = true; + } + + condition.notify_all(); + + for (std::thread &worker: workers) { + worker.join(); + } +} + +UnityTaskProcessor::UnityTaskProcessor() + : _threadPool(new UnityThreadPool(UNITY_THREAD_POOL_SIZE)) { +} + +UnityTaskProcessor::~UnityTaskProcessor() { + delete _threadPool; +} +#else +UnityTaskProcessor::UnityTaskProcessor() {} + +UnityTaskProcessor::~UnityTaskProcessor() {} +#endif // __EMSCRIPTEN__ + void UnityTaskProcessor::startTask(std::function f) { - System::Threading::Tasks::Task::Run(f); +#ifdef __EMSCRIPTEN__ + _threadPool->enqueue(f); +#else // __EMSCRIPTEN__ + DotNet::System::Threading::Tasks::Task::Run(f); +#endif } } // namespace CesiumForUnityNative diff --git a/native~/Shared/src/UnityTaskProcessor.h b/native~/Shared/src/UnityTaskProcessor.h index b49bde86..1906e767 100644 --- a/native~/Shared/src/UnityTaskProcessor.h +++ b/native~/Shared/src/UnityTaskProcessor.h @@ -4,9 +4,21 @@ namespace CesiumForUnityNative { +class UnityThreadPool; + class UnityTaskProcessor : public CesiumAsync::ITaskProcessor { public: + UnityTaskProcessor(); + + virtual ~UnityTaskProcessor() override; + virtual void startTask(std::function f) override; + +private: +#ifdef __EMSCRIPTEN__ + // Unity Wasm can't use C# System/Threads, so we need to implement our own thread pool. + UnityThreadPool* _threadPool = nullptr; +#endif }; } // namespace CesiumForUnityNative diff --git a/native~/extern/blend2d b/native~/extern/blend2d new file mode 160000 index 00000000..007bf482 --- /dev/null +++ b/native~/extern/blend2d @@ -0,0 +1 @@ +Subproject commit 007bf4828120dd1f5a3fd17d73c8cd7137155494 diff --git a/native~/vcpkg/ports/cpp-httplib/fix-find-brotli.patch b/native~/vcpkg/ports/cpp-httplib/fix-find-brotli.patch new file mode 100644 index 00000000..9c0dcc67 --- /dev/null +++ b/native~/vcpkg/ports/cpp-httplib/fix-find-brotli.patch @@ -0,0 +1,55 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0353b0c..5c0cd33 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -151,10 +151,10 @@ endif() + # This is so we can use our custom FindBrotli.cmake + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + if(HTTPLIB_REQUIRE_BROTLI) +- find_package(Brotli COMPONENTS encoder decoder common REQUIRED) ++ find_package(unofficial-brotli CONFIG REQUIRED) + set(HTTPLIB_IS_USING_BROTLI TRUE) + elseif(HTTPLIB_USE_BROTLI_IF_AVAILABLE) +- find_package(Brotli COMPONENTS encoder decoder common QUIET) ++ find_package(unofficial-brotli CONFIG QUIET) + set(HTTPLIB_IS_USING_BROTLI ${Brotli_FOUND}) + endif() + +@@ -236,9 +236,9 @@ target_link_libraries(${PROJECT_NAME} ${_INTERFACE_OR_PUBLIC} + # Needed for API from MacOS Security framework + "$<$,$,$>:-framework CoreFoundation -framework Security>" + # Can't put multiple targets in a single generator expression or it bugs out. +- $<$:Brotli::common> +- $<$:Brotli::encoder> +- $<$:Brotli::decoder> ++ $<$:unofficial::brotli::brotlicommon> ++ $<$:unofficial::brotli::brotlienc> ++ $<$:unofficial::brotli::brotlidec> + $<$:ZLIB::ZLIB> + $<$:zstd::libzstd> + $<$:OpenSSL::SSL> +@@ -296,9 +296,6 @@ if(HTTPLIB_INSTALL) + install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" +- # Install it so it can be used later by the httplibConfig.cmake file. +- # Put it in the same dir as our config file instead of a global path so we don't potentially stomp on other packages. +- "${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindBrotli.cmake" + DESTINATION ${_TARGET_INSTALL_CMAKEDIR} + ) + +diff --git a/cmake/httplibConfig.cmake.in b/cmake/httplibConfig.cmake.in +index bf57364..1c6fe62 100644 +--- a/cmake/httplibConfig.cmake.in ++++ b/cmake/httplibConfig.cmake.in +@@ -34,8 +34,8 @@ if(@HTTPLIB_IS_USING_BROTLI@) + # Note that the FindBrotli.cmake file is installed in the same dir as this file. + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + set(BROTLI_USE_STATIC_LIBS @BROTLI_USE_STATIC_LIBS@) +- find_dependency(Brotli COMPONENTS common encoder decoder) +- set(httplib_Brotli_FOUND ${Brotli_FOUND}) ++ find_dependency(unofficial-brotli COMPONENTS common encoder decoder) ++ set(httplib_Brotli_FOUND ${unofficial-brotli_FOUND}) + endif() + + if(@HTTPLIB_IS_USING_ZSTD@) diff --git a/native~/vcpkg/ports/cpp-httplib/fix-system-version.patch b/native~/vcpkg/ports/cpp-httplib/fix-system-version.patch new file mode 100644 index 00000000..4841aa88 --- /dev/null +++ b/native~/vcpkg/ports/cpp-httplib/fix-system-version.patch @@ -0,0 +1,13 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index d39958a..cdee3ce 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -117,7 +117,7 @@ if(BUILD_SHARED_LIBS AND WIN32 AND HTTPLIB_COMPILE) + set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON) + endif() + +-if(CMAKE_SYSTEM_NAME MATCHES "Windows" AND ${CMAKE_SYSTEM_VERSION} VERSION_LESS "10.0.0") ++if(CMAKE_SYSTEM_NAME MATCHES "Windows" AND DEFINED CMAKE_SYSTEM_VERSION AND CMAKE_SYSTEM_VERSION VERSION_LESS "10.0.0") + message(SEND_ERROR "Windows ${CMAKE_SYSTEM_VERSION} or lower is not supported. Please use Windows 10 or later.") + endif() + if(CMAKE_SIZEOF_VOID_P LESS 8) diff --git a/native~/vcpkg/ports/cpp-httplib/portfile.cmake b/native~/vcpkg/ports/cpp-httplib/portfile.cmake new file mode 100644 index 00000000..f5639bbe --- /dev/null +++ b/native~/vcpkg/ports/cpp-httplib/portfile.cmake @@ -0,0 +1,37 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO yhirose/cpp-httplib + REF "v${VERSION}" + SHA512 c355ab3814efce40759a3328b4e1079dc372d3cce8a841c42d22adb4eb228351f0602b5e82135c0bf69321fd5138a0052882ab801908ad4c32fa963d655a11d9 + HEAD_REF master + PATCHES + fix-find-brotli.patch +) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + brotli HTTPLIB_REQUIRE_BROTLI + openssl HTTPLIB_REQUIRE_OPENSSL + zlib HTTPLIB_REQUIRE_ZLIB + zstd HTTPLIB_REQUIRE_ZSTD +) + +set(VCPKG_BUILD_TYPE release) # header-only port + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + ${FEATURE_OPTIONS} + -DHTTPLIB_USE_OPENSSL_IF_AVAILABLE=OFF + -DHTTPLIB_USE_ZLIB_IF_AVAILABLE=OFF + -DHTTPLIB_USE_BROTLI_IF_AVAILABLE=OFF + -DHTTPLIB_USE_ZSTD_IF_AVAILABLE=OFF +) + +vcpkg_cmake_install() +vcpkg_cmake_config_fixup(PACKAGE_NAME httplib CONFIG_PATH lib/cmake/httplib) + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/lib") + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE") +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") diff --git a/native~/vcpkg/ports/cpp-httplib/usage b/native~/vcpkg/ports/cpp-httplib/usage new file mode 100644 index 00000000..8ee7571a --- /dev/null +++ b/native~/vcpkg/ports/cpp-httplib/usage @@ -0,0 +1,4 @@ +cpp-httplib provides CMake targets: + + find_package(httplib CONFIG REQUIRED) + target_link_libraries(main PRIVATE httplib::httplib) diff --git a/native~/vcpkg/ports/cpp-httplib/vcpkg.json b/native~/vcpkg/ports/cpp-httplib/vcpkg.json new file mode 100644 index 00000000..ead1a328 --- /dev/null +++ b/native~/vcpkg/ports/cpp-httplib/vcpkg.json @@ -0,0 +1,47 @@ +{ + "name": "cpp-httplib", + "version": "0.22.0", + "description": "A single file C++11 header-only HTTP/HTTPS server and client library", + "homepage": "https://github.com/yhirose/cpp-httplib", + "license": "MIT", + "supports": "!x86 & !arm32", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + } + ], + "default-features": [ + "brotli" + ], + "features": { + "brotli": { + "description": "Enables brotli compression support using brotli", + "dependencies": [ + "brotli" + ] + }, + "openssl": { + "description": "Enables HTTPS support using OpenSSL", + "dependencies": [ + "openssl" + ] + }, + "zlib": { + "description": "Enables gzip compression support using zlib", + "dependencies": [ + "zlib" + ] + }, + "zstd": { + "description": "Enables zstd support", + "dependencies": [ + "zstd" + ] + } + } +} diff --git a/native~/vcpkg/ports/ktx/0001-Use-vcpkg-zstd.patch b/native~/vcpkg/ports/ktx/0001-Use-vcpkg-zstd.patch new file mode 100644 index 00000000..0895a72b --- /dev/null +++ b/native~/vcpkg/ports/ktx/0001-Use-vcpkg-zstd.patch @@ -0,0 +1,122 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 2f141ac..f34503b 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -383,7 +383,6 @@ set(KTX_MAIN_SRC + external/basisu/transcoder/basisu_transcoder.cpp + external/basisu/transcoder/basisu_transcoder.h + external/basisu/transcoder/basisu.h +- external/basisu/zstd/zstd.c + lib/checkheader.c + external/dfdutils/createdfd.c + external/dfdutils/colourspaces.c +@@ -588,7 +587,6 @@ macro(common_libktx_settings target enable_write library_type) + external + + $ +- $ + + $ + $ +@@ -707,6 +705,11 @@ macro(common_libktx_settings target enable_write library_type) + target_compile_definitions(${target} PUBLIC KTX_FEATURE_KTX2) + endif() + ++ # Use vcpkg zstd ++ find_package(zstd CONFIG REQUIRED) ++ set(ZSTD_LIBRARIES "$,zstd::libzstd_shared,zstd::libzstd_static>") ++ target_link_libraries(${target} PRIVATE ${ZSTD_LIBRARIES}) ++ + if(WIN32) + if(MINGW) + # Check if the Threads package is provided; if using Mingw it MIGHT be +diff --git a/cmake/KtxConfig.cmake b/cmake/KtxConfig.cmake +index 6386ba2..537bf4f 100644 +--- a/cmake/KtxConfig.cmake ++++ b/cmake/KtxConfig.cmake +@@ -1,7 +1,8 @@ + # Copyright 2015-2020 The Khronos Group Inc. + # SPDX-License-Identifier: Apache-2.0 + +-# include(CMakeFindDependencyMacro) +-# find_dependency() ++include(CMakeFindDependencyMacro) ++find_dependency(Threads) ++find_dependency(zstd CONFIG) + + include("${CMAKE_CURRENT_LIST_DIR}/KtxTargets.cmake") +diff --git a/external/basisu/CMakeLists.txt b/external/basisu/CMakeLists.txt +index 492233a..152ceb5 100644 +--- a/external/basisu/CMakeLists.txt ++++ b/external/basisu/CMakeLists.txt +@@ -145,9 +145,6 @@ set(BASISU_SRC_LIST ${COMMON_SRC_LIST} + transcoder/basisu_transcoder.cpp + ) + +-if (ZSTD) +- set(BASISU_SRC_LIST ${BASISU_SRC_LIST} zstd/zstd.c) +-endif() + + if (APPLE) + set(BIN_DIRECTORY "bin_osx") +@@ -165,6 +162,10 @@ else() + target_compile_definitions(basisu PRIVATE BASISD_SUPPORT_KTX2_ZSTD=0) + endif() + ++if(ZSTD_LIBRARIES) ++ target_link_libraries(basisu ${ZSTD_LIBRARIES}) ++endif() ++ + if (NOT MSVC) + # For Non-Windows builds, let cmake try and find the system OpenCL headers/libs for us. + if (OPENCL_FOUND) +diff --git a/external/basisu/webgl/encoder/CMakeLists.txt b/external/basisu/webgl/encoder/CMakeLists.txt +index 588d91b..a337b13 100644 +--- a/external/basisu/webgl/encoder/CMakeLists.txt ++++ b/external/basisu/webgl/encoder/CMakeLists.txt +@@ -34,9 +34,6 @@ if (EMSCRIPTEN) + ) + + if (KTX2_ZSTANDARD) +- set(SRC_LIST ${SRC_LIST} +- ../../zstd/zstd.c +- ) + set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=1) + else() + set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=0) +@@ -55,6 +52,10 @@ if (EMSCRIPTEN) + target_compile_options(basis_encoder.js PRIVATE -fno-strict-aliasing -O3) + + target_include_directories(basis_encoder.js PRIVATE ../../transcoder) ++ ++ if(ZSTD_LIBRARIES) ++ target_link_libraries(basis_encoder.js ${ZSTD_LIBRARIES}) ++ endif() + + set_target_properties(basis_encoder.js PROPERTIES + OUTPUT_NAME "basis_encoder" +diff --git a/external/basisu/webgl/transcoder/CMakeLists.txt b/external/basisu/webgl/transcoder/CMakeLists.txt +index 372653d..5ebc3cf 100644 +--- a/external/basisu/webgl/transcoder/CMakeLists.txt ++++ b/external/basisu/webgl/transcoder/CMakeLists.txt +@@ -28,9 +28,6 @@ if (EMSCRIPTEN) + endif() + + if (KTX2_ZSTANDARD) +- set(SRC_LIST ${SRC_LIST} +- ../../zstd/zstddeclib.c +- ) + set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=1) + else() + set(ZSTD_DEFINITION BASISD_SUPPORT_KTX2_ZSTD=0) +@@ -44,6 +41,10 @@ if (EMSCRIPTEN) + target_compile_definitions(basis_transcoder.js PRIVATE NDEBUG BASISD_SUPPORT_UASTC=1 BASISD_SUPPORT_BC7=1 BASISD_SUPPORT_ATC=0 BASISD_SUPPORT_ASTC_HIGHER_OPAQUE_QUALITY=0 BASISD_SUPPORT_PVRTC2=0 BASISD_SUPPORT_FXT1=0 BASISD_SUPPORT_ETC2_EAC_RG11=0 BASISU_SUPPORT_ENCODING=0 ${KTX2_DEFINITION} ${ZSTD_DEFINITION} ) + target_compile_options(basis_transcoder.js PRIVATE -O3 -fno-strict-aliasing) + target_include_directories(basis_transcoder.js PRIVATE ../../transcoder) ++ ++ if(ZSTD_LIBRARIES) ++ target_link_libraries(basis_transcoder.js ${ZSTD_LIBRARIES}) ++ endif() + + set_target_properties(basis_transcoder.js PROPERTIES + OUTPUT_NAME "basis_transcoder" diff --git a/native~/vcpkg/ports/ktx/0003-mkversion.patch b/native~/vcpkg/ports/ktx/0003-mkversion.patch new file mode 100644 index 00000000..7e080d12 --- /dev/null +++ b/native~/vcpkg/ports/ktx/0003-mkversion.patch @@ -0,0 +1,13 @@ +diff --git a/cmake/version.cmake b/cmake/version.cmake +index 9a90622..0fc3521 100644 +--- a/cmake/version.cmake ++++ b/cmake/version.cmake +@@ -176,7 +176,7 @@ function( create_version_header dest_path target ) + add_custom_command( + OUTPUT ${version_h_output} + # On Windows this command has to be invoked by a shell in order to work +- COMMAND ${BASH_EXECUTABLE} -c "\"scripts/mkversion\" \"-v\" \"${KTX_GIT_VERSION_FULL}\" \"-o\" \"version.h\" \"${dest_path}\"" ++ COMMAND "${BASH_EXECUTABLE}" -- scripts/mkversion -v ${KTX_GIT_VERSION_FULL} -o version.h "${dest_path}" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMENT "Generate ${version_h_output}" + VERBATIM diff --git a/native~/vcpkg/ports/ktx/0004-quirks.patch b/native~/vcpkg/ports/ktx/0004-quirks.patch new file mode 100644 index 00000000..abc35b6e --- /dev/null +++ b/native~/vcpkg/ports/ktx/0004-quirks.patch @@ -0,0 +1,21 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index f34503b..20d431a 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -299,7 +299,7 @@ endif() + # Global compile & link options including optimization flags + if(MSVC) + add_compile_options( /W4;$<$:/WX> ) +- add_compile_options( $,/Gz,/O2> ) ++ add_compile_options( $,,/O2> ) + # Enable UTF-8 support + add_compile_options( $<$:/utf-8> ) + add_compile_options( $<$:/utf-8> ) +@@ -1103,6 +1103,7 @@ if(EMSCRIPTEN) + endif() + + add_library( objUtil STATIC ++ EXCLUDE_FROM_ALL + utils/argparser.cpp + utils/argparser.h + utils/ktxapp.h diff --git a/native~/vcpkg/ports/ktx/0005-no-vendored-libs.patch b/native~/vcpkg/ports/ktx/0005-no-vendored-libs.patch new file mode 100644 index 00000000..94b5a47c --- /dev/null +++ b/native~/vcpkg/ports/ktx/0005-no-vendored-libs.patch @@ -0,0 +1,18 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 20d431a..11a4c99 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1278,11 +1278,11 @@ if((KTX_FEATURE_TOOLS OR KTX_FEATURE_TESTS) AND NOT TARGET fmt::fmt) + set(BUILD_SHARED_LIBS OFF) + set(FMT_INSTALL OFF) + set(FMT_SYSTEM_HEADERS ON) +- add_subdirectory(external/fmt) ++ find_package(fmt CONFIG REQUIRED) + set(BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS_RESET}) + endif() + if(KTX_FEATURE_TOOLS AND NOT TARGET cxxopts::cxxopts) +- add_subdirectory(external/cxxopts) ++ find_package(cxxopts CONFIG REQUIRED) + endif() + + # Tools diff --git a/native~/vcpkg/ports/ktx/0006-fix-ios-install.patch b/native~/vcpkg/ports/ktx/0006-fix-ios-install.patch new file mode 100644 index 00000000..8a8cdbf0 --- /dev/null +++ b/native~/vcpkg/ports/ktx/0006-fix-ios-install.patch @@ -0,0 +1,22 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 11a4c99..4b27a7c 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -527,7 +527,7 @@ macro(common_libktx_settings target enable_write library_type) + SOVERSION ${PROJECT_VERSION_MAJOR} + XCODE_ATTRIBUTE_ENABLE_HARDENED_RUNTIME "YES" + ) +- if(APPLE_LOCKED_OS) ++ if(0) + set_target_properties(${target} PROPERTIES + FRAMEWORK TRUE + ) +@@ -1353,7 +1353,7 @@ endif() + # Use of this to install KHR/khr_df.h is due to CMake's failure to + # preserve the include source folder hierarchy. + # See https://gitlab.kitware.com/cmake/cmake/-/issues/16739. +-if (APPLE_LOCKED_OS) ++if (0) + set_source_files_properties( + include/KHR/khr_df.h + PROPERTIES MACOSX_PACKAGE_LOCATION Headers/KHR diff --git a/native~/vcpkg/ports/ktx/0007-remove-transcoder.patch b/native~/vcpkg/ports/ktx/0007-remove-transcoder.patch new file mode 100644 index 00000000..fe136193 --- /dev/null +++ b/native~/vcpkg/ports/ktx/0007-remove-transcoder.patch @@ -0,0 +1,62 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 2f141ac9..3927a565 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -1054,49 +1054,6 @@ if(EMSCRIPTEN) + DESTINATION . + COMPONENT ktx_js_read + ) +- +- add_executable( msc_basis_transcoder_js interface/js_binding/transcoder_wrapper.cpp ) +- target_link_libraries( msc_basis_transcoder_js ktx_read ) +- target_include_directories( msc_basis_transcoder_js +- PRIVATE +- lib +- external +- external/basisu/transcoder +- ) +- +- # Re-use ktx's compile options +- target_compile_options(msc_basis_transcoder_js +- PRIVATE +- $ +- ) +- +- target_link_options( +- msc_basis_transcoder_js +- PUBLIC +- ${KTX_EM_COMMON_LINK_FLAGS} +- "SHELL:-s EXPORT_NAME=MSC_TRANSCODER" +- # Re-use ktx's link options +- $ +- ) +- set_target_properties( msc_basis_transcoder_js PROPERTIES OUTPUT_NAME "msc_basis_transcoder") +- +- add_custom_command( +- TARGET msc_basis_transcoder_js +- POST_BUILD +- COMMAND ${CMAKE_COMMAND} -E copy "$/$$.js" "${PROJECT_SOURCE_DIR}/tests/webgl" +- COMMAND ${CMAKE_COMMAND} -E copy "$/$$.wasm" "${PROJECT_SOURCE_DIR}/tests/webgl" +- COMMENT "Copy msc_basis_transcoder.js and msc_basis_transcoder.wasm to tests/webgl" +- ) +- +- install(TARGETS msc_basis_transcoder_js +- RUNTIME +- DESTINATION . +- COMPONENT msc_basis_transcoder_js +- ) +- install(FILES ${CMAKE_BINARY_DIR}/msc_basis_transcoder.wasm +- DESTINATION . +- COMPONENT msc_basis_transcoder_js +- ) + endif() + + add_library( objUtil STATIC +@@ -1564,7 +1521,6 @@ if(EMSCRIPTEN) + set(CPACK_COMPONENTS_ALL + ktx_js + ktx_js_read +- msc_basis_transcoder_js + ) + else() + set(CPACK_COMPONENTS_ALL diff --git a/native~/vcpkg/ports/ktx/portfile.cmake b/native~/vcpkg/ports/ktx/portfile.cmake new file mode 100644 index 00000000..dadf0ab1 --- /dev/null +++ b/native~/vcpkg/ports/ktx/portfile.cmake @@ -0,0 +1,89 @@ +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO KhronosGroup/KTX-Software + REF "v${VERSION}" + SHA512 07c8564e1db57fea44ed565b1bc7d93ec82c29d1aa525cea0c1b1b42a8a587de0ab61b29e2c179fed4edd7cd539d13ee0112ce35728f3fe7e751de8640c679d2 + HEAD_REF master + PATCHES + 0001-Use-vcpkg-zstd.patch + 0003-mkversion.patch + 0004-quirks.patch + 0005-no-vendored-libs.patch + 0006-fix-ios-install.patch + 0007-remove-transcoder.patch +) +file(REMOVE "${SOURCE_PATH}/other_include/zstd_errors.h") +file(REMOVE_RECURSE "${SOURCE_PATH}/external/basisu/zstd") +file(REMOVE_RECURSE "${SOURCE_PATH}/lib/basisu/zstd") + +# Local patches to get things compiled with Emscripten 3.1.39 +vcpkg_replace_string("${SOURCE_PATH}/interface/js_binding/ktx_wrapper.cpp" "/* -*- tab-width: 4; -*- */" "#if 0\n/* -*- tab-width: 4; -*- */") +vcpkg_replace_string("${SOURCE_PATH}/interface/js_binding/ktx_wrapper.cpp" "#endif\n}" "#endif\n}\n#endif//0") +vcpkg_replace_string("${SOURCE_PATH}/CMakeLists.txt" "\"SHELL:-s GL_ENABLE_GET_PROC_ADDRESS=1\" # For Emscripten 3.1.51+" "#\"SHELL:-s GL_ENABLE_GET_PROC_ADDRESS=1\" # For Emscripten 3.1.51+") + + +vcpkg_list(SET OPTIONS) +if(VCPKG_TARGET_IS_WINDOWS) + vcpkg_acquire_msys(MSYS_ROOT + PACKAGES + bash + DIRECT_PACKAGES + # Required for "getopt" + "https://repo.msys2.org/msys/x86_64/util-linux-2.40.2-2-x86_64.pkg.tar.zst" + bf45b16cd470f8d82a9fe03842a09da2e6c60393c11f4be0bab354655072c7a461afc015b9c07f9f5c87a0e382cd867e4f079ede0d42f1589aa99ebbb3f76309 + # Required for "dos2unix" + "https://mirror.msys2.org/msys/x86_64/dos2unix-7.5.2-1-x86_64.pkg.tar.zst" + e5e949f01b19c82630131e338a4642da75e42f84220f5af4a97a11dd618e363396567b233d2adab79e05422660a0000abcbbabcd17efcadf37f07fe7565f041e + ) + vcpkg_add_to_path("${MSYS_ROOT}/usr/bin") + vcpkg_list(APPEND OPTIONS "-DBASH_EXECUTABLE=${MSYS_ROOT}/usr/bin/bash.exe") +endif() + +string(COMPARE EQUAL "${VCPKG_LIBRARY_LINKAGE}" "dynamic" ENABLE_SHARED) + +vcpkg_check_features(OUT_FEATURE_OPTIONS FEATURE_OPTIONS + FEATURES + tools KTX_FEATURE_TOOLS + vulkan KTX_FEATURE_VK_UPLOAD +) + +vcpkg_cmake_configure( + SOURCE_PATH "${SOURCE_PATH}" + OPTIONS + -DKTX_VERSION_FULL=v${VERSION} + -DKTX_FEATURE_TESTS=OFF + -DKTX_FEATURE_LOADTEST_APPS=OFF + -DBUILD_SHARED_LIBS=${ENABLE_SHARED} + ${FEATURE_OPTIONS} + ${OPTIONS} + DISABLE_PARALLEL_CONFIGURE +) + +vcpkg_cmake_install() + +if(tools IN_LIST FEATURES) + vcpkg_copy_tools( + TOOL_NAMES + ktx + toktx + ktxsc + ktxinfo + ktx2ktx2 + ktx2check + AUTO_CLEAN + ) +else() + vcpkg_copy_pdbs() +endif() + +vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/ktx) + +file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include") + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") +endif() + +file(GLOB LICENSE_FILES "${SOURCE_PATH}/LICENSES/*") +file(COPY ${LICENSE_FILES} DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}/LICENSES") +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.md") diff --git a/native~/vcpkg/ports/ktx/vcpkg.json b/native~/vcpkg/ports/ktx/vcpkg.json new file mode 100644 index 00000000..7350e517 --- /dev/null +++ b/native~/vcpkg/ports/ktx/vcpkg.json @@ -0,0 +1,36 @@ +{ + "name": "ktx", + "version-semver": "4.4.0", + "description": [ + "The Khronos KTX library and tools.", + "Functions for writing and reading KTX files, and instantiating OpenGL®, OpenGL ES™️ and Vulkan® textures from them." + ], + "homepage": "https://github.com/KhronosGroup/KTX-Software", + "license": null, + "supports": "arm64 | x64 | !windows", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + }, + "zstd" + ], + "features": { + "tools": { + "description": "Build tools", + "supports": "!android & !uwp", + "dependencies": [ + "cxxopts", + "fmt" + ] + }, + "vulkan": { + "description": "Build Vulkan support", + "supports": "!emscripten" + } + } +} diff --git a/native~/vcpkg/ports/openssl/cmake-config.patch b/native~/vcpkg/ports/openssl/cmake-config.patch new file mode 100644 index 00000000..d86d1c44 --- /dev/null +++ b/native~/vcpkg/ports/openssl/cmake-config.patch @@ -0,0 +1,104 @@ +diff --git forkSrcPrefix/Configurations/unix-Makefile.tmpl forkDstPrefix/Configurations/unix-Makefile.tmpl +index 7fdb0b86eb87a78746b311cd44885362b5da2a8f..ad0c5ff756cae42b06a5c79c79bda68f57619b00 100644 +--- forkSrcPrefix/Configurations/unix-Makefile.tmpl ++++ forkDstPrefix/Configurations/unix-Makefile.tmpl +@@ -11,6 +11,7 @@ + our $makedepcmd = platform->makedepcmd(); + + sub windowsdll { $config{target} =~ /^(?:Cygwin|mingw)/ } ++ sub run_on_windows { $^O =~ /^(?:cygwin|msys|MSWin32)/ } + + # Shared AIX support is special. We put libcrypto[64].so.ver into + # libcrypto.a and use libcrypto_a.a as static one, unless using +@@ -1899,13 +1900,27 @@ $import: $full + EOF + } + } +- $recipe .= <<"EOF"; ++ if (!run_on_windows()) { ++ $recipe .= <<"EOF"; + $full: $fulldeps + \$(CC) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\ + -o $full$shared_def \\ + $fullobjs \\ + $linklibs \$(LIB_EX_LIBS) + EOF ++ } else { ++ $recipe .= <<"EOF"; ++ $full: $fulldeps ++ \$(file >\$@.lst, \\ ++ $fullobjs \\ ++ ) ++ \$(CC) \$(LIB_CFLAGS) $linkflags\$(LIB_LDFLAGS)$shared_soname$shared_imp \\ ++ -o $full$shared_def \\ ++ @\$@.lst \\ ++ $linklibs \$(LIB_EX_LIBS) ++ rm -f \$@.lst ++EOF ++ } + if (windowsdll()) { + $recipe .= <<"EOF"; + rm -f apps/$full + +diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl +index 09303c4..487ff68 100644 +--- a/Configurations/unix-Makefile.tmpl ++++ b/Configurations/unix-Makefile.tmpl +@@ -338,7 +338,7 @@ bindir={- file_name_is_absolute($bindir) + ? $bindir : '$(INSTALLTOP)/$(BINDIR)' -} + + PKGCONFIGDIR=$(libdir)/pkgconfig +-CMAKECONFIGDIR=$(libdir)/cmake/OpenSSL ++CMAKECONFIGDIR=$(INSTALLTOP)/share/openssl + + MANDIR=$(INSTALLTOP)/share/man + DOCDIR=$(INSTALLTOP)/share/doc/$(BASENAME) +diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl +index 894834c..d6d3c41 100644 +--- a/Configurations/windows-makefile.tmpl ++++ b/Configurations/windows-makefile.tmpl +@@ -254,7 +254,7 @@ MODULESDIR=$(MODULESDIR_dev)$(MODULESDIR_dir) + libdir={- file_name_is_absolute($libdir) + ? $libdir : '$(INSTALLTOP)\$(LIBDIR)' -} + +-CMAKECONFIGDIR=$(libdir)\cmake\OpenSSL ++CMAKECONFIGDIR=$(INSTALLTOP)\share\openssl + + ##### User defined commands and flags ################################ + +diff --git a/exporters/cmake/OpenSSLConfig.cmake.in b/exporters/cmake/OpenSSLConfig.cmake.in +index 766aebe..026680a 100644 +--- a/exporters/cmake/OpenSSLConfig.cmake.in ++++ b/exporters/cmake/OpenSSLConfig.cmake.in +@@ -91,8 +91,7 @@ get_filename_component(_ossl_prefix "${CMAKE_CURRENT_LIST_FILE}" PATH) + {- + # For each component in $OpenSSL::safe::installdata::CMAKECONFIGDIR[0] relative to + # $OpenSSL::safe::installdata::PREFIX[0], have CMake figure out the parent directory. +- my $d = join('/', unixify(catdir($OpenSSL::safe::installdata::LIBDIR_REL_PREFIX[0], +- $OpenSSL::safe::installdata::CMAKECONFIGDIR_REL_LIBDIR[0]), 1)); ++ my $d = 'share/openssl'; + $OUT = ''; + if ($d ne '.') { + $OUT .= 'get_filename_component(_ossl_prefix "${_ossl_prefix}" PATH)' . "\n" +@@ -141,6 +140,14 @@ set(OPENSSL_APPLINK_SOURCE "${_ossl_prefix}/{- unixify($OpenSSL::safe::installda + {- output_on() if $disabled{uplink}; "" -} + set(OPENSSL_PROGRAM "${OPENSSL_RUNTIME_DIR}/{- platform->bin('openssl') -}") + ++if(NOT Z_VCPKG_OPENSSL_USE_SINGLE_CONFIG) ++ # Prevent loop ++ set(Z_VCPKG_OPENSSL_USE_SINGLE_CONFIG "prevent-loop") ++ # Chainload vcpkg's module-based multi-config target setup ++ find_package(OpenSSL MODULE) ++ set(Z_VCPKG_OPENSSL_USE_SINGLE_CONFIG 0) ++else() ++ # Use official single-config target setup + # Set up the imported targets + if(_ossl_use_static_libs) + {- output_off() unless $no_static; "" -} +@@ -240,5 +247,6 @@ set_property(TARGET OpenSSL::applink PROPERTY + INTERFACE_SOURCES "${OPENSSL_APPLINK_SOURCE}") + {- output_on() if $disabled{uplink}; "" -} + ++endif() + unset(_ossl_prefix) + unset(_ossl_use_static_libs) diff --git a/native~/vcpkg/ports/openssl/command-line-length.patch b/native~/vcpkg/ports/openssl/command-line-length.patch new file mode 100644 index 00000000..b0284add --- /dev/null +++ b/native~/vcpkg/ports/openssl/command-line-length.patch @@ -0,0 +1,13 @@ +diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl +index 8ddb128..52b9ad6 100644 +--- a/Configurations/unix-Makefile.tmpl ++++ b/Configurations/unix-Makefile.tmpl +@@ -1961,7 +1961,7 @@ EOF + my @objs = map { platform->obj($_) } @{$args{objs}}; + my $deps = join(" \\\n" . ' ' x (length($lib) + 2), + fill_lines(' ', $COLUMNS - length($lib) - 2, @objs)); +- my $max_per_call = 500; ++ my $max_per_call = 80; + my @objs_grouped; + push @objs_grouped, join(" ", splice @objs, 0, $max_per_call) while @objs; + my $fill_lib = diff --git a/native~/vcpkg/ports/openssl/install-pc-files.cmake b/native~/vcpkg/ports/openssl/install-pc-files.cmake new file mode 100644 index 00000000..04897fae --- /dev/null +++ b/native~/vcpkg/ports/openssl/install-pc-files.cmake @@ -0,0 +1,32 @@ +function(install_pc_file name pc_data) + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release") + configure_file("${CMAKE_CURRENT_LIST_DIR}/openssl.pc.in" "${CURRENT_PACKAGES_DIR}/lib/pkgconfig/${name}.pc" @ONLY) + endif() + if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug") + configure_file("${CMAKE_CURRENT_LIST_DIR}/openssl.pc.in" "${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/${name}.pc" @ONLY) + endif() +endfunction() + +install_pc_file(openssl [[ +Name: OpenSSL +Description: Secure Sockets Layer and cryptography libraries and tools +Requires: libssl libcrypto +]]) + +install_pc_file(libssl [[ +Name: OpenSSL-libssl +Description: Secure Sockets Layer and cryptography libraries +Libs: -L"${libdir}" -llibssl +Requires: libcrypto +Cflags: -I"${includedir}" +]]) + +install_pc_file(libcrypto [[ +Name: OpenSSL-libcrypto +Description: OpenSSL cryptography library +Libs: -L"${libdir}" -llibcrypto +Libs.private: -lcrypt32 -lws2_32 -ladvapi32 -luser32 +Cflags: -I"${includedir}" +]]) + +vcpkg_fixup_pkgconfig() diff --git a/native~/vcpkg/ports/openssl/openssl.pc.in b/native~/vcpkg/ports/openssl/openssl.pc.in new file mode 100644 index 00000000..f7fa9d18 --- /dev/null +++ b/native~/vcpkg/ports/openssl/openssl.pc.in @@ -0,0 +1,6 @@ +prefix=${pcfiledir}/../.. +exec_prefix=${prefix} +libdir=${exec_prefix}/lib +includedir=${prefix}/include +Version: @VERSION@ +@pc_data@ diff --git a/native~/vcpkg/ports/openssl/portfile.cmake b/native~/vcpkg/ports/openssl/portfile.cmake new file mode 100644 index 00000000..5d631bce --- /dev/null +++ b/native~/vcpkg/ports/openssl/portfile.cmake @@ -0,0 +1,93 @@ +if(EXISTS "${CURRENT_INSTALLED_DIR}/share/libressl/copyright" + OR EXISTS "${CURRENT_INSTALLED_DIR}/share/boringssl/copyright") + message(FATAL_ERROR "Can't build openssl if libressl/boringssl is installed. Please remove libressl/boringssl, and try install openssl again if you need it.") +endif() + +if(VCPKG_TARGET_IS_EMSCRIPTEN) + vcpkg_check_linkage(ONLY_STATIC_LIBRARY) +endif() + +vcpkg_from_github( + OUT_SOURCE_PATH SOURCE_PATH + REPO openssl/openssl + REF "openssl-${VERSION}" + SHA512 3e1796708155454c118550ba0964b42c0c1055b651fec00cfb55038e8a8abbf5f85df02449e62b50b99d2a4a2f7b47862067f8a965e9c8a72f71dee0153672d9 + PATCHES + cmake-config.patch + command-line-length.patch + script-prefix.patch + windows/install-layout.patch + windows/install-pdbs.patch + windows/install-programs.diff # https://github.com/openssl/openssl/issues/28744 + unix/android-cc.patch + unix/move-openssldir.patch + unix/no-empty-dirs.patch + unix/no-static-libs-for-shared.patch +) + +vcpkg_list(SET CONFIGURE_OPTIONS + enable-static-engine + enable-capieng + no-tests + no-docs +) + +# https://github.com/openssl/openssl/blob/master/INSTALL.md#enable-ec_nistp_64_gcc_128 +vcpkg_cmake_get_vars(cmake_vars_file) +include("${cmake_vars_file}") +if(VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "^(GNU|Clang|AppleClang)$" + AND VCPKG_TARGET_ARCHITECTURE MATCHES "^(x64|arm64|riscv64|ppc64le)$") + vcpkg_list(APPEND CONFIGURE_OPTIONS enable-ec_nistp_64_gcc_128) +endif() + +set(INSTALL_FIPS "") +if("fips" IN_LIST FEATURES) + vcpkg_list(APPEND INSTALL_FIPS install_fips) + vcpkg_list(APPEND CONFIGURE_OPTIONS enable-fips) +endif() + +if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic") + vcpkg_list(APPEND CONFIGURE_OPTIONS shared) +else() + vcpkg_list(APPEND CONFIGURE_OPTIONS no-shared no-module) +endif() + +if(NOT "tools" IN_LIST FEATURES) + vcpkg_list(APPEND CONFIGURE_OPTIONS no-apps) +endif() + +if("weak-ssl-ciphers" IN_LIST FEATURES) + vcpkg_list(APPEND CONFIGURE_OPTIONS enable-weak-ssl-ciphers) +endif() + +if("ssl3" IN_LIST FEATURES) + vcpkg_list(APPEND CONFIGURE_OPTIONS enable-ssl3) + vcpkg_list(APPEND CONFIGURE_OPTIONS enable-ssl3-method) +endif() + +if(DEFINED OPENSSL_USE_NOPINSHARED) + vcpkg_list(APPEND CONFIGURE_OPTIONS no-pinshared) +endif() + +if(OPENSSL_NO_AUTOLOAD_CONFIG) + vcpkg_list(APPEND CONFIGURE_OPTIONS no-autoload-config) +endif() + +if(VCPKG_TARGET_IS_WINDOWS AND NOT VCPKG_TARGET_IS_MINGW) + include("${CMAKE_CURRENT_LIST_DIR}/windows/portfile.cmake") + include("${CMAKE_CURRENT_LIST_DIR}/install-pc-files.cmake") +else() + include("${CMAKE_CURRENT_LIST_DIR}/unix/portfile.cmake") +endif() + +file(INSTALL "${CMAKE_CURRENT_LIST_DIR}/usage" DESTINATION "${CURRENT_PACKAGES_DIR}/share/${PORT}") + +if (NOT "${VERSION}" MATCHES [[^([0-9]+)\.([0-9]+)\.([0-9]+)$]]) + message(FATAL_ERROR "Version regex did not match.") +endif() +set(OPENSSL_VERSION_MAJOR "${CMAKE_MATCH_1}") +set(OPENSSL_VERSION_MINOR "${CMAKE_MATCH_2}") +set(OPENSSL_VERSION_FIX "${CMAKE_MATCH_3}") +configure_file("${CMAKE_CURRENT_LIST_DIR}/vcpkg-cmake-wrapper.cmake.in" "${CURRENT_PACKAGES_DIR}/share/${PORT}/vcpkg-cmake-wrapper.cmake" @ONLY) + +vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.txt") diff --git a/native~/vcpkg/ports/openssl/script-prefix.patch b/native~/vcpkg/ports/openssl/script-prefix.patch new file mode 100644 index 00000000..fd3316b8 --- /dev/null +++ b/native~/vcpkg/ports/openssl/script-prefix.patch @@ -0,0 +1,22 @@ +diff --git a/tools/c_rehash.in b/tools/c_rehash.in +index 343cdc1..e48038e 100644 +--- a/tools/c_rehash.in ++++ b/tools/c_rehash.in +@@ -12,7 +12,7 @@ + # and add symbolic links to their hash values. + + my $dir = {- quotify1($config{openssldir}) -}; +-my $prefix = {- quotify1($config{prefix}) -}; ++use FindBin; + + my $errorcount = 0; + my $openssl = $ENV{OPENSSL} || "openssl"; +@@ -61,7 +61,7 @@ if (defined(&Cwd::getcwd)) { + + # DOS/Win32 or Unix delimiter? Prefix our installdir, then search. + my $path_delim = ($pwd =~ /^[a-z]\:/i) ? ';' : ':'; +-$ENV{PATH} = "$prefix/bin" . ($ENV{PATH} ? $path_delim . $ENV{PATH} : ""); ++$ENV{PATH} = "$FindBin::Bin" . ($ENV{PATH} ? $path_delim . $ENV{PATH} : ""); + + if (!(-f $openssl && -x $openssl)) { + my $found = 0; diff --git a/native~/vcpkg/ports/openssl/unix/android-cc.patch b/native~/vcpkg/ports/openssl/unix/android-cc.patch new file mode 100644 index 00000000..f4c3d683 --- /dev/null +++ b/native~/vcpkg/ports/openssl/unix/android-cc.patch @@ -0,0 +1,20 @@ +diff --git a/Configurations/15-android.conf b/Configurations/15-android.conf +index 41ad922..d15e34c 100644 +--- a/Configurations/15-android.conf ++++ b/Configurations/15-android.conf +@@ -102,6 +102,7 @@ + my $cflags; + my $cppflags; + ++if (0) { + # see if there is NDK clang on $PATH, "universal" or "standalone" + if (which("clang") =~ m|^$ndk/.*/prebuilt/([^/]+)/|) { + my $host=$1; +@@ -158,6 +159,7 @@ + $sysroot =~ s|^$ndk/||; + $sysroot = " --sysroot=\$($ndk_var)/$sysroot"; + } ++} + $android_ndk = { + cflags => $cflags . $sysroot, + cppflags => $cppflags, diff --git a/native~/vcpkg/ports/openssl/unix/configure b/native~/vcpkg/ports/openssl/unix/configure new file mode 100644 index 00000000..2d49b3d1 --- /dev/null +++ b/native~/vcpkg/ports/openssl/unix/configure @@ -0,0 +1,31 @@ +#!/usr/bin/env bash + +set -e + +declare -a OUT_OPTIONS + +INTERPRETER=perl + +LAST_SEEN= +COPY_OPTIONS=no +for OPTION; do + case "${OPTION},${COPY_OPTIONS}" in + */Configure,no) + OUT_OPTIONS+=("${OPTION}") + INTERPRETER="${LAST_SEEN}" + COPY_OPTIONS=yes + ;; + --prefix=*|--openssldir=*|--libdir=*|--cross-compile-prefix=*|--debug,*) + OUT_OPTIONS+=("${OPTION}") + ;; + -*|*=*) + ;; + *,yes) + OUT_OPTIONS+=("${OPTION}") + ;; + esac + LAST_SEEN="${OPTION}" +done + +set -x +"${INTERPRETER}" ${OUT_OPTIONS[@]} diff --git a/native~/vcpkg/ports/openssl/unix/move-openssldir.patch b/native~/vcpkg/ports/openssl/unix/move-openssldir.patch new file mode 100644 index 00000000..2a39bdbe --- /dev/null +++ b/native~/vcpkg/ports/openssl/unix/move-openssldir.patch @@ -0,0 +1,16 @@ +diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl +index c82c086..6c5402d 100644 +--- a/Configurations/unix-Makefile.tmpl ++++ b/Configurations/unix-Makefile.tmpl +@@ -690,6 +690,11 @@ install_ssldirs: + chmod 644 "$(DESTDIR)$(OPENSSLDIR)/ct_log_list.cnf"; \ + fi + ++ $(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(INSTALLTOP)$(OPENSSLDIR) ++ for I in $(DESTDIR)$(OPENSSLDIR)/*; do \ ++ mv $$I $(DESTDIR)$(INSTALLTOP)$(OPENSSLDIR)/; \ ++ done ++ + install_dev: install_runtime_libs + @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1) + @$(ECHO) "*** Installing development files" diff --git a/native~/vcpkg/ports/openssl/unix/no-empty-dirs.patch b/native~/vcpkg/ports/openssl/unix/no-empty-dirs.patch new file mode 100644 index 00000000..7cf0cf05 --- /dev/null +++ b/native~/vcpkg/ports/openssl/unix/no-empty-dirs.patch @@ -0,0 +1,22 @@ +diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl +index 6c5402d..fc982df 100644 +--- a/Configurations/unix-Makefile.tmpl ++++ b/Configurations/unix-Makefile.tmpl +@@ -823,7 +823,7 @@ _install_modules_deps: install_runtime_libs build_modules + + install_engines: _install_modules_deps + @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1) +- @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(ENGINESDIR)/" ++ @[ -z "$(INSTALL_ENGINES)" ] || $(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(ENGINESDIR)/ + @$(ECHO) "*** Installing engines" + @set -e; for e in dummy $(INSTALL_ENGINES); do \ + if [ "$$e" = "dummy" ]; then continue; fi; \ +@@ -847,7 +847,7 @@ uninstall_engines: + + install_modules: _install_modules_deps + @[ -n "$(INSTALLTOP)" ] || (echo INSTALLTOP should not be empty; exit 1) +- @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(MODULESDIR)/" ++ @[ -z "$(INSTALL_MODULES)" ] || $(PERL) $(SRCDIR)/util/mkdir-p.pl $(DESTDIR)$(MODULESDIR)/ + @$(ECHO) "*** Installing modules" + @set -e; for e in dummy $(INSTALL_MODULES); do \ + if [ "$$e" = "dummy" ]; then continue; fi; \ diff --git a/native~/vcpkg/ports/openssl/unix/no-static-libs-for-shared.patch b/native~/vcpkg/ports/openssl/unix/no-static-libs-for-shared.patch new file mode 100644 index 00000000..d6aa34cf --- /dev/null +++ b/native~/vcpkg/ports/openssl/unix/no-static-libs-for-shared.patch @@ -0,0 +1,12 @@ +diff --git a/Configurations/unix-Makefile.tmpl b/Configurations/unix-Makefile.tmpl +index fc982df..10f1c54 100644 +--- a/Configurations/unix-Makefile.tmpl ++++ b/Configurations/unix-Makefile.tmpl +@@ -713,6 +713,7 @@ install_dev: install_runtime_libs + done + @$(PERL) $(SRCDIR)/util/mkdir-p.pl "$(DESTDIR)$(libdir)" + @set -e; for l in $(INSTALL_LIBS); do \ ++ if [ -n "$(INSTALL_SHLIBS)" ] ; then continue ; fi ; \ + fn=`basename $$l`; \ + $(ECHO) "install $$l -> $(DESTDIR)$(libdir)/$$fn"; \ + cp $$l "$(DESTDIR)$(libdir)/$$fn.new"; \ diff --git a/native~/vcpkg/ports/openssl/unix/portfile.cmake b/native~/vcpkg/ports/openssl/unix/portfile.cmake new file mode 100644 index 00000000..fdde69e7 --- /dev/null +++ b/native~/vcpkg/ports/openssl/unix/portfile.cmake @@ -0,0 +1,168 @@ +if (VCPKG_TARGET_IS_LINUX) + message(NOTICE [[ +openssl requires Linux kernel headers from the system package manager. + They can be installed on Alpine systems via `apk add linux-headers`. + They can be installed on Ubuntu systems via `apt install linux-libc-dev`. +]]) +endif() + +if(VCPKG_HOST_IS_WINDOWS) + vcpkg_acquire_msys(MSYS_ROOT PACKAGES make perl) + set(MAKE "${MSYS_ROOT}/usr/bin/make.exe") + set(PERL "${MSYS_ROOT}/usr/bin/perl.exe") +else() + find_program(MAKE make) + if(NOT MAKE) + message(FATAL_ERROR "Could not find make. Please install it through your package manager.") + endif() + vcpkg_find_acquire_program(PERL) +endif() +set(INTERPRETER "${PERL}") + +execute_process( + COMMAND "${PERL}" -e "use IPC::Cmd;" + RESULT_VARIABLE perl_ipc_cmd_result +) +if(NOT perl_ipc_cmd_result STREQUAL "0") + message(FATAL_ERROR "\nPerl cannot find IPC::Cmd. Please install it through your system package manager.\n") +endif() + +# Ideally, OpenSSL should use `CC` from vcpkg as is (absolute path). +# But in reality, OpenSSL expects to locate the compiler via `PATH`, +# and it makes its own choices e.g. for Android. +vcpkg_cmake_get_vars(cmake_vars_file) +include("${cmake_vars_file}") +cmake_path(GET VCPKG_DETECTED_CMAKE_C_COMPILER PARENT_PATH compiler_path) +cmake_path(GET VCPKG_DETECTED_CMAKE_C_COMPILER FILENAME compiler_name) +find_program(compiler_in_path NAMES "${compiler_name}" PATHS ENV PATH NO_DEFAULT_PATH) +if(NOT compiler_in_path) + vcpkg_host_path_list(APPEND ENV{PATH} "${compiler_path}") +elseif(NOT compiler_in_path STREQUAL VCPKG_DETECTED_CMAKE_C_COMPILER) + vcpkg_host_path_list(PREPEND ENV{PATH} "${compiler_path}") +endif() + +vcpkg_list(SET MAKEFILE_OPTIONS) +if(VCPKG_TARGET_IS_ANDROID) + set(ENV{ANDROID_NDK_ROOT} "${VCPKG_DETECTED_CMAKE_ANDROID_NDK}") + set(OPENSSL_ARCH "android-${VCPKG_DETECTED_CMAKE_ANDROID_ARCH}") + if(VCPKG_DETECTED_CMAKE_ANDROID_ARCH STREQUAL "arm" AND NOT VCPKG_DETECTED_CMAKE_ANDROID_ARM_NEON) + vcpkg_list(APPEND CONFIGURE_OPTIONS no-asm) + endif() +elseif(VCPKG_TARGET_IS_LINUX) + if(VCPKG_TARGET_ARCHITECTURE MATCHES "arm64") + set(OPENSSL_ARCH linux-aarch64) + elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "arm") + set(OPENSSL_ARCH linux-armv4) + elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "x64") + set(OPENSSL_ARCH linux-x86_64) + elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "x86") + set(OPENSSL_ARCH linux-x86) + else() + set(OPENSSL_ARCH linux-generic32) + endif() +elseif(VCPKG_TARGET_IS_IOS) + if(VCPKG_TARGET_ARCHITECTURE MATCHES "arm64") + set(OPENSSL_ARCH ios64-xcrun) + elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "arm") + set(OPENSSL_ARCH ios-xcrun) + elseif(VCPKG_TARGET_ARCHITECTURE MATCHES "x86" OR VCPKG_TARGET_ARCHITECTURE MATCHES "x64") + set(OPENSSL_ARCH iossimulator-xcrun) + else() + message(FATAL_ERROR "Unknown iOS target architecture: ${VCPKG_TARGET_ARCHITECTURE}") + endif() + # disable that makes linkage error (e.g. require stderr usage) + list(APPEND CONFIGURE_OPTIONS no-ui no-asm) +elseif(VCPKG_TARGET_IS_OSX) + if(VCPKG_TARGET_ARCHITECTURE MATCHES "arm64") + set(OPENSSL_ARCH darwin64-arm64) + else() + set(OPENSSL_ARCH darwin64-x86_64) + endif() +elseif(VCPKG_TARGET_IS_BSD) + set(OPENSSL_ARCH BSD-nodef-generic64) +elseif(VCPKG_TARGET_IS_SOLARIS) + if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(OPENSSL_ARCH solaris64-x86_64-gcc) + else() + set(OPENSSL_ARCH solaris-x86-gcc) + endif() +elseif(VCPKG_TARGET_IS_MINGW) + if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(OPENSSL_ARCH mingw64) + elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") + set(OPENSSL_ARCH mingwarm64) + else() + set(OPENSSL_ARCH mingw) + endif() +elseif(VCPKG_TARGET_IS_EMSCRIPTEN) + set(OPENSSL_ARCH linux-x32) + vcpkg_list(APPEND CONFIGURE_OPTIONS + no-engine + no-asm + no-sse2 + no-srtp + --cross-compile-prefix= + ) + # Cf. https://emscripten.org/docs/porting/pthreads.html: + # For Pthreads support, not just openssl but everything + # must be compiled and linked with `-pthread`. + # This makes it a triplet/toolchain-wide setting. + if(NOT " ${VCPKG_DETECTED_CMAKE_C_FLAGS} " MATCHES " -pthread ") + vcpkg_list(APPEND CONFIGURE_OPTIONS no-threads) + endif() +else() + message(FATAL_ERROR "Unknown platform") +endif() + +file(MAKE_DIRECTORY "${SOURCE_PATH}/vcpkg") +file(COPY "${CMAKE_CURRENT_LIST_DIR}/configure" DESTINATION "${SOURCE_PATH}/vcpkg") +vcpkg_configure_make( + SOURCE_PATH "${SOURCE_PATH}" + PROJECT_SUBPATH "vcpkg" + NO_ADDITIONAL_PATHS + OPTIONS + "${INTERPRETER}" + "${SOURCE_PATH}/Configure" + ${OPENSSL_ARCH} + ${CONFIGURE_OPTIONS} + "--openssldir=/etc/ssl" + "--libdir=lib" + OPTIONS_DEBUG + --debug +) +vcpkg_install_make( + ${MAKEFILE_OPTIONS} + BUILD_TARGET build_inst_sw +) +vcpkg_fixup_pkgconfig() + +if("tools" IN_LIST FEATURES) + file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/${PORT}") + file(RENAME "${CURRENT_PACKAGES_DIR}/bin/c_rehash" "${CURRENT_PACKAGES_DIR}/tools/${PORT}/c_rehash") + file(REMOVE "${CURRENT_PACKAGES_DIR}/debug/bin/c_rehash") + vcpkg_copy_tools(TOOL_NAMES openssl AUTO_CLEAN) +elseif(VCPKG_LIBRARY_LINKAGE STREQUAL "static" OR NOT VCPKG_TARGET_IS_WINDOWS) + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/etc/ssl/misc") +endif() + +file(TOUCH "${CURRENT_PACKAGES_DIR}/etc/ssl/certs/.keep") +file(TOUCH "${CURRENT_PACKAGES_DIR}/etc/ssl/private/.keep") + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/debug/etc" + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" +) + +# For consistency of mingw build with nmake build +file(GLOB engines "${CURRENT_PACKAGES_DIR}/lib/ossl-modules/*.dll") +if(NOT engines STREQUAL "") + file(COPY ${engines} DESTINATION "${CURRENT_PACKAGES_DIR}/bin") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/lib/ossl-modules") +endif() +file(GLOB engines "${CURRENT_PACKAGES_DIR}/debug/lib/ossl-modules/*.dll") +if(NOT engines STREQUAL "") + file(COPY ${engines} DESTINATION "${CURRENT_PACKAGES_DIR}/debug/bin") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/lib/ossl-modules") +endif() diff --git a/native~/vcpkg/ports/openssl/unix/remove-deps.cmake b/native~/vcpkg/ports/openssl/unix/remove-deps.cmake new file mode 100644 index 00000000..a57c70fe --- /dev/null +++ b/native~/vcpkg/ports/openssl/unix/remove-deps.cmake @@ -0,0 +1,7 @@ +file(GLOB_RECURSE MAKEFILES ${DIR}/*/Makefile) +foreach(MAKEFILE ${MAKEFILES}) + message("removing deps from ${MAKEFILE}") + file(READ "${MAKEFILE}" _contents) + string(REGEX REPLACE "\n# DO NOT DELETE THIS LINE.*" "" _contents "${_contents}") + file(WRITE "${MAKEFILE}" "${_contents}") +endforeach() diff --git a/native~/vcpkg/ports/openssl/usage b/native~/vcpkg/ports/openssl/usage new file mode 100644 index 00000000..14e12e95 --- /dev/null +++ b/native~/vcpkg/ports/openssl/usage @@ -0,0 +1,5 @@ +openssl is compatible with built-in CMake targets: + + find_package(OpenSSL REQUIRED) + target_link_libraries(main PRIVATE OpenSSL::SSL) + target_link_libraries(main PRIVATE OpenSSL::Crypto) diff --git a/native~/vcpkg/ports/openssl/vcpkg-cmake-wrapper.cmake.in b/native~/vcpkg/ports/openssl/vcpkg-cmake-wrapper.cmake.in new file mode 100644 index 00000000..5008112c --- /dev/null +++ b/native~/vcpkg/ports/openssl/vcpkg-cmake-wrapper.cmake.in @@ -0,0 +1,82 @@ +cmake_policy(PUSH) +cmake_policy(SET CMP0012 NEW) +cmake_policy(SET CMP0054 NEW) +cmake_policy(SET CMP0057 NEW) + +set(OPENSSL_VERSION_MAJOR @OPENSSL_VERSION_MAJOR@) +set(OPENSSL_VERSION_MINOR @OPENSSL_VERSION_MINOR@) +set(OPENSSL_VERSION_FIX @OPENSSL_VERSION_FIX@) + +if(OPENSSL_USE_STATIC_LIBS) + if("@VCPKG_LIBRARY_LINKAGE@" STREQUAL "dynamic") + message(WARNING "OPENSSL_USE_STATIC_LIBS is set, but vcpkg port openssl was built with dynamic linkage") + endif() + set(OPENSSL_USE_STATIC_LIBS_BAK "${OPENSSL_USE_STATIC_LIBS}") + set(OPENSSL_USE_STATIC_LIBS FALSE) +endif() + +if(DEFINED OPENSSL_ROOT_DIR) + set(OPENSSL_ROOT_DIR_BAK "${OPENSSL_ROOT_DIR}") +endif() +get_filename_component(OPENSSL_ROOT_DIR "${CMAKE_CURRENT_LIST_DIR}" DIRECTORY) +get_filename_component(OPENSSL_ROOT_DIR "${OPENSSL_ROOT_DIR}" DIRECTORY) +find_path(OPENSSL_INCLUDE_DIR NAMES openssl/ssl.h PATH "${OPENSSL_ROOT_DIR}/include" NO_DEFAULT_PATH) +if(MSVC) + find_library(LIB_EAY_DEBUG NAMES libcrypto PATHS "${OPENSSL_ROOT_DIR}/debug/lib" NO_DEFAULT_PATH) + find_library(LIB_EAY_RELEASE NAMES libcrypto PATHS "${OPENSSL_ROOT_DIR}/lib" NO_DEFAULT_PATH) + find_library(SSL_EAY_DEBUG NAMES libssl PATHS "${OPENSSL_ROOT_DIR}/debug/lib" NO_DEFAULT_PATH) + find_library(SSL_EAY_RELEASE NAMES libssl PATHS "${OPENSSL_ROOT_DIR}/lib" NO_DEFAULT_PATH) +elseif(WIN32) + find_library(LIB_EAY NAMES libcrypto crypto NAMES_PER_DIR) + find_library(SSL_EAY NAMES libssl ssl NAMES_PER_DIR) +else() + find_library(OPENSSL_CRYPTO_LIBRARY NAMES crypto) + find_library(OPENSSL_SSL_LIBRARY NAMES ssl) +endif() + +_find_package(${ARGS}) + +unset(OPENSSL_ROOT_DIR) +if(DEFINED OPENSSL_ROOT_DIR_BAK) + set(OPENSSL_ROOT_DIR "${OPENSSL_ROOT_DIR_BAK}") + unset(OPENSSL_ROOT_DIR_BAK) +endif() + +if(DEFINED OPENSSL_USE_STATIC_LIBS_BAK) + set(OPENSSL_USE_STATIC_LIBS "${OPENSSL_USE_STATIC_LIBS_BAK}") + unset(OPENSSL_USE_STATIC_LIBS_BAK) +endif() + +if(OPENSSL_FOUND AND "@VCPKG_LIBRARY_LINKAGE@" STREQUAL "static") + if(WIN32) + list(APPEND OPENSSL_LIBRARIES crypt32 ws2_32) + if(TARGET OpenSSL::Crypto) + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY INTERFACE_LINK_LIBRARIES "crypt32;ws2_32") + endif() + if(TARGET OpenSSL::SSL) + set_property(TARGET OpenSSL::SSL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "crypt32;ws2_32") + endif() + else() + find_library(OPENSSL_DL_LIBRARY NAMES dl) + if(OPENSSL_DL_LIBRARY) + list(APPEND OPENSSL_LIBRARIES "dl") + if(TARGET OpenSSL::Crypto) + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY INTERFACE_LINK_LIBRARIES "dl") + endif() + endif() + + if("REQUIRED" IN_LIST ARGS) + find_package(Threads REQUIRED) + else() + find_package(Threads) + endif() + list(APPEND OPENSSL_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + if(TARGET OpenSSL::Crypto) + set_property(TARGET OpenSSL::Crypto APPEND PROPERTY INTERFACE_LINK_LIBRARIES "Threads::Threads") + endif() + if(TARGET OpenSSL::SSL) + set_property(TARGET OpenSSL::SSL APPEND PROPERTY INTERFACE_LINK_LIBRARIES "Threads::Threads") + endif() + endif() +endif() +cmake_policy(POP) diff --git a/native~/vcpkg/ports/openssl/vcpkg.json b/native~/vcpkg/ports/openssl/vcpkg.json new file mode 100644 index 00000000..a777f3ec --- /dev/null +++ b/native~/vcpkg/ports/openssl/vcpkg.json @@ -0,0 +1,37 @@ +{ + "name": "openssl", + "version": "3.6.0", + "description": "OpenSSL is an open source project that provides a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library.", + "homepage": "https://www.openssl.org", + "license": "Apache-2.0", + "dependencies": [ + { + "name": "vcpkg-cmake", + "host": true + }, + { + "name": "vcpkg-cmake-config", + "host": true + }, + { + "name": "vcpkg-cmake-get-vars", + "host": true + } + ], + "features": { + "fips": { + "description": "Enable fips", + "supports": "!static" + }, + "ssl3": { + "description": "Enable SSL3" + }, + "tools": { + "description": "Install openssl executable and scripts", + "supports": "!uwp" + }, + "weak-ssl-ciphers": { + "description": "Enable weak-ssl-ciphers" + } + } +} diff --git a/native~/vcpkg/ports/openssl/windows/install-layout.patch b/native~/vcpkg/ports/openssl/windows/install-layout.patch new file mode 100644 index 00000000..be9df768 --- /dev/null +++ b/native~/vcpkg/ports/openssl/windows/install-layout.patch @@ -0,0 +1,13 @@ +diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl +index f71f3bf..116954f 100644 +--- a/Configurations/windows-makefile.tmpl ++++ b/Configurations/windows-makefile.tmpl +@@ -223,7 +223,7 @@ MODULESDIR_dev={- use File::Spec::Functions qw(:DEFAULT splitpath catpath); + splitpath($modulesprefix, 1); + our $modulesdir_dev = $modulesprefix_dev; + our $modulesdir_dir = +- catdir($modulesprefix_dir, "ossl-modules"); ++ catdir($modulesprefix_dir, "../bin"); + our $modulesdir = catpath($modulesdir_dev, $modulesdir_dir); + our $enginesdir_dev = $modulesprefix_dev; + our $enginesdir_dir = diff --git a/native~/vcpkg/ports/openssl/windows/install-pdbs.patch b/native~/vcpkg/ports/openssl/windows/install-pdbs.patch new file mode 100644 index 00000000..55254540 --- /dev/null +++ b/native~/vcpkg/ports/openssl/windows/install-pdbs.patch @@ -0,0 +1,46 @@ +diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl +index 5946c89..f71f3bf 100644 +--- a/Configurations/windows-makefile.tmpl ++++ b/Configurations/windows-makefile.tmpl +@@ -564,8 +564,9 @@ + "$(INSTALLTOP)\include\openssl" + @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(libdir)" + @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_LIBS) "$(libdir)" + @if "$(SHLIBS)"=="" \ ++ @if "$(INSTALL_PDBS)"=="ON" \ + "$(PERL)" "$(SRCDIR)\util\copy.pl" ossl_static.pdb "$(libdir)" + @"$(PERL)" "$(SRCDIR)\util\mkdir-p.pl" "$(CMAKECONFIGDIR)" + @"$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_EXPORTERS_CMAKE) "$(CMAKECONFIGDIR)" + +@@ -569,6 +570,7 @@ install_engines: _install_modules_deps + @if not "$(INSTALL_ENGINES)"=="" \ + "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINES) "$(ENGINESDIR)" + @if not "$(INSTALL_ENGINES)"=="" \ ++ @if "$(INSTALL_PDBS)"=="ON" \ + "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_ENGINEPDBS) "$(ENGINESDIR)" + + uninstall_engines: +@@ -580,6 +582,7 @@ install_modules: _install_modules_deps + @if not "$(INSTALL_MODULES)"=="" \ + "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_MODULES) "$(MODULESDIR)" + @if not "$(INSTALL_MODULES)"=="" \ ++ @if "$(INSTALL_PDBS)"=="ON" \ + "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_MODULEPDBS) "$(MODULESDIR)" + + uninstall_modules: +@@ -593,6 +596,7 @@ install_runtime_libs: build_libs + @if not "$(SHLIBS)"=="" \ + "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBS) "$(INSTALLTOP)\bin" + @if not "$(SHLIBS)"=="" \ ++ @if "$(INSTALL_PDBS)"=="ON" \ + "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_SHLIBPDBS) \ + "$(INSTALLTOP)\bin" + +@@ -605,6 +609,7 @@ install_programs: install_runtime_libs build_programs + "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMS) \ + "$(INSTALLTOP)\bin" + @if not "$(INSTALL_PROGRAMS)"=="" \ ++ @if "$(INSTALL_PDBS)"=="ON" \ + "$(PERL)" "$(SRCDIR)\util\copy.pl" $(INSTALL_PROGRAMPDBS) \ + "$(INSTALLTOP)\bin" + @if not "$(INSTALL_PROGRAMS)"=="" \ diff --git a/native~/vcpkg/ports/openssl/windows/install-programs.diff b/native~/vcpkg/ports/openssl/windows/install-programs.diff new file mode 100644 index 00000000..257ad7d3 --- /dev/null +++ b/native~/vcpkg/ports/openssl/windows/install-programs.diff @@ -0,0 +1,13 @@ +diff --git a/Configurations/windows-makefile.tmpl b/Configurations/windows-makefile.tmpl +index b587212..c031cfb 100644 +--- a/Configurations/windows-makefile.tmpl ++++ b/Configurations/windows-makefile.tmpl +@@ -134,7 +134,7 @@ INSTALL_FIPSMODULE={- + -} + INSTALL_FIPSMODULECONF=providers\fipsmodule.cnf + INSTALL_PROGRAMS={- +- join(" ", map { quotify1(platform->bin($_)) } ++ join(" ", map { platform->bin($_) } + grep { !$unified_info{attributes}->{programs}->{$_}->{noinst} } + @{$unified_info{programs}}) + -} diff --git a/native~/vcpkg/ports/openssl/windows/portfile.cmake b/native~/vcpkg/ports/openssl/windows/portfile.cmake new file mode 100644 index 00000000..d35f3097 --- /dev/null +++ b/native~/vcpkg/ports/openssl/windows/portfile.cmake @@ -0,0 +1,158 @@ +# Need cmd to pass quoted CC from nmake to mkbuildinf.pl, GH-37134 +find_program(CMD_EXECUTABLE cmd HINTS ENV PATH NO_DEFAULT_PATH REQUIRED) +cmake_path(NATIVE_PATH CMD_EXECUTABLE cmd) +set(ENV{COMSPEC} "${cmd}") + +vcpkg_find_acquire_program(PERL) +get_filename_component(PERL_EXE_PATH "${PERL}" DIRECTORY) +vcpkg_add_to_path("${PERL_EXE_PATH}") + +vcpkg_cmake_get_vars(cmake_vars_file) +include("${cmake_vars_file}") + +if(VCPKG_TARGET_ARCHITECTURE STREQUAL "x86") + set(OPENSSL_ARCH VC-WIN32) +elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "x64") + set(OPENSSL_ARCH VC-WIN64A) +elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm") + set(OPENSSL_ARCH VC-WIN32-ARM) +elseif(VCPKG_TARGET_ARCHITECTURE STREQUAL "arm64") + if(VCPKG_TARGET_IS_UWP) + set(OPENSSL_ARCH VC-WIN64-ARM) + elseif(VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "Clang") + set(OPENSSL_ARCH VC-CLANG-WIN64-CLANGASM-ARM) + else() + set(OPENSSL_ARCH VC-WIN64-CLANGASM-ARM) + endif() +else() + message(FATAL_ERROR "Unsupported target architecture: ${VCPKG_TARGET_ARCHITECTURE}") +endif() + +if(VCPKG_TARGET_IS_UWP) + vcpkg_list(APPEND CONFIGURE_OPTIONS + no-unit-test + no-asm + no-uplink + ) + string(APPEND OPENSSL_ARCH "-UWP") +endif() + +if(VCPKG_CONCURRENCY GREATER "1") + vcpkg_list(APPEND CONFIGURE_OPTIONS no-makedepend) +endif() + +cmake_path(NATIVE_PATH CURRENT_PACKAGES_DIR NORMALIZE install_dir_native) + +# Clang always uses /Z7; Patching /Zi /Fd out of openssl requires more work. +set(OPENSSL_BUILD_MAKES_PDBS ON) +if (VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "Clang" OR VCPKG_LIBRARY_LINKAGE STREQUAL "static") + set(OPENSSL_BUILD_MAKES_PDBS OFF) +endif() + +cmake_path(NATIVE_PATH VCPKG_DETECTED_CMAKE_C_COMPILER NORMALIZE cc) +if(OPENSSL_ARCH MATCHES "CLANG") + vcpkg_find_acquire_program(CLANG) + cmake_path(GET CLANG PARENT_PATH clang_path) + vcpkg_add_to_path("${clang_path}") + if(VCPKG_DETECTED_CMAKE_C_COMPILER_ID MATCHES "Clang") + string(APPEND VCPKG_COMBINED_C_FLAGS_DEBUG " --target=aarch64-win32-msvc") + string(APPEND VCPKG_COMBINED_C_FLAGS_RELEASE " --target=aarch64-win32-msvc") + endif() +endif() +if(OPENSSL_ARCH MATCHES "CLANGASM") + vcpkg_list(APPEND CONFIGURE_OPTIONS "ASFLAGS=--target=aarch64-win32-msvc") +else() + vcpkg_find_acquire_program(NASM) + cmake_path(NATIVE_PATH NASM NORMALIZE as) + cmake_path(GET NASM PARENT_PATH nasm_path) + vcpkg_add_to_path("${nasm_path}") # Needed by Configure +endif() + +cmake_path(NATIVE_PATH VCPKG_DETECTED_CMAKE_AR NORMALIZE ar) +cmake_path(NATIVE_PATH VCPKG_DETECTED_CMAKE_LINKER NORMALIZE ld) + +vcpkg_build_nmake( + SOURCE_PATH "${SOURCE_PATH}" + PREFER_JOM + CL_LANGUAGE NONE + PRERUN_SHELL_RELEASE "${PERL}" Configure + ${CONFIGURE_OPTIONS} + ${OPENSSL_ARCH} + "--prefix=${install_dir_native}" + "--openssldir=${install_dir_native}" + "AS=${as}" + "CC=${cc}" + "CFLAGS=${VCPKG_COMBINED_C_FLAGS_RELEASE}" + "AR=${ar}" + "ARFLAGS=${VCPKG_COMBINED_STATIC_LINKER_FLAGS_RELEASE}" + "LD=${ld}" + "LDFLAGS=${VCPKG_COMBINED_SHARED_LINKER_FLAGS_RELEASE}" + PRERUN_SHELL_DEBUG "${PERL}" Configure + ${CONFIGURE_OPTIONS} + ${OPENSSL_ARCH} + --debug + "--prefix=${install_dir_native}\\debug" + "--openssldir=${install_dir_native}\\debug" + "AS=${as}" + "CC=${cc}" + "CFLAGS=${VCPKG_COMBINED_C_FLAGS_DEBUG}" + "AR=${ar}" + "ARFLAGS=${VCPKG_COMBINED_STATIC_LINKER_FLAGS_DEBUG}" + "LD=${ld}" + "LDFLAGS=${VCPKG_COMBINED_SHARED_LINKER_FLAGS_DEBUG}" + PROJECT_NAME "makefile" + TARGET install_dev install_modules ${INSTALL_FIPS} + LOGFILE_ROOT install + OPTIONS + "INSTALL_PDBS=${OPENSSL_BUILD_MAKES_PDBS}" # install-pdbs.patch + OPTIONS_RELEASE + install_runtime install_ssldirs # extra targets +) + +set(scripts "bin/c_rehash.pl" "misc/CA.pl" "misc/tsget.pl") +if("tools" IN_LIST FEATURES) + file(MAKE_DIRECTORY "${CURRENT_PACKAGES_DIR}/tools/${PORT}") + file(RENAME "${CURRENT_PACKAGES_DIR}/openssl.cnf" "${CURRENT_PACKAGES_DIR}/tools/${PORT}/openssl.cnf") + if("fips" IN_LIST FEATURES) + file(RENAME "${CURRENT_PACKAGES_DIR}/fipsmodule.cnf" "${CURRENT_PACKAGES_DIR}/tools/${PORT}/fipsmodule.cnf") + endif() + foreach(script IN LISTS scripts) + file(COPY "${CURRENT_PACKAGES_DIR}/${script}" DESTINATION "${CURRENT_PACKAGES_DIR}/tools/${PORT}") + file(REMOVE "${CURRENT_PACKAGES_DIR}/${script}" "${CURRENT_PACKAGES_DIR}/debug/${script}") + endforeach() + vcpkg_copy_tools(TOOL_NAMES openssl AUTO_CLEAN) +else() + file(REMOVE "${CURRENT_PACKAGES_DIR}/openssl.cnf") + file(REMOVE "${CURRENT_PACKAGES_DIR}/fipsmodule.cnf") + foreach(script IN LISTS scripts) + file(REMOVE "${CURRENT_PACKAGES_DIR}/${script}" "${CURRENT_PACKAGES_DIR}/debug/${script}") + endforeach() + if(VCPKG_LIBRARY_LINKAGE STREQUAL "static") + file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/bin" "${CURRENT_PACKAGES_DIR}/debug/bin") + endif() +endif() + +vcpkg_copy_pdbs() + +file(REMOVE_RECURSE + "${CURRENT_PACKAGES_DIR}/certs" + "${CURRENT_PACKAGES_DIR}/misc" + "${CURRENT_PACKAGES_DIR}/private" + "${CURRENT_PACKAGES_DIR}/lib/engines-3" + "${CURRENT_PACKAGES_DIR}/debug/certs" + "${CURRENT_PACKAGES_DIR}/debug/misc" + "${CURRENT_PACKAGES_DIR}/debug/lib/engines-3" + "${CURRENT_PACKAGES_DIR}/debug/private" + "${CURRENT_PACKAGES_DIR}/debug/include" + "${CURRENT_PACKAGES_DIR}/debug/share" +) +file(REMOVE + "${CURRENT_PACKAGES_DIR}/ct_log_list.cnf" + "${CURRENT_PACKAGES_DIR}/ct_log_list.cnf.dist" + "${CURRENT_PACKAGES_DIR}/openssl.cnf.dist" + "${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf" + "${CURRENT_PACKAGES_DIR}/debug/ct_log_list.cnf.dist" + "${CURRENT_PACKAGES_DIR}/debug/openssl.cnf" + "${CURRENT_PACKAGES_DIR}/debug/openssl.cnf.dist" + "${CURRENT_PACKAGES_DIR}/debug/fipsmodule.cnf" +) diff --git a/native~/vcpkg/triplets/wasm32-emscripten-unity.cmake b/native~/vcpkg/triplets/wasm32-emscripten-unity.cmake new file mode 100644 index 00000000..aca933b0 --- /dev/null +++ b/native~/vcpkg/triplets/wasm32-emscripten-unity.cmake @@ -0,0 +1,30 @@ +set(VCPKG_ENV_PASSTHROUGH_UNTRACKED EMSCRIPTEN_ROOT EMSDK PATH EM_CONFIG) + +if(NOT DEFINED ENV{EMSCRIPTEN_ROOT}) + find_path(EMSCRIPTEN_ROOT "emcc") +else() + set(EMSCRIPTEN_ROOT "$ENV{EMSCRIPTEN_ROOT}") +endif() + +if(NOT EMSCRIPTEN_ROOT) + if(NOT DEFINED ENV{EMSDK}) + message(FATAL_ERROR "The emcc compiler not found in PATH") + endif() + set(EMSCRIPTEN_ROOT "$ENV{EMSDK}/upstream/emscripten") + if(NOT EXISTS "${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake") + set(EMSCRIPTEN_ROOT "$ENV{EMSDK}/emscripten") + endif() +endif() + +if(NOT EXISTS "${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake") + message(FATAL_ERROR "Emscripten.cmake toolchain file not found") +endif() + +set(VCPKG_TARGET_ARCHITECTURE wasm32) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Emscripten) +set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake") + +set(_configureFlags "-pthread -msimd128 -mnontrapping-fptoint -fwasm-exceptions -sSUPPORT_LONGJMP=wasm -DSIZEOF_SIZE_T=4 -DHAS_FUTIME=0") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DCMAKE_C_FLAGS=${_configureFlags} -DCMAKE_CXX_FLAGS=${_configureFlags} -DCMAKE_EXE_LINKER_FLAGS=${_configureFlags}) diff --git a/native~/vcpkg/triplets/wasm64-emscripten-unity.cmake b/native~/vcpkg/triplets/wasm64-emscripten-unity.cmake new file mode 100644 index 00000000..44f61e85 --- /dev/null +++ b/native~/vcpkg/triplets/wasm64-emscripten-unity.cmake @@ -0,0 +1,27 @@ +set(VCPKG_ENV_PASSTHROUGH_UNTRACKED EMSCRIPTEN_ROOT EMSDK PATH EM_CONFIG) + +if(NOT DEFINED ENV{EMSCRIPTEN_ROOT}) + find_path(EMSCRIPTEN_ROOT "emcc") +else() + set(EMSCRIPTEN_ROOT "$ENV{EMSCRIPTEN_ROOT}") +endif() + +if(NOT EMSCRIPTEN_ROOT) + if(NOT DEFINED ENV{EMSDK}) + message(FATAL_ERROR "The emcc compiler not found in PATH") + endif() + set(EMSCRIPTEN_ROOT "$ENV{EMSDK}/upstream/emscripten") +endif() + +if(NOT EXISTS "${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake") + message(FATAL_ERROR "Emscripten.cmake toolchain file not found") +endif() + +set(VCPKG_TARGET_ARCHITECTURE wasm32) +set(VCPKG_CRT_LINKAGE dynamic) +set(VCPKG_LIBRARY_LINKAGE static) +set(VCPKG_CMAKE_SYSTEM_NAME Emscripten) +set(VCPKG_CHAINLOAD_TOOLCHAIN_FILE "${EMSCRIPTEN_ROOT}/cmake/Modules/Platform/Emscripten.cmake") + +set(_configureFlags "-sMEMORY64=1 -pthread -msimd128 -mnontrapping-fptoint -fwasm-exceptions -sSUPPORT_LONGJMP=wasm -DSIZEOF_SIZE_T=8 -DHAS_FUTIME=0") +set(VCPKG_CMAKE_CONFIGURE_OPTIONS -DCMAKE_C_FLAGS=${_configureFlags} -DCMAKE_CXX_FLAGS=${_configureFlags} -DCMAKE_EXE_LINKER_FLAGS=${_configureFlags})