Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PhysX Emscripten WebAssembly build target #238

Open
wants to merge 2 commits into
base: 4.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions externals/cmakemodules/GetCompilerAndPlatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ FUNCTION (GetPlatformBinName PLATFORM_BIN_NAME LIBPATH_SUFFIX)
ENDIF()
ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "android")
SET(RETVAL "android.${ANDROID_ABI}.fp-soft")
ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "emscripten")
SET(RETVAL "emscripten")
ELSEIF(TARGET_BUILD_PLATFORM STREQUAL "linux")
IF (${CMAKE_LIBRARY_ARCHITECTURE} STREQUAL "x86_64-unknown-linux-gnu" OR ${CMAKE_LIBRARY_ARCHITECTURE} STREQUAL "x86_64-linux-gnu")
SET(RETVAL "linux.clang")
Expand Down
15 changes: 12 additions & 3 deletions physx/buildtools/cmake_generate_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def cmakeExt():


def filterPreset(presetName):
winPresetFilter = ['win','uwp','ps4','switch','xboxone','android','crosscompile']
winPresetFilter = ['win','uwp','ps4','switch','xboxone','android','crosscompile', 'emscripten']
if sys.platform == 'win32':
if any(presetName.find(elem) != -1 for elem in winPresetFilter):
return True
Expand Down Expand Up @@ -120,6 +120,8 @@ def isMultiConfigPlatform(self):
return False
elif self.targetPlatform == 'android':
return False
if self.targetPlatform == 'emscripten':
return False
return True

def getCMakeSwitches(self):
Expand Down Expand Up @@ -292,6 +294,11 @@ def getPlatformCMakeParams(self):
os.environ['PM_CMakeModules_PATH'] + '/ios/ios.toolchain.cmake\"'
outString = outString + ' -DPX_OUTPUT_ARCH=arm'
return outString
elif self.targetPlatform == 'emscripten':
outString = outString + ' -DTARGET_BUILD_PLATFORM=emscripten'
outString = outString + ' -DCMAKE_TOOLCHAIN_FILE=\"' + \
os.path.join(os.environ['EMSCRIPTEN'] + '/cmake/Modules/Platform/Emscripten.cmake\"')
return outString
return ''


Expand Down Expand Up @@ -325,6 +332,8 @@ def presetProvided(pName):

if os.environ.get('PM_cmake_PATH') is not None:
cmakeExec = os.environ['PM_cmake_PATH'] + '/bin/cmake' + cmakeExt()
elif pName == "emscripten":
cmakeExec = 'emcmake cmake' + cmakeExt()
else:
cmakeExec = 'cmake' + cmakeExt()
print('Cmake: ' + cmakeExec)
Expand All @@ -346,7 +355,7 @@ def presetProvided(pName):
cleanupCompilerDir(outputDir)

# run the cmake script
#print('Cmake params:' + cmakeParams)
# print('Cmake params:' + cmakeParams)
os.chdir(os.path.join(os.environ['PHYSX_ROOT_DIR'], outputDir))
os.system(cmakeExec + ' \"' +
os.environ['PHYSX_ROOT_DIR'] + '/compiler/' + cmakeMasterDir + '\"' + cmakeParams)
Expand All @@ -359,7 +368,7 @@ def presetProvided(pName):
cleanupCompilerDir(outputDir)

