mirror of
https://github.com/shadowsocks/shadowsocks-libev.git
synced 2026-10-28 10:44:43 +08:00
* Enable C++20 alongside C11 in the build Add CXX to the project with C++20 (no extensions) and build C++ sources with -Wextra -fno-exceptions -fno-rtti -fno-threadsafe-statics on top of the existing warning flags. Give every toolchain a C++ compiler: the zig Windows toolchain, the static macOS/Windows CI jobs, the static musl image (clang++ plus libstdc++ headers) and the RPM spec. * Add C++20 ownership and allocation core Header-only primitives for the no-heap-after-startup design: Result/Status, Region, ObjectPool with PoolPtr (std::unique_ptr with a pool deleter), generation-checked Handle and asynchronous close support, intrusive RefPtr, FixedBuffer, MonotonicArena, FixedHashMap and FixedLru, IntrusiveList, and a bounded FixedHeap for third-party allocator hooks. Unit tests cover each primitive (test_core_*). scripts/check_no_heap.py rejects heap allocation in C++ sources under src/ and runs as a ctest. clang-tidy now also analyses C++ sources and the core headers. * Add heap allocation audit for relayed connections alloc_counter is a preloadable malloc counter (glibc, macOS) that writes a snapshot on SIGUSR2. measure_alloc.py warms ss-local and ss-server up, snapshots both, relays more connections and reports allocations per connection. It runs report-only as the alloc_audit_report ctest. interop.peers() now yields the started processes. * Document the C++20 port and allocation baseline docs/cpp-core.md describes the language profile, the core primitives, the phase plan and the measured C baseline (77-89 allocations per connection in ss-server, 27-39 in ss-local). The compatibility contract now keeps the C11 public header instead of a C11 code base. CLAUDE.md drops stale libev, submodule and gnu99 references. * Fix CI for the C++ core: libstdc++ headers, static unwinder, newer clang - docker/static: Alpine's libstdc++ headers come with g++, and the C++ tests' static libstdc++ needs an unwinder that compiler-rt lacks; add g++ and llvm-libunwind. - FixedBuffer: drop the unused kCapacity (clang-tidy 18 reports it as a dynamically initialized header static). - ss-server on Windows: manager_addr was only read in POSIX-only code, which newer clang rejects (-Wunused-but-set-global); say that the option is ignored there. * CI: allow running the test and build workflows by hand Stacked PRs target their parent branch, which these workflows do not trigger on; workflow_dispatch lets each layer run the full matrix. * CI: let clang-tidy ignore GCC-only warning flags The compile database comes from a GCC build, whose flags (for example -Wno-class-memaccess) clang-tidy does not know and reports as errors.
162 lines
5.9 KiB
CMake
162 lines
5.9 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
|
|
set(PROJECT_NAME shadowsocks-c)
|
|
set(RELEASE_DATE 2026-02-09)
|
|
set(PROJECT_VERSION "3.3.6")
|
|
set(PROJECT_DESC "a lightweight secured socks5 proxy")
|
|
set(PROJECT_URL "https://shadowsocks.org")
|
|
set(PROJECT_ISSUES_URL "https://github.com/shadowsocks/shadowsocks-libev")
|
|
project(${PROJECT_NAME} VERSION ${PROJECT_VERSION} LANGUAGES C CXX)
|
|
if(MSVC)
|
|
message(FATAL_ERROR "MSVC is not supported yet. Use MinGW-w64 (UCRT64) or the Zig Windows toolchain; see docs/modernization.md.")
|
|
endif()
|
|
|
|
include(GNUInstallDirs)
|
|
include(CTest)
|
|
|
|
# Compilation database for clang-tidy and other tooling
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
# C11 with GNU extensions. _GNU_SOURCE stays for the glibc-specific
|
|
# interfaces used by the Linux-only modules (ss-redir, connmark/nftables).
|
|
set(CMAKE_C_STANDARD 11)
|
|
set(CMAKE_C_STANDARD_REQUIRED ON)
|
|
set(CMAKE_C_EXTENSIONS ON)
|
|
|
|
# The C++20 core (src/core) is being introduced module by module; see
|
|
# docs/cpp-core.md. It is built without exceptions or RTTI, so it adds
|
|
# no unwinding tables or typeinfo to the static binaries.
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
option(ENABLE_SANITIZERS "Build with AddressSanitizer and UndefinedBehaviorSanitizer" OFF)
|
|
option(ENABLE_COVERAGE "Build with coverage instrumentation" OFF)
|
|
option(SS_WARNINGS_AS_ERRORS "Treat project warnings as errors" ON)
|
|
|
|
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
|
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
|
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
|
|
|
|
set(CMAKE_MACOSX_RPATH TRUE)
|
|
|
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
|
|
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
|
|
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build configuration" FORCE)
|
|
endif ()
|
|
# Detect linux
|
|
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
|
set(LINUX TRUE)
|
|
endif ()
|
|
|
|
message(STATUS "Running cmake version ${CMAKE_VERSION}")
|
|
|
|
option(WITH_STATIC "Link executable dependencies statically" ON)
|
|
option(SS_BUILD_EXECUTABLES "Build command-line programs" ON)
|
|
option(SS_BUILD_STATIC_LIBRARY "Build the static embedding library" ON)
|
|
option(SS_BUILD_SHARED_LIBRARY "Build the shared embedding library" ON)
|
|
option(SS_INSTALL_TOOLS "Install platform shell tools" OFF)
|
|
option(ENABLE_CONNMARKTOS "Enable saved connmark to IP TOS QoS feature" OFF)
|
|
option(ENABLE_NFTABLES "Report malicious IP to nftables" OFF)
|
|
|
|
option(SS_MINIMAL "Disable regex, plugins, manager and legacy stream ciphers" OFF)
|
|
option(SS_ENABLE_REGEX "Enable PCRE2 ACL patterns" ON)
|
|
option(SS_ENABLE_PLUGINS "Enable SIP003 and obfsproxy subprocesses" ON)
|
|
option(SS_ENABLE_LEGACY "Enable legacy stream ciphers" ON)
|
|
if(SS_MINIMAL)
|
|
set(SS_ENABLE_REGEX OFF)
|
|
set(SS_ENABLE_PLUGINS OFF)
|
|
set(SS_ENABLE_LEGACY OFF)
|
|
set(WITH_SS_MANAGER OFF)
|
|
endif()
|
|
include(cmake/Dependencies.cmake)
|
|
|
|
# Connmarktos support
|
|
if(ENABLE_CONNMARKTOS)
|
|
if(NOT LINUX)
|
|
message(FATAL_ERROR "connmarktos is only supported on Linux")
|
|
endif()
|
|
find_library(NETFILTER_CONNTRACK_LIB netfilter_conntrack)
|
|
find_library(NFNETLINK_LIB nfnetlink)
|
|
if(NOT NETFILTER_CONNTRACK_LIB)
|
|
message(FATAL_ERROR "--enable-connmarktos specified but libnetfilter_conntrack not found")
|
|
endif()
|
|
set(USE_NFCONNTRACK_TOS 1)
|
|
message(STATUS "Connmarktos enabled")
|
|
endif()
|
|
|
|
# Nftables support
|
|
if(ENABLE_NFTABLES)
|
|
if(NOT LINUX)
|
|
message(FATAL_ERROR "nftables is only supported on Linux")
|
|
endif()
|
|
find_library(MNL_LIB mnl)
|
|
find_library(NFTNL_LIB nftnl)
|
|
if(NOT MNL_LIB OR NOT NFTNL_LIB)
|
|
message(FATAL_ERROR "--enable-nftables specified but libmnl or libnftnl not found")
|
|
endif()
|
|
set(USE_NFTABLES 1)
|
|
message(STATUS "Nftables enabled")
|
|
endif()
|
|
|
|
# Run platform tests
|
|
include(${PROJECT_SOURCE_DIR}/cmake/configure.cmake)
|
|
configure_file(${PROJECT_SOURCE_DIR}/cmake/config.h.cmake ${PROJECT_BINARY_DIR}/src/config.h)
|
|
include(cmake/ProjectOptions.cmake)
|
|
ss_project_options(ss_ev)
|
|
include_directories(${PROJECT_BINARY_DIR}/src)
|
|
add_compile_definitions(HAVE_CONFIG_H)
|
|
|
|
set(LIBBLOOM_SOURCE
|
|
third_party/bloom/bloom.c
|
|
third_party/bloom/murmur2/MurmurHash2.c
|
|
)
|
|
|
|
add_library(bloom STATIC ${LIBBLOOM_SOURCE})
|
|
target_include_directories(bloom PUBLIC third_party/bloom third_party/bloom/murmur2)
|
|
|
|
add_subdirectory(src)
|
|
include(cmake/InstallPackage.cmake)
|
|
add_subdirectory(doc)
|
|
|
|
# Testing
|
|
include(CTest)
|
|
if(BUILD_TESTING)
|
|
add_subdirectory(tests)
|
|
endif()
|
|
|
|
# Coverage report (requires ENABLE_COVERAGE=ON, lcov and genhtml)
|
|
# Usage: make coverage (after running ctest / integration tests)
|
|
if (ENABLE_COVERAGE)
|
|
find_program(LCOV_EXECUTABLE lcov)
|
|
find_program(GENHTML_EXECUTABLE genhtml)
|
|
if (LCOV_EXECUTABLE AND GENHTML_EXECUTABLE)
|
|
add_custom_target(coverage
|
|
COMMAND ${LCOV_EXECUTABLE} --capture --directory ${PROJECT_BINARY_DIR}
|
|
--output-file ${PROJECT_BINARY_DIR}/coverage.info
|
|
--include ${PROJECT_SOURCE_DIR}/src/*
|
|
--ignore-errors mismatch,unused,empty,gcov
|
|
COMMAND ${LCOV_EXECUTABLE} --list ${PROJECT_BINARY_DIR}/coverage.info
|
|
COMMAND ${GENHTML_EXECUTABLE} ${PROJECT_BINARY_DIR}/coverage.info
|
|
--output-directory ${PROJECT_BINARY_DIR}/coverage-html
|
|
COMMAND ${CMAKE_COMMAND} -E echo "Coverage report: ${PROJECT_BINARY_DIR}/coverage-html/index.html"
|
|
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
|
VERBATIM
|
|
)
|
|
else ()
|
|
message(WARNING "lcov/genhtml not found - 'coverage' target unavailable")
|
|
endif ()
|
|
endif ()
|
|
|
|
# Install ss-nat on Linux
|
|
if(LINUX AND SS_INSTALL_TOOLS)
|
|
install(PROGRAMS src/ss-nat DESTINATION ${CMAKE_INSTALL_BINDIR})
|
|
endif()
|
|
|
|
# Install ss-setup TUI tool
|
|
if(UNIX AND SS_INSTALL_TOOLS)
|
|
install(PROGRAMS scripts/ss-setup.sh DESTINATION ${CMAKE_INSTALL_BINDIR} RENAME ss-setup)
|
|
endif()
|