Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for apple watch / watchos #192

Open
VityaSchel opened this issue Mar 13, 2024 · 5 comments
Open

Add support for apple watch / watchos #192

VityaSchel opened this issue Mar 13, 2024 · 5 comments

Comments

@VityaSchel
Copy link

No description provided.

@VityaSchel
Copy link
Author

why

@VityaSchel
Copy link
Author

why even visionos but no watchos

@VityaSchel
Copy link
Author

wow even tvos

I surely think someone uses openssl on tv I literally can imagine how you open your pentium tv and generate pgp crypto keys on it for watching youtube

@VityaSchel
Copy link
Author

I'll briefly describe steps for future reference:

  1. add build_watchos function to scripts/build.sh with call in the end of this script
build_watchos() {
   local TMP_BUILD_DIR=$( mktemp -d )

   # Clean up whatever was left from our previous build
   rm -rf "${SCRIPT_DIR}"/../{watchsimulator/include,watchsimulator/lib}
   mkdir -p "${SCRIPT_DIR}"/../{watchsimulator/include,watchsimulator/lib}

   build "x86_64" "WatchSimulator" ${TMP_BUILD_DIR} "watchsimulator"
   build "arm64" "WatchSimulator" ${TMP_BUILD_DIR} "watchsimulator"

   rm -rf "${SCRIPT_DIR}"/../{watchos/include,watchos/lib}
   mkdir -p "${SCRIPT_DIR}"/../{watchos/include,watchos/lib}

   build "arm64" "WatchOS" ${TMP_BUILD_DIR} "watchos"

   ditto "${TMP_BUILD_DIR}/${OPENSSL_VERSION}-WatchOS-arm64/include/openssl" "${SCRIPT_DIR}/../watchos/include/${FWNAME}"
   cp -f "${SCRIPT_DIR}/../shim/shim.h" "${SCRIPT_DIR}/../watchos/include/${FWNAME}/shim.h"

   # Copy headers
   ditto "${TMP_BUILD_DIR}/${OPENSSL_VERSION}-WatchSimulator-arm64/include/openssl" "${SCRIPT_DIR}/../watchsimulator/include/${FWNAME}"
   cp -f "${SCRIPT_DIR}/../shim/shim.h" "${SCRIPT_DIR}/../watchsimulator/include/${FWNAME}/shim.h"

   # fix inttypes.h
   # find "${SCRIPT_DIR}/../appletvos/include/${FWNAME}" -type f -name "*.h" -exec sed -i "" -e "s/include <inttypes\.h>/include <sys\/types\.h>/g" {} \;
   # find "${SCRIPT_DIR}/../appletvsimulator/include/${FWNAME}" -type f -name "*.h" -exec sed -i "" -e "s/include <inttypes\.h>/include <sys\/types\.h>/g" {} \;

   local OPENSSLCONF_PATH="${SCRIPT_DIR}/../watchsimulator/include/${FWNAME}/opensslconf.h"
   echo "#if defined(__APPLE__) && defined (__x86_64__)" >> ${OPENSSLCONF_PATH}
   cat ${TMP_BUILD_DIR}/${OPENSSL_VERSION}-WatchSimulator-x86_64/include/openssl/opensslconf.h >> ${OPENSSLCONF_PATH}

   echo "#elif defined(__APPLE__) && defined (__arm64__)" >> ${OPENSSLCONF_PATH}
   cat ${TMP_BUILD_DIR}/${OPENSSL_VERSION}-WatchSimulator-arm64/include/openssl/opensslconf.h >> ${OPENSSLCONF_PATH}
   echo "#endif" >> ${OPENSSLCONF_PATH}

   OPENSSLCONF_PATH="${SCRIPT_DIR}/../watchos/include/${FWNAME}/opensslconf.h"
   echo "#if defined(__APPLE__) && defined (__x86_64__)" >> ${OPENSSLCONF_PATH}
   
   echo "#elif defined(__APPLE__) && defined (__arm64__)" >> ${OPENSSLCONF_PATH}
   cat ${TMP_BUILD_DIR}/${OPENSSL_VERSION}-WatchOS-arm64/include/openssl/opensslconf.h >> ${OPENSSLCONF_PATH}
   echo "#endif" >> ${OPENSSLCONF_PATH}
   
   # Update include "openssl/" to "OpenSSL/"
   grep -rl '#\s*include\s*<openssl' --include \*.h ${SCRIPT_DIR}/../watchos/include | xargs -I@ sed -i '' -e 's/#[[:space:]]*include[[:space:]]*<openssl/#include <OpenSSL/gi' @
   grep -rl '#\s*include\s*<openssl' --include \*.h ${SCRIPT_DIR}/../watchsimulator/include | xargs -I@ sed -i '' -e 's/#[[:space:]]*include[[:space:]]*<openssl/#include <OpenSSL/gi' @

   rm -rf ${TMP_BUILD_DIR}
}
  1. add section to scripts/create-frameworks.sh
