-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
130 lines (110 loc) · 3.71 KB
/
build.sh
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
#!/bin/bash
get_vulkan_minor_version() {
local full_version=""
local minor_version=""
# Try vulkaninfo first
if command -v vulkaninfo >/dev/null 2>&1; then
full_version=$(vulkaninfo 2>/dev/null | grep "Vulkan Instance Version:" | awk '{print $4}')
if [ -n "$full_version" ]; then
# Extract minor version from format like 1.3.xxx
minor_version=$(echo "$full_version" | cut -d'.' -f2)
echo "$minor_version"
return 0
fi
fi
# Check VULKAN_SDK path
if [ -n "${VULKAN_SDK}" ] && [ -d "${VULKAN_SDK}" ]; then
if [ -f "${VULKAN_SDK}/version.txt" ]; then
full_version=$(cat "${VULKAN_SDK}/version.txt")
minor_version=$(echo "$full_version" | cut -d'.' -f2)
echo "$minor_version"
return 0
fi
fi
echo "0"
return 1
}
VULKAN_MINOR_VERSION=3
# Check if the Vulkan minor version is provided as the first argument
if [ -n "$1" ]; then
VULKAN_MINOR_VERSION=$1
echo "Using provided Vulkan minor version: $VULKAN_MINOR_VERSION"
else
VULKAN_MINOR_VERSION=$(get_vulkan_minor_version)
fi
# Construct the VMA_VULKAN_VERSION
if [ -n "$VULKAN_MINOR_VERSION" ]; then
if [ "$VULKAN_MINOR_VERSION" -ge 4 ]; then
VMA_VULKAN_VERSION=1004000
elif [ "$VULKAN_MINOR_VERSION" -ge 3 ]; then
VMA_VULKAN_VERSION=1003000
elif [ "$VULKAN_MINOR_VERSION" -ge 2 ]; then
VMA_VULKAN_VERSION=1002000
elif [ "$VULKAN_MINOR_VERSION" -ge 1 ]; then
VMA_VULKAN_VERSION=1001000
else
VMA_VULKAN_VERSION=1000000
fi
else
echo "Unable to detect Vulkan version from VULKAN_SDK, defaulting to 1000000"
VMA_VULKAN_VERSION=1000000
fi
# Print out the version for verification
echo "VMA_VULKAN_VERSION: $VMA_VULKAN_VERSION"
# Set the VMA version
VMA_VERSION="v3.2.1"
# Check if git is available
if ! command -v git &> /dev/null; then
echo "Error: Ensure git is installed and added to your PATH."
exit 1
fi
BUILD_DIR="./build"
# Check if the build directory exists, create if not
if [ ! -d "$BUILD_DIR" ]; then
mkdir "$BUILD_DIR"
fi
# Set the VMA Git path
VMA_GIT_PATH="$BUILD_DIR/VulkanMemoryAllocator"
if [ ! -d "$VMA_GIT_PATH" ]; then
# Fetch VulkanMemoryAllocator
echo "Fetching VulkanMemoryAllocator $VMA_VERSION"
git clone https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator.git -b "$VMA_VERSION" "$VMA_GIT_PATH"
fi
# Create the implementation file
echo "#define VMA_VULKAN_VERSION $VMA_VULKAN_VERSION" > "./$BUILD_DIR/vk_mem_alloc.cpp"
echo "#define VMA_STATIC_VULKAN_FUNCTIONS 0" >> "./$BUILD_DIR/vk_mem_alloc.cpp"
echo "#define VMA_DYNAMIC_VULKAN_FUNCTIONS 0" >> "./$BUILD_DIR/vk_mem_alloc.cpp"
echo "#define VMA_IMPLEMENTATION" >> "./$BUILD_DIR/vk_mem_alloc.cpp"
echo "#include \"vk_mem_alloc.h\"" >> "./$BUILD_DIR/vk_mem_alloc.cpp"
# Compiler flags
CXXFLAGS="-O1 -DNDEBUG"
# Determine platform and architecture for library naming
OS_NAME=$(uname -s | tr '[:upper:]' '[:lower:]')
ARCH_NAME=$(uname -m)
if [ "$ARCH_NAME" == "aarch64" ]; then
ARCH_NAME="arm64"
else
ARCH_NAME="x64"
fi
LIB_EXTENSION="a"
# Set the target platform name to match Odin's foreign block pattern
TARGET_PLATFORM="vma_${OS_NAME}_${ARCH_NAME}.${LIB_EXTENSION}"
# Compile the VMA library
echo "Compiling VulkanMemoryAllocator..."
g++ -c \
-I "$VMA_GIT_PATH/include" \
-I "$VULKAN_SDK/include" \
$CXXFLAGS "$BUILD_DIR/vk_mem_alloc.cpp" \
-o "$BUILD_DIR/vk_mem_alloc.o"
if [ $? -ne 0 ]; then
echo "Compilation failed."
exit 1
fi
# Create a static library
echo "Creating static library..."
ar rcs "$TARGET_PLATFORM" "$BUILD_DIR/vk_mem_alloc.o"
if [ $? -ne 0 ]; then
echo "Library creation failed."
exit 1
fi
echo "Done. Library created as $TARGET_PLATFORM"