diff --git a/.github/workflows/build-package.yaml b/.github/workflows/build-package.yaml index f7a78a91..57935071 100644 --- a/.github/workflows/build-package.yaml +++ b/.github/workflows/build-package.yaml @@ -175,6 +175,11 @@ jobs: if: runner.os == 'Windows' uses: ilammy/msvc-dev-cmd@v1.13.0 + - name: Setup Emscripten + uses: mymindstorm/setup-emsdk@v14 + with: + version: 4.0.10 + - name: Setup NDK env: ANDROID_NDK_VERSION: 25.1.8937393 diff --git a/Scripts/builders/vcpkgbuilder.py b/Scripts/builders/vcpkgbuilder.py index b3a6063f..60129b89 100644 --- a/Scripts/builders/vcpkgbuilder.py +++ b/Scripts/builders/vcpkgbuilder.py @@ -69,6 +69,10 @@ def tripletForPlatform(platformName: str, static: bool): 'ios': { True: 'arm64-ios', False: 'arm64-ios-dynamic', + }, + 'wasm32': { + True: 'wasm32-emscripten', + False: 'wasm32-emscripten', } } try: diff --git a/Scripts/extras/pull_and_build_from_git.py b/Scripts/extras/pull_and_build_from_git.py index ec5df7bb..5d447677 100644 --- a/Scripts/extras/pull_and_build_from_git.py +++ b/Scripts/extras/pull_and_build_from_git.py @@ -100,6 +100,7 @@ for situations where the generator does not support multiple configs) the key can contain the suffix of the configuration name (cmake_generate_args_debug, cmake_generate_args_release). For common args that should apply to every config, see cmake_generate_args_common above. + Note : If your Target Platform is Emscripten, the generate call is wrapped by emcmake utility * cmake_build_args : Additional build args to pass to cmake during the cmake build command @@ -191,6 +192,9 @@ """ +# The platform used to target WebAssembly +EMSCRIPTEN_PLATFORM = 'Emscripten' + # The current path of this script, expected to be under '3rdPartySource/Scripts' CURRENT_PATH = pathlib.Path(os.path.dirname(__file__)).resolve() @@ -746,7 +750,12 @@ def build_and_install_cmake(self): if self.package_info.cmake_src_subfolder: cmakelists_folder = cmakelists_folder / self.package_info.cmake_src_subfolder - cmake_generate_cmd = [self.cmake_command, + # emcmake self configure the proper environment when targeting WebAssembly + cmake_command = self.cmake_command + if self.package_info.platform_name == EMSCRIPTEN_PLATFORM: + cmake_command = 'emcmake ' + self.cmake_command + + cmake_generate_cmd = [cmake_command, '-S', str(cmakelists_folder.resolve()), '-B', str(self.build_folder.name)] diff --git a/package-system/Lua/build_config.json b/package-system/Lua/build_config.json index 41ad06e2..f97fd8f6 100644 --- a/package-system/Lua/build_config.json +++ b/package-system/Lua/build_config.json @@ -13,6 +13,9 @@ "CMakeLists.txt", "LICENSE.txt" ], + "cmake_generate_args_common": [ + "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" + ], "cmake_build_args_common": [ "--parallel" ], @@ -36,6 +39,14 @@ "-DCMAKE_C_FLAGS=\"-fPIC -O2 -Wall -Wextra\"", "-DCMAKE_BUILD_TYPE=Release" ] + }, + "Emscripten":{ + "cmake_generate_args": [ + "-G", + "Ninja", + "-DCMAKE_C_FLAGS=\"-fPIC -O2 -Wall -Wextra\"", + "-DCMAKE_BUILD_TYPE=Release" + ] } }, "Darwin":{ @@ -69,7 +80,7 @@ "-DCMAKE_BUILD_TYPE=Release" ] }, - "Linux-aarch64": "@Linux" + "Linux-aarch64": "@Linux" } } } diff --git a/package-system/OpenSSL/build_package_image.py b/package-system/OpenSSL/build_package_image.py index ba78b67c..7ba946d4 100644 --- a/package-system/OpenSSL/build_package_image.py +++ b/package-system/OpenSSL/build_package_image.py @@ -24,7 +24,7 @@ def main(): parser.add_argument( '--platform-name', dest='platformName', - choices=['windows', 'android', 'mac', 'ios'], + choices=['windows', 'android', 'mac', 'ios', 'wasm32'], default=VcpkgBuilder.defaultPackagePlatformName(), ) args = parser.parse_args() @@ -45,20 +45,23 @@ def main(): 'mac': True, 'ios': True, 'windows': True, + 'wasm32': True, } revisionForPlatform = { 'android': 'rev2', 'mac': 'rev1', 'ios': 'rev1', - 'windows': 'rev1' + 'windows': 'rev1', + "wasm32": 'rev1', } testScriptForPlatform = { 'android' : opensslPackageSourceDir / 'test_OpenSSL_android.cmd', 'mac' : opensslPackageSourceDir / 'test_OpenSSL_mac.sh', 'ios' : opensslPackageSourceDir / 'test_OpenSSL_ios.sh', - 'windows' : opensslPackageSourceDir / 'test_OpenSSL_windows.cmd' + 'windows' : opensslPackageSourceDir / 'test_OpenSSL_windows.cmd', + 'wasm32' : opensslPackageSourceDir / 'test_OpenSSL_wasm32.cmd' } with TemporaryDirectory() as tempdir: diff --git a/package-system/OpenSSL/test_OpenSSL_wasm32.cmd b/package-system/OpenSSL/test_OpenSSL_wasm32.cmd new file mode 100644 index 00000000..71eb511a --- /dev/null +++ b/package-system/OpenSSL/test_OpenSSL_wasm32.cmd @@ -0,0 +1,9 @@ +@rem # +@rem # Copyright (c) Contributors to the Open 3D Engine Project. +@rem # For complete copyright and license terms please see the LICENSE at the root of this distribution. +@rem # +@rem # SPDX-License-Identifier: Apache-2.0 OR MIT +@rem # +@rem # + +exit /b 0 diff --git a/package-system/expat/build_config.json b/package-system/expat/build_config.json index ae312bee..f1578f0e 100644 --- a/package-system/expat/build_config.json +++ b/package-system/expat/build_config.json @@ -23,7 +23,8 @@ "-DEXPAT_BUILD_FUZZERS=OFF", "-DEXPAT_BUILD_TESTS=OFF", "-DEXPAT_BUILD_TOOLS=OFF", - "-DEXPAT_SHARED_LIBS=OFF" + "-DEXPAT_SHARED_LIBS=OFF", + "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" ], "cmake_build_args_common": [ "--parallel" @@ -52,6 +53,12 @@ "custom_test_cmd" : [ "test_expat_android.cmd" ] + }, + "Emscripten": { + "cmake_generate_args": [ + "-G", + "Ninja" + ] } }, "Darwin": { diff --git a/package-system/libsamplerate/build_config.json b/package-system/libsamplerate/build_config.json index 59f7668a..f1b514a4 100644 --- a/package-system/libsamplerate/build_config.json +++ b/package-system/libsamplerate/build_config.json @@ -8,6 +8,9 @@ "package_license_file":"COPYING", "cmake_find_template":"Findlibsamplerate.cmake.template", "cmake_find_target":"Findlibsamplerate.cmake", + "cmake_generate_args_common": [ + "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" + ], "Platforms":{ "Windows":{ "Windows":{ @@ -45,6 +48,19 @@ "cmake_build_args":[ "--target samplerate" ] + }, + "Emscripten":{ + "build_configs":[ + "Release" + ], + "cmake_generate_args_release":[ + "-G", + "Ninja", + "-DCMAKE_BUILD_TYPE=Release" + ], + "cmake_build_args":[ + "--target samplerate" + ] } }, "Darwin":{ diff --git a/package-system/lz4/build_config.json b/package-system/lz4/build_config.json index f079951c..5eff73a2 100644 --- a/package-system/lz4/build_config.json +++ b/package-system/lz4/build_config.json @@ -13,7 +13,8 @@ ], "cmake_generate_args_common": [ "-DBUILD_SHARED_LIBS=0", - "-DCMAKE_CXX_STANDARD=17" + "-DCMAKE_CXX_STANDARD=17", + "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" ], "cmake_build_args_common": [ "-j" @@ -36,6 +37,13 @@ "-DCMAKE_TOOLCHAIN_FILE=../../../../Scripts/cmake/Platform/Android/Toolchain_android.cmake", "-DCMAKE_BUILD_TYPE=Release" ] + }, + "Emscripten": { + "cmake_generate_args_release": [ + "-G", + "Ninja", + "-DCMAKE_BUILD_TYPE=Release" + ] } }, "Darwin": { diff --git a/package-system/zlib/.gitattributes b/package-system/zlib/.gitattributes new file mode 100644 index 00000000..771936b6 --- /dev/null +++ b/package-system/zlib/.gitattributes @@ -0,0 +1 @@ +emscripten-alias-fix.patch eol=lf diff --git a/package-system/zlib/build_config.json b/package-system/zlib/build_config.json index 3873d2af..6a4a6a9d 100644 --- a/package-system/zlib/build_config.json +++ b/package-system/zlib/build_config.json @@ -12,6 +12,9 @@ "package_license_file":"LICENSE", "cmake_find_source":"FindZLIB.cmake", "cmake_find_target":"FindZLIB.cmake", + "cmake_generate_args_common": [ + "-DCMAKE_POLICY_VERSION_MINIMUM=3.5" + ], "Platforms":{ "Windows":{ "Windows":{ @@ -29,6 +32,26 @@ "custom_install_cmd": [ "install_zlib_android.cmd" ] + }, + "Emscripten":{ + "patch_file": "emscripten-alias-fix.patch", + "cmake_generate_args" : [ + "-G", + "Ninja", + "-DCMAKE_BUILD_TYPE=Release", + "-DCMAKE_CXX_STANDARD=17", + "-DBUILD_SHARED_LIBS=OFF", + "-DSKIP_INSTALL_ALL=ON" + ], + "cmake_build_args": [ + "--target", + "zlibstatic" + ], + "extra_files_to_copy": [ + ["temp/build/zconf.h", "zlib/include/zconf.h"], + ["temp/build/libz.a", "zlib/lib/libz.a"], + ["temp/src/zlib.h", "zlib/include/zlib.h"] + ] } }, diff --git a/package-system/zlib/emscripten-alias-fix.patch b/package-system/zlib/emscripten-alias-fix.patch new file mode 100644 index 00000000..085d64d6 --- /dev/null +++ b/package-system/zlib/emscripten-alias-fix.patch @@ -0,0 +1,13 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 0fe939d..0cce489 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -201,7 +201,7 @@ endif() + + if(UNIX) + # On unix-like platforms the library is almost always called libz +- set_target_properties(zlib zlibstatic PROPERTIES OUTPUT_NAME z) ++ set_target_properties(zlibstatic PROPERTIES OUTPUT_NAME z) + if(NOT APPLE) + set_target_properties(zlib PROPERTIES LINK_FLAGS "-Wl,--version-script,\"${CMAKE_CURRENT_SOURCE_DIR}/zlib.map\"") + endif() diff --git a/package_build_list_host_windows.json b/package_build_list_host_windows.json index 8415aef1..c67c2b98 100644 --- a/package_build_list_host_windows.json +++ b/package_build_list_host_windows.json @@ -16,6 +16,7 @@ "DirectXShaderCompilerDxc-1.7.2308-o3de-rev2-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/DirectXShaderCompiler --platform-name Windows --package-root ../../package-system --clean", "expat-2.4.2-rev2-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/expat --platform-name Android --package-root ../../package-system/expat/temp --clean", "expat-2.4.2-rev2-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/expat --platform-name Windows --package-root ../../package-system/expat/temp --clean", + "expat-2.4.2-rev2-emscripten": "Scripts/extras/pull_and_build_from_git.py ../../package-system/expat --platform-name Emscripten --package-root ../../package-system/expat/temp --clean", "freetype-2.11.1-rev1-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/freetype --platform-name Android --package-root ../../package-system/freetype/temp --clean", "freetype-2.11.1-rev1-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/freetype --platform-name Windows --package-root ../../package-system/freetype/temp --clean", "googlebenchmark-1.7.0-rev2-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/googlebenchmark --platform-name Android --package-root ../../package-system --clean", @@ -27,6 +28,7 @@ "libsamplerate-0.2.1-rev2-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/libsamplerate --platform-name Windows --package-root ../../package-system --clean", "Lua-5.4.4-rev1-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/Lua --platform-name Android --package-root ../../package-system/Lua/temp --clean", "Lua-5.4.4-rev1-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/Lua --platform-name Windows --package-root ../../package-system/Lua/temp --clean", + "Lua-5.4.4-rev1-emscripten": "Scripts/extras/pull_and_build_from_git.py ../../package-system/Lua --platform-name Emscripten --package-root ../../package-system/Lua/temp --clean", "lz4-1.9.4-rev1-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/lz4 --platform-name Android --package-root ../../package-system/lz4/temp --clean", "lz4-1.9.4-rev1-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/lz4 --platform-name Windows --package-root ../../package-system/lz4/temp --clean", "mcpp-2.7.2_az.2-rev1-windows": "package-system/mcpp/get_and_build_mcpp.py mcpp-2.7.2_az.2-rev1", @@ -62,6 +64,7 @@ "vulkan-validationlayers-1.3.261-rev1-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/vulkan-validationlayers --platform-name Windows --package-root ../../package-system --clean", "vulkan-validationlayers-1.3.261-rev1-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/vulkan-validationlayers --platform-name Android --package-root ../../package-system --clean", "zlib-1.2.11-rev5-android": "Scripts/extras/pull_and_build_from_git.py ../../package-system/zlib --platform-name Android --package-root ../../package-system --clean", + "zlib-1.2.11-rev5-emscripten": "Scripts/extras/pull_and_build_from_git.py ../../package-system/zlib --platform-name Emscripten --package-root ../../package-system --clean", "zlib-1.2.11-rev5-windows": "Scripts/extras/pull_and_build_from_git.py ../../package-system/zlib --platform-name Windows --package-root ../../package-system --clean" }, "build_from_folder": { @@ -81,6 +84,7 @@ "d3dx12-headers-rev1-windows": "package-system/d3dx12-windows", "expat-2.4.2-rev2-android": "package-system/expat/temp/expat-android", "expat-2.4.2-rev2-windows": "package-system/expat/temp/expat-windows", + "expat-2.4.2-rev2-emscripten": "package-system/expat/temp/expat-emscripten", "freetype-2.11.1-rev1-android": "package-system/freetype/temp/freetype-android", "freetype-2.11.1-rev1-windows": "package-system/freetype/temp/freetype-windows", "glad-2.0.0-beta-rev2-multiplatform": "package-system/glad-multiplatform", @@ -96,6 +100,7 @@ "lz4-1.9.4-rev1-windows": "package-system/lz4/temp/lz4-windows", "Lua-5.4.4-rev1-android": "package-system/Lua/temp/Lua-android", "Lua-5.4.4-rev1-windows": "package-system/Lua/temp/Lua-windows", + "Lua-5.4.4-rev1-emscripten": "package-system/Lua/temp/Lua-emscripten", "lux_core-2.2-rev5-multiplatform": "package-system/luxcore-multiplatform", "mcpp-2.7.2_az.2-rev1-windows": "package-system/mcpp-windows", "md5-2.0-multiplatform": "package-system/md5-multiplatform", @@ -135,6 +140,7 @@ "xxhash-0.7.4-rev1-multiplatform": "package-system/xxhash-multiplatform", "zlib-1.2.11-rev5-android": "package-system/zlib-android", "zlib-1.2.11-rev5-windows": "package-system/zlib-windows", + "zlib-1.2.11-rev5-emscripten": "package-system/zlib-emscripten", "zstd-1.35-multiplatform": "package-system/zstd-multiplatform" } }