FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-131999: Add support for tvOS, visionOS and watchOS. by freakboy3742 · Pull Request #159944 · python/cpython · GitHub

gh-131999: Add support for tvOS, visionOS and watchOS. by freakboy3742 · Pull Request #159944 · python/cpython · GitHub
Skip to content

Navigation Menu

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ac  (1) .c  (1) .h  (11) .in  (5) .json  (3) .m  (8) .md  (3) .pbxproj  (3) .plist  (7) .py  (18) .rst  (1) .sh  (1) .storyboard  (1) .sub  (1) .xcscheme  (3) .xctestplan  (3) No extension  (53) dotfile  (1) All 18 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
15 changes: 9 additions & 6 deletions .gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,19 @@ Lib/test/data/*
/_bootstrap_python
/Makefile
/Makefile.pre
/iOSTestbed.*
Apple/iOS/Frameworks/
Apple/iOS/Resources/Info.plist
Apple/testbed/build
/AppleTestbed.*
Platforms/Apple/iOS/Frameworks/*
Platforms/Apple/iOS/Resources/Info.plist
Platforms/Apple/testbed/Python*.xcframework/*/bin
Platforms/Apple/testbed/Python*.xcframework/*/include
Platforms/Apple/testbed/Python*.xcframework/*/lib
Platforms/Apple/testbed/Python*.xcframework/*/Python*.framework
Apple/testbed/*Testbed.xcodeproj/project.xcworkspace
Apple/testbed/*Testbed.xcodeproj/xcuserdata
Platforms/Apple/tvOS/Frameworks/*
Platforms/Apple/tvOS/Resources/Info.plist
Platforms/Apple/visionOS/Frameworks/*
Platforms/Apple/visionOS/Resources/Info.plist
Platforms/Apple/watchOS/Frameworks/*
Platforms/Apple/watchOS/Resources/Info.plist
Mac/Makefile
Mac/PythonLauncher/Info.plist
Mac/PythonLauncher/Makefile
Expand Down
8 changes: 6 additions & 2 deletions Include/cpython/object.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,12 @@ _Py_ThreadId(void)
#elif defined(__arm__) && __ARM_ARCH >= 7
__asm__ ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tid));
#elif defined(__aarch64__) && defined(__APPLE__)
__asm__ ("mrs %0, tpidrro_el0" : "=r" (tid));
#elif defined(__aarch64__)
// Use a 64-bit temporary: on arm64_32 (ILP32), uintptr_t is 32 bits
// but system registers are 64 bits.
uint64_t tp;
__asm__ ("mrs %0, tpidrro_el0" : "=r" (tp));
tid = (uintptr_t)tp;
#elif defined (__aarch64__)
__asm__ ("mrs %0, tpidr_el0" : "=r" (tid));
#elif defined(__powerpc64__)
#if defined(__clang__) && _Py__has_builtin(__builtin_thread_pointer)
Expand Down
20 changes: 14 additions & 6 deletions Include/internal/mimalloc/mimalloc/prim.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,17 @@ static inline void* mi_prim_tls_slot(size_t slot) mi_attr_noexcept {
__asm__ volatile ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tcb));
res = tcb[slot];
#elif defined(__aarch64__)
void** tcb; MI_UNUSED(ofs);
// CPython: patched for watchOS support.
// Submitted upstream as microsoft/mimalloc#1444
// Use a 64-bit temporary: on arm64_32 (ILP32), pointers are 32 bits
Comment thread
freakboy3742 marked this conversation as resolved.
// but system registers are 64 bits.
uint64_t tp; MI_UNUSED(ofs);
#if defined(__APPLE__) // M1, issue #343
__asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tcb));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Could you add comment when you adding downstream code here

Something like:
// CPython: blahblahblach

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

We need this when we upgrade mimalloc to the latest version

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Also any chance you could try and upstream this to mimalloc? It seems like it's moved around a little but I think it's here now: https://github.com/microsoft/mimalloc/blob/dev3/include/mimalloc/prim/prim-tls.h#L103C15-L103C19

If we can get it upstreamed into the v3 branch then when we upgrade it'll just be there.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I've added a comment; and I've submitted microsoft/mimalloc#1444 to upstream the equivalent change in mimalloc v3.

__asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tp));
#else
__asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
__asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tp));
#endif
void** tcb = (void**)(uintptr_t)tp;
res = tcb[slot];
#elif defined(__riscv)
void** tcb; MI_UNUSED(ofs);
Expand Down Expand Up @@ -200,12 +205,15 @@ static inline void mi_prim_tls_slot_set(size_t slot, void* value) mi_attr_noexce
__asm__ volatile ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tcb));
tcb[slot] = value;
#elif defined(__aarch64__)
void** tcb; MI_UNUSED(ofs);
// Use a 64-bit temporary: on arm64_32 (ILP32), pointers are 32 bits
// but system registers are 64 bits.
uint64_t tp; MI_UNUSED(ofs);
#if defined(__APPLE__) // M1, issue #343
__asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tcb));
__asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tp));
#else
__asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
__asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tp));
#endif
void** tcb = (void**)(uintptr_t)tp;
tcb[slot] = value;
#elif defined(__riscv)
void** tcb; MI_UNUSED(ofs);
Expand Down
6 changes: 5 additions & 1 deletion Include/internal/pycore_pystate.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,11 @@ _Py_get_machine_stack_pointer(void) {
#elif defined(_MSC_VER) && (defined(_M_X64) || defined(_M_IX86))
result = (uintptr_t)_AddressOfReturnAddress();
#elif defined(__aarch64__)
__asm__ ("mov %0, sp" : "=r" (result));
// Use a 64-bit temporary: on arm64_32 (ILP32), uintptr_t is 32 bits
// but sp is a 64-bit register.
uint64_t sp;
__asm__ ("mov %0, sp" : "=r" (sp));
result = (uintptr_t)sp;
#elif defined(__x86_64__)
__asm__ ("{movq %%rsp, %0|mov %0, rsp}" : "=r" (result));
#else
Expand Down
4 changes: 2 additions & 2 deletions Lib/asyncio/unix_events.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,10 @@ def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
# end polls as readable whenever unread data sits in the FIFO, and no
# event is delivered when the read end is closed, so it can only
# ever report a false disconnection (gh-145030). The same XNU
# behaviour applies on iOS/tvOS/watchOS (sys.platform is not
# behaviour applies on iOS/tvOS/visionOS/watchOS (sys.platform is not
# "darwin" there).
is_named_fifo_without_close_event = (
sys.platform in {"darwin", "ios", "tvos", "watchos", "sunos5"}
sys.platform in {"darwin", "ios", "tvos", "visionos", "watchos", "sunos5"}
and is_fifo and pipe_stat.st_nlink > 0)
if is_socket or (is_fifo
and not sys.platform.startswith("aix")
Expand Down
6 changes: 3 additions & 3 deletions Lib/ctypes/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -447,9 +447,9 @@ def _load_library(self, name, mode, handle, winmode):

else:
def _load_library(self, name, mode, handle, winmode):
# If the filename that has been provided is an iOS/tvOS/watchOS
# .fwork file, dereference the location to the true origin of the
# binary.
# If the filename that has been provided is an iOS, tvOS, visionOS
# or watchOS .fwork file, dereference the location to the true
# origin of the binary.
if name and name.endswith(".fwork"):
with open(name) as f:
name = _os.path.join(
Expand Down
2 changes: 1 addition & 1 deletion Lib/ctypes/util.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def dllist():
if (name := _get_module_filename(h)) is not None]
return libraries

elif os.name == "posix" and sys.platform in {"darwin", "ios", "tvos", "watchos"}:
elif os.name == "posix" and sys.platform in {"darwin", "ios", "tvos", "visionos", "watchos"}:
from ctypes.macholib.dyld import dyld_find as _dyld_find
def find_library(name):
possible = ['lib%s.dylib' % name,
Expand Down
4 changes: 2 additions & 2 deletions Lib/importlib/_bootstrap_external.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@

# Bootstrap-related code ######################################################
_CASE_INSENSITIVE_PLATFORMS_STR_KEY = 'win',
_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY = 'cygwin', 'darwin', 'ios', 'tvos', 'watchos'
_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY = 'cygwin', 'darwin', 'ios', 'tvos', 'visionos', 'watchos'
_CASE_INSENSITIVE_PLATFORMS = (_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY
+ _CASE_INSENSITIVE_PLATFORMS_STR_KEY)

Expand Down Expand Up @@ -1570,7 +1570,7 @@ def _get_supported_file_loaders():
"""
extension_loaders = []
if hasattr(_imp, 'create_dynamic'):
if sys.platform in {"ios", "tvos", "watchos"}:
if sys.platform in {"ios", "tvos", "visionos", "watchos"}:
extension_loaders = [(AppleFrameworkLoader, [
suffix.replace(".so", ".fwork")
for suffix in _imp.extension_suffixes()
Expand Down
36 changes: 26 additions & 10 deletions Lib/platform.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -526,13 +526,13 @@ def mac_ver(release='', versioninfo=('', '', ''), machine=''):


def ios_ver(system="", release="", model="", is_simulator=False):
"""Get iOS version information, and return it as a namedtuple:
(system, release, model, is_simulator).
"""Get iOS/tvOS/watchOS/visionOS version information, and return it as a
namedtuple: (system, release, model, is_simulator).
If values can't be determined, they are set to values provided as
parameters.
"""
if sys.platform == "ios":
if sys.platform in {"ios", "tvos", "visionos", "watchos"}:
import _ios_support
result = _ios_support.get_platform_ios()
if result is not None:
Expand Down Expand Up @@ -685,7 +685,7 @@ def _syscmd_file(target, default=''):
default in case the command should fail.
"""
if sys.platform in {'dos', 'win32', 'win16', 'ios', 'tvos', 'watchos'}:
if sys.platform in {'dos', 'win32', 'win16', 'ios', 'tvos', 'visionos', 'watchos'}:
# XXX Others too ?
return default

Expand Down Expand Up @@ -849,14 +849,30 @@ def get_OpenVMS():
csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
return 'Alpha' if cpu_number >= 128 else 'VAX'

# On the iOS simulator, os.uname returns the architecture as uname.machine.
# On device it returns the model name for some reason; but there's only one
# CPU architecture for iOS devices, so we know the right answer.
# On the iOS/tvOS/visionOS/watchOS simulator, os.uname returns the
# architecture as uname.machine. On device it returns the model name for
# some reason; but there's only one CPU architecture for devices, so we know
# the right answer.
def get_ios():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64'

def get_tvos():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64'

def get_visionos():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64'

def get_watchos():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64_32'

def from_subprocess():
"""
Fall back to `uname -p`
Expand Down Expand Up @@ -1009,8 +1025,8 @@ def uname():
system = 'Android'
release = android_ver().release

# Normalize responses on iOS
if sys.platform == 'ios':
# Normalize responses on Apple mobile platforms
if sys.platform in {"ios", "tvos", "visionos", "watchos"}:
system, release, _, _ = ios_ver()

vals = system, node, release, version, machine
Expand Down Expand Up @@ -1299,7 +1315,7 @@ def platform(aliased=False, terse=False):

if system == 'Darwin':
# macOS and iOS both report as a "Darwin" kernel
if sys.platform == "ios":
if sys.platform in {"ios", "tvos", "visionos", "watchos"}:
system, release, _, _ = ios_ver()
else:
macos_release = mac_ver()[0]
Expand Down
4 changes: 2 additions & 2 deletions Lib/site.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ def _getuserbase():
if env_base:
return env_base

# Emscripten, iOS, tvOS, VxWorks, WASI, and watchOS have no home directories
if sys.platform in {"emscripten", "ios", "tvos", "vxworks", "wasi", "watchos"}:
# Emscripten, iOS, tvOS, visionOS, VxWorks, WASI, and watchOS have no home directories
if sys.platform in {"emscripten", "ios", "tvos", "vxworks", "visionos", "wasi", "watchos"}:
return None

def joinuser(*args):
Expand Down
2 changes: 1 addition & 1 deletion Lib/subprocess.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
_mswindows = True

# some platforms do not support subprocesses
_can_fork_exec = sys.platform not in {"emscripten", "wasi", "ios", "tvos", "watchos"}
_can_fork_exec = sys.platform not in {"emscripten", "wasi", "ios", "tvos", "visionos", "watchos"}

if _mswindows:
import _winapi
Expand Down
17 changes: 16 additions & 1 deletion Lib/sysconfig/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
_ALWAYS_STR = {
'IPHONEOS_DEPLOYMENT_TARGET',
'MACOSX_DEPLOYMENT_TARGET',
'TVOS_DEPLOYMENT_TARGET',
'WATCHOS_DEPLOYMENT_TARGET',
'XROS_DEPLOYMENT_TARGET',
}

_INSTALL_SCHEMES = {
Expand Down Expand Up @@ -119,7 +122,7 @@ def _getuserbase():
# Emscripten, iOS, tvOS, VxWorks, WASI, and watchOS have no home directories.
# Use _PYTHON_HOST_PLATFORM to get the correct platform when cross-compiling.
system_name = os.environ.get('_PYTHON_HOST_PLATFORM', sys.platform).split('-')[0]
if system_name in {"emscripten", "ios", "tvos", "vxworks", "wasi", "watchos"}:
if system_name in {"emscripten", "ios", "tvos", "visionos", "vxworks", "wasi", "watchos"}:
return None

def joinuser(*args):
Expand Down Expand Up @@ -750,6 +753,18 @@ def get_platform():
release = get_config_vars().get("IPHONEOS_DEPLOYMENT_TARGET", "13.0")
osname = sys.platform
machine = sys.implementation._multiarch
elif sys.platform == "tvos":
release = get_config_vars().get("TVOS_DEPLOYMENT_TARGET", "12.0")
osname = sys.platform
machine = sys.implementation._multiarch
elif sys.platform == "watchos":
release = get_config_vars().get("WATCHOS_DEPLOYMENT_TARGET", "9.0")
osname = sys.platform
machine = sys.implementation._multiarch
elif sys.platform == "visionos":
release = get_config_vars().get("XROS_DEPLOYMENT_TARGET", "2.0")
osname = sys.platform
machine = sys.implementation._multiarch
else:
import _osx_support
osname, release, machine = _osx_support.get_platform_osx(
Expand Down
4 changes: 2 additions & 2 deletions Lib/test/datetimetester.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7475,9 +7475,9 @@ def test_datetime_from_timestamp(self):
self.assertEqual(dt_orig, dt_rt)

def test_type_check_in_subinterp(self):
# iOS requires the use of the custom framework loader,
# Apple mobile platforms require the use of the custom framework loader,
# not the ExtensionFileLoader.
if sys.platform == "ios":
if support.is_apple_mobile:
extension_loader = "AppleFrameworkLoader"
else:
extension_loader = "ExtensionFileLoader"
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/pythoninfo.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@


MS_WINDOWS = (sys.platform == "win32")
APPLE = (sys.platform in ("darwin", "ios", "tvos", "watchos"))
APPLE = (sys.platform in ("darwin", "ios", "tvos", "watchos", "visionos"))

COMMAND_TIMEOUT = 60.0

Expand Down
4 changes: 2 additions & 2 deletions Lib/test/support/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def skip_android_selinux(name):
sys.platform == "android", f"Android blocks {name} with SELinux"
)

if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos"}:
if sys.platform not in {"win32", "vxworks", "ios", "tvos", "visionos", "watchos"}:
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
else:
unix_shell = None
Expand All @@ -647,7 +647,7 @@ def skip_emscripten_stack_overflow():
def skip_wasi_stack_overflow():
return unittest.skipIf(is_wasi, "Exhausts stack on WASI")

is_apple_mobile = sys.platform in {"ios", "tvos", "watchos"}
is_apple_mobile = sys.platform in {"ios", "tvos", "visionos", "watchos"}
is_apple = is_apple_mobile or sys.platform == "darwin"

has_fork_support = hasattr(os, "fork") and not (
Expand Down
1 change: 1 addition & 0 deletions Lib/test/test__interpreters.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ def test_shareable_types(self):
f'assert(obj == {obj!r})',
)

@support.requires_subprocess()
def test_os_exec(self):
expected = 'spam spam spam spam spam'
subinterp = _interpreters.create()
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_ctypes/test_dllist.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


WINDOWS = os.name == "nt"
APPLE = sys.platform in {"darwin", "ios", "tvos", "watchos"}
APPLE = sys.platform in {"darwin", "ios", "tvos", "watchos", "visionos"}

if WINDOWS:
KNOWN_LIBRARIES = ["KERNEL32.DLL"]
Expand Down
Loading
Loading

Footer

© 2026 GitHub, Inc.

Back | FazBrowse Home | New Git URL