From 15c9f8f458669ebe19c86727df3c16427bef4260 Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Mon, 25 Mar 2024 13:50:17 -0400 Subject: [PATCH] Rudimentary support for building the executable with data attached. Pushed some things around in the makefile to fix issues along the way. #46 --- GNUmakefile | 40 +++++++++++++++++++++++----------------- src/file.js.c | 4 +++- src/main.c | 1 + src/task.c | 5 +++++ 4 files changed, 32 insertions(+), 18 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 563aba73..90e08d74 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -17,18 +17,6 @@ UNAME_M := $(shell uname -m) ANDROID_SDK ?= ~/Android/Sdk -ifeq ($(UNAME_M),x86_64) -ifneq ($(UNAME_S),Haiku) -debug: CFLAGS += -fsanitize=address -fsanitize=undefined -fno-common -debug: LDFLAGS += -fsanitize=address -fsanitize=undefined -endif -endif - -ifeq ($(UNAME_M),aarch64) -debug: CFLAGS += -fsanitize=address -fsanitize=undefined -fno-common -debug: LDFLAGS += -fsanitize=address -fsanitize=undefined -endif - ifeq ($(UNAME_S),Darwin) BUILD_TYPES := macosdebug macosrelease iosdebug iosrelease iossimdebug iossimrelease else ifeq ($(UNAME_S),Linux) @@ -222,6 +210,18 @@ $(IOS_TARGETS): LDFLAGS += -Ldeps/openssl/ios/ios64-xcrun/usr/local/lib $(IOSSIM_TARGETS): CFLAGS += -Ideps/openssl/ios/iossimulator-xcrun/usr/local/include $(IOSSIM_TARGETS): LDFLAGS += -Ldeps/openssl/ios/iossimulator-xcrun/usr/local/lib +ifeq ($(UNAME_M),x86_64) +ifneq ($(UNAME_S),Haiku) +out/debug/tildefriends: CFLAGS += -fsanitize=address -fsanitize=undefined -fno-common +out/debug/tildefriends: LDFLAGS += -fsanitize=address -fsanitize=undefined +endif +endif + +ifeq ($(UNAME_M),aarch64) +out/debug/tildefriends: CFLAGS += -fsanitize=address -fsanitize=undefined -fno-common +out/debug/tildefriends: LDFLAGS += -fsanitize=address -fsanitize=undefined +endif + get_objs = \ $(foreach build_type,$(BUILD_TYPES),$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)))))) \ $(foreach build_type,debug release,$(addprefix $(BUILD_DIR)/$(build_type)/,$(addsuffix .o,$(basename $(value $(1)_unix))))) \ @@ -578,7 +578,7 @@ $(MINIUNZIP_OBJS): CFLAGS += \ LDFLAGS += \ -pthread \ -lm -debug release $(MACOS_TARGETS) $(IOS_TARGETS) $(IOSSIM_TARGETS): LDFLAGS += \ +$(LINUX_TARGETS) $(MACOS_TARGETS) $(IOS_TARGETS) $(IOSSIM_TARGETS): LDFLAGS += \ -lssl \ -lcrypto ifneq ($(UNAME_S),Haiku) @@ -728,7 +728,7 @@ out/apk/TildeFriends-arm-%.unsigned.apk: @cp out/apk/res.apk $@.zip @cp out/apk/classes.dex out/apk-arm-$(BUILD_TYPE)/ @cd out/apk-arm-$(BUILD_TYPE) && zip -u ../../$@.zip -q -9 -r . && cd ../../ - @zip -u $@.zip -q $(RAW_FILES) + @zip -u $@.zip -q -9 $(RAW_FILES) @$(ANDROID_BUILD_TOOLS)/zipalign -f 4 $@.zip $@ out/apk/TildeFriends-x86-%.unsigned.apk: @@ -741,7 +741,7 @@ out/apk/TildeFriends-x86-%.unsigned.apk: @cp out/apk/res.apk $@.zip @cp out/apk/classes.dex out/apk-x86-$(BUILD_TYPE)/ @cd out/apk-x86-$(BUILD_TYPE) && zip -u ../../$@.zip -q -9 -r . && cd ../../ - @zip -u $@.zip -q $(RAW_FILES) + @zip -u $@.zip -q -9 $(RAW_FILES) @$(ANDROID_BUILD_TOOLS)/zipalign -f 4 $@.zip $@ out/%.apk: out/apk/%.unsigned.apk @@ -769,10 +769,10 @@ out/%.app/tildefriends.png: src/ios/tildefriends.png @mkdir -p $(dir $@) @cp -v $< $@ -out/%/data.zip: $(RAW_FILES) +out/data.zip: $(RAW_FILES) @zip -u $@ -q -9 $(RAW_FILES) -out/tildefriends-%.app/tildefriends: out/%/tildefriends out/tildefriends-%.app/Info.plist out/tildefriends-%.app/tildefriends.png out/tildefriends-%.app/data.zip +out/tildefriends-%.app/tildefriends: out/%/tildefriends out/tildefriends-%.app/Info.plist out/tildefriends-%.app/tildefriends.png out/data.zip @mkdir -p $(dir $@) @cp -v $< $@ ifeq ($(HAVE_LINUX_IOS),1) @@ -787,6 +787,12 @@ out/tildefriends-%.ipa: out/tildefriends-ios%.app/tildefriends @cd $@.tmp/ && zip -u ../../$@ -q -9 -r ./ @rm -rf $@.tmp/ + +out/%/tildefriends.standalone: out/%/tildefriends out/data.zip + @echo "[standalone] $@" + @cat $< out/data.zip > $@ + @chmod +x $@ + iossimdebug-app: out/tildefriends-iossimdebug.app/tildefriends iossimrelease-app: out/tildefriends-iossimrelease.app/tildefriends iosdebug-app: out/tildefriends-iosdebug.app/tildefriends diff --git a/src/file.js.c b/src/file.js.c index a49a325f..795e50be 100644 --- a/src/file.js.c +++ b/src/file.js.c @@ -316,7 +316,9 @@ static void _file_read_file_zip_after_work(uv_work_t* work, int status) tf_trace_begin(trace, "file_read_zip_after_work"); if (data->result >= 0) { - tf_task_resolve_promise(data->task, data->promise, tf_util_new_uint8_array(data->context, data->buffer, data->result)); + JSValue array = tf_util_new_uint8_array(data->context, data->buffer, data->result); + tf_task_resolve_promise(data->task, data->promise, array); + JS_FreeValue(data->context, array); } else { diff --git a/src/main.c b/src/main.c index 486aeb26..f82d7a67 100644 --- a/src/main.c +++ b/src/main.c @@ -412,6 +412,7 @@ static int _tf_command_run(const char* file, int argc, char* argv[]) .http_port = 12345, .https_port = 12346, .ssb_port = 8008, + .zip = file, .db_path = k_db_path_default, }; bool show_usage = false; diff --git a/src/task.c b/src/task.c index 0e76a712..ba657663 100644 --- a/src/task.c +++ b/src/task.c @@ -1939,6 +1939,11 @@ void tf_task_destroy(tf_task_t* task) tf_free(task->_promise_stacks); tf_free((void*)task->_path); bool was_trusted = task->_trusted; + if (task->_zip) + { + unzClose(task->_zip); + task->_zip = NULL; + } tf_free(task); if (was_trusted) {