Skip to content

Commit 0bda362

Browse files
dgovilpixar-oss
authored andcommitted
APPLE: Extract TBB Patches
As discussed with @meshula , this PR moves the TBB patches from the main build_usd.py to apple_utils.py so that we can introduce more platform specific patches in the future. This PR will be necessary for adding future PRs for Simulator support or any other apple platforms that might get added here (e.g tvOS or watchOS purely hypothetically) TBB will still be required once GCD lands in OpenUSD for some of the algorithms, so this patch is still necessary. There is no functional behaviour change here. Additionally, as part of this change, GetSDKRoot has been split into GetSDKName and GetSDKRoot, and now verifies that the SDK is installed in the currently active Xcode. Closes #3706 (Internal change: 2393524)
1 parent f3f6bc2 commit 0bda362

2 files changed

Lines changed: 50 additions & 24 deletions

File tree

build_scripts/apple_utils.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,25 @@ def SupportsMacOSUniversalBinaries():
119119
XcodeVersion = GetXcodeVersion()[0]
120120
return XcodeVersion > (11, 0)
121121

122-
def GetSDKRoot(context) -> Optional[str]:
122+
def GetSDKName(context) -> str:
123123
sdk = "macosx"
124124
if context.buildTarget == TARGET_IOS:
125-
sdk = "iphoneos"
125+
sdk = "iPhoneOS"
126126
elif context.buildTarget == TARGET_VISIONOS:
127-
sdk = "xros"
127+
sdk = "xrOS"
128+
return sdk
128129

130+
def GetSDKRoot(context) -> Optional[str]:
131+
sdk = GetSDKName(context).lower()
129132
for arg in (context.cmakeBuildArgs or '').split():
130133
if "CMAKE_OSX_SYSROOT" in arg:
131134
override = arg.split('=')[1].strip('"').strip()
132135
if override:
133136
sdk = override
134-
return GetCommandOutput(["xcrun", "--sdk", sdk, "--show-sdk-path"])
137+
sdkroot = GetCommandOutput(["xcrun", "--sdk", sdk, "--show-sdk-path"])
138+
if not sdkroot:
139+
raise RuntimeError(f"Could not find an sdk path. Make sure you have the {sdk} sdk installed.")
140+
return sdkroot
135141

136142
def SetTarget(context, targetName):
137143
context.targetNative = (targetName == TARGET_NATIVE)
@@ -408,3 +414,30 @@ def ConfigureCMakeExtraArgs(context, args:List[str]) -> List[str]:
408414
args.append(f"-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH")
409415

410416
return args
417+
418+
def GetTBBPatches(context):
419+
if context.buildTarget not in EMBEDDED_PLATFORMS or context.buildTarget == TARGET_IOS:
420+
# TBB already handles these so we don't patch them out
421+
return [], []
422+
423+
sdk_name = GetSDKName(context)
424+
425+
# Standard Target based names
426+
target_config_patches = [("ios", context.buildTarget.lower()),
427+
("iOS", context.buildTarget),
428+
("IPHONEOS", sdk_name.upper())]
429+
430+
clang_config_patches = [("ios",context.buildTarget.lower()),
431+
("iOS", context.buildTarget),
432+
("IPHONEOS",sdk_name.upper())]
433+
434+
if context.buildTarget == TARGET_VISIONOS:
435+
target_config_patches.extend([("iPhone", "XR"),
436+
("?= 8.0", "?= 1.0")])
437+
438+
clang_config_patches.append(("iPhone", "XR"),)
439+
440+
if context.buildTarget == TARGET_VISIONOS:
441+
clang_config_patches.append(("-miphoneos-version-min=", "-target arm64-apple-xros"))
442+
443+
return target_config_patches, clang_config_patches

build_scripts/build_usd.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,31 +1082,24 @@ def InstallTBB_MacOS(context, force, buildArgs):
10821082
("ifeq ($(arch),$(filter $(arch),armv7 armv7s arm64))",
10831083
"ifeq ($(arch),$(filter $(arch),armv7 armv7s {0}))"
10841084
.format(apple_utils.GetTargetArmArch()))])
1085+
target_config_patches, clang_config_patches = \
1086+
apple_utils.GetTBBPatches(context)
1087+
if target_config_patches:
1088+
# Create config from iOS config
1089+
shutil.copy(src="build/ios.macos.inc",
1090+
dst=f"build/{context.buildTarget.lower()}.macos.inc")
10851091

1086-
if context.buildTarget == apple_utils.TARGET_VISIONOS:
1087-
# Create visionOS config from iOS config
1088-
shutil.copy(
1089-
src="build/ios.macos.inc",
1090-
dst="build/visionos.macos.inc")
1091-
1092-
PatchFile("build/visionos.macos.inc",
1093-
[("ios","visionos"),
1094-
("iOS", "visionOS"),
1095-
("iPhone", "XR"),
1096-
("IPHONEOS","XROS"),
1097-
("?= 8.0", "?= 1.0")])
1092+
PatchFile(f"build/{context.buildTarget.lower()}.macos.inc",
1093+
target_config_patches)
10981094

1095+
if clang_config_patches:
10991096
# iOS clang just reuses the macOS one,
11001097
# so it's easier to copy it directly.
11011098
shutil.copy(src="build/macos.clang.inc",
1102-
dst="build/visionos.clang.inc")
1103-
1104-
PatchFile("build/visionos.clang.inc",
1105-
[("ios","visionos"),
1106-
("-miphoneos-version-min=", "-target arm64-apple-xros"),
1107-
("iOS", "visionOS"),
1108-
("iPhone", "XR"),
1109-
("IPHONEOS","XROS")])
1099+
dst=f"build/{context.buildTarget.lower()}.clang.inc")
1100+
1101+
PatchFile(f"build/{context.buildTarget.lower()}.clang.inc",
1102+
clang_config_patches)
11101103

11111104
(primaryArch, secondaryArch) = apple_utils.GetTargetArchPair(context)
11121105

0 commit comments

Comments
 (0)