From 7213cfdd0644879093ca4b009f748dbacb325601 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Mon, 18 Nov 2024 23:19:59 +0000 Subject: [PATCH] Build ngtcp2/nghttp3 into worker for WebTransport. --- env/cmake.sh | 66 +++++++++++++++++++++++++++++++++++++++++ env/cpu-arm64.mk | 14 --------- env/cpu-x86_64.mk | 15 ---------- env/fnoident.cfg | 1 + env/lnx-arch.sh | 3 +- env/lnx-debian.sh | 3 +- env/meson.sh | 1 + env/output.mk | 7 +++++ env/setup-mac.sh | 3 +- env/target-and.mk | 1 + env/target-any.mk | 20 ++++++++++--- env/target-ios.mk | 2 ++ env/target-lnx.mk | 1 + env/target-mac.mk | 2 ++ env/target-win.mk | 1 + min-boringssl/target.mk | 15 ++++++++++ min-cairo/target.mk | 6 ++-- min-http3/nghttp3.mk | 34 +++++++++++++++++++++ min-http3/ngtcp2 | 2 +- min-http3/ngtcp2.mk | 46 ++++++++++++++++++++++++++++ min-http3/target.mk | 22 ++++++++++++++ min-openssl/target.mk | 7 +++-- srv-worker/http3 | 1 + srv-worker/makefile | 1 + 24 files changed, 232 insertions(+), 42 deletions(-) create mode 100755 env/cmake.sh delete mode 100644 env/cpu-arm64.mk delete mode 100644 env/cpu-x86_64.mk create mode 100644 env/fnoident.cfg create mode 100644 min-http3/nghttp3.mk create mode 100644 min-http3/ngtcp2.mk create mode 100644 min-http3/target.mk create mode 120000 srv-worker/http3 diff --git a/env/cmake.sh b/env/cmake.sh new file mode 100755 index 000000000..1c0b8d5cd --- /dev/null +++ b/env/cmake.sh @@ -0,0 +1,66 @@ +#!/bin/bash +set -e +exec 1>&2 + +arch=${1} +output=${2} +curdir=${3} +meson=${4} +ar=${5} +strip=${6} +windres=${7} +cc=${8} +cxx=${9} +objc=${10} +qflags=${11} +wflags=${12} +xflags=${13} +mflags=${14} +shift 14 + +if [[ $# -ne 0 ]]; then + exit 1 +fi + +meson=(${meson}) + +cc=(${cc}) +cxx=(${cxx}) +objc=(${objc}) + +qflags=(${qflags}) +wflags=(${wflags}) +xflags=(${xflags}) + +mkdir -p "${output}/${arch}" + +cflags=(-I"${curdir}/${output}/${arch}/usr/include") +lflags=(-L"${curdir}/${output}/${arch}/usr/lib") + +cflags+=("${qflags[@]}") + +cfg="${curdir}/${output}/${arch}/cmake.cfg" +echo "${wflags[@]}" >"${curdir}/${output}/${arch}/cmake.cfg" +cfg=(--config "${cfg}") + + +# XXX: I need to set CMAKE_SYSTEM_VERSION +cat >"${output}/${arch}"/cmake.new </dev/null; then + rm -f "${output}/${arch}"/cmake.new +else + mv -f "${output}/${arch}"/cmake.{new,txt} +fi diff --git a/env/cpu-arm64.mk b/env/cpu-arm64.mk deleted file mode 100644 index 0eef4aa33..000000000 --- a/env/cpu-arm64.mk +++ /dev/null @@ -1,14 +0,0 @@ -# Cycc/Cympile - Shared Build Scripts for Make -# Copyright (C) 2013-2020 Jay Freeman (saurik) - -# Zero Clause BSD license {{{ -# -# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# }}} - - -# XXX: this broke ARM iOS/macOS exception handling in coroutines -# XXX: consider using =pac-ret+leaf -#qflags += -mbranch-protection=standard diff --git a/env/cpu-x86_64.mk b/env/cpu-x86_64.mk deleted file mode 100644 index 647c38a49..000000000 --- a/env/cpu-x86_64.mk +++ /dev/null @@ -1,15 +0,0 @@ -# Cycc/Cympile - Shared Build Scripts for Make -# Copyright (C) 2013-2020 Jay Freeman (saurik) - -# Zero Clause BSD license {{{ -# -# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. -# -# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -# }}} - - -ifneq ($(target),win) -# XXX: this breaks libgcrypt due to cet.h being ELF-specific -qflags += -fcf-protection=full -endif diff --git a/env/fnoident.cfg b/env/fnoident.cfg new file mode 100644 index 000000000..96cc31975 --- /dev/null +++ b/env/fnoident.cfg @@ -0,0 +1 @@ +-fno-ident diff --git a/env/lnx-arch.sh b/env/lnx-arch.sh index 9b62eb387..f30bb4e55 100755 --- a/env/lnx-arch.sh +++ b/env/lnx-arch.sh @@ -16,5 +16,6 @@ pacman -Sy \ bison flex gperf \ gettext groff texinfo \ autoconf{,-archive} automake libtool \ - make meson ninja pkgconf \ + make ninja pkgconf \ + cmake meson \ qemu-system-{x86,aarch64} \ diff --git a/env/lnx-debian.sh b/env/lnx-debian.sh index 2f8cc063b..0506d01a7 100755 --- a/env/lnx-debian.sh +++ b/env/lnx-debian.sh @@ -19,7 +19,8 @@ apt-get -y install \ bison flex gperf \ gettext groff texinfo \ autoconf{,-archive} automake libtool \ - make meson ninja-build pkg-config \ + make ninja-build pkg-config \ + cmake meson \ qemu-system-{x86,arm} \ if dpkg --compare-versions $(meson --version) '<<' "1.2.0"; then diff --git a/env/meson.sh b/env/meson.sh index 2a364ac63..64ffec2b6 100755 --- a/env/meson.sh +++ b/env/meson.sh @@ -43,6 +43,7 @@ cfg="${curdir}/${output}/${arch}/meson.cfg" echo "${wflags[@]}" >"${curdir}/${output}/${arch}/meson.cfg" cfg=(--config "${cfg}") + function args() { comma=false for arg in "$@"; do diff --git a/env/output.mk b/env/output.mk index c4ebe3c7c..52b73a009 100644 --- a/env/output.mk +++ b/env/output.mk @@ -112,6 +112,7 @@ export ENV_CURDIR := $(CURDIR) export ENV_OUTPUT := $(output) define _ +$(shell env/cmake.sh $(1) $(output) '$(CURDIR)' '$(cmake) $(meson/$(1))' '$(ar/$(1))' '$(strip/$(1))' '$(windres/$(1))' '$(cc) $(more/$(1))' '$(cxx) $(more/$(1))' '$(objc) $(more/$(1))' '$(qflags)' '$(wflags)' '$(xflags)' '$(mflags)') $(shell env/meson.sh $(1) $(output) '$(CURDIR)' '$(meson) $(meson/$(1))' '$(ar/$(1))' '$(strip/$(1))' '$(windres/$(1))' '$(cc) $(more/$(1))' '$(cxx) $(more/$(1))' '$(objc) $(more/$(1))' '$(qflags)' '$(wflags)' '$(xflags)' '$(mflags)') endef $(each) @@ -134,6 +135,12 @@ $(output)/%/Makefile: $$(specific) $$(folder)/configure $(sysroot) $$(call head, --enable-static --disable-shared $(subst =@/,=$(CURDIR)/$(output)/$(arch)/,$(w_$(subst -,_,$(notdir $(patsubst %/configure,%,$<))))) cd $(dir $@); $(m_$(subst -,_,$(notdir $(patsubst %/configure,%,$<)))) +$(output)/%/cmake/Makefile: $$(specific) $$(folder)/CMakeLists.txt $(output)/$$(arch)/cmake.txt $(sysroot) $$(call head,$$(folder)) + $(specific) + @rm -rf $(dir $@) + @mkdir -p $(dir $@) + cmake -S$(dir $<) --toolchain $(CURDIR)/$(output)/$(arch)/cmake.txt -B$(dir $@) -DCMAKE_BUILD_TYPE=Release + $(output)/%/build.ninja: $$(specific) $$(folder)/meson.build $(output)/$$(arch)/meson.txt $(sysroot) $$(call head,$$(folder)) $(output)/$$(arch)/usr/bin/pkg-config $(specific) @rm -rf $(dir $@) diff --git a/env/setup-mac.sh b/env/setup-mac.sh index 6ee678936..a4243014e 100755 --- a/env/setup-mac.sh +++ b/env/setup-mac.sh @@ -12,7 +12,8 @@ brew install \ python-packaging \ groff \ autoconf{,-archive} automake libtool \ - make meson ninja pkg-config \ + make ninja pkg-config \ + cmake meson \ rustup-init \ rustup-init -y --no-modify-path --no-update-default-toolchain diff --git a/env/target-and.mk b/env/target-and.mk index 3aacfdf7b..bdf68757f 100644 --- a/env/target-and.mk +++ b/env/target-and.mk @@ -15,6 +15,7 @@ lib := a exe := meson := linux +cmake += Android archs += armeabi-v7a openssl/armeabi-v7a := android-arm diff --git a/env/target-any.mk b/env/target-any.mk index 2c241aebd..bf0ac1ea0 100644 --- a/env/target-any.mk +++ b/env/target-any.mk @@ -102,6 +102,7 @@ else zflags := -0 endif + objc := false include $(pwd)/target-$(target).mk @@ -109,9 +110,15 @@ ifeq ($(machine),) machine := $(default) endif --include $(pwd)/cpu-$(machine).mk +ifneq ($(target),win) +# XXX: this breaks libgcrypt due to cet.h being ELF-specific +more/x86_64 += -fcf-protection=full +endif + +# XXX: this broke ARM iOS/macOS exception handling in coroutines +# XXX: consider using =pac-ret+leaf +#more/arm64 += -mbranch-protection=standard -cflags += -I@/usr/include define depend $(foreach arch,$(archs),$(eval $(output)/$(arch)/$(1): $(patsubst @/%,$(output)/$(arch)/%,$(2)))) @@ -124,8 +131,11 @@ $(eval folder := $(subst $(space),/,$(wordlist 2,$(words $(temp)),$(temp)))) endef specific = $(eval $(value preamble)) -cflags += -I$(output)/extra + cflags += -I@/extra +cflags += -I$(output)/extra + +cflags += -I@/usr/include # I doubt this will ever become important, but just in case: v8 had this idea ;P @@ -141,7 +151,9 @@ qflags += -ffile-prefix-map=$(CURDIR)=. rflags += --remap-path-prefix=$(CURDIR)/$(output)/cargo/=~/.cargo/ -qflags += -fno-ident +# putting -fno-ident directly into qflags breaks cmake +qflags += --config=$(CURDIR)/$(pwd)/fnoident.cfg + $(output)/%/extra/revision.hpp: force @mkdir -p $(dir $@) diff --git a/env/target-ios.mk b/env/target-ios.mk index 0cf283189..735968292 100644 --- a/env/target-ios.mk +++ b/env/target-ios.mk @@ -9,6 +9,8 @@ # }}} +cmake := iOS + archs += armv7 openssl/armv7 := ios-xcrun host/armv7 := arm-apple-darwin diff --git a/env/target-lnx.mk b/env/target-lnx.mk index c5eca05ce..dc18a157a 100644 --- a/env/target-lnx.mk +++ b/env/target-lnx.mk @@ -19,6 +19,7 @@ libc := gnu endif meson := linux +cmake := Linux archs += i386 openssl/i386 := linux-x86 diff --git a/env/target-mac.mk b/env/target-mac.mk index 3cb411664..55b2773ea 100644 --- a/env/target-mac.mk +++ b/env/target-mac.mk @@ -9,6 +9,8 @@ # }}} +cmake := Darwin + archs += i386 openssl/i386 := darwin-i386-cc host/i386 := i386-apple-darwin diff --git a/env/target-win.mk b/env/target-win.mk index 3d2608831..1906dff5f 100644 --- a/env/target-win.mk +++ b/env/target-win.mk @@ -15,6 +15,7 @@ lib := lib exe := .exe meson := windows +cmake := CYGWIN archs += i686 openssl/i686 := mingw diff --git a/min-boringssl/target.mk b/min-boringssl/target.mk index 12aa47e73..2e3e8aac0 100644 --- a/min-boringssl/target.mk +++ b/min-boringssl/target.mk @@ -18,4 +18,19 @@ # }}} +pwd/boringssl := $(pwd)/boringssl + +boringssl := +boringssl += $(pwd/boringssl)/cmake/libssl.a +boringssl += $(pwd/boringssl)/cmake/libcrypto.a + +$(subst @,%,$(patsubst %,$(output)/@/%,$(boringssl))): $(output)/%/$(pwd/boringssl)/cmake/Makefile + $(MAKE) -C $(dir $<) ssl + cflags += -I$(pwd)/boringssl/include + +linked += $(boringssl) + +export BORINGSSL_CFLAGS := -I$(CURDIR)/$(pwd/boringssl)/include +# XXX: this needs to be shoved down and then split for each architecture +export BORINGSSL_LIBS := -L$(CURDIR)/$(output)/$(machine)/$(pwd/boringssl)/cmake -lcrypto -lssl diff --git a/min-cairo/target.mk b/min-cairo/target.mk index e74e7336c..51f4aadb8 100644 --- a/min-cairo/target.mk +++ b/min-cairo/target.mk @@ -23,12 +23,12 @@ p_cairo += -Wno-unused-variable p_cairo += -I$(CURDIR)/$(pwd)/zlb/libz l_cairo += -L@/$(pwd)/zlb -p_cairo += -I$(CURDIR)/$(pwd)/libpng p_cairo += -I@/$(pwd)/libpng +p_cairo += -I$(CURDIR)/$(pwd)/libpng l_cairo += -L@/libpbg/.libs -p_cairo += -I$(CURDIR)/$(pwd)/pixman/pixman p_cairo += -I@/$(pwd)/pixman/pixman +p_cairo += -I$(CURDIR)/$(pwd)/pixman/pixman l_cairo += -L@/$(pwd)/pixman/.libs libcairo := $(pwd)/cairo/src/.libs/libcairo.a @@ -38,8 +38,8 @@ $(subst @,%,$(patsubst %,$(output)/@/%,$(libcairo))) \ : $(output)/%/$(pwd)/cairo/Makefile $(sysroot) $(MAKE) -C $(dir $<)/src -cflags += -I$(pwd)/cairo/src cflags += -I@/$(pwd)/cairo/src +cflags += -I$(pwd)/cairo/src linked += $(libcairo) diff --git a/min-http3/nghttp3.mk b/min-http3/nghttp3.mk new file mode 100644 index 000000000..ff02bbb00 --- /dev/null +++ b/min-http3/nghttp3.mk @@ -0,0 +1,34 @@ +# Orchid - WebRTC P2P VPN Market (on Ethereum) +# Copyright (C) 2017-2020 The Orchid Authors + +# GNU Affero General Public License, Version 3 {{{ */ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# }}} + + +w_nghttp3 += --enable-lib-only + +nghttp3 := +nghttp3 += $(pwd)/nghttp3/lib/.libs/libnghttp3.a + +$(output)/%/$(pwd)/nghttp3/lib/includes/nghttp3/version.h $(subst @,%,$(patsubst %,$(output)/@/%,$(nghttp3))): $(output)/%/$(pwd)/nghttp3/Makefile + $(MAKE) -C $(dir $<) + +cflags += -I@/$(pwd)/nghttp3/lib/includes +cflags += -I$(pwd)/nghttp3/lib/includes + +header += @/$(pwd)/nghttp3/lib/includes/nghttp3/version.h + +linked += $(nghttp3) diff --git a/min-http3/ngtcp2 b/min-http3/ngtcp2 index 7698761e1..9ddd87d6d 160000 --- a/min-http3/ngtcp2 +++ b/min-http3/ngtcp2 @@ -1 +1 @@ -Subproject commit 7698761e13af544f03b8da8c35eefced013c32ee +Subproject commit 9ddd87d6d9b40af328f76d5b8579652aa8f6e4b8 diff --git a/min-http3/ngtcp2.mk b/min-http3/ngtcp2.mk new file mode 100644 index 000000000..0fcec0388 --- /dev/null +++ b/min-http3/ngtcp2.mk @@ -0,0 +1,46 @@ +# Orchid - WebRTC P2P VPN Market (on Ethereum) +# Copyright (C) 2017-2020 The Orchid Authors + +# GNU Affero General Public License, Version 3 {{{ */ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# }}} + + +w_ngtcp2 += --enable-lib-only + +w_ngtcp2 += --without-libev +w_ngtcp2 += --without-openssl +w_ngtcp2 += --with-boringssl + +define _ +$(output)/$(1)/$(pwd)/ngtcp2/Makefile: $(output)/$(1)/$(pwd/boringssl)/cmake/libssl.a +endef +$(each) + +ngtcp2 := +ngtcp2 += $(pwd)/ngtcp2/lib/.libs/libngtcp2.a +ngtcp2 += $(pwd)/ngtcp2/crypto/boringssl/libngtcp2_crypto_boringssl.a + +$(output)/%/$(pwd)/ngtcp2/lib/includes/ngtcp2/version.h $(subst @,%,$(patsubst %,$(output)/@/%,$(ngtcp2))): $(output)/%/$(pwd)/ngtcp2/Makefile + $(MAKE) -C $(dir $<) + +cflags += -I$(pwd)/ngtcp2/crypto/includes + +cflags += -I@/$(pwd)/ngtcp2/lib/includes +cflags += -I$(pwd)/ngtcp2/lib/includes + +header += @/$(pwd)/ngtcp2/lib/includes/ngtcp2/version.h + +linked += $(ngtcp2) diff --git a/min-http3/target.mk b/min-http3/target.mk new file mode 100644 index 000000000..f83b5c9b2 --- /dev/null +++ b/min-http3/target.mk @@ -0,0 +1,22 @@ +# Orchid - WebRTC P2P VPN Market (on Ethereum) +# Copyright (C) 2017-2020 The Orchid Authors + +# GNU Affero General Public License, Version 3 {{{ */ +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# }}} + + +include $(pwd)/ngtcp2.mk +include $(pwd)/nghttp3.mk diff --git a/min-openssl/target.mk b/min-openssl/target.mk index cf034fe78..0453bdaf1 100644 --- a/min-openssl/target.mk +++ b/min-openssl/target.mk @@ -34,12 +34,15 @@ $(output)/%/openssl/Makefile $(subst @,%,$(patsubst %,$(output)/@/openssl/includ $(output)/%/openssl/libssl.a $(output)/%/openssl/libcrypto.a: $(output)/%/openssl/Makefile $(sysroot) $(if $(findstring /,$(word 1,$(cc))),PATH=$(dir $(word 1,$(cc))):$${PATH}) $(MAKE) -C $(output)/$*/openssl build_libs +cflags += -I@/openssl/include cflags += -I$(pwd)/openssl/include + cflags += -I$(pwd)/openssl/test/ossl_shim/include -cflags += -I@/openssl/include + +header += @/openssl/include/openssl/opensslconf.h + linked += openssl/libssl.a linked += openssl/libcrypto.a -header += @/openssl/include/openssl/opensslconf.h define _ export $(subst -,_,$(call uc,$(triple/$(1))))_OPENSSL_LIB_DIR := $(CURDIR)/$(output)/$(1)/openssl diff --git a/srv-worker/http3 b/srv-worker/http3 new file mode 120000 index 000000000..2f90ff968 --- /dev/null +++ b/srv-worker/http3 @@ -0,0 +1 @@ +../min-http3 \ No newline at end of file diff --git a/srv-worker/makefile b/srv-worker/makefile index 1c84f2ea4..c31bc1d47 100644 --- a/srv-worker/makefile +++ b/srv-worker/makefile @@ -52,6 +52,7 @@ cflags += -I$(pwd)/extra $(call include,cv8/target.mk) $(call include,lib/target.mk) +$(call include,http3/target.mk) # XXX: I might not need this anymore cflags += -D_LIBCPP_HAS_NO_STDIN=