Skip to content

Commit

Permalink
Add support for watchOS and tvOS
Browse files Browse the repository at this point in the history
Co-authored-by: Ole André Vadla Ravnås <oleavr@gmail.com>
  • Loading branch information
tmm1 and oleavr committed Oct 27, 2022
1 parent 9839654 commit 469635b
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 52 deletions.
38 changes: 33 additions & 5 deletions include/v8config.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ path. Add it with -I<path> to the command line
// V8_OS_FREEBSD - FreeBSD
// V8_OS_FUCHSIA - Fuchsia
// V8_OS_LINUX - Linux (Android, ChromeOS, Linux, ...)
// V8_OS_DARWIN - Darwin (macOS, iOS)
// V8_OS_DARWIN - Darwin (macOS, iOS, watchOS, tvOS)
// V8_OS_MACOS - macOS
// V8_OS_IOS - iOS
// V8_OS_WATCHOS - watchOS
// V8_OS_TVOS - tvOS
// V8_OS_NETBSD - NetBSD
// V8_OS_OPENBSD - OpenBSD
// V8_OS_POSIX - POSIX compatible (mostly everything except Windows)
Expand All @@ -93,13 +95,21 @@ path. Add it with -I<path> to the command line
# define V8_OS_POSIX 1
# define V8_OS_BSD 1
# define V8_OS_DARWIN 1
# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
# if defined(TARGET_OS_OSX) && TARGET_OS_OSX
# define V8_OS_MACOS 1
# define V8_OS_STRING "macos"
# elif defined(TARGET_OS_IOS) && TARGET_OS_IOS
# define V8_OS_IOS 1
# define V8_OS_STRING "ios"
# elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH
# define V8_OS_WATCHOS 1
# define V8_OS_STRING "watchos"
# elif defined(TARGET_OS_TV) && TARGET_OS_TV
# define V8_OS_TVOS 1
# define V8_OS_STRING "tvos"
# else
# define V8_OS_MACOS 1
# define V8_OS_STRING "macos"
# endif // defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
# error Unsupported Apple OS.
# endif

#elif defined(__CYGWIN__)
# define V8_OS_CYGWIN 1
Expand Down Expand Up @@ -171,6 +181,8 @@ path. Add it with -I<path> to the command line
// V8_TARGET_OS_FREEBSD
// V8_TARGET_OS_FUCHSIA
// V8_TARGET_OS_IOS
// V8_TARGET_OS_WATCHOS
// V8_TARGET_OS_TVOS
// V8_TARGET_OS_LINUX
// V8_TARGET_OS_MACOS
// V8_TARGET_OS_WIN
Expand All @@ -184,6 +196,8 @@ path. Add it with -I<path> to the command line
&& !defined(V8_TARGET_OS_FREEBSD) \
&& !defined(V8_TARGET_OS_FUCHSIA) \
&& !defined(V8_TARGET_OS_IOS) \
&& !defined(V8_TARGET_OS_WATCHOS) \
&& !defined(V8_TARGET_OS_TVOS) \
&& !defined(V8_TARGET_OS_LINUX) \
&& !defined(V8_TARGET_OS_MACOS) \
&& !defined(V8_TARGET_OS_WIN)
Expand All @@ -196,6 +210,8 @@ path. Add it with -I<path> to the command line
|| defined(V8_TARGET_OS_FREEBSD) \
|| defined(V8_TARGET_OS_FUCHSIA) \
|| defined(V8_TARGET_OS_IOS) \
|| defined(V8_TARGET_OS_WATCHOS) \
|| defined(V8_TARGET_OS_TVOS) \
|| defined(V8_TARGET_OS_LINUX) \
|| defined(V8_TARGET_OS_MACOS) \
|| defined(V8_TARGET_OS_WIN)
Expand All @@ -219,6 +235,14 @@ path. Add it with -I<path> to the command line
# define V8_TARGET_OS_IOS
#endif

#ifdef V8_OS_WATCHOS
# define V8_TARGET_OS_WATCHOS
#endif

#ifdef V8_OS_TVOS
# define V8_TARGET_OS_TVOS
#endif

