Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/build-ios-mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ jobs:
- name: build
run: |
if [[ "${{ matrix.os }}" == "macos-14" ]]; then
export IOS_DEPLOYMENT_TARGET=13.0;
export CMAKE_OSX_DEPLOYMENT_TARGET=13.0;
elif [[ "${{ matrix.os }}" == "macos-15" ]]; then
export IOS_DEPLOYMENT_TARGET=15.0;
export CMAKE_OSX_DEPLOYMENT_TARGET=15.0;
fi
./build-tests-ios.sh ${{ matrix.config }} ${{ matrix.simulator }}
78 changes: 16 additions & 62 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,88 +47,42 @@ if(APPLE)
message(STATUS "BUILD_IOS: ${BUILD_IOS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fobjc-arc")

# iOS build options
option(BUILD_IOS "Build for iOS" NO)
option(FORCE_RESET_OSX_DEPLOYMENT_TARGET "Clear the OSX Deployment Target Set" YES)
if (DEFINED FORCE_RESET_DEPLOYMENT_TARGET)
set(FORCE_RESET_OSX_DEPLOYMENT_TARGET ${FORCE_RESET_DEPLOYMENT_TARGET})
endif()
option(BUILD_IOS "Build for iOS-family Apple platforms" NO)

# When building via vcpkg, the toolchain file handles architecture, sysroot,
# deployment target, and platform flags. Skip manual flag configuration.
if(NOT MATSDK_USE_VCPKG_DEPS)
if(CMAKE_SYSTEM_NAME MATCHES "^(iOS|visionOS)$")
set(BUILD_IOS ON)
endif()
if(BUILD_IOS)
set(TARGET_ARCH "APPLE")
set(IOS True)
set(APPLE True)

if(FORCE_RESET_OSX_DEPLOYMENT_TARGET)
set(CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment target for iOS" FORCE)
if (${IOS_PLAT} STREQUAL "iphonesimulator")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mios-simulator-version-min=${IOS_DEPLOYMENT_TARGET}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mios-simulator-version-min=${IOS_DEPLOYMENT_TARGET}")
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -miphoneos-version-min=${IOS_DEPLOYMENT_TARGET}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -miphoneos-version-min=${IOS_DEPLOYMENT_TARGET}")
endif()
endif()

if((${IOS_PLAT} STREQUAL "iphoneos") OR (${IOS_PLAT} STREQUAL "iphonesimulator") OR (${IOS_PLAT} STREQUAL "xros") OR (${IOS_PLAT} STREQUAL "xrsimulator"))
set(IOS_PLATFORM "${IOS_PLAT}")
else()
message(FATAL_ERROR "Unrecognized iOS platform '${IOS_PLAT}'")
if(NOT CMAKE_OSX_SYSROOT)
message(FATAL_ERROR "CMAKE_OSX_SYSROOT must identify an Apple SDK")
endif()

if(${IOS_ARCH} STREQUAL "x86_64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64")
set(CMAKE_SYSTEM_PROCESSOR x86_64)
elseif(${IOS_ARCH} STREQUAL "arm64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64")
set(CMAKE_SYSTEM_PROCESSOR arm64)
elseif(${IOS_ARCH} STREQUAL "arm64e")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64e")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64e")
set(CMAKE_SYSTEM_PROCESSOR arm64e)
else()
message(FATAL_ERROR "Unrecognized iOS architecture '${IOS_ARCH}'")
endif()