# run the cmake script
#print('Cmake params:' + cmakeParams)
# print('Cmake params:' + cmakeParams)
os.chdir(os.path.join(os.environ['PHYSX_ROOT_DIR'], outputDir))
# print(cmakeExec + ' \"' + os.environ['PHYSX_ROOT_DIR'] + '/compiler/' + cmakeMasterDir + '\"' + cmakeParams + ' -DCMAKE_BUILD_TYPE=' + config)
os.system(cmakeExec + ' \"' + os.environ['PHYSX_ROOT_DIR'] + '/compiler/' +
Expand Down
12 changes: 12 additions & 0 deletions physx/buildtools/presets/public/emscripten.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<preset name="emscripten" comment="Emscripten web build PhysX SDK general settings">
<platform targetPlatform="emscripten" compiler="emscripten" />
<CMakeSwitches>
<cmakeSwitch name="PX_BUILDSNIPPETS" value="False" comment="Generate the snippets" />
<cmakeSwitch name="PX_BUILDSAMPLES" value="False" comment="Generate the samples" />
<cmakeSwitch name="PX_GENERATE_STATIC_LIBRARIES" value="True" comment="Generate static libs" />
</CMakeSwitches>
<CMakeParams>
<cmakeParam name="CMAKE_INSTALL_PREFIX" value="install/emscripten/PhysX" comment="Install path relative to PhysX SDK root" />
</CMakeParams>
</preset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<html>

<head>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
<title>NVIDIA PhysX SDK for Emscripten ReadMe</title>
<link rel="stylesheet" href="stylesheet.css" type="text/css">
</head>

<body>
<h1 style="TEXT-ALIGN: center">NVIDIA<sup>&reg;</sup> PhysX<sup>&reg;</sup> SDK for Emscripten/Web ReadMe</h1>

<blockquote>
<h4>Location of Binaries:</h4>
<ul>
<li>SDK libraries: bin/physx.wasm</li>
</ul>

<h4>Required packages to generate projects:</h4>
<ul>
<li>CMake, minimum version 3.12 (can be acquired: sudo apt-get install cmake or sudo pip install cmake)</li>
<li>Python, minimum version 2.7</li>
<li>emsdk, tested on version 1.38.31</li>
</ul>

<h4>Generating Makefiles:</h4>
<ul>
<li>Makefiles are generated through a script in physx root directory: generate_projects.sh. source emsdk_env.sh before generating or building the project </li>
<li>Script generate_projects.sh expects a preset name as a parameter, if a parameter is not provided it does list the available presets and you can select one.</li>
<li>Supported presets for web platform are: emscripten.</li>
<li>Generated solutions are in folder compiler/emscripten-debug, compiler/emscripten-checked, compiler/emscripten-profile, compiler/emscripten-release.</li>
</ul>

<h4>Building SDK:</h4>
<ul>
<li>Makefiles are in compiler/emscripten-debug etc</li>
<li>Clean solution: make clean</li>
<li>Build solution: make</li>
</ul>

<h4>PhysX GPU Acceleration:</h4>
<ul>
<li>GPU Acceleration is not available on web platforms</li>
</ul>

<h4>PhysX Snippets and Samples:</h4>
<ul>
<li>Snippets and Samples currently do not build in emscripten</li>
</ul>

This build type generates physx.wasm and physx.js files using the emscripten toolchain.

</blockquote>

<p><br>
Copyright (c) 2008-2019 NVIDIA Corporation, 2701 San Thomas Expressway, Santa Clara, CA 95050 U.S.A. All rights reserved. <A href="http://www.nvidia.com">www.nvidia.com</A>
</p>
</body>
</html>
99 changes: 99 additions & 0 deletions physx/source/compiler/cmake/emscripten/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions
## are met:
## * Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimer in the
## documentation and/or other materials provided with the distribution.
## * Neither the name of NVIDIA CORPORATION nor the names of its
## contributors may be used to endorse or promote products derived
## from this software without specific prior written permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
## OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
##
## Copyright (c) 2018-2019 NVIDIA Corporation. All rights reserved.

STRING(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWERCASE)

SET(CLANG_WARNINGS "-ferror-limit=0 -Wall -Wextra -Werror -Wstrict-aliasing=2 -Weverything -Wno-documentation-deprecated-sync -Wno-documentation-unknown-command -Wno-gnu-anonymous-struct -Wno-undef -Wno-unused-function -Wno-nested-anon-types -Wno-float-equal -Wno-padded -Wno-weak-vtables -Wno-cast-align -Wno-conversion -Wno-missing-noreturn -Wno-missing-variable-declarations -Wno-shift-sign-overflow -Wno-covered-switch-default -Wno-exit-time-destructors -Wno-global-constructors -Wno-missing-prototypes -Wno-unreachable-code -Wno-unused-macros -Wno-unused-member-function -Wno-used-but-marked-unused -Wno-weak-template-vtables -Wno-deprecated -Wno-non-virtual-dtor -Wno-invalid-noreturn -Wno-return-type-c-linkage -Wno-reserved-id-macro -Wno-c++98-compat-pedantic -Wno-unused-local-typedef -Wno-old-style-cast -Wno-newline-eof -Wno-unused-private-field -Wno-format-nonliteral -Wno-implicit-fallthrough -Wno-undefined-reinterpret-cast -Wno-disabled-macro-expansion -Wno-zero-as-null-pointer-constant -Wno-shadow -Wno-unknown-warning-option -Wno-atomic-implicit-seq-cst -Wno-extra-semi-stmt -Wno-dollar-in-identifier-extension -Wno-alloca -Wno-anon-enum-enum-conversion -Wno-dtor-name")
SET(CMAKE_STATIC_LIBRARY_PREFIX "")

SET(PHYSX_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-exceptions -ffunction-sections -fdata-sections -fstrict-aliasing ${CLANG_WARNINGS}" CACHE INTERNAL "PhysX CXX")

SET(CMAKE_CXX_FLAGS ${PHYSX_CXX_FLAGS})

SET(PHYSX_EMSCRIPTEN_COMPILE_DEFS "${CUDA_FLAG};${PHYSX_AUTOBUILD}" CACHE INTERNAL "Base PhysX preprocessor definitions")

SET(PHYSX_EMSCRIPTEN_DEBUG_COMPILE_DEFS "NDEBUG;PX_DEBUG=1;PX_CHECKED=1;${NVTX_FLAG};PX_SUPPORT_PVD=1" CACHE INTERNAL "Debug PhysX preprocessor definitions")
SET(PHYSX_EMSCRIPTEN_CHECKED_COMPILE_DEFS "NDEBUG;PX_CHECKED=1;${NVTX_FLAG};PX_SUPPORT_PVD=1" CACHE INTERNAL "Checked PhysX preprocessor definitions")
SET(PHYSX_EMSCRIPTEN_PROFILE_COMPILE_DEFS "NDEBUG;PX_PROFILE=1;${NVTX_FLAG};PX_SUPPORT_PVD=1" CACHE INTERNAL "Profile PhysX preprocessor definitions")
SET(PHYSX_EMSCRIPTEN_RELEASE_COMPILE_DEFS "NDEBUG;PX_SUPPORT_PVD=0" CACHE INTERNAL "Release PhysX preprocessor definitions")

# TODO: Turn on SIMD
ADD_DEFINITIONS(-DPX_SIMD_DISABLED)


# We need to output .bc files instead of .a files for our emscripten build
SET(CMAKE_STATIC_LIBRARY_SUFFIX ".bc")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not required anymore since 2.0.x emscripten

SET(CMAKE_AR "emcc")
SET(CMAKE_CXX_CREATE_STATIC_LIBRARY "<CMAKE_AR> -o <TARGET> <LINK_FLAGS> <OBJECTS>")





INCLUDE(PhysXFoundation.cmake)
INCLUDE(LowLevel.cmake)
INCLUDE(LowLevelAABB.cmake)
INCLUDE(LowLevelDynamics.cmake)
INCLUDE(PhysX.cmake)
INCLUDE(PhysXCharacterKinematic.cmake)
INCLUDE(PhysXCommon.cmake)
INCLUDE(PhysXCooking.cmake)
INCLUDE(PhysXExtensions.cmake)
INCLUDE(PhysXVehicle.cmake)
INCLUDE(SceneQuery.cmake)
INCLUDE(SimulationController.cmake)
INCLUDE(FastXml.cmake)
INCLUDE(PhysXPvdSDK.cmake)
INCLUDE(PhysXTask.cmake)
INCLUDE(emscripten/PhysXWebBindings.cmake)

# Set folder PhysX SDK to all common SDK source projects
SET_PROPERTY(TARGET PhysX PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET PhysXCharacterKinematic PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET PhysXCommon PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET PhysXCooking PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET PhysXExtensions PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET PhysXVehicle PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET LowLevel PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET LowLevelAABB PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET LowLevelDynamics PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET SceneQuery PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET SimulationController PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET FastXml PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET PhysXPvdSDK PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET PhysXTask PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET PhysXFoundation PROPERTY FOLDER "PhysX SDK")
SET_PROPERTY(TARGET PhysXWebBindings PROPERTY FOLDER "PhysX SDK")

SET(PHYSXDISTRO_LIBS PhysXFoundation PhysX PhysXCharacterKinematic PhysXPvdSDK PhysXCommon PhysXCooking PhysXExtensions PhysXVehicle PhysXWebBindings)

INSTALL(
TARGETS ${PHYSXDISTRO_LIBS}
EXPORT PhysXSDK
DESTINATION $<$<CONFIG:debug>:${PX_ROOT_LIB_DIR}/debug>$<$<CONFIG:release>:${PX_ROOT_LIB_DIR}/release>$<$<CONFIG:checked>:${PX_ROOT_LIB_DIR}/checked>$<$<CONFIG:profile>:${PX_ROOT_LIB_DIR}/profile>
)

43 changes: 43 additions & 0 deletions physx/source/compiler/cmake/emscripten/FastXml.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions
## are met:
## * Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimer in the
## documentation and/or other materials provided with the distribution.
## * Neither the name of NVIDIA CORPORATION nor the names of its
## contributors may be used to endorse or promote products derived
## from this software without specific prior written permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
## OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
##
## Copyright (c) 2018-2019 NVIDIA Corporation. All rights reserved.

#
# Build FastXml
#

# Use generator expressions to set config specific preprocessor definitions
SET(FASTXML_COMPILE_DEFS
# Common to all configurations
${PHYSX_EMSCRIPTEN_COMPILE_DEFS};

$<$<CONFIG:debug>:${PHYSX_EMSCRIPTEN_DEBUG_COMPILE_DEFS};>
$<$<CONFIG:checked>:${PHYSX_EMSCRIPTEN_CHECKED_COMPILE_DEFS};>
$<$<CONFIG:profile>:${PHYSX_EMSCRIPTEN_PROFILE_COMPILE_DEFS};>
$<$<CONFIG:release>:${PHYSX_EMSCRIPTEN_RELEASE_COMPILE_DEFS};>
)

SET(FASTXML_LIBTYPE OBJECT)
67 changes: 67 additions & 0 deletions physx/source/compiler/cmake/emscripten/LowLevel.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
##
## Redistribution and use in source and binary forms, with or without
## modification, are permitted provided that the following conditions
## are met:
## * Redistributions of source code must retain the above copyright
## notice, this list of conditions and the following disclaimer.
## * Redistributions in binary form must reproduce the above copyright
## notice, this list of conditions and the following disclaimer in the
## documentation and/or other materials provided with the distribution.
## * Neither the name of NVIDIA CORPORATION nor the names of its
## contributors may be used to endorse or promote products derived
## from this software without specific prior written permission.
##
## THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
## EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
## PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
## CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
## EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
## PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
## PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
## OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
##
## Copyright (c) 2018-2019 NVIDIA Corporation. All rights reserved.

#
# Build LowLevel
#


SET(LOWLEVEL_PLATFORM_INCLUDES
${PHYSX_SOURCE_DIR}/Common/src/linux
${PHYSX_SOURCE_DIR}/LowLevel/software/include/linux
${PHYSX_SOURCE_DIR}/LowLevelDynamics/include/linux
${PHYSX_SOURCE_DIR}/LowLevel/common/include/pipeline/linux
)

SET(LOWLEVEL_COMPILE_DEFS
# Common to all configurations
${PHYSX_EMSCRIPTEN_COMPILE_DEFS};PX_PHYSX_STATIC_LIB
)

IF(PX_GENERATE_GPU_STATIC_LIBRARIES)
SET(LOWLEVEL_GPU_LIBTYPE_DEFS
PX_PHYSX_GPU_STATIC;
)
ENDIF()

SET(LOWLEVEL_COMPILE_DEFS
# Common to all configurations
${PHYSX_EMSCRIPTEN_COMPILE_DEFS};PX_PHYSX_STATIC_LIB;${LOWLEVEL_GPU_LIBTYPE_DEFS}

$<$<CONFIG:debug>:${PHYSX_EMSCRIPTEN_DEBUG_COMPILE_DEFS};>
$<$<CONFIG:checked>:${PHYSX_EMSCRIPTEN_CHECKED_COMPILE_DEFS};>
$<$<CONFIG:profile>:${PHYSX_EMSCRIPTEN_PROFILE_COMPILE_DEFS};>
$<$<CONFIG:release>:${PHYSX_EMSCRIPTEN_RELEASE_COMPILE_DEFS};>
)

SET(LOWLEVEL_PLATFORM_LINK_FLAGS " ")

SET(LOWLEVEL_LIBTYPE OBJECT)

# NOTE: Is this a UE4 specific change?
# enable -fPIC so we can link static libs with the editor
#SET_TARGET_PROPERTIES(LowLevel PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
Loading