3 # Copyright (c) 2016-2024 The Brenwill Workshop Ltd.
5 # fetchDependencies - Retrieves the correct versions of all dependencies
7 # macOS usage: ./fetchDependencies [--macos] [--ios] [--iossim] [--maccat] [--tvos] [--tvossim]
8 # [--visionos] [--visionossim] [--all] [--none]
9 # [-v] [--debug] [--build-spirv-tools]
10 # [--v-headers-root path] [--spirv-cross-root path] [--spirv-tools-root path]
13 # Build the external libraries for the macOS platform.
16 # Build the external libraries for the iOS platform.
19 # Build the external libraries for the iOS Simulator platform.
22 # Build the external libraries for the Mac Catalyst platform.
25 # Build the external libraries for the tvOS platform.
28 # Build the external libraries for the tvOS Simulator platform.
31 # Build the external libraries for the visionOS platform.
34 # Build the external libraries for the visionOS Simulator platform.
37 # Equivalent to specifying [--macos --ios --iossim --maccat --tvos --tvossim].
38 # Results in one XCFramework for each external library, each containing
39 # binaries for all supported platforms.
40 # Currently excludes --visionos and --visionossim targets because those
41 # require Xcode 15+ and will abort a multi-platform build.
44 # Don't build the external libraries for any platform (this is the default).
46 # Multiple platform options may be specified. At least one platform option must be specified.
49 # Build the external libraries against Address Sanitizer, which may be useful when debugging
50 # and tracing calls into those libraries.
53 # Build the external libraries against Thread Sanitizer, which may be useful when debugging
54 # and tracing calls into those libraries.
57 # Build the external libraries against Undefined Behavior Sanitizer, which may be useful when debugging
58 # and tracing calls into those libraries.
61 # Build the external libraries in Debug mode, which may be useful when debugging
62 # and tracing calls into those libraries.
65 # Build the external libraries in parallel using background processes.
68 # Build the external libraries serially instead of in parallel. This is the default.
71 # Do not remove the External/build/Intermediates cache directory after building.
72 # Removing the Intermediates directory returns significant disk space after the
73 # build, and is the default behaviour. Use this option if you intend to run this
74 # script repeatedly to incrementally build one platform at a time.
76 # --spirv-tools-root path
77 # "path" specifies a directory path to a KhronosGroup/SPIRV-tools repository.
78 # This repository does need to be built and the build directory must be in the
79 # specified directory. It should be built the same way this script builds it.
82 # Build the full spirv-tools distribution. Normally this is not needed, because
83 # MoltenVK includes a template of pre-generated SPIRV-Tools header files, which
84 # is all that is needed. Avoiding the spirv-tools build saves significant time
85 # during the running of this script, and is necessary during CI because Travis CI
86 # cannot support the required use of Python3 by the spirv-tools build. This flag
87 # is used by the packagePregenSpirvToolsHeaders script which regenerates the
88 # spirv-tools header files and repackages the Templates/spirv-tools/build.zip
89 # file when the spirv-tools library version is upgraded.
91 # --spirv-cross-root path
92 # "path" specifies a directory path to a KhronosGroup/SPIRV-Cross repository.
93 # This repository does not have to be built.
97 # --v-headers-root path
98 # "path" specifies a directory path to a KhronosGroup/Vulkan-Headers repository.
99 # This repository does not have to be built.
104 # ----------------- Functions -------------------
117 XC_BUILD_VERBOSITY
="-quiet"
169 # BLD_VISIONOS="Y" # Requires Xcode 15+
170 # BLD_VISIONOS_SIM="Y" # Requires Xcode 15+
206 XC_BUILD_VERBOSITY
=""
213 --skip-spirv-tools-build) #deprecated
230 echo "Error: Unsupported option $1" >&2
236 # Update a repository. If it exists, fetch it; if not, clone it.
239 # $3 repo revision (commit SHA)
240 function update_repo
() {
242 echo "$1 revision: $3"
244 if [ -d $1 -a -d $1/.git
]; then
246 git cat-file
-e $3 || git fetch
--all
247 git checkout
--force $3
260 function build_repo
() {
265 if type ninja
>/dev
/null
2>&1 ; then
266 cmake
-G Ninja
-D CMAKE_BUILD_TYPE
=Release
-D CMAKE_INSTALL_PREFIX
=install ..
269 cmake
-D CMAKE_BUILD_TYPE
=Release
-D CMAKE_INSTALL_PREFIX
=install ..
270 make -j $
(sysctl
-n hw.activecpu
)
277 # ----------------- Main -------------------
280 EXT_REV_DIR
=..
/ExternalRevisions
283 echo ========== Retrieving MoltenVK dependencies into
${EXT_DIR} ==========
289 # ----------------- Cereal -------------------
292 echo ========== Cereal
==========
296 REPO_URL
="https://github.com/USCiLab/${REPO_NAME}.git"
297 REPO_REV
=$
(cat "${EXT_REV_DIR}/${REPO_NAME}_repo_revision")
299 update_repo
${REPO_NAME} ${REPO_URL} ${REPO_REV}
302 # ----------------- Vulkan-Headers -------------------
305 echo ========== Vulkan-Headers
==========
308 # When MoltenVK is built by something that already has
309 # a copy of this repo, use it by creating a symlink.
311 REPO_NAME
=Vulkan-Headers
313 if [ ! "$V_HEADERS_ROOT" = "" ]; then
315 ln -sfn ${V_HEADERS_ROOT} ${REPO_NAME}
317 REPO_URL
="https://github.com/KhronosGroup/${REPO_NAME}.git"
318 REPO_REV
=$
(cat "${EXT_REV_DIR}/${REPO_NAME}_repo_revision")
320 update_repo
${REPO_NAME} ${REPO_URL} ${REPO_REV}
324 # ----------------- SPIRV-Cross -------------------
327 echo ========== SPIRV-Cross
==========
330 # When MoltenVK is built by something that already has
331 # a copy of this repo, use it by creating a symlink.
333 REPO_NAME
=SPIRV-Cross
335 if [ ! "$SPIRV_CROSS_ROOT" = "" ]; then
337 ln -sfn ${SPIRV_CROSS_ROOT} ${REPO_NAME}
339 REPO_URL
="https://github.com/KhronosGroup/${REPO_NAME}.git"
340 REPO_REV
=$
(cat "${EXT_REV_DIR}/${REPO_NAME}_repo_revision")
342 update_repo
${REPO_NAME} ${REPO_URL} ${REPO_REV}
346 # ----------------- SPIRV-Tools -------------------
349 echo ========== SPIRV-Tools and SPIRV-Headers
==========
352 # When MoltenVK is built by something that already has
353 # a copy of this repo, use it by creating a symlink.
355 REPO_NAME
=SPIRV-Tools
357 if [ ! "$SPIRV_TOOLS_ROOT" = "" ]; then
359 ln -sfn ${SPIRV_TOOLS_ROOT} ${REPO_NAME}
361 REPO_URL
="https://github.com/KhronosGroup/${REPO_NAME}.git"
362 REPO_REV
=$
(cat "${EXT_REV_DIR}/${REPO_NAME}_repo_revision")
364 update_repo
${REPO_NAME} ${REPO_URL} ${REPO_REV}
366 SPIRV_HEADERS_REV
=$
(cat "${EXT_REV_DIR}/SPIRV-Headers_repo_revision")
367 update_repo SPIRV-Tools
/external
/spirv-headers
"https://github.com/KhronosGroup/SPIRV-Headers.git" ${SPIRV_HEADERS_REV}
369 # Build spirv-tools, or use option of pre-generated headers
370 if [ "$BLD_SPV_TLS" = "Y" ]; then
371 build_repo
"${REPO_NAME}"
373 unzip -o -q -d "${REPO_NAME}" ..
/Templates
/spirv-tools
/build.
zip
374 rm -rf "${REPO_NAME}/__MACOSX"
379 # ----------------- Vulkan-Tools -------------------
382 echo ========== Vulkan-Tools
==========
385 REPO_NAME
=Vulkan-Tools
386 REPO_URL
="https://github.com/KhronosGroup/${REPO_NAME}.git"
387 REPO_REV
=$
(cat "${EXT_REV_DIR}/${REPO_NAME}_repo_revision")
389 update_repo
${REPO_NAME} ${REPO_URL} ${REPO_REV}
392 # ----------------- Volk -------------------
395 echo ========== Volk
==========
399 REPO_URL
="https://github.com/zeux/${REPO_NAME}.git"
400 REPO_REV
=$
(cat "${EXT_REV_DIR}/${REPO_NAME}_repo_revision")
402 update_repo
${REPO_NAME} ${REPO_URL} ${REPO_REV}
405 # ----------------- Cleanup -------------------
410 # -------------- Build MoltenVK external library dependencies -----------------
413 echo ========== Started building dependency libraries
at `date +"%r"` ==========
414 echo Please be patient on first build
416 function execute_xcodebuild_command
() {
417 if [ -n "${XCPRETTY}" ]; then
418 set -o pipefail
&& xcodebuild
"$@" |
tee -a "dependenciesbuild.log" |
${XCPRETTY}
424 # Build an Xcode scheme for an OS and platform
427 # 3 - Destination (Optional. Defaults to same as platform)
428 function build_impl
() {
431 if [ "${3}" != "" ]; then
437 XC_SCHEME
="${EXT_DEPS}-${XC_OS}"
438 XC_LCL_DD_PATH
="${XC_DD_PATH}/Intermediates/${XC_PLTFM}"
440 echo Building external libraries
for platform
${XC_PLTFM} and destination
${XC_DEST}
442 execute_xcodebuild_command \
443 -project "${XC_PROJ}" \
444 -scheme "${XC_SCHEME}" \
445 -destination "generic/platform=${XC_DEST}" \
446 -configuration "${XC_CONFIG}" \
447 -enableAddressSanitizer "${XC_USE_ASAN}" \
448 -enableThreadSanitizer "${XC_USE_TSAN}" \
449 -enableUndefinedBehaviorSanitizer "${XC_USE_UBSAN}" \
450 -derivedDataPath "${XC_LCL_DD_PATH}" \
451 ${XC_BUILD_VERBOSITY} \
454 echo Completed building external libraries
for ${XC_PLTFM}
457 # Select whether or not to run the build in parallel.
460 # 3 - Destination (Optional. Defaults to same as platform)
463 if [ "$XC_USE_BCKGND" != "" ]; then
464 build_impl
"${1}" "${2}" "${3}" &
466 build_impl
"${1}" "${2}" "${3}"
470 EXT_DEPS
=ExternalDependencies
471 XC_PROJ
="${EXT_DEPS}.xcodeproj"
472 XC_DD_PATH
="${EXT_DIR}/build"
473 export SKIP_PACKAGING
="Y"
475 # Determine if xcpretty is present
476 XCPRETTY_PATH
=$
(command -v xcpretty
2> /dev
/null || true
) # ignore failures
478 # If xcpretty is present, use it to format xcodebuild output
480 if [ -n "$XCPRETTY_PATH" ]; then
481 XCPRETTY
="xcpretty -c"
483 if [ "$XC_USE_BCKGND" != "" ]; then
484 # For now, avoid using xcpretty if parallel background tasks are being used
488 # Structure build tasks by platform so they can be built in parallel per platform.
489 # Content for each platform must be built in series to avoid
490 if [ "$XC_USE_BCKGND" != "" ]; then
491 trap "exit" INT TERM ERR
495 if [ "$BLD_MACOS" != "" ]; then
496 build
"macOS" "macOS"
499 if [ "$BLD_IOS" != "" ]; then
503 if [ "$BLD_IOS_SIM" != "" ]; then
504 build
"iOS" "iOS Simulator"
507 if [ "$BLD_MAC_CAT" != "" ]; then
508 build
"iOS" "Mac Catalyst" "macOS,variant=Mac Catalyst"
511 if [ "$BLD_TVOS" != "" ]; then
515 if [ "$BLD_TVOS_SIM" != "" ]; then
516 build
"tvOS" "tvOS Simulator"
519 if [ "$BLD_VISIONOS" != "" ]; then
523 if [ "$BLD_VISIONOS_SIM" != "" ]; then
524 build
"xrOS" "xrOS Simulator"
527 # Wait for any background process (if selected) to finish
528 if [ "$XC_USE_BCKGND" != "" ]; then
532 if [ "$BLD_SPECIFIED" != "" ]; then
533 # Build XCFrameworks, update latest symlink, remove intermediates, and clean MoltenVK for rebuild
535 CONFIGURATION
=${XC_CONFIG}
537 .
"./Scripts/create_ext_lib_xcframeworks.sh"
538 .
"./Scripts/package_ext_libs_finish.sh"
540 if [ "$BLD_NONE" != "" ]; then
541 echo Not building any platforms
543 echo "WARNING: You did not specify a platform to build."
544 echo "To build the external libraries, include one or"
545 echo "more of the following platform options:"
546 echo " --macos --ios --iossim --maccat --tvos --tvossim --visionos --visionossim --all"
547 echo "See the instructions in the fetchDependencies script for more info."
551 echo ========== Finished
at `date +"%r"` ==========