create_tbds.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #!/usr/bin/env python3
  2. import argparse
  3. import dataclasses
  4. import enum
  5. from pathlib import Path
  6. import json
  7. import subprocess
  8. import sys
  9. import tempfile
  10. SDL_ROOT = Path(__file__).resolve().parents[1]
  11. @dataclasses.dataclass
  12. class TbdInfo:
  13. install_name: str
  14. target_infos: list[dict[str, str]]
  15. class TbdPlatform(enum.StrEnum):
  16. MACOS = "macOS"
  17. IOS = "iOS"
  18. TBDINFOS = {
  19. TbdPlatform.MACOS: TbdInfo(
  20. install_name="@rpath/SDL3.framework/Versions/A/SDL3",
  21. target_infos=[
  22. {
  23. "min_deployment": "10.13",
  24. "target": "arm64-macos",
  25. },
  26. {
  27. "min_deployment": "10.13",
  28. "target": "x86_64-macos",
  29. },
  30. ]
  31. ),
  32. TbdPlatform.IOS: TbdInfo(
  33. install_name="@rpath/SDL3.framework/SDL3",
  34. target_infos=[
  35. {
  36. "min_deployment": "11.0",
  37. "target": "arm64-ios",
  38. },
  39. {
  40. "min_deployment": "11.0",
  41. "target": "arm64-ios-simulator",
  42. },
  43. {
  44. "min_deployment": "11.0",
  45. "target": "x86_64-ios-simulator",
  46. },
  47. {
  48. "min_deployment": "11.0",
  49. "target": "arm64-tvos",
  50. },
  51. {
  52. "min_deployment": "11.0",
  53. "target": "arm64-tvos-simulator",
  54. },
  55. {
  56. "min_deployment": "11.0",
  57. "target": "x86_64-tvos-simulator",
  58. },
  59. {
  60. "min_deployment": "1.3",
  61. "target": "arm64-xros",
  62. },
  63. {
  64. "min_deployment": "1.3",
  65. "target": "arm64-xros-simulator",
  66. },
  67. ]
  68. ),
  69. }
  70. def create_sdl3_tbd(symbols: list[str], tbd_info: TbdInfo):
  71. return {
  72. "main_library": {
  73. "compatibility_versions": [
  74. {
  75. "version": "201"
  76. }
  77. ],
  78. "current_versions": [
  79. {
  80. "version": "201"
  81. }
  82. ],
  83. "exported_symbols": [
  84. {
  85. "text": {
  86. "global": symbols
  87. }
  88. }
  89. ],
  90. "flags": [
  91. {
  92. "attributes": [
  93. "not_app_extension_safe"
  94. ]
  95. }
  96. ],
  97. "install_names": [
  98. {
  99. "name": tbd_info.install_name
  100. }
  101. ],
  102. "target_info": tbd_info.target_infos
  103. },
  104. "tapi_tbd_version": 5
  105. }
  106. def main():
  107. parser = argparse.ArgumentParser(allow_abbrev=False)
  108. parser.add_argument("--output", "-o", type=Path, help="Output path (default is stdout)")
  109. parser.add_argument("--platform", type=TbdPlatform, required=True,
  110. choices=[str(e) for e in TbdPlatform], help="Apple Platform")
  111. args = parser.parse_args()
  112. with tempfile.NamedTemporaryFile() as f_temp:
  113. f_temp.close()
  114. subprocess.check_call([sys.executable,SDL_ROOT / "src/dynapi/gendynapi.py", "--dump", f_temp.name],
  115. stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
  116. with open(f_temp.name) as f_json:
  117. sdl3_json = json.load(f_json)
  118. sdl3_macos_symbols = [f"_{symbol_info['name']}" for symbol_info in sdl3_json]
  119. sdl3_macos_symbols.sort()
  120. tbd = create_sdl3_tbd(symbols=sdl3_macos_symbols, tbd_info=TBDINFOS[args.platform])
  121. with (args.output.open("w", newline="") if args.output else sys.stdout) as f_out:
  122. json.dump(tbd, fp=f_out, indent=2)
  123. f_out.write("\n")
  124. if __name__ == "__main__":
  125. raise SystemExit(main())