Skip to content

Commit

Permalink
Build ngtcp2/nghttp3 into worker for WebTransport.
Browse files Browse the repository at this point in the history
  • Loading branch information
saurik committed Nov 18, 2024
1 parent 30410bc commit 7213cfd
Show file tree
Hide file tree
Showing 24 changed files with 232 additions and 42 deletions.
66 changes: 66 additions & 0 deletions env/cmake.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
set(CMAKE_SYSTEM_NAME ${meson[0]})
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "${meson[1]}")
set(CMAKE_ASM_COMPILER ${cc[@]} ${cfg[@]})
set(CMAKE_C_COMPILER ${cc[@]} ${cfg[@]})
set(CMAKE_CXX_COMPILER ${cxx[@]} ${cfg[@]})
set(CMAKE_ASM_FLAGS "\${CMAKE_ASM_FLAGS} ${cflags[@]}" CACHE STRING "asm flags")
set(CMAKE_C_FLAGS "\${CMAKE_C_FLAGS} ${cflags[@]}" CACHE STRING "c flags")
set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} ${cflags[@]} ${xflags[@]}" CACHE STRING "c++ flags")
EOF

if diff "${output}/${arch}"/cmake.{new,txt} &>/dev/null; then
rm -f "${output}/${arch}"/cmake.new
else
mv -f "${output}/${arch}"/cmake.{new,txt}
fi
14 changes: 0 additions & 14 deletions env/cpu-arm64.mk

This file was deleted.

15 changes: 0 additions & 15 deletions env/cpu-x86_64.mk

This file was deleted.

1 change: 1 addition & 0 deletions env/fnoident.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-fno-ident
3 changes: 2 additions & 1 deletion env/lnx-arch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
3 changes: 2 additions & 1 deletion env/lnx-debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions env/meson.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions env/output.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 $@)
Expand Down
3 changes: 2 additions & 1 deletion env/setup-mac.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions env/target-and.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ lib := a
exe :=

meson := linux
cmake += Android

archs += armeabi-v7a
openssl/armeabi-v7a := android-arm
Expand Down
20 changes: 16 additions & 4 deletions env/target-any.mk
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,23 @@ else
zflags := -0
endif


objc := false
include $(pwd)/target-$(target).mk

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))))
Expand All @@ -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
Expand All @@ -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 $@)
Expand Down
2 changes: 2 additions & 0 deletions env/target-ios.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# }}}


cmake := iOS

archs += armv7
openssl/armv7 := ios-xcrun
host/armv7 := arm-apple-darwin
Expand Down
1 change: 1 addition & 0 deletions env/target-lnx.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ libc := gnu
endif

meson := linux
cmake := Linux

archs += i386
openssl/i386 := linux-x86
Expand Down
2 changes: 2 additions & 0 deletions env/target-mac.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
# }}}


cmake := Darwin

archs += i386
openssl/i386 := darwin-i386-cc
host/i386 := i386-apple-darwin
Expand Down
1 change: 1 addition & 0 deletions env/target-win.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ lib := lib
exe := .exe

meson := windows
cmake := CYGWIN

archs += i686
openssl/i686 := mingw
Expand Down
15 changes: 15 additions & 0 deletions min-boringssl/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions min-cairo/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
34 changes: 34 additions & 0 deletions min-http3/nghttp3.mk
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
# }}}


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)
2 changes: 1 addition & 1 deletion min-http3/ngtcp2
46 changes: 46 additions & 0 deletions min-http3/ngtcp2.mk
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.
# }}}


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)
Loading

0 comments on commit 7213cfd

Please sign in to comment.