From 757da06c6419a0657e2f6542bb1a36e9949b2069 Mon Sep 17 00:00:00 2001 From: Subhaditya Nath Date: Mon, 28 Mar 2022 19:49:52 +0530 Subject: [PATCH 1/2] mongoose: update to 7.6 --- srcpkgs/mongoose/patches/add-makefile.patch | 50 ----------------- srcpkgs/mongoose/patches/fix-makefile.patch | 59 +++++++++++++++++++++ srcpkgs/mongoose/patches/fix-tests.patch | 17 ++++++ srcpkgs/mongoose/template | 41 +++++++++++--- 4 files changed, 109 insertions(+), 58 deletions(-) delete mode 100644 srcpkgs/mongoose/patches/add-makefile.patch create mode 100644 srcpkgs/mongoose/patches/fix-makefile.patch create mode 100644 srcpkgs/mongoose/patches/fix-tests.patch diff --git a/srcpkgs/mongoose/patches/add-makefile.patch b/srcpkgs/mongoose/patches/add-makefile.patch deleted file mode 100644 index fd0b21095472..000000000000 --- a/srcpkgs/mongoose/patches/add-makefile.patch +++ /dev/null @@ -1,50 +0,0 @@ ---- /dev/null -+++ b/Makefile -@@ -0,0 +1,47 @@ -+PROG = mongoose -+LIB = lib$(PROG).so.0 -+ -+ifndef PREFIX -+ PREFIX=/usr/local -+endif -+ -+ifndef DOCDIR -+ DOCDIR=$(PREFIX)/share/$(PROG)/doc -+endif -+ -+CPPFLAGS+=-DMONGOOSE_ENABLE_THREADS -DMG_ENABLE_SSL -+CFLAGS+=-fPIC -c -Wall -+LDFLAGS+=-shared -lssl -pthread -lcrypto -+ -+SRCS=mongoose.c -+OBJS=mongoose.o -+INCLUDE=. -+ -+all: $(LIB) -+ -+$(LIB): $(OBJS) -+ $(CC) $(OBJS) $(LDFLAGS) -o $(LIB) -+ -+$(OBJS): $(SRCS) -+ $(CC) $(CPPFLAGS) $(CFLAGS) -I$(INCLUDE) $(SRCS) -o $(OBJS) -+ -+install: -+ install -d $(DESTDIR)$(PREFIX)/include -+ install -m644 mongoose.h $(DESTDIR)$(PREFIX)/include -+ install -d $(DESTDIR)$(PREFIX)/lib -+ ln -sf $(LIB) $(LIB).0; cp -a $(LIB).0 $(DESTDIR)$(PREFIX)/lib -+ ln -sf $(LIB) libmongoose.so; cp -a libmongoose.so $(DESTDIR)$(PREFIX)/lib -+ install -m755 $(LIB) $(DESTDIR)$(PREFIX)/lib -+ install -dm755 $(DESTDIR)$(DOCDIR) -+ cp -a examples $(DESTDIR)$(DOCDIR) -+ cp -a docs/* $(DESTDIR)$(DOCDIR)/ -+ -+ -+test: -+ $(MAKE) -C test/ -+clean: -+ rm -f $(OBJS) $(LIB) -+ $(MAKE) -C test/ clean -+ -+.PHONY: clean test all -+ diff --git a/srcpkgs/mongoose/patches/fix-makefile.patch b/srcpkgs/mongoose/patches/fix-makefile.patch new file mode 100644 index 000000000000..d829ea8adc8c --- /dev/null +++ b/srcpkgs/mongoose/patches/fix-makefile.patch @@ -0,0 +1,59 @@ +--- a/Makefile ++++ b/Makefile +@@ -5,5 +5,5 @@ SRCS = mongoose.c test/unit_test.c test/packed_fs.c + OPTS ?= -O3 -g3 + INCS ?= -Isrc -I. +-CFLAGS ?= $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) $(EXTRA) ++CFLAGS := $(OPTS) $(WARN) $(INCS) $(DEFS) $(TFLAGS) $(CFLAGS) + SSL ?= MBEDTLS + CWD ?= $(realpath $(CURDIR)) +@@ -10,6 +10,9 @@ CWD ?= $(realpath $(CURDIR)) + DOCKER ?= docker run --rm -e Tmp=. -e WINEDEBUG=-all -v $(CWD):$(CWD) -w $(CWD) + VCFLAGS = /nologo /W3 /O2 /I. $(DEFS) $(TFLAGS) + IPV6 ?= 1 ++ifneq "$(NO_SANITIZE)" "1" ++SANITIZE = -fsanitize=address,undefined ++endif + ASAN_OPTIONS ?= + EXAMPLES := $(wildcard examples/*) + PREFIX ?= /usr/local +@@ -19,12 +22,12 @@ VERSION ?= $(shell cut -d'"' -f2 src/version.h) + ifeq "$(SSL)" "MBEDTLS" + MBEDTLS ?= /usr + CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLS)/include -I/usr/include +-LDFLAGS ?= -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509 ++LDFLAGS += -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509 + endif + ifeq "$(SSL)" "OPENSSL" + OPENSSL ?= /usr + CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL)/include +-LDFLAGS ?= -L$(OPENSSL)/lib -lssl -lcrypto ++LDFLAGS += -L$(OPENSSL)/lib -lssl -lcrypto + endif + + all: mg_prefix unamalgamated unpacked test test++ arm examples vc98 vc2017 mingw mingw++ linux linux++ fuzz +@@ -59,7 +62,7 @@ fuzz: fuzzer + $(RUN) ./fuzzer + + # make CC=/usr/local/opt/llvm\@8/bin/clang ASAN_OPTIONS=detect_leaks=1 +-test: CFLAGS += -DMG_ENABLE_IPV6=$(IPV6) -fsanitize=address,undefined ++test: CFLAGS += -DMG_ENABLE_IPV6=$(IPV6) $(SANITIZE) + test: mongoose.h Makefile $(SRCS) + $(CC) $(SRCS) $(CFLAGS) -coverage $(LDFLAGS) -g -o unit_test + ASAN_OPTIONS=$(ASAN_OPTIONS) $(RUN) ./unit_test +@@ -108,10 +111,12 @@ linux++: CC = g++ + linux++: WARN += -Wno-missing-field-initializers + linux++: linux + +-linux-libs: CFLAGS += -fPIC +-linux-libs: mongoose.o +- $(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION) ++.PHONY: linux-libs ++linux-libs: libmongoose.a libmongoose.so.$(VERSION) ++libmongoose.a: mongoose.o + $(AR) rcs libmongoose.a mongoose.o ++libmongoose.so.$(VERSION): mongoose.o ++ $(CC) mongoose.o $(LDFLAGS) -shared -o libmongoose.so.$(VERSION) + + install: linux-libs + install -Dm644 libmongoose.a libmongoose.so.$(VERSION) $(DESTDIR)$(PREFIX)/lib diff --git a/srcpkgs/mongoose/patches/fix-tests.patch b/srcpkgs/mongoose/patches/fix-tests.patch new file mode 100644 index 000000000000..8b25527492d5 --- /dev/null +++ b/srcpkgs/mongoose/patches/fix-tests.patch @@ -0,0 +1,17 @@ +Skip tests that want to connect to the internet + +--- a/test/unit_test.c ++++ b/test/unit_test.c +@@ -1680,11 +1562,9 @@ int main(void) { + test_ws(); + test_ws_fragmentation(); + test_http_server(); +- test_http_client(); + test_http_no_content_length(); + test_http_pipeline(); + test_http_range(); +- test_mqtt(); + printf("SUCCESS. Total tests: %d\n", s_num_tests); + return EXIT_SUCCESS; + } + diff --git a/srcpkgs/mongoose/template b/srcpkgs/mongoose/template index eddadc647333..c9e41c4f7a2e 100644 --- a/srcpkgs/mongoose/template +++ b/srcpkgs/mongoose/template @@ -1,22 +1,45 @@ # Template file for 'mongoose' pkgname=mongoose -version=6.18 -revision=4 +version=7.6 +revision=1 build_style=gnu-makefile -make_use_env=compliant +make_use_env=yes +make_check_target=test +make_build_target=linux-libs makedepends="openssl-devel" -short_desc="Easy to use Web server" -maintainer="Orphaned " +checkdepends="openssl-devel" +short_desc="Embedded Networking Library for TCP,UDP,HTTP,MQTT,WebSocket and SSL/TLS" +maintainer="Subhaditya Nath " license="GPL-2.0-only" -homepage="https://cesanta.com/" +homepage="https://mongoose.ws/" distfiles="https://github.com/cesanta/mongoose/archive/${version}.tar.gz" -checksum=f5c10346abc9c72f7cac7885d853ca064fb09aad57580433941a8fd7a3543769 +checksum=1ef09d971b6de1a6317c109980d6fb5a9c19b39efef2506d6b76869644b3dafa + +export SSL=OPENSSL +CFLAGS+=" -fPIC" + +case "$XBPS_TARGET_MACHINE" in + *-musl) CFLAGS+=" -Wno-error=sign-conversion" # FD(c_) macro is broken + make_check_args+=" NO_SANITIZE=1" ;; # libsanitizer-devel unavailable + *) checkdepends+=" libsanitizer-devel" ;; +esac + +# GitHub CI runner doesn't support IPv6, causing tests to fail +if [ "$XBPS_BUILD_ENVIRONMENT" = "void-packages-ci" ]; then + make_check_args+=" IPV6=0" +fi + +pre_check() { + # -Wunused-function -Werror and fix-tests.patch are enemies + CFLAGS+=" -Wno-error=unused-function" +} mongoose-devel_package() { depends="${sourcepkg}>=${version}_${revision}" short_desc+=" - development files" pkg_install() { vmove usr/include + vmove "usr/lib/*.a" vmove "usr/lib/*.so" } } @@ -24,6 +47,8 @@ mongoose-devel_package() { mongoose-doc_package() { short_desc+=" - documentation" pkg_install() { - vmove usr/share + vmkdir "usr/share/${sourcepkg}/doc" + vcopy examples "usr/share/${sourcepkg}/doc" + vcopy "docs/*" "usr/share/${sourcepkg}/doc" } } From c8fdf1f8a63dba8462754977a9f02323e9f4c419 Mon Sep 17 00:00:00 2001 From: Subhaditya Nath Date: Wed, 30 Mar 2022 20:41:15 +0530 Subject: [PATCH 2/2] TEMP --- srcpkgs/mongoose/template | 41 ++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/srcpkgs/mongoose/template b/srcpkgs/mongoose/template index c9e41c4f7a2e..6d1797315cc9 100644 --- a/srcpkgs/mongoose/template +++ b/srcpkgs/mongoose/template @@ -18,17 +18,48 @@ checksum=1ef09d971b6de1a6317c109980d6fb5a9c19b39efef2506d6b76869644b3dafa export SSL=OPENSSL CFLAGS+=" -fPIC" -case "$XBPS_TARGET_MACHINE" in - *-musl) CFLAGS+=" -Wno-error=sign-conversion" # FD(c_) macro is broken - make_check_args+=" NO_SANITIZE=1" ;; # libsanitizer-devel unavailable - *) checkdepends+=" libsanitizer-devel" ;; -esac +if [ "$XBPS_TARGET_LIBC" = musl ]; then + # libsanitizer-devel is currenly not available on musl + make_check_args+=" NO_SANITIZE=1" +else + checkdepends+=" libsanitizer-devel" +fi # GitHub CI runner doesn't support IPv6, causing tests to fail if [ "$XBPS_BUILD_ENVIRONMENT" = "void-packages-ci" ]; then make_check_args+=" IPV6=0" fi +post_extract() { + if [ "$XBPS_TARGET_LIBC" = musl ]; then + # GCC falsely flags musl's FD_{SET,ISSET,CLR} macros as -Wsign-conversion + # https://github.com/cesanta/mongoose/issues/1501#issuecomment-1082750154 + # https://inbox.vuxu.org/musl/20200803174707.GF6949@brightrain.aerifal.cx/T/ + vsed -i src/sock.c -e ' +/[[:space:]]FD_SET(/b label +/[[:space:]]FD_ISSET(/b label +/[[:space:]]FD_CLR(/b label +b +:label +i\ +#pragma GCC diagnostic push\ +#pragma GCC diagnostic ignored "-Wsign-conversion" +p +i\ +#pragma GCC diagnostic pop +d' + # What the above sed script does - + # Searches for FD_{SET,ISSET,CLR} + # - If found, jump to the line after :label + # - If not found, go to the end of the script (print current line as-is) + # :label + # - [i] Insert the two #pragma lines + # - [p] Insert the current line + # - [i] Insert the remaining #pragma line + # - [d] Proceed to the next line of input + fi +} + pre_check() { # -Wunused-function -Werror and fix-tests.patch are enemies CFLAGS+=" -Wno-error=unused-function"