#ifdef V8_OS_LINUX
# define V8_TARGET_OS_LINUX
#endif
Expand All @@ -241,6 +265,10 @@ path. Add it with -I<path> to the command line
# define V8_TARGET_OS_STRING "fuchsia"
#elif defined(V8_TARGET_OS_IOS)
# define V8_TARGET_OS_STRING "ios"
#elif defined(V8_TARGET_OS_WATCHOS)
# define V8_TARGET_OS_STRING "watchos"
#elif defined(V8_TARGET_OS_TVOS)
# define V8_TARGET_OS_STRING "tvos"
#elif defined(V8_TARGET_OS_LINUX)
# define V8_TARGET_OS_STRING "linux"
#elif defined(V8_TARGET_OS_MACOS)
Expand Down
69 changes: 35 additions & 34 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -18,40 +18,41 @@ python = import('python').find_installation().path()
build_os = build_machine.system()
host_os = host_machine.system()

target_conditionals_prefix = '#include <TargetConditionals.h>'
is_macos_src = target_conditionals_prefix + '''
#if !TARGET_OS_OSX
# error Not macOS
#endif
'''
is_ios_src = target_conditionals_prefix + '''
#if !TARGET_OS_IOS
# error Not iOS
#endif
'''

if build_os == 'windows'
build_os = 'win'
elif build_os == 'darwin'
if cpp_native.compiles(is_macos_src, name: 'compiling on macOS')
build_os = 'macos'
elif cpp_native.compiles(is_ios_src, name: 'compiling on iOS')
build_os = 'ios'
endif
elif build_os == 'linux' and cpp_native.has_header('android/api-level.h')
build_os = 'android'
endif
if host_os == 'windows'
host_os = 'win'
elif host_os == 'darwin'
if cpp.compiles(is_macos_src, name: 'compiling for macOS')
host_os = 'macos'
elif cpp.compiles(is_ios_src, name: 'compiling for iOS')
host_os = 'ios'
apple_os_flavors = [
['macOS', 'OSX'],
['iOS', 'IOS'],
['watchOS', 'WATCH'],
['tvOS', 'TV'],
]
foreach machine : ['build', 'host']
compiler = (machine == 'build') ? cpp_native : cpp
os = get_variable(machine + '_os')
if os == 'windows'
os = 'win'
elif os == 'darwin'
foreach candidate : apple_os_flavors
name = candidate[0]
constant = candidate[1]
if compiler.compiles('''
#include <TargetConditionals.h>
#if !TARGET_OS_@0@
# error Nope
#endif
'''.format(constant),
name: 'compiling @0@ @1@'.format((machine == 'build') ? 'on' : 'for',
name))
os = name.to_lower()
break
endif
endforeach
if os == 'darwin'
error(f'Unable to detect @machine@ machine Apple OS flavor')
endif
elif os == 'linux' and compiler.has_header('android/api-level.h')
os = 'android'
endif
elif host_os == 'linux' and cpp.has_header('android/api-level.h')
host_os = 'android'
endif
set_variable(machine + '_os', os)
endforeach
host_os_nick = (host_os == 'macos') ? 'mac' : host_os

