Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/metal-cpp/update-metal-cpp.sh
21038 views
1
#!/bin/bash -e
2
3
# metal-cpp update script for Godot
4
#
5
# metal-cpp source: https://developer.apple.com/metal/cpp/
6
# This version includes Metal 4 APIs (macOS 26 / iOS 26).
7
8
VERSION="macOS26-iOS26"
9
10
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
11
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
12
13
# If a zip is provided as argument, extract it
14
if [ -n "$1" ]; then
15
echo "Updating metal-cpp from: $1"
16
17
rm -rf \
18
"$SCRIPT_DIR/Foundation" \
19
"$SCRIPT_DIR/Metal" \
20
"$SCRIPT_DIR/MetalFX" \
21
"$SCRIPT_DIR/QuartzCore" \
22
"$SCRIPT_DIR/SingleHeader"
23
24
unzip -q "$1" -d "$SCRIPT_DIR"
25
26
echo "Extracted metal-cpp $VERSION"
27
else
28
echo "Applying patches only..."
29
fi
30
31
# =============================================================================
32
# Apply Godot-specific patches
33
# =============================================================================
34
35
echo "Applying Godot compatibility patches..."
36
37
# Apply patch files (idempotent)
38
PATCH_DIR="$SCRIPT_DIR/patches"
39
if [ -d "$PATCH_DIR" ]; then
40
for PATCH in "$PATCH_DIR"/*.patch; do
41
if [ ! -e "$PATCH" ]; then
42
echo " No patches found in $PATCH_DIR"
43
break
44
fi
45
46
PATCH_NAME="$(basename "$PATCH")"
47
if git -C "$REPO_ROOT" apply --check "$PATCH" > /dev/null 2>&1; then
48
git -C "$REPO_ROOT" apply "$PATCH"
49
echo " $PATCH_NAME: applied"
50
elif git -C "$REPO_ROOT" apply --reverse --check "$PATCH" > /dev/null 2>&1; then
51
echo " $PATCH_NAME: already applied"
52
else
53
echo " $PATCH_NAME: failed to apply"
54
exit 1
55
fi
56
done
57
else
58
echo " Warning: $PATCH_DIR not found"
59
fi
60
61
# Patch 1: Add forward declarations to NSDefines.hpp to avoid conflicts with
62
# Godot's global types (String, Object, Error).
63
#
64
# Without this patch, metal-cpp's "class String*" forward declarations conflict
65
# with Godot's ::String, ::Object, and ::Error types.
66
67
NSDEFINES="$SCRIPT_DIR/Foundation/NSDefines.hpp"
68
69
if [ -f "$NSDEFINES" ]; then
70
# Check if patch already applied
71
if grep -q "Forward declarations to avoid conflicts with Godot" "$NSDEFINES"; then
72
echo " NSDefines.hpp: already patched"
73
else
74
# Find the line with #pragma once and insert after the next separator
75
sed -i '' '/^#pragma once$/,/^\/\/---/{
76
/^\/\/---/ {
77
a\
78
\
79
// Forward declarations to avoid conflicts with Godot types (String, Object, Error)\
80
namespace NS {\
81
class Array;\
82
class Dictionary;\
83
class Error;\
84
class Object;\
85
class String;\
86
class URL;\
87
} // namespace NS
88
}
89
}' "$NSDEFINES"
90
echo " NSDefines.hpp: patched"
91
fi
92
else
93
echo " Warning: $NSDEFINES not found"
94
fi
95
96
echo "Done."
97
98