Skip to content

Commit b71bf91

Browse files
committed
Boost: Use Headers instead of building when not required
When building USD without Python, OIIO or VDB, Boost libs aren't required. In this scenario, it is preferable to just copy over the headers instead and save some time and complexity. As requested, I have added an ignore list to bring down the size of the headers considerably. Prior to this PR, boost would include ~170M-180M of headers. After this patch, boost only includes about 37M of headers. This could be further reduced in a future PR with better heuristics, but a 80% savings in size felt like a good win. This also has a significant benefit that it allows the core USD build to be supported on platforms that Boost doesn't natively build on yet like iOS and visionOS. It means that the build_usd.py script doesn't need to carry as many patches to Boost itself if someone is just building the core USD library. This is similar to [PR 2914](#2914) but can short circuit the entire bootstrap and b2 process, which may still error on platforms that b2 doesn't understand.
1 parent 0244f25 commit b71bf91

1 file changed

Lines changed: 32 additions & 2 deletions

File tree

build_scripts/build_usd.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,15 +307,15 @@ def CopyFiles(context, src, dest):
307307
.format(file=f, destDir=instDestDir))
308308
shutil.copy(f, instDestDir)
309309

310-
def CopyDirectory(context, srcDir, destDir):
310+
def CopyDirectory(context, srcDir, destDir, **kwargs):
311311
"""Copy directory like shutil.copytree."""
312312
instDestDir = os.path.join(context.instDir, destDir)
313313
if os.path.isdir(instDestDir):
314314
shutil.rmtree(instDestDir)
315315

316316
PrintCommandOutput("Copying {srcDir} to {destDir}\n"
317317
.format(srcDir=srcDir, destDir=instDestDir))
318-
shutil.copytree(srcDir, instDestDir)
318+
shutil.copytree(srcDir, instDestDir, **kwargs)
319319

320320
def AppendCXX11ABIArg(buildFlag, context, buildArgs):
321321
"""Append a build argument that defines _GLIBCXX_USE_CXX11_ABI
@@ -756,8 +756,38 @@ def InstallBoost_Helper(context, force, buildArgs):
756756
"*/libs/wave/test/testwave/testfiles/utf8-test-*"
757757
]
758758

759+
headersOnly = not (context.buildOIIO or context.enableOpenVDB or context.buildPython)
760+
759761
with CurrentWorkingDirectory(DownloadURL(BOOST_URL, context, force,
760762
dontExtract=dontExtract)):
763+
if headersOnly:
764+
# We don't need all the headers, so we elide some for space
765+
accepted = {'assert', 'config', 'core', 'detail', 'function', 'intrusive_ptr', 'iterator', 'lexical_cast',
766+
'mpl', 'exception', 'move', 'container', 'integer', 'range', 'concept', 'noncopyable',
767+
'numeric', 'optional', 'preprocessor', 'smart_ptr', 'variant', 'vmd', 'type', 'utility'}
768+
769+
def _filteredHeaderCopy(src, dst):
770+
"""This utility function only copies over headers that meet our criteria"""
771+
doCopy = False
772+
parent = os.path.dirname(src)
773+
# First we copy over any headers that are in the root of the boost dir, but have no associated subdir
774+
# We assume these are shared across many boost libs
775+
if src.endswith(".hpp") and os.path.basename(parent) == "boost":
776+
lookFor = os.path.join(parent, os.path.splitext(os.path.basename(src))[0])
777+
doCopy = not os.path.exists(lookFor)
778+
# For everything else, we check against the accepted list above to see if they're a dir we want
779+
if not doCopy:
780+
for accept in accepted:
781+
if f"boost/{accept}" in dst:
782+
doCopy = True
783+
break
784+
if doCopy:
785+
return shutil.copy2(src, dst)
786+
787+
headersDir = os.path.abspath("./boost")
788+
CopyDirectory(context, headersDir, "include/boost", copy_function=_filteredHeaderCopy)
789+
return
790+
761791
if Windows():
762792
bootstrap = "bootstrap.bat"
763793
else:

0 commit comments

Comments
 (0)