v8_arch_from_cpu_family = {
Expand Down Expand Up @@ -298,7 +299,7 @@ if enable_snapshot_compression
endif

if get_option('pointer_compression').auto()
enable_pointer_compression = host_is_64bit and host_os not in ['macos', 'ios']
enable_pointer_compression = host_is_64bit and host_os not in ['macos', 'ios', 'watchos', 'tvos']
else
enable_pointer_compression = get_option('pointer_compression').enabled()
endif
Expand Down
10 changes: 5 additions & 5 deletions src/base/cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -756,7 +756,10 @@ CPU::CPU()
delete[] features;
}
#elif V8_OS_DARWIN
#if V8_OS_IOS
#if V8_OS_MACOS
// ARM64 Macs always have JSCVT.
has_jscvt_ = true;
#else
int64_t feat_jscvt = 0;
size_t feat_jscvt_size = sizeof(feat_jscvt);
if (sysctlbyname("hw.optional.arm.FEAT_JSCVT", &feat_jscvt, &feat_jscvt_size,
Expand All @@ -765,10 +768,7 @@ CPU::CPU()
} else {
has_jscvt_ = feat_jscvt;
}
#else
// ARM64 Macs always have JSCVT.
has_jscvt_ = true;
#endif // V8_OS_IOS
#endif // !V8_OS_MACOS
#endif // V8_OS_WIN

#elif V8_HOST_ARCH_PPC || V8_HOST_ARCH_PPC64
Expand Down
8 changes: 8 additions & 0 deletions src/base/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ libbase_os_sources = {
'debug' / 'stack_trace_posix.cc',
'platform' / 'platform-darwin.cc',
],
'watchos': libbase_posix_sources + [
'debug' / 'stack_trace_posix.cc',
'platform' / 'platform-darwin.cc',
],
'tvos': libbase_posix_sources + [
'debug' / 'stack_trace_posix.cc',
'platform' / 'platform-darwin.cc',
],
'android': libbase_posix_sources + [
'debug' / 'stack_trace_android.cc',
'platform' / 'platform-linux.cc',
Expand Down
2 changes: 1 addition & 1 deletion src/codegen/arm64/assembler-arm64.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ constexpr unsigned CpuFeaturesFromCompiler() {

constexpr unsigned CpuFeaturesFromTargetOS() {
unsigned features = 0;
#if defined(V8_TARGET_OS_MACOS) && !defined(V8_TARGET_OS_IOS)
#if defined(V8_TARGET_OS_MACOS)
// TODO(v8:13004): Detect if an iPhone is new enough to support jscvt.
features |= 1u << JSCVT;
#endif
Expand Down
12 changes: 6 additions & 6 deletions src/libsampler/sampler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,10 @@ void SignalHandler::FillRegisterState(void* context, RegisterState* state) {
state->fp = reinterpret_cast<void*>(mcontext.__gregs[REG_S0]);
state->lr = reinterpret_cast<void*>(mcontext.__gregs[REG_RA]);
#endif // V8_HOST_ARCH_*
#elif V8_OS_IOS
#elif V8_OS_DARWIN && !V8_OS_MACOS

#if V8_TARGET_ARCH_ARM64
// Building for the iOS device.
// Building for the iOS/watchOS/tvOS device.
#ifdef __DARWIN_OPAQUE_ARM_THREAD_STATE64
state->pc = reinterpret_cast<void*>(
__darwin_arm_thread_state64_get_pc(mcontext->__ss));
Expand All @@ -479,22 +479,22 @@ void SignalHandler::FillRegisterState(void* context, RegisterState* state) {
state->fp = reinterpret_cast<void*>(mcontext->__ss.__fp);
#endif
#elif V8_TARGET_ARCH_ARM
// Building for the iOS device.
// Building for the iOS/watchOS/tvOS device.
state->pc = reinterpret_cast<void *>(mcontext->__ss.__pc);
state->sp = reinterpret_cast<void *>(mcontext->__ss.__sp);
state->fp = reinterpret_cast<void *>(mcontext->__ss.__r[7]);
#elif V8_TARGET_ARCH_X64
// Building for the iOS simulator.
// Building for the iOS/watchOS/tvOS simulator.
state->pc = reinterpret_cast<void*>(mcontext->__ss.__rip);
state->sp = reinterpret_cast<void*>(mcontext->__ss.__rsp);
state->fp = reinterpret_cast<void*>(mcontext->__ss.__rbp);
#elif V8_TARGET_ARCH_IA32
// Building for the iOS simulator.
// Building for the iOS/watchOS/tvOS simulator.
state->pc = reinterpret_cast<void*>(mcontext->__ss.__eip);
state->sp = reinterpret_cast<void*>(mcontext->__ss.__esp);
state->fp = reinterpret_cast<void*>(mcontext->__ss.__ebp);
#else
#error Unexpected iOS target architecture.
#error Unexpected iOS/watchOS/tvOS target architecture.
#endif // V8_TARGET_ARCH_ARM64

#elif V8_OS_DARWIN
Expand Down
3 changes: 2 additions & 1 deletion src/snapshot/embedded/platform-embedded-file-writer-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ EmbeddedTargetOs ToEmbeddedTargetOs(const char* s) {
return EmbeddedTargetOs::kChromeOS;
} else if (string == "fuchsia") {
return EmbeddedTargetOs::kFuchsia;
} else if (string == "ios" || string == "mac") {
} else if (string == "ios" || string == "watchos" || string == "tvos" ||
string == "mac") {
return EmbeddedTargetOs::kMac;
} else if (string == "win") {
return EmbeddedTargetOs::kWin;
Expand Down

0 comments on commit 469635b

Please sign in to comment.