Skip to content

Commit 1404293

Browse files
dgovilpixar-oss
authored andcommitted
On Darwin, add "darwin.h" and "darwin.mm" files into the arch target for using darwin code via ObjectiveC++, to use System API for Temporary Directory location instead of looking up an env var. This matches Windows behavior, and
is required for stricter containerized temp directory in macOS 26 for sandbox processes. Closes #3705 (Internal change: 2392207)
1 parent f29bb6c commit 1404293

4 files changed

Lines changed: 54 additions & 6 deletions

File tree

pxr/base/arch/CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ set(PXR_PREFIX pxr/base)
55
set(PXR_PACKAGE arch)
66

77
if(NOT EMSCRIPTEN)
8-
set(PLATFORM_LIBS ${M_LIB})
8+
set(ARCH_PLATFORM_LIBS ${M_LIB})
9+
set(ARCH_PLATFORM_HEADERS "")
10+
set(ARCH_PLATFORM_CPPFILES "")
911
endif()
12+
1013
if(WIN32)
11-
set(PLATFORM_LIBS Ws2_32.lib Dbghelp.lib ${PLATFORM_LIBS})
14+
set(ARCH_PLATFORM_LIBS Ws2_32.lib Dbghelp.lib ${ARCH_PLATFORM_LIBS})
15+
elseif (APPLE)
16+
set(ARCH_PLATFORM_HEADERS darwin.h)
17+
set(ARCH_PLATFORM_CPPFILES darwin.mm)
18+
set(ARCH_PLATFORM_LIBS "-framework Foundation" ${ARCH_PLATFORM_LIBS})
1219
endif()
1320

1421
pxr_library(arch
1522
LIBRARIES
1623
${CMAKE_DL_LIBS}
17-
${PLATFORM_LIBS}
24+
${ARCH_PLATFORM_LIBS}
1825

1926
PUBLIC_CLASSES
2027
align
@@ -53,10 +60,12 @@ pxr_library(arch
5360
PRIVATE_HEADERS
5461
testArchAbi.h
5562
testArchUtil.h
63+
${ARCH_PLATFORM_HEADERS}
5664

5765
CPPFILES
5866
assumptions.cpp
5967
initConfig.cpp
68+
${ARCH_PLATFORM_CPPFILES}
6069

6170
DOXYGEN_FILES
6271
overview.dox

pxr/base/arch/darwin.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// Copyright 2025 Apple
3+
//
4+
// Licensed under the terms set forth in the LICENSE.txt file available at
5+
// https://openusd.org/license.
6+
//
7+
#ifndef PXR_ARCH_DARWIN_H
8+
#define PXR_ARCH_DARWIN_H
9+
#include "pxr/pxr.h"
10+
11+
PXR_NAMESPACE_OPEN_SCOPE
12+
13+
const char* Arch_DarwinGetTemporaryDirectory();
14+
15+
PXR_NAMESPACE_CLOSE_SCOPE
16+
#endif // PXR_ARCH_DARWIN_H

pxr/base/arch/darwin.mm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Copyright 2025 Apple
3+
//
4+
// Licensed under the terms set forth in the LICENSE.txt file available at
5+
// https://openusd.org/license.
6+
//
7+
8+
#include "pxr/base/arch/darwin.h"
9+
#import <Foundation/Foundation.h>
10+
11+
PXR_NAMESPACE_OPEN_SCOPE
12+
13+
14+
const char* Arch_DarwinGetTemporaryDirectory() {
15+
return [NSTemporaryDirectory() UTF8String];
16+
}
17+
18+
PXR_NAMESPACE_CLOSE_SCOPE

pxr/base/arch/fileSystem.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
#include <unistd.h>
4242
#endif
4343

44+
#if defined(ARCH_OS_DARWIN)
45+
#include "pxr/base/arch/darwin.h"
46+
#endif
47+
4448
PXR_NAMESPACE_OPEN_SCOPE
4549

4650
using std::pair;
@@ -727,6 +731,9 @@ Arch_InitTmpDir()
727731
// Strip the trailing slash
728732
tmpPath[sizeOfPath-1] = 0;
729733
_TmpDir = _strdup(ArchWindowsUtf16ToUtf8(tmpPath).c_str());
734+
#elif defined(ARCH_OS_DARWIN)
735+
// On Apple platforms, we use the system APIs to get the designated temp directory
736+
_TmpDir = strdup(Arch_DarwinGetTemporaryDirectory());
730737
#else
731738
const std::string tmpdir = ArchGetEnv("TMPDIR");
732739
if (!tmpdir.empty()) {
@@ -735,9 +742,7 @@ Arch_InitTmpDir()
735742
// set, the following call will leak a string.
736743
_TmpDir = strdup(tmpdir.c_str());
737744
} else {
738-
#if defined(ARCH_OS_DARWIN)
739-
_TmpDir = "/tmp";
740-
#elif defined(ARCH_OS_WASM_VM)
745+
#if defined(ARCH_OS_WASM_VM)
741746
// Note: WASM will always create /tmp as part of its in memory
742747
// filesystem. All data will be lost when the VM is shut down.
743748
_TmpDir = "/tmp";

0 commit comments

Comments
 (0)