Repository navigation
Expand file tree
/
Copy pathSCsub
More file actions
148 lines (122 loc) · 6.54 KB
/
Copy pathSCsub
File metadata and controls
148 lines (122 loc) · 6.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python
import json
import os
import shutil
import tempfile
import urllib.request
import zipfile
from misc.utility.scons_hints import *
Import("env")
Import("env_modules")
def get_platform_lib():
"""Get the library file based on platform and architecture."""
platform = env["platform"]
arch = env["arch"]
base_path = "#modules/rapier_3d/addons/godot-rapier3d/bin"
if platform in ["macos", "osx"]:
suffix = "arm64" if arch == "arm64" else "x86_64"
return f"{base_path}/libgodot_rapier3d.macos.framework/libgodot_rapier3d.macos.{suffix}.a"
elif platform == "ios":
if arch not in ["arm64", "x86_64"]:
raise Exception(f"Unsupported iOS architecture: {arch}")
return f"{base_path}/libgodot_rapier3d.ios.{arch}.framework/libgodot_rapier3d.a"
elif platform == "linuxbsd":
arch_map = {"x86_64": "x86_64-unknown-linux-gnu", "arm64": "aarch64-unknown-linux-gnu", "arm32": "armv7-unknown-linux-gnueabihf"}
if arch not in arch_map:
raise Exception(f"Unsupported Linux architecture: {arch}")
return f"{base_path}/libgodot_rapier3d.linux.{arch_map[arch]}.a"
elif platform == "windows":
arch_map = {"x86_64": "x86_64-pc-windows-msvc", "x86_32": "i686-pc-windows-msvc", "arm64": "aarch64-pc-windows-msvc"}
if arch not in arch_map:
raise Exception(f"Unsupported Windows architecture: {arch}")
return f"{base_path}/libgodot_rapier3d.windows.{arch_map[arch]}.a"
elif platform == "android":
arch_map = {"arm64": "aarch64-linux-android", "arm32": "armv7-linux-androideabi", "x86_64": "x86_64-linux-android", "x86_32": "i686-linux-android"}
if arch not in arch_map:
raise Exception(f"Unsupported Android architecture: {arch}")
return f"{base_path}/libgodot_rapier3d.android.{arch_map[arch]}.a"
elif platform == "web":
if arch != "wasm32":
raise Exception(f"Unsupported Web architecture: {arch}")
if env.get("threads", True):
return f"{base_path}/libgodot_rapier3d.a"
else:
return f"{base_path}/wasm-nothreads/libgodot_rapier3d.a"
raise Exception(f"Unsupported platform: {platform}")
def download_and_extract_release():
target_dir = os.path.join("addons", "godot-rapier3d")
github_token = os.environ.get("GH_TOKEN")
if os.path.isdir(target_dir):
if not github_token:
return
shutil.rmtree(target_dir)
release_url = "https://api.github.com/repos/appsinacup/godot-rapier-physics/releases/latest"
asset_name = "static-rapier-3d-single-simd-parallel.zip"
request = urllib.request.Request(release_url)
if github_token:
request.add_header("Authorization", f"token {github_token}")
with urllib.request.urlopen(request) as response:
release_data = json.loads(response.read().decode())
download_url = next((a["browser_download_url"] for a in release_data.get("assets", []) if a.get("name") == asset_name), None)
if not download_url:
raise RuntimeError(f"Could not find '{asset_name}' in the latest release.")
with tempfile.TemporaryDirectory() as tmp_dir:
archive_path = os.path.join(tmp_dir, asset_name)
urllib.request.urlretrieve(download_url, archive_path)
with zipfile.ZipFile(archive_path, "r") as zip_ref:
zip_ref.extractall(tmp_dir)
extracted_addons_dir = next((os.path.join(root, "addons") for root, dirs, _ in os.walk(tmp_dir) if "addons" in dirs), None)
if not extracted_addons_dir:
raise RuntimeError("Release archive did not contain an 'addons' directory.")
source_addon_dir = os.path.join(extracted_addons_dir, "godot-rapier3d")
if not os.path.isdir(source_addon_dir):
raise RuntimeError("Release archive missing 'addons/godot-rapier3d'.")
shutil.copytree(source_addon_dir, target_dir)
# Rename all library files from libgodot_rapier.* to libgodot_rapier3d.*
bin_dir = os.path.join(target_dir, "bin")
if os.path.isdir(bin_dir):
# First pass: rename files (including those inside framework directories)
for root, dirs, files in os.walk(bin_dir, topdown=False):
for filename in files:
if filename.startswith("libgodot_rapier.") or filename == "libgodot_rapier.a":
old_path = os.path.join(root, filename)
new_filename = filename.replace("libgodot_rapier.", "libgodot_rapier3d.").replace("libgodot_rapier.a", "libgodot_rapier3d.a")
new_path = os.path.join(root, new_filename)
os.rename(old_path, new_path)
# Second pass: rename directories (frameworks)
for root, dirs, files in os.walk(bin_dir, topdown=False):
for dirname in dirs:
if dirname.startswith("libgodot_rapier."):
old_path = os.path.join(root, dirname)
new_dirname = dirname.replace("libgodot_rapier.", "libgodot_rapier3d.")
new_path = os.path.join(root, new_dirname)
os.rename(old_path, new_path)
try:
download_and_extract_release()
except RuntimeError as e:
print(f"Error: {e}")
raise
lib_file = get_platform_lib()
env.Append(LIBS=[env.File(lib_file)])
# Add linker flags to handle duplicate Rust symbols
if env["platform"] == "linuxbsd" or env["platform"] == "android":
env.Append(LINKFLAGS=["-Wl,--allow-multiple-definition"])
print("Added Linux linker flags to allow multiple symbol definitions")
elif env["platform"] == "windows":
if env.get("use_llvm", False):
# LLVM linker (lld-link)
env.Append(LINKFLAGS=["/FORCE:MULTIPLE"])
print("Added Windows LLVM linker flags to allow multiple symbol definitions")
elif env.get("use_mingw", False):
# MinGW linker (GNU ld)
env.Append(LINKFLAGS=["-Wl,--allow-multiple-definition"])
print("Added Windows MinGW linker flags to allow multiple symbol definitions")
else:
# MSVC linker (link.exe)
env.Append(LINKFLAGS=["/FORCE:MULTIPLE", "/ignore:4006", "/ignore:4088", "/WX-"])
print("Added Windows MSVC linker flags to allow multiple symbol definitions")
elif env["platform"] in ["macos", "osx"]:
env.Append(LINKFLAGS=["-Wl,-flat_namespace", "-Wl,-undefined,suppress"])
print("Added macOS linker flags to allow multiple symbol definitions")
env_rapier_3d = env_modules.Clone()
env_rapier_3d.add_source_files(env.modules_sources, "*.cpp")