diff --git a/Makefile b/Makefile index 255237a3..1e910fbf 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,7 @@ BUILD_DIR ?= out UNAME_S := $(shell uname -s) UNAME_M := $(shell uname -m) ifeq ($(UNAME_S),Darwin) -BUILD_TYPES := macosdebug macosrelease +BUILD_TYPES := macosdebug macosrelease iosdebug iosrelease else BUILD_TYPES := debug release windebug winrelease androiddebug androidrelease androiddebug-x86 androidrelease-x86 androiddebug-x86_64 androidrelease-x86_64 androiddebug-armv7a androidrelease-armv7a endif @@ -59,10 +59,14 @@ WINDOWS_TARGETS := \ MACOS_TARGETS := \ out/macosdebug/tildefriends \ out/macosrelease/tildefriends +IOS_TARGETS := \ + out/iosdebug/tildefriends \ + out/iosrelease/tildefriends DEBUG_TARGETS := \ out/debug/tildefriends \ out/windebug/tildefriends.exe \ + out/iosdebug/tildefriends \ out/macosdebug/tildefriends \ out/androiddebug/tildefriends \ out/androiddebug-armv7a/tildefriends \ @@ -71,6 +75,7 @@ DEBUG_TARGETS := \ RELEASE_TARGETS := \ out/release/tildefriends \ out/winrelease/tildefriends.exe \ + out/iosrelease/tildefriends \ out/macosrelease/tildefriends \ out/androidrelease/tildefriends \ out/androidrelease-armv7a/tildefriends \ @@ -79,7 +84,7 @@ RELEASE_TARGETS := \ ANDROID_RELEASE_TARGETS := $(filter-out $(DEBUG_TARGETS),$(ANDROID_TARGETS)) NONANDROID_RELEASE_TARGETS := $(filter-out $(ANDROID_ARM64_TARGETS),$(RELEASE_TARGETS)) NONANDROID_TARGETS := $(filter-out $(ANDROID_TARGETS),$(DEBUG_TARGETS) $(RELEASE_TARGETS)) -NONMACOS_TARGETS := $(filter-out $(MACOS_TARGETS),$(DEBUG_TARGETS) $(RELEASE_TARGETS)) +NONMACOS_TARGETS := $(filter-out $(MACOS_TARGETS) $(IOS_TARGETS),$(DEBUG_TARGETS) $(RELEASE_TARGETS)) $(NONANDROID_TARGETS): CFLAGS += -fno-omit-frame-pointer $(filter-out $(ANDROID_TARGETS) $(WINDOWS_TARGETS),$(DEBUG_TARGETS) $(RELEASE_TARGETS)): LDFLAGS += -rdynamic @@ -107,6 +112,9 @@ $(WINDOWS_TARGETS): LDFLAGS += \ -lm \ -Ldeps/openssl/mingw64/lib $(MACOS_TARGETS): CC = xcrun clang +IOS_SYSROOT := $(shell xcrun --sdk iphoneos --show-sdk-path) +$(info $(IOS_SYSROOT)) +$(IOS_TARGETS): CC = xcrun --sdk iphoneos clang -isysroot $(IOS_SYSROOT) -arch arm64 $(ANDROID_X86_64_TARGETS): ANDROID_NDK_TARGET_TRIPLE := x86_64-linux-android $(ANDROID_X86_TARGETS): ANDROID_NDK_TARGET_TRIPLE := i686-linux-android $(ANDROID_ARMV7A_TARGETS): ANDROID_NDK_TARGET_TRIPLE := armv7a-linux-androideabi @@ -127,6 +135,8 @@ $(ANDROID_X86_64_TARGETS): CFLAGS += -Ideps/openssl/android/x86_64/usr/local/inc $(ANDROID_X86_64_TARGETS): LDFLAGS += -Ldeps/openssl/android/x86_64/usr/local/lib $(NONMACOS_TARGETS): CFLAGS += -Wno-cast-function-type $(NONMACOS_TARGETS): LDFLAGS += -Wl,--gc-sections +$(IOS_TARGETS): CFLAGS += -Ideps/openssl/ios/ios64-xcrun/usr/local/include +$(IOS_TARGETS): LDFLAGS += -Ldeps/openssl/ios/ios64-xcrun/usr/local/lib ifeq ($(UNAME_M),x86_64) debug: CFLAGS += -fsanitize=address -fsanitize=undefined -fno-common @@ -139,7 +149,7 @@ get_objs = \ $(foreach build_type,windebug winrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_win))))) \ $(foreach build_type,androiddebug androidrelease androiddebug-x86 androidrelease-x86 androiddebug-x86_64 androidrelease-x86_64 androiddebug-armv7a androiddebug-armv7a,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_android))))) \ $(foreach build_type,androiddebug androidrelease androiddebug-x86 androidrelease-x86 androiddebug-x86_64 androidrelease-x86_64 androiddebug-armv7a androidrelease-armv7a,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_unix))))) \ - $(foreach build_type,macosdebug macosrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_macos))))) \ + $(foreach build_type,macosdebug macosrelease iosdebug iosrelease,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_macos))))) \ $(foreach build_type,androiddebug-x86 androidrelease-x86,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_x86))))) APP_SOURCES := $(wildcard src/*.c) @@ -161,7 +171,7 @@ $(APP_OBJS): CFLAGS += \ -Wdouble-promotion \ -Werror ifeq ($(UNAME_M),x86_64) -$(filter-out $(BUILD_DIR)/android% $(BUILD_DIR)/macos%,$(APP_OBJS)): CFLAGS += \ +$(filter-out $(BUILD_DIR)/android% $(BUILD_DIR)/macos% $(BUILD_DIR)/ios%,$(APP_OBJS)): CFLAGS += \ -fanalyzer endif @@ -463,7 +473,7 @@ $(MINIUNZIP_OBJS): CFLAGS += \ LDFLAGS += \ -pthread \ -lm -debug release $(MACOS_TARGETS): LDFLAGS += \ +debug release $(MACOS_TARGETS) $(IOS_TARGETS): LDFLAGS += \ -ldl \ -lssl \ -lcrypto diff --git a/src/bcrypt.js.c b/src/bcrypt.js.c index f4921d9a..2e59793a 100644 --- a/src/bcrypt.js.c +++ b/src/bcrypt.js.c @@ -8,6 +8,13 @@ #define WIN32_LEAN_AND_MEAN #include extern BOOLEAN NTAPI SystemFunction036(PVOID Buffer, ULONG BufferLength); +#elif __APPLE__ +#include +#if TARGET_OS_IPHONE +#include +#else +#include +#endif #else #include #endif @@ -44,7 +51,9 @@ JSValue _crypt_gensalt(JSContext* context, JSValueConst this_val, int argc, JSVa char buffer[16]; #if defined(_WIN32) ssize_t bytes = SystemFunction036(buffer, sizeof(buffer)) ? sizeof(buffer) : 0; -#elif defined(__APPLE__) +#elif defined(__APPLE__) && TARGET_OS_IPHONE + ssize_t bytes = CCRandomGenerateBytes(buffer, sizeof(buffer)) == kCCSuccess ? sizeof(buffer) : 0; +#elif defined(__APPLE__) && !TARGET_OS_IPHONE ssize_t bytes = 0; if (getentropy(buffer, sizeof(buffer)) == 0) { diff --git a/src/tests.c b/src/tests.c index 36a7744b..9afaf817 100644 --- a/src/tests.c +++ b/src/tests.c @@ -16,6 +16,11 @@ #define WEXITSTATUS(x) (x) #endif +#if defined(__APPLE__) +#include +#endif + +#if !TARGET_OS_IPHONE static void _test_nop(const tf_test_options_t* options) { FILE* file = fopen("out/test.js", "w"); @@ -692,9 +697,11 @@ static void _tf_test_run(const tf_test_options_t* options, const char* name, voi #undef RESET } } +#endif void tf_tests(const tf_test_options_t* options) { +#if !TARGET_OS_IPHONE _tf_test_run(options, "ssb", tf_ssb_test_ssb, false); _tf_test_run(options, "ssb_id", tf_ssb_test_id_conversion, false); _tf_test_run(options, "ssb_following", tf_ssb_test_following, false); @@ -719,4 +726,5 @@ void tf_tests(const tf_test_options_t* options) _tf_test_run(options, "bench", tf_ssb_test_bench, false); _tf_test_run(options, "go-ssb-room", tf_ssb_test_go_ssb_room, true); tf_printf("Tests completed.\n"); +#endif } diff --git a/tools/ssl-ios b/tools/ssl-ios new file mode 100755 index 00000000..43352425 --- /dev/null +++ b/tools/ssl-ios @@ -0,0 +1,64 @@ +#!/bin/sh + +OPENSSL_VERSION=3.1.3 + +API_LEVEL=28 + +BUILD_DIR=out/openssl_ios_build + +BUILD_TARGETS="ios64-xcrun" + +rm -rfv openssl-${OPENSSL_VERSION} + +if [ ! -d openssl-${OPENSSL_VERSION} ] +then + if [ ! -f openssl-${OPENSSL_VERSION}.tar.gz ] + then + curl https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz -o openssl-${OPENSSL_VERSION}.tar.gz || exit 128 + fi + tar xzf openssl-${OPENSSL_VERSION}.tar.gz || exit 128 +fi +WORK_DIR=openssl-${OPENSSL_VERSION} + +##### export ndk directory. Required by openssl-build-scripts ##### + +##### build-function ##### +build_the_thing() { + export PATH=$TOOLCHAIN/$TRIBLE/bin:$TOOLCHAIN/bin:$PATH + echo $PATH + echo "./Configure $SSL_TARGET $OPTIONS" && \ + ./Configure $SSL_TARGET $OPTIONS no-tests && \ + make clean && \ + make build_generated && \ + make libcrypto.a libssl.a || exit 128 +} + +##### set variables according to build-tagret ##### +for build_target in $BUILD_TARGETS +do + echo "Building $build_target" + cd $WORK_DIR || exit 128 + + case $build_target in + ios64-xcrun) + TRIBLE="arm64-darwin-ios" + OPTIONS="--static -static -ffunction-sections -fdata-sections -fPIC -Wno-macro-redefined" + DESTDIR="/tmp/$BUILD_DIR/arm64-ios" + SSL_TARGET="ios64-xcrun" + CC=clang + ;; + esac + + rm -rf $DESTDIR + build_the_thing + cd .. +#### copy libraries and includes to output-directory ##### + echo WORK_DIR=$WORK_DIR + rm -rf deps/openssl/ios/$build_target/ + mkdir -p deps/openssl/ios/$build_target/usr/local/include + mkdir -p deps/openssl/ios/$build_target/usr/local/lib/ + cp -R $WORK_DIR/include/* deps/openssl/ios/$build_target/usr/local/include/ + cp $WORK_DIR/*.a deps/openssl/ios/$build_target/usr/local/lib/ +done + +echo Success