execute_process(COMMAND xcodebuild -version -sdk ${IOS_PLATFORM} ONLY_ACTIVE_ARCH=NO Path
if(NOT IS_ABSOLUTE "${CMAKE_OSX_SYSROOT}")
execute_process(COMMAND xcodebuild -version -sdk "${CMAKE_OSX_SYSROOT}" Path
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT CMAKE_OSX_SYSROOT)
message(FATAL_ERROR "Unable to resolve the Apple SDK sysroot")
endif()
set(CMAKE_OSX_SYSROOT "${CMAKE_OSX_SYSROOT}" CACHE PATH "Apple SDK sysroot" FORCE)
endif()
message(STATUS "CMAKE_OSX_SYSROOT ${CMAKE_OSX_SYSROOT}")
message(STATUS "ARCHITECTURE: ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "PLATFORM: ${IOS_PLATFORM}")
message(STATUS "DEPLOYMENT TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
else()
if("${MAC_ARCH}" STREQUAL "x86_64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64")
set(CMAKE_SYSTEM_PROCESSOR x86_64)
set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
set(CMAKE_OSX_ARCHITECTURES ${MAC_ARCH})
set(APPLE True)
elseif("${MAC_ARCH}" STREQUAL "arm64")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch arm64")
set(CMAKE_SYSTEM_PROCESSOR arm64)
set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
set(CMAKE_OSX_ARCHITECTURES ${MAC_ARCH})
set(APPLE True)
else()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -arch x86_64 -arch arm64")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -arch x86_64 -arch arm64")
endif()
message(STATUS "MAC_ARCH: ${MAC_ARCH}")
message(STATUS "ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
endif()
else()
# vcpkg mode: just set internal flags from what the toolchain provides
if(BUILD_IOS OR CMAKE_SYSTEM_NAME STREQUAL "iOS")
if(BUILD_IOS OR CMAKE_SYSTEM_NAME MATCHES "^(iOS|visionOS)$")
set(BUILD_IOS ON)
set(TARGET_ARCH "APPLE")
set(IOS True)
endif()
message(STATUS "vcpkg toolchain managing architecture and platform flags")
endif()
Expand Down
3 changes: 1 addition & 2 deletions build-gtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ if(BUILD_IOS)
set(CMAKE_OSX_DEPLOYMENT_TARGET "12.2" CACHE STRING "Force set of the deployment target for iOS" FORCE)
set(CMAKE_C_FLAGS "\${CMAKE_C_FLAGS} -miphoneos-version-min=10.0")
set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -miphoneos-version-min=10.0 -std=c++11")
set(IOS_PLATFORM "iphonesimulator")
set(CMAKE_SYSTEM_PROCESSOR x86_64)
execute_process(COMMAND xcodebuild -version -sdk \${IOS_PLATFORM} Path
execute_process(COMMAND xcodebuild -version -sdk iphonesimulator Path
OUTPUT_VARIABLE CMAKE_OSX_SYSROOT_OUT
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
Expand Down
30 changes: 13 additions & 17 deletions build-ios.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,51 +25,47 @@ elif [ "$1" == "debug" ]; then
fi

# Set Architecture: arm64, arm64e or x86_64
IOS_ARCH=$(/usr/bin/uname -m)
APPLE_ARCH=$(/usr/bin/uname -m)
if [ "$1" == "arm64" ]; then
IOS_ARCH="arm64"
APPLE_ARCH="arm64"
shift
elif [ "$1" == "arm64e" ]; then
IOS_ARCH="arm64e"
APPLE_ARCH="arm64e"
shift
elif [ "$1" == "x86_64" ]; then
IOS_ARCH="x86_64"
APPLE_ARCH="x86_64"
shift
fi

# the last param is expected to specify the platform name: iphoneos|iphonesimulator|xros|xrsimulator
# so if it is non-empty and it is not "device", we take it as a valid platform name
# otherwise we fall back to old iOS logic which only supported iphoneos|iphonesimulator
IOS_PLAT="iphonesimulator"
APPLE_PLATFORM="iphonesimulator"
if [ -n "$1" ] && [ "$1" != "device" ]; then
IOS_PLAT="$1"
APPLE_PLATFORM="$1"
elif [ "$1" == "device" ]; then
IOS_PLAT="iphoneos"
APPLE_PLATFORM="iphoneos"
fi

echo "IOS_ARCH = $IOS_ARCH, IOS_PLAT = $IOS_PLAT, BUILD_TYPE = $BUILD_TYPE"
echo "architecture = $APPLE_ARCH, platform = $APPLE_PLATFORM, build type = $BUILD_TYPE"

FORCE_RESET_DEPLOYMENT_TARGET=NO
DEPLOYMENT_TARGET=""

if [ "$IOS_PLAT" == "iphoneos" ] || [ "$IOS_PLAT" == "iphonesimulator" ]; then
if [ "$APPLE_PLATFORM" == "iphoneos" ] || [ "$APPLE_PLATFORM" == "iphonesimulator" ]; then
SYS_NAME="iOS"
DEPLOYMENT_TARGET="$IOS_DEPLOYMENT_TARGET"
DEPLOYMENT_TARGET="$CMAKE_OSX_DEPLOYMENT_TARGET"
if [ -z "$DEPLOYMENT_TARGET" ]; then
DEPLOYMENT_TARGET="12.0"
FORCE_RESET_DEPLOYMENT_TARGET=YES
fi
elif [ "$IOS_PLAT" == "xros" ] || [ "$IOS_PLAT" == "xrsimulator" ]; then
elif [ "$APPLE_PLATFORM" == "xros" ] || [ "$APPLE_PLATFORM" == "xrsimulator" ]; then
SYS_NAME="visionOS"
DEPLOYMENT_TARGET="$XROS_DEPLOYMENT_TARGET"
DEPLOYMENT_TARGET="$CMAKE_OSX_DEPLOYMENT_TARGET"
if [ -z "$DEPLOYMENT_TARGET" ]; then
DEPLOYMENT_TARGET="1.0"
FORCE_RESET_DEPLOYMENT_TARGET=YES
fi
fi

echo "deployment target = $DEPLOYMENT_TARGET"
echo "force reset deployment target = $FORCE_RESET_DEPLOYMENT_TARGET"

# Install build tools and recent sqlite3
FILE=".buildtools"
Expand All @@ -92,7 +88,7 @@ cd out

CMAKE_PACKAGE_TYPE=tgz

cmake_cmd="cmake -DCMAKE_OSX_SYSROOT=$IOS_PLAT -DCMAKE_SYSTEM_NAME=$SYS_NAME -DCMAKE_IOS_ARCH_ABI=$IOS_ARCH -DCMAKE_OSX_DEPLOYMENT_TARGET=$DEPLOYMENT_TARGET -DBUILD_IOS=YES -DIOS_ARCH=$IOS_ARCH -DIOS_PLAT=$IOS_PLAT -DIOS_DEPLOYMENT_TARGET=$DEPLOYMENT_TARGET -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PACKAGE_TYPE=$CMAKE_PACKAGE_TYPE -DFORCE_RESET_DEPLOYMENT_TARGET=$FORCE_RESET_DEPLOYMENT_TARGET $CMAKE_OPTS .."
cmake_cmd="cmake -DCMAKE_OSX_SYSROOT=$APPLE_PLATFORM -DCMAKE_SYSTEM_NAME=$SYS_NAME -DCMAKE_OSX_ARCHITECTURES=$APPLE_ARCH -DCMAKE_OSX_DEPLOYMENT_TARGET=$DEPLOYMENT_TARGET -DBUILD_IOS=YES -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PACKAGE_TYPE=$CMAKE_PACKAGE_TYPE $CMAKE_OPTS .."
echo "${cmake_cmd}"
eval $cmake_cmd

Expand Down
21 changes: 10 additions & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ while [[ $# -gt 0 ]]; do
echo "BUILD_TYPE = $BUILD_TYPE"
;;
arm64|x86_64|universal)
if [[ -n "$MAC_ARCH" ]]; then
echo "Error: MAC_ARCH is already set to '$MAC_ARCH'. Cannot overwrite with $ARG." 1>&2
if [[ -n "$APPLE_ARCH" ]]; then
echo "Error: APPLE_ARCH is already set to '$APPLE_ARCH'. Cannot overwrite with $ARG." 1>&2
exit 1
else
MAC_ARCH="$ARG"
APPLE_ARCH="$ARG"
fi
echo "MAC_ARCH = $MAC_ARCH"
echo "APPLE_ARCH = $APPLE_ARCH"
;;
CUSTOM_BUILD_FLAGS*)
CUSTOM_CMAKE_CXX_FLAG="\"${ARG:19:999}\""
Expand All @@ -91,9 +91,9 @@ if [[ -z "$BUILD_TYPE" ]]; then
echo "Assuming default BUILD_TYPE = Debug"
fi

if [[ -z "$MAC_ARCH" ]]; then
MAC_ARCH=$(/usr/bin/uname -m)
echo "Using current machine MAC_ARCH = $MAC_ARCH"
if [[ -z "$APPLE_ARCH" ]]; then
APPLE_ARCH=$(/usr/bin/uname -m)
echo "Using current machine APPLE_ARCH = $APPLE_ARCH"
fi

# Evaluate switches
Expand Down Expand Up @@ -137,7 +137,7 @@ if [ "$LINK_TYPE" == "shared" ]; then
fi

# Set target MacOS minver
default_mac_os_target=$([ "$MAC_ARCH" == "arm64" ] && echo "11.10" || echo "10.10")
default_mac_os_target=$([ "$APPLE_ARCH" == "arm64" ] && echo "11.10" || echo "10.10")
[ -z $MACOSX_DEPLOYMENT_TARGET ] && export MACOSX_DEPLOYMENT_TARGET=${default_mac_os_target}
echo "macosx deployment target="$MACOSX_DEPLOYMENT_TARGET

Expand All @@ -147,7 +147,7 @@ OS_NAME=`uname -a`

if [ ! -f $FILE ]; then
case "$OS_NAME" in
*Darwin*) CMD="tools/setup-buildtools-apple.sh $MAC_ARCH" ;;
*Darwin*) CMD="tools/setup-buildtools-apple.sh $APPLE_ARCH" ;;
*Linux*) CMD="tools/setup-buildtools.sh" ;;
*) CMD=""; echo "WARNING: unsupported OS $OS_NAME, skipping build tools installation.." ;;
esac
Expand Down Expand Up @@ -185,8 +185,7 @@ fi
# Fail on error
set -e

# TODO: should this be improved to verify if the platform is Apple? Right now we unconditionally pass -DMAC_ARCH even if building for Windows or Linux.
cmake_cmd="cmake -DMAC_ARCH=$MAC_ARCH -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PACKAGE_TYPE=$CMAKE_PACKAGE_TYPE -DCMAKE_CXX_FLAGS="${CUSTOM_CMAKE_CXX_FLAG}" $CMAKE_OPTS .."
cmake_cmd="cmake -DCMAKE_OSX_ARCHITECTURES=$APPLE_ARCH -DCMAKE_OSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_PACKAGE_TYPE=$CMAKE_PACKAGE_TYPE -DCMAKE_CXX_FLAGS="${CUSTOM_CMAKE_CXX_FLAG}" $CMAKE_OPTS .."
echo $cmake_cmd
eval $cmake_cmd

Expand Down
11 changes: 10 additions & 1 deletion lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,12 @@ if(MATSDK_BUNDLE_SQLITE AND NOT TARGET sqlite3_bundled)
else()
# Unstripped vendored build (Android legacy): keep the existing narrower
# warning suppression. -fno-finite-math-only guards the INFINITY macro.
target_compile_options(sqlite3_bundled PRIVATE -fno-finite-math-only -Wno-unused-function)
target_compile_options(sqlite3_bundled PRIVATE
-fno-finite-math-only
-Wno-unused-function
-Wno-shorten-64-to-32
-Wno-ambiguous-macro
)
endif()
endif()

Expand Down Expand Up @@ -561,6 +566,10 @@ else()
# real POSIX declarations for read/write/lseek/close instead of relying on
# implicit (int-returning) declarations.
target_compile_definitions(zlib_bundled PRIVATE Z_HAVE_UNISTD_H)
target_compile_options(zlib_bundled PRIVATE
-Wno-shorten-64-to-32
-Wno-ambiguous-macro
)

target_link_libraries(mat PRIVATE sqlite3_bundled zlib_bundled ${LIBS})
elseif(PAL_IMPLEMENTATION STREQUAL "WIN32")
Expand Down
2 changes: 1 addition & 1 deletion lib/http/HttpClient_Apple.mm
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ void HandleResponse(NSData* data, NSURLResponse* response, NSError* error)
NSHTTPURLResponse *httpResp = static_cast<NSHTTPURLResponse*>(response);
auto simpleResponse = new SimpleHttpResponse { NextRespId() };

simpleResponse->m_statusCode = httpResp.statusCode;
simpleResponse->m_statusCode = static_cast<unsigned int>(httpResp.statusCode);

NSDictionary *responseHeaders = [httpResp allHeaderFields];
for (id key in responseHeaders)
Expand Down
28 changes: 23 additions & 5 deletions lib/pal/PAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,26 @@ namespace PAL_NS_BEGIN {
{
#ifdef _WIN32
FILETIME tocks;
::GetSystemTimeAsFileTime(&tocks);
// Resolve the precise API dynamically so the SDK retains its Windows 7
// runtime compatibility and falls back when the API is unavailable.
using GetSystemTimePreciseAsFileTimeProc = VOID (WINAPI*)(LPFILETIME);
static const GetSystemTimePreciseAsFileTimeProc getSystemTimePreciseAsFileTime =
[]() -> GetSystemTimePreciseAsFileTimeProc
{
HMODULE kernel32 = ::GetModuleHandleW(L"kernel32.dll");
return kernel32
? reinterpret_cast<GetSystemTimePreciseAsFileTimeProc>(
::GetProcAddress(kernel32, "GetSystemTimePreciseAsFileTime"))
: nullptr;
}();
if (getSystemTimePreciseAsFileTime)
{
getSystemTimePreciseAsFileTime(&tocks);
}
else
{
::GetSystemTimeAsFileTime(&tocks);
}
ULONGLONG ticks = (ULONGLONG(tocks.dwHighDateTime) << 32) | tocks.dwLowDateTime;
// number of days from beginning to 1601 multiplied by ticks per day
return ticks + 0x701ce1722770000ULL;
Expand All @@ -440,10 +459,9 @@ namespace PAL_NS_BEGIN {
// This UTC epoch contract has been signed in blood since C++20
std::chrono::time_point<std::chrono::system_clock> now = std::chrono::system_clock::now();
auto duration = now.time_since_epoch();
auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
uint64_t ticks = millis;
ticks *= 10000; // convert millis to ticks (1 tick = 100ns)
ticks += 0x89F7FF5F7B58000ULL; // UTC time 0 in .NET ticks
auto nanos = std::chrono::duration_cast<std::chrono::nanoseconds>(duration).count();
int64_t ticks = nanos / 100; // convert nanoseconds to .NET ticks (1 tick = 100ns)
ticks += static_cast<int64_t>(0x89F7FF5F7B58000ULL); // UTC time 0 in .NET ticks
return ticks;
#endif
}
Expand Down
16 changes: 16 additions & 0 deletions tests/unittests/PalTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,22 @@ TEST_F(PalTests, SystemTime)
EXPECT_THAT(t1, Lt(t0 + 1000));
}

#if !defined(_WIN32) && !defined(_WIN64)
TEST_F(PalTests, SystemTimeInTicksPreservesSubMillisecondPrecision)
{
constexpr int64_t TicksPerMillisecond = 10000;
bool observedSubMillisecondTick = false;

for (int i = 0; i < 1000 && !observedSubMillisecondTick; ++i)
{
observedSubMillisecondTick =
PAL::getUtcSystemTimeinTicks() % TicksPerMillisecond != 0;
}

EXPECT_TRUE(observedSubMillisecondTick);
}
#endif

TEST_F(PalTests, FormatUtcTimestampMsAsISO8601)
{
EXPECT_THAT(PAL::formatUtcTimestampMsAsISO8601(0ll), Eq("1970-01-01T00:00:00.000Z"));
Expand Down
9 changes: 9 additions & 0 deletions tools/ports/cpp-client-telemetry/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ if(VCPKG_TARGET_IS_IOS)
set(MATSDK_BUILD_IOS ON)
endif()

# Keep the port's iOS deployment target aligned with the consumer test and the
# SDK's supported minimum instead of letting Clang default to the SDK version.
set(MATSDK_APPLE_DEPLOYMENT_OPTIONS)
if(VCPKG_TARGET_IS_IOS)
list(APPEND MATSDK_APPLE_DEPLOYMENT_OPTIONS
-DCMAKE_OSX_DEPLOYMENT_TARGET=12.0)
endif()

set(MATSDK_ANDROID_HTTP_CLIENT AUTO)
if(VCPKG_TARGET_IS_ANDROID)
file(READ "${SOURCE_PATH}/CMakeLists.txt" _matsdk_root_cmake)
Expand Down Expand Up @@ -131,6 +139,7 @@ vcpkg_cmake_configure(
-DBUILD_VERSION=${VERSION}
-DBUILD_APPLE_HTTP=${MATSDK_BUILD_APPLE_HTTP}
-DBUILD_IOS=${MATSDK_BUILD_IOS}
${MATSDK_APPLE_DEPLOYMENT_OPTIONS}
)

vcpkg_cmake_install()
Expand Down
Loading