Skip to content

Commit 743600a

Browse files
authored
Merge pull request #6 from mpretty-cyro/libquic
Libquic integration
2 parents 730c5b9 + 82be3ae commit 743600a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+8078
-985
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ SpacesInAngles: 'false'
2828
SpacesInContainerLiterals: 'false'
2929
SpacesInParentheses: 'false'
3030
SpacesInSquareBrackets: 'false'
31-
Standard: c++17
31+
Standard: c++20
3232
UseTab: Never
3333
SortIncludes: true
3434
ColumnLimit: 100

.drone.jsonnet

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ local submodules = {
1010

1111
local apt_get_quiet = 'apt-get -o=Dpkg::Use-Pty=0 -q';
1212

13-
local libngtcp2_deps = ['libgnutls28-dev', 'libprotobuf-dev'];
13+
local libngtcp2_deps = ['libgnutls28-dev', 'libprotobuf-dev', 'libngtcp2-dev', 'libngtcp2-crypto-gnutls-dev'];
1414

1515
local default_deps_nocxx = [
1616
'nlohmann-json3-dev',
@@ -375,12 +375,14 @@ local static_build(name,
375375
'libsession-util-windows-x64-TAG.zip',
376376
deps=['g++-mingw-w64-x86-64-posix'],
377377
cmake_extra='-DCMAKE_CXX_FLAGS=-fdiagnostics-color=always -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-x86-64-toolchain.cmake'),
378+
/* currently broken:
378379
static_build('Static Windows x86',
379380
docker_base + 'debian-win32-cross',
380381
'libsession-util-windows-x86-TAG.zip',
381382
deps=['g++-mingw-w64-i686-posix'],
382383
allow_fail=true,
383384
cmake_extra='-DCMAKE_CXX_FLAGS=-fdiagnostics-color=always -DCMAKE_TOOLCHAIN_FILE=../cmake/mingw-i686-toolchain.cmake'),
385+
*/
384386
debian_pipeline(
385387
'Static Android',
386388
docker_base + 'android',

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
/compile_commands.json
33
/.cache/
44
/.vscode/
5-
*.DS_Store
5+
.DS_STORE

.gitmodules

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[submodule "external/oxen-encoding"]
2-
path = external/oxen-encoding
3-
url = https://github.com/session-foundation/oxen-encoding.git
41
[submodule "external/libsodium-internal"]
52
path = external/libsodium-internal
63
url = https://github.com/session-foundation/libsodium-internal.git
@@ -16,6 +13,9 @@
1613
[submodule "external/nlohmann-json"]
1714
path = external/nlohmann-json
1815
url = https://github.com/nlohmann/json.git
16+
[submodule "external/oxen-libquic"]
17+
path = external/oxen-libquic
18+
url = https://github.com/oxen-io/oxen-libquic.git
1919
[submodule "external/protobuf"]
2020
path = external/protobuf
2121
url = https://github.com/protocolbuffers/protobuf.git

CMakeLists.txt

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14...3.23)
33
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
44

55
# Has to be set before `project()`, and ignored on non-macos:
6-
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.13 CACHE STRING "macOS deployment target (Apple clang only)")
6+
set(CMAKE_OSX_DEPLOYMENT_TARGET 10.15 CACHE STRING "macOS deployment target (Apple clang only)")
77

88
set(LANGS C CXX)
99
find_program(CCACHE_PROGRAM ccache)
@@ -16,7 +16,6 @@ if(CCACHE_PROGRAM)
1616
endforeach()
1717
endif()
1818

19-
2019
project(libsession-util
2120
VERSION 1.2.0
2221
DESCRIPTION "Session client utility library"
@@ -41,7 +40,7 @@ else()
4140
endif()
4241

4342

44-
set(CMAKE_CXX_STANDARD 17)
43+
set(CMAKE_CXX_STANDARD 20)
4544
set(CMAKE_CXX_STANDARD_REQUIRED ON)
4645
set(CMAKE_CXX_EXTENSIONS OFF)
4746

@@ -81,7 +80,7 @@ option(STATIC_LIBSTD "Statically link libstdc++/libgcc" ${default_static_libstd}
8180

8281
option(USE_LTO "Use Link-Time Optimization" ${use_lto_default})
8382

84-
# Provide this as an option for now because GMP and iOS are sometimes unhappy with each other.
83+
# Provide this as an option for now because GMP and Desktop are sometimes unhappy with each other.
8584
option(ENABLE_ONIONREQ "Build with onion request functionality" ON)
8685

8786
if(USE_LTO)
@@ -118,6 +117,21 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ON)
118117

119118

120119
add_subdirectory(external)
120+
121+
if(ENABLE_ONIONREQ)
122+
if(NOT TARGET nettle::nettle)
123+
if(BUILD_STATIC_DEPS)
124+
message(FATAL_ERROR "Internal error: nettle::nettle target (expected via libquic BUILD_STATIC_DEPS) not found")
125+
else()
126+
find_package(PkgConfig REQUIRED)
127+
pkg_check_modules(NETTLE REQUIRED IMPORTED_TARGET nettle)
128+
add_library(nettle INTERFACE)
129+
target_link_libraries(nettle INTERFACE PkgConfig::NETTLE)
130+
add_library(nettle::nettle ALIAS nettle)
131+
endif()
132+
endif()
133+
endif()
134+
121135
add_subdirectory(src)
122136
add_subdirectory(proto)
123137

cmake/AddStaticBundleLib.cmake

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11

22
set(LIBSESSION_STATIC_BUNDLE_LIBS "" CACHE INTERNAL "list of libs to go into the static bundle lib")
33

4+
function(_libsession_static_bundle_append tgt)
5+
list(APPEND LIBSESSION_STATIC_BUNDLE_LIBS "${tgt}")
6+
set(LIBSESSION_STATIC_BUNDLE_LIBS "${LIBSESSION_STATIC_BUNDLE_LIBS}" CACHE INTERNAL "")
7+
endfunction()
8+
49
# Call as:
510
#
611
# libsession_static_bundle(target [target2 ...])
712
#
813
# to append the given target(s) to the list of libraries that will be combined to make the static
914
# bundled libsession-util.a.
1015
function(libsession_static_bundle)
11-
list(APPEND LIBSESSION_STATIC_BUNDLE_LIBS "${ARGN}")
12-
list(REMOVE_DUPLICATES LIBSESSION_STATIC_BUNDLE_LIBS)
13-
set(LIBSESSION_STATIC_BUNDLE_LIBS "${LIBSESSION_STATIC_BUNDLE_LIBS}" CACHE INTERNAL "")
16+
foreach(tgt IN LISTS ARGN)
17+
if(TARGET "${tgt}" AND NOT "${tgt}" IN_LIST LIBSESSION_STATIC_BUNDLE_LIBS)
18+
get_target_property(tgt_type ${tgt} TYPE)
19+
20+
if(tgt_type STREQUAL STATIC_LIBRARY)
21+
message(STATUS "Adding ${tgt} to libsession-util bundled library list")
22+
_libsession_static_bundle_append("${tgt}")
23+
endif()
24+
25+
if(tgt_type STREQUAL INTERFACE_LIBRARY)
26+
get_target_property(tgt_link_deps ${tgt} INTERFACE_LINK_LIBRARIES)
27+
else()
28+
get_target_property(tgt_link_deps ${tgt} LINK_LIBRARIES)
29+
endif()
30+
31+
if(tgt_link_deps)
32+
libsession_static_bundle(${tgt_link_deps})
33+
endif()
34+
endif()
35+
endforeach()
1436
endfunction()

cmake/GenVersion.cmake

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ else()
4141
OUTPUT_VARIABLE git_tag
4242
OUTPUT_STRIP_TRAILING_WHITESPACE)
4343

44-
if(git_tag)
44+
if(git_tag AND git_tag MATCHES "^v[0-9]+\\.[0-9]+\\.[0-9]+$")
4545
message(STATUS "${git_commit} is tagged (${git_tag}); tagging version as 'release'")
4646
set(vfull "v${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}")
4747
set(PROJECT_VERSION_TAG "release")
4848

4949
if (NOT git_tag STREQUAL "${vfull}")
5050
message(FATAL_ERROR "This commit is tagged, but the tag (${git_tag}) does not match the project version (${vfull})!")
5151
endif()
52+
elseif(git_tag)
53+
message(WARNING "Did not recognize git tag (${git_tag}) for ${git_commit}; tagging with commit hash")
54+
set(PROJECT_VERSION_TAG "${git_commit}")
5255
else()
5356
message(STATUS "Did not find a git tag for ${git_commit}; tagging version with the commit hash")
5457
set(PROJECT_VERSION_TAG "${git_commit}")

cmake/StaticBuild.cmake

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,6 @@
55

66
set(LOCAL_MIRROR "" CACHE STRING "local mirror path/URL for lib downloads")
77

8-
set(GMP_VERSION 6.3.0 CACHE STRING "gmp version")
9-
set(GMP_MIRROR ${LOCAL_MIRROR} https://gmplib.org/download/gmp
10-
CACHE STRING "gmp mirror(s)")
11-
set(GMP_SOURCE gmp-${GMP_VERSION}.tar.xz)
12-
set(GMP_HASH SHA512=e85a0dab5195889948a3462189f0e0598d331d3457612e2d3350799dba2e244316d256f8161df5219538eb003e4b5343f989aaa00f96321559063ed8c8f29fd2
13-
CACHE STRING "gmp source hash")
14-
15-
set(NETTLE_VERSION 3.9.1 CACHE STRING "nettle version")
16-
set(NETTLE_MIRROR ${LOCAL_MIRROR} https://ftp.gnu.org/gnu/nettle
17-
CACHE STRING "nettle mirror(s)")
18-
set(NETTLE_SOURCE nettle-${NETTLE_VERSION}.tar.gz)
19-
set(NETTLE_HASH SHA512=5939c4b43cf9ff6c6272245b85f123c81f8f4e37089fa4f39a00a570016d837f6e706a33226e4bbfc531b02a55b2756ff312461225ed88de338a73069e031ced
20-
CACHE STRING "nettle source hash")
21-
22-
238
include(ExternalProject)
249

2510
set(DEPS_DESTDIR ${CMAKE_BINARY_DIR}/static-deps)
@@ -230,32 +215,6 @@ elseif(gmp_build_host STREQUAL "")
230215
set(gmp_build_host "--build=${CMAKE_LIBRARY_ARCHITECTURE}")
231216
endif()
232217

233-
if(ENABLE_ONIONREQ)
234-
build_external(gmp
235-
CONFIGURE_COMMAND ./configure ${gmp_build_host} --disable-shared --prefix=${DEPS_DESTDIR} --with-pic
236-
"CC=${deps_cc}" "CXX=${deps_cxx}" "CFLAGS=${deps_CFLAGS}${apple_cflags_arch}" "CXXFLAGS=${deps_CXXFLAGS}${apple_cxxflags_arch}"
237-
"LDFLAGS=${apple_ldflags_arch}" ${cross_rc} CC_FOR_BUILD=cc CPP_FOR_BUILD=cpp
238-
)
239-
add_static_target(gmp gmp_external libgmp.a)
240-
241-
build_external(nettle
242-
CONFIGURE_COMMAND ./configure ${gmp_build_host} --disable-shared --prefix=${DEPS_DESTDIR} --libdir=${DEPS_DESTDIR}/lib
243-
--with-pic --disable-openssl
244-
"CC=${deps_cc}" "CXX=${deps_cxx}"
245-
"CFLAGS=${deps_CFLAGS}${apple_cflags_arch}" "CXXFLAGS=${deps_CXXFLAGS}${apple_cxxflags_arch}"
246-
"CPPFLAGS=-I${DEPS_DESTDIR}/include"
247-
"LDFLAGS=-L${DEPS_DESTDIR}/lib${apple_ldflags_arch}"
248-
249-
DEPENDS gmp_external
250-
BUILD_BYPRODUCTS
251-
${DEPS_DESTDIR}/lib/libnettle.a
252-
${DEPS_DESTDIR}/lib/libhogweed.a
253-
${DEPS_DESTDIR}/include/nettle/version.h
254-
)
255-
add_static_target(nettle nettle_external libnettle.a gmp)
256-
add_static_target(hogweed nettle_external libhogweed.a nettle)
257-
endif()
258-
259218
link_libraries(-static-libstdc++)
260219
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
261220
link_libraries(-static-libgcc)

external/CMakeLists.txt

Lines changed: 31 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if(SUBMODULE_CHECK)
2626
message(STATUS "Checking submodules")
2727
check_submodule(ios-cmake)
2828
check_submodule(libsodium-internal)
29-
check_submodule(oxen-encoding)
29+
check_submodule(oxen-libquic external/oxen-logging external/oxen-encoding)
3030
check_submodule(nlohmann-json)
3131
check_submodule(zstd)
3232
check_submodule(protobuf)
@@ -37,7 +37,7 @@ if(NOT BUILD_STATIC_DEPS AND NOT FORCE_ALL_SUBMODULES)
3737
find_package(PkgConfig REQUIRED)
3838
endif()
3939

40-
macro(system_or_submodule BIGNAME smallname pkgconf subdir)
40+
macro(libsession_system_or_submodule BIGNAME smallname pkgconf subdir)
4141
option(FORCE_${BIGNAME}_SUBMODULE "force using ${smallname} submodule" OFF)
4242
if(NOT BUILD_STATIC_DEPS AND NOT FORCE_${BIGNAME}_SUBMODULE AND NOT FORCE_ALL_SUBMODULES)
4343
pkg_check_modules(${BIGNAME} ${pkgconf} IMPORTED_TARGET GLOBAL)
@@ -57,6 +57,9 @@ macro(system_or_submodule BIGNAME smallname pkgconf subdir)
5757
if(TARGET ${smallname} AND NOT TARGET ${smallname}::${smallname})
5858
add_library(${smallname}::${smallname} ALIAS ${smallname})
5959
endif()
60+
if(BUILD_STATIC_DEPS AND STATIC_BUNDLE)
61+
libsession_static_bundle(${smallname}::${smallname})
62+
endif()
6063
endmacro()
6164

6265

@@ -65,11 +68,6 @@ set(cross_host "")
6568
set(cross_rc "")
6669
if(CMAKE_CROSSCOMPILING)
6770
if(APPLE_TARGET_TRIPLE)
68-
if(PLATFORM MATCHES "OS64" OR PLATFORM MATCHES "SIMULATORARM64")
69-
set(APPLE_TARGET_TRIPLE aarch64-apple-ios)
70-
elseif(PLATFORM MATCHES "SIMULATOR64")
71-
set(APPLE_TARGET_TRIPLE x86_64-apple-ios)
72-
endif()
7371
set(cross_host "--host=${APPLE_TARGET_TRIPLE}")
7472
elseif(ANDROID)
7573
if(CMAKE_ANDROID_ARCH_ABI MATCHES x86_64)
@@ -102,8 +100,31 @@ if(CMAKE_CROSSCOMPILING)
102100
endif()
103101
endif()
104102

103+
set(LIBQUIC_BUILD_TESTS OFF CACHE BOOL "")
104+
if(ENABLE_ONIONREQ)
105+
libsession_system_or_submodule(OXENQUIC quic liboxenquic>=1.1.0 oxen-libquic)
106+
endif()
107+
108+
if(NOT TARGET oxenc::oxenc)
109+
# The oxenc target will already exist if we load libquic above via submodule
110+
set(OXENC_BUILD_TESTS OFF CACHE BOOL "")
111+
set(OXENC_BUILD_DOCS OFF CACHE BOOL "")
112+
libsession_system_or_submodule(OXENC oxenc liboxenc>=1.1.0 oxen-libquic/external/oxen-encoding)
113+
endif()
105114

106-
system_or_submodule(OXENC oxenc liboxenc>=1.0.10 oxen-encoding)
115+
if(NOT TARGET oxen::logging)
116+
add_subdirectory(oxen-libquic/external/oxen-logging)
117+
endif()
118+
119+
oxen_logging_add_source_dir("${PROJECT_SOURCE_DIR}")
120+
121+
# Apple xcode 15 has a completely broken std::source_location; we can't fix it, but at least we can
122+
# hack up the source locations to hide the path that it uses (which is the useless path to
123+
# oxen/log.hpp where the info/critical/etc. bodies are).
124+
if(APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL AppleClang AND NOT CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 16)
125+
message(WARNING "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION} is broken: filenames in logging statements will not display properly")
126+
oxen_logging_add_source_dir("${CMAKE_CURRENT_SOURCE_DIR}/oxen-libquic/external/oxen-logging/include/oxen")
127+
endif()
107128

108129

109130
if(CMAKE_C_COMPILER_LAUNCHER)
@@ -143,7 +164,7 @@ set(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
143164
set(protobuf_ABSL_PROVIDER "module" CACHE STRING "" FORCE)
144165
set(protobuf_BUILD_PROTOC_BINARIES OFF CACHE BOOL "")
145166
set(protobuf_BUILD_PROTOBUF_BINARIES ON CACHE BOOL "" FORCE)
146-
system_or_submodule(PROTOBUF_LITE protobuf_lite protobuf-lite>=3.21 protobuf)
167+
libsession_system_or_submodule(PROTOBUF_LITE protobuf_lite protobuf-lite>=3.21 protobuf)
147168
if(TARGET PkgConfig::PROTOBUF_LITE AND NOT TARGET protobuf::libprotobuf-lite)
148169
add_library(protobuf::libprotobuf-lite ALIAS PkgConfig::PROTOBUF_LITE)
149170
endif()
@@ -172,4 +193,4 @@ libsession_static_bundle(libzstd_static)
172193

173194
set(JSON_BuildTests OFF CACHE INTERNAL "")
174195
set(JSON_Install ON CACHE INTERNAL "") # Required to export targets that we use
175-
system_or_submodule(NLOHMANN nlohmann_json nlohmann_json>=3.7.0 nlohmann-json)
196+
libsession_system_or_submodule(NLOHMANN nlohmann_json nlohmann_json>=3.7.0 nlohmann-json)

external/oxen-encoding

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)