build_package_image.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #!/usr/bin/env python3
  2. #
  3. # Copyright (c) Contributors to the Open 3D Engine Project.
  4. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  5. #
  6. # SPDX-License-Identifier: Apache-2.0 OR MIT
  7. #
  8. #
  9. from pathlib import Path
  10. from tempfile import TemporaryDirectory
  11. import argparse
  12. import sys
  13. sys.path.append(str(Path(__file__).parent.parent.parent / 'Scripts'))
  14. from builders.vcpkgbuilder import VcpkgBuilder
  15. import builders.monkeypatch_tempdir_cleanup
  16. def main():
  17. parser = argparse.ArgumentParser()
  18. parser.add_argument(
  19. '--platform-name',
  20. dest='platformName',
  21. choices=['windows', 'android', 'mac', 'ios', 'linux'],
  22. default=VcpkgBuilder.defaultPackagePlatformName(),
  23. )
  24. args = parser.parse_args()
  25. packageSystemDir = Path(__file__).resolve().parents[1]
  26. physxPackageSourceDir = packageSystemDir / 'PhysX'
  27. outputDir = packageSystemDir / f'PhysX-{args.platformName}'
  28. cmakeFindFile = physxPackageSourceDir / f'FindPhysX_{args.platformName}.cmake.template'
  29. if not cmakeFindFile.exists():
  30. cmakeFindFile = physxPackageSourceDir / 'FindPhysX.cmake.template'
  31. cmakeFindFileTemplate = cmakeFindFile.open().read()
  32. buildPhysXInProfileConfigPatch = (physxPackageSourceDir / 'Build-physx-profile-config.patch')
  33. extraLibsPerPlatform = {
  34. 'linux': {
  35. 'EXTRA_SHARED_LIBS': '${PATH_TO_SHARED_LIBS}/libPhysXGpu_64.so',
  36. 'EXTRA_STATIC_LIBS_NON_MONOLITHIC': '',
  37. },
  38. 'windows': {
  39. 'EXTRA_SHARED_LIBS': '\n'.join((
  40. '${PATH_TO_SHARED_LIBS}/PhysXDevice64.dll',
  41. '${PATH_TO_SHARED_LIBS}/PhysXGpu_64.dll'
  42. )),
  43. 'EXTRA_STATIC_LIBS_NON_MONOLITHIC': '\n'.join((
  44. '${PATH_TO_STATIC_LIBS}/LowLevel_static_64.lib',
  45. '${PATH_TO_STATIC_LIBS}/LowLevelAABB_static_64.lib',
  46. '${PATH_TO_STATIC_LIBS}/LowLevelDynamics_static_64.lib',
  47. '${PATH_TO_STATIC_LIBS}/PhysXTask_static_64.lib',
  48. '${PATH_TO_STATIC_LIBS}/SceneQuery_static_64.lib',
  49. '${PATH_TO_STATIC_LIBS}/SimulationController_static_64.lib',
  50. )),
  51. },
  52. 'mac': {
  53. 'EXTRA_SHARED_LIBS': '',
  54. 'EXTRA_STATIC_LIBS_NON_MONOLITHIC': '',
  55. },
  56. 'ios': {
  57. 'EXTRA_SHARED_LIBS': '',
  58. 'EXTRA_STATIC_LIBS_NON_MONOLITHIC': '',
  59. },
  60. 'android': {
  61. 'EXTRA_SHARED_LIBS': '',
  62. 'EXTRA_STATIC_LIBS_NON_MONOLITHIC': '',
  63. },
  64. }
  65. with TemporaryDirectory() as tempdir:
  66. tempdir = Path(tempdir)
  67. firstTime = True
  68. # We package PhysX static and dynamic libraries for all supported platforms
  69. for maybeStatic in (True, False):
  70. builder = VcpkgBuilder(
  71. packageName='PhysX',
  72. portName='physx',
  73. vcpkgDir=tempdir,
  74. targetPlatform=args.platformName,
  75. static=maybeStatic
  76. )
  77. if firstTime:
  78. builder.cloneVcpkg('751fc199af8d33eb300af5edbd9e3b77c48f0bca')
  79. builder.patch(buildPhysXInProfileConfigPatch)
  80. builder.bootstrap()
  81. builder.build()
  82. if maybeStatic:
  83. subdir = 'static'
  84. else:
  85. subdir = 'shared'
  86. builder.copyBuildOutputTo(
  87. outputDir,
  88. extraFiles={
  89. next(builder.vcpkgDir.glob(f'buildtrees/physx/src/*/LICENSE.md')): outputDir / builder.packageName / 'LICENSE.md',
  90. next(builder.vcpkgDir.glob(f'buildtrees/physx/src/*/README.md')): outputDir / builder.packageName / 'README.md',
  91. },
  92. subdir=subdir
  93. )
  94. if firstTime:
  95. builder.writePackageInfoFile(
  96. outputDir,
  97. settings={
  98. 'PackageName': f'PhysX-4.1.2.29882248-rev5-{args.platformName}',
  99. 'URL': 'https://github.com/NVIDIAGameWorks/PhysX',
  100. 'License': 'BSD-3-Clause',
  101. 'LicenseFile': 'PhysX/LICENSE.md'
  102. },
  103. )
  104. builder.writeCMakeFindFile(
  105. outputDir,
  106. template=cmakeFindFileTemplate,
  107. templateEnv=extraLibsPerPlatform[args.platformName],
  108. )
  109. firstTime = False
  110. if __name__ == '__main__':
  111. main()