# watchOS
DERIVED_DATA_PATH=$( mktemp -d )
xcrun xcodebuild build \
	$COMMON_SETUP \
    -scheme "${FWNAME} (watchOS)" \
	-derivedDataPath "${DERIVED_DATA_PATH}" \
	-destination 'generic/platform=watchOS'

rm -rf "${OUTPUT_DIR}/watchos"
mkdir -p "${OUTPUT_DIR}/watchos"
ditto "${DERIVED_DATA_PATH}/Build/Products/Release-watchos/${FWNAME}.framework" "${OUTPUT_DIR}/watchos/${FWNAME}.framework"
rm -rf "${DERIVED_DATA_PATH}"

# watchOS Simulator
DERIVED_DATA_PATH=$( mktemp -d )
xcrun xcodebuild build \
	$COMMON_SETUP \
    -scheme "${FWNAME} (watchOS Simulator)" \
	-derivedDataPath "${DERIVED_DATA_PATH}" \
	-destination 'generic/platform=watchOS Simulator'

rm -rf "${OUTPUT_DIR}/watchsimulator"
mkdir -p "${OUTPUT_DIR}/watchsimulator"
ditto "${DERIVED_DATA_PATH}/Build/Products/Release-watchsimulator/${FWNAME}.framework" "${OUTPUT_DIR}/watchsimulator/${FWNAME}.framework"
rm -rf "${DERIVED_DATA_PATH}"
  1. add configurations to conf/20-apple.conf otherwise you'll get Usage: Configure [no-<cipher> ...] [enable-<cipher> ...] [-Dxxx] [-lxxx] [-Lxxx] [-fxxx] [-Kxxx] [no-hw-xxx|no-hw] [[no-]threads] [[no-]shared] [[no-]zlib|zlib-dynamic] [no-asm] [no-egd] [sctp] [386] [--prefix=DIR] [--openssldir=OPENSSLDIR] [--with-xxx[=vvv]] [--config=FILE] os/compiler[:flags] and pick os/compiler from: and Using os-specific seed configuration
'watchos-cross-base' => {
        template => 1,
        cflags => combine('-isysroot $(CROSS_TOP)/SDKs/$(CROSS_SDK) -fno-common',
            sub { defined($ENV{'WATCHOS_DEPLOYMENT_VERSION'}) ? '-mwatchos-version-min=$(WATCHOS_DEPLOYMENT_VERSION)' : '-mwatchos-version-min=4.0'; }),
        disable => [ 'engine', 'async' ],
        defines => [ "HAVE_FORK=0" ]
    },

    'watchos-sim-cross-base' => {
        inherit_from => [ 'watchos-cross-base' ],
        template => 1,
        cflags => add(sub { defined($ENV{'WATCHOS_DEPLOYMENT_VERSION'}) ? '-mwatchos-simulator-version-min=$(WATCHOS_DEPLOYMENT_VERSION)' : '-mwatchos-simulator-version-min=4.0'; }),
    },

    'watchos-sim-cross-x86_64' => {
        inherit_from => [ 'darwin-common', 'watchos-sim-cross-base' ],
        CC => 'xcrun -sdk watchsimulator cc',
        cflags => add('-arch x86_64'),
        lib_cppflags => add('-DL_ENDIAN'),
        bn_ops => 'SIXTY_FOUR_BIT_LONG',
        sys_id => 'watchOS',
        perlasm_scheme => 'watchos64',
    },

    'watchos-sim-cross-arm64' => {
        inherit_from => [ 'darwin-common', 'watchos-sim-cross-base' ],
        CC => 'xcrun -sdk watchsimulator cc',
        cflags => add('-arch arm64'),
        asm_arch => 'aarch64',
        lib_cppflags => add('-DL_ENDIAN'),
        bn_ops => 'SIXTY_FOUR_BIT_LONG RC4_CHAR',
        perlasm_scheme => 'watchos64',
        sys_id => 'watchOS',
    },

    'watchos-cross-arm64' => {
        inherit_from => [ 'darwin-common', 'watchos-cross-base' ],
        cflags => add('-arch arm64'),
        asm_arch => 'aarch64',
        bn_ops => 'SIXTY_FOUR_BIT_LONG RC4_CHAR',
        lib_cppflags => add('-DL_ENDIAN'),
        perlasm_scheme => 'watchos64',
        sys_id => 'watchOS',
    },

    'watchos-cross-armv7k' => {
        inherit_from => [ 'darwin-common', 'watchos-cross-base' ],
        cflags => add('-arch armv7k'),
        asm_arch => 'arm',
        bn_ops => 'BN_LLONG RC4_INT',
        lib_cppflags => add('-DL_ENDIAN'),
        perlasm_scheme => 'ios32',
        sys_id => 'watchOS',
    },

we're also having defines => [ "HAVE_FORK=0" ] in base config because watchos does not support fork()

then run make and it should create watchos and watchsimulator directories in repo root, after than figure out on your own how to add these to frameworks in xcode project

@krzyzanowskim
Copy link
Owner

There's always a way to make a PR. This may be an inspiration how to make it: #205

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants