Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
d7fc15b
Fix compile issues with clang 22
Zitrax Dec 15, 2025
a54abd0
Fix clang-tidy-22 issues
Zitrax Dec 16, 2025
0e38637
Disable -Weffc++ better covered by clang-tidy and newer compilers now
Zitrax Dec 18, 2025
e03d146
Make both g++-14 and clang++-22 happy with nrvo
Zitrax Dec 18, 2025
b643d98
Update ci to clang 22 and gcc 14
Zitrax Dec 18, 2025
a331a96
Update build instructions
Zitrax Dec 18, 2025
c2d1e16
Fix windows compile errors
Zitrax Dec 18, 2025
25773d6
Update dependencies
Zitrax Dec 18, 2025
fdadb82
Add torrent writer support
Zitrax Dec 19, 2025
e9769cd
Minor cleanup
Zitrax Dec 20, 2025
99f1a59
Add the torrent writer tests and multi support
Zitrax Dec 20, 2025
6ff6c47
Fix use after free
Zitrax Dec 20, 2025
22424f8
Fix various issues with the integration tests
Zitrax Dec 21, 2025
47ffc51
Do not restrict clang-tidy headers as long as we have no related issues
Zitrax Dec 21, 2025
0f59526
Copy msg to avoid it going out of scope (use after free)
Zitrax Dec 21, 2025
5d64d75
Better torrent dump info
Zitrax Dec 21, 2025
208f1fd
Improve torrent writer error message
Zitrax Dec 21, 2025
00eb108
Mark as not interested properly
Zitrax Dec 21, 2025
be6bdea
Fix clang-tidy issues
Zitrax Dec 21, 2025
6f51734
Add HOST_IP fallbacks
Zitrax Dec 21, 2025
9e07a0b
Fix permissions when webtorrent write files
Zitrax Dec 21, 2025
7643911
Ensure correct destination for multi_upload
Zitrax Dec 21, 2025
3ecbc09
Revert test .torrent files to master
Zitrax Dec 22, 2025
b57e2d7
Ifdef out non-win code on win
Zitrax Dec 22, 2025
e85dca1
Remove unused transmission code
Zitrax Dec 22, 2025
50dbc15
Minor polish
Zitrax Dec 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Magic number check is a bit noisy, so off by default
# -altera-struct-pack-align (too specific performance issue)
# -boost-* (not using boost)
# -cert-err58-cpp statics might throw. Allowing this for now.
# -clang-analyzer-cplusplus.NewDelete (temporary due to https://github.com/boostorg/asio/issues/341)
# -cppcoreguidelines-avoid-const-or-ref-data-members (TODO: Recheck later)
Expand All @@ -20,6 +21,7 @@
# -misc-non-private-member-variables-in-classes (optimally I would like to allow protected but not private)
# -modernize-avoid-c-arrays (covered by cppcore)
# -modernize-use-trailing-return-type (prefer old style for now)
# -portability-avoid-pragma-once (pragma once is nicer)
# -readability-braces-around-statements (can't handle constexpr if)
# -readability-function-cognitive-complexity (no hard limit on this)
# -readability-inconsistent-declaration-parameter-name (prefer different names on templates)
Expand All @@ -30,6 +32,7 @@ Checks: '*,
-abseil-*,
-altera-*,
-altera-struct-pack-align,
-boost-*,
-cert-err58-cpp,
-clang-analyzer-cplusplus.NewDelete,
-cppcoreguidelines-avoid-const-or-ref-data-members,
Expand All @@ -55,6 +58,7 @@ Checks: '*,
-modernize-avoid-c-arrays,
-modernize-use-trailing-return-type,
-objc-*,
-portability-avoid-pragma-once,
-readability-braces-around-statements,
-readability-function-cognitive-complexity,
-readability-identifier-length,
Expand All @@ -65,8 +69,7 @@ Checks: '*,
-readability-named-parameter,
'
WarningsAsErrors: '*'
HeaderFilterRegex: '(src|tests)/*.h$'
AnalyzeTemporaryDtors: false
HeaderFilterRegex: '.*'
FormatStyle: none
User: db
CheckOptions:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ jobs:
strategy:
matrix:
compiler:
- { os: ubuntu-24.04, bin: clang++-18 }
- { os: ubuntu-24.04, bin: g++-13 }
- { os: ubuntu-24.04, bin: clang++-22 }
- { os: ubuntu-24.04, bin: g++-14 }
- { os: windows-2022, bin: cl.exe }

runs-on: ${{ matrix.compiler.os }}
Expand All @@ -30,7 +30,7 @@ jobs:

- name: Apt install
if: runner.os == 'Linux'
run: sudo apt install -y ninja-build clang-18 g++-12
run: sudo apt install -y ninja-build clang-22 g++-14

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -GNinja -DDISABLE_LTO=ON -DUSE_CLANG_TIDY=OFF -DCMAKE_TOOLCHAIN_FILE=${{github.workspace}}/vcpkg/scripts/buildsystems/vcpkg.cmake
Expand Down
26 changes: 14 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,24 @@ endif()
include_directories(SYSTEM "external")

if(UNIX)
add_compile_options(-Wall -Wextra -Werror -Weffc++ -Wconversion -Wsign-conversion)
add_compile_options(-Wall -Wextra -Werror -Wconversion -Wsign-conversion)
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
# Be strict and just disable unwanted or noisy warnings
add_compile_options(
-Weverything
-Wno-c++98-compat # Don't care about c++98
-Wno-c++98-compat-pedantic # Don't care about c++98
-Wno-switch-default # Conflicts with -Wcovered-switch-default
-Wno-ctad-maybe-unsupported # Triggers on use of scoped_lock
-Wno-padded #
-Wno-weak-vtables #
-Wno-global-constructors # performance startup-time
-Wno-exit-time-destructors # similar as ^ for destructors
-Wno-undefined-func-template # does not seem very important
-Wno-zero-as-null-pointer-constant # fails clang-10 on travis but not locally?
-Wno-disabled-macro-expansion # Does not work when interfacing with csignal
-Wno-c++98-compat # Don't care about c++98
-Wno-c++98-compat-pedantic # Don't care about c++98
-Wno-switch-default # Conflicts with -Wcovered-switch-default
-Wno-ctad-maybe-unsupported # Triggers on use of scoped_lock
-Wno-padded #
-Wno-weak-vtables #
-Wno-global-constructors # performance startup-time
-Wno-exit-time-destructors # similar as ^ for destructors
-Wno-undefined-func-template # does not seem very important
-Wno-zero-as-null-pointer-constant # fails clang-10 on travis but not locally?
-Wno-disabled-macro-expansion # Does not work when interfacing with csignal
-Wno-unsafe-buffer-usage-in-libc-call # Complains about fgets but would like finer grain control like https://github.com/llvm/llvm-project/issues/127849
-Wno-unsafe-buffer-usage-in-container # We sametimes use spans to shorten the bound
)
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
add_compile_options(
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

# Build instructions

## Compilers

Note that at the moment the tested compilers are clang 22 and gcc 14 on Linux.

## CMake + vcpkg

* `git submodule update --init --recursive`
Expand All @@ -14,7 +18,3 @@
Or with --preset zit-gcc.

Note that on Linux `pkg-config` and `clang` or `gcc` must be installed.

## [Nix](https://nixos.org)

* `nix-build`
68 changes: 0 additions & 68 deletions default.nix

This file was deleted.

18 changes: 11 additions & 7 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
option(USE_CLANG_TIDY "Use clang-tidy if available" ON)
option(USE_CLANG_TIDY_CACHE "Use clang-tidy-cache if available" ON)
option(ASIO_DEBUG "Add asio debug output" OFF)
option(DISABLE_LTO "Turn off lto" OFF)

Expand All @@ -10,16 +11,18 @@ option(DISABLE_LTO "Turn off lto" OFF)
# the compile time went from 16s to 48s.
#
if(USE_CLANG_TIDY)
find_program(CLANG_TIDY NAMES clang-tidy-18)
find_program(CLANG_TIDY NAMES clang-tidy-22)

if(CLANG_TIDY)
find_program(CLANG_TIDY_CACHE NAMES "clang-tidy-cache")

if(CLANG_TIDY_CACHE)
message(STATUS "Found clang-tidy-cache: ${CLANG_TIDY_CACHE}")
set(CLANG_TIDY_CACHE_PREFIX "${CLANG_TIDY_CACHE};")
else()
message(STATUS "No clang-tidy-cache found")
if(USE_CLANG_TIDY_CACHE)
if(CLANG_TIDY_CACHE)
message(STATUS "Found clang-tidy-cache: ${CLANG_TIDY_CACHE}")
set(CLANG_TIDY_CACHE_PREFIX "${CLANG_TIDY_CACHE};")
else()
message(STATUS "No clang-tidy-cache found")
endif()
endif()

message(STATUS "Enabling clang-tidy: ${CLANG_TIDY}")
Expand Down Expand Up @@ -120,4 +123,5 @@ if(NOT WIN32)
endif()
endif()

add_subdirectory(socket_test)
add_subdirectory(socket_test)
add_subdirectory(torrent_writer)
4 changes: 2 additions & 2 deletions src/arg_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void ArgParser::parse(const std::vector<std::string>& argv) {
unsigned positional{0};
for (size_t i = 1; i < argv.size(); i++) {
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
const std::string& name = argv[i];
const std::string& name = argv.at(i);
auto m = find(name);
if (m == m_options.end()) {
// No named argument - check if we have positional
Expand Down Expand Up @@ -113,7 +113,7 @@ void ArgParser::parse(const std::vector<std::string>& argv) {
throw runtime_error(fmt::format("Missing value for {}", name));
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
val = argv[i++ + 1];
val = argv.at(i++ + 1);
}

switch (arg->get_type()) {
Expand Down
18 changes: 8 additions & 10 deletions src/arg_parser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ namespace zit {
*/
class ArgParser {
public:
enum class Type { INT, UINT, FLOAT, STRING, BOOL };
enum class Type : std::uint8_t { INT, UINT, FLOAT, STRING, BOOL };

private:
struct BaseArg {
explicit BaseArg(std::string option, Type type)
: m_option(std::move(option)), m_type(type) {}

virtual ~BaseArg() = default;
virtual void* dst() = 0;

[[nodiscard]] auto get_option() const { return m_option; }
[[nodiscard]] const auto& get_aliases() const { return m_aliases; }
Expand All @@ -45,15 +44,15 @@ class ArgParser {

protected:
std::string m_option;
std::string m_help{};
std::set<std::string> m_aliases{};
std::string m_help;
std::set<std::string> m_aliases;
Type m_type;
bool m_provided = false;
bool m_required = false;
bool m_help_arg = false;
bool m_is_multi = false;
bool m_is_collecting = false;
std::optional<unsigned> m_position{};
std::optional<unsigned> m_position;
};

template <typename T>
Expand Down Expand Up @@ -86,15 +85,14 @@ class ArgParser {
}
}

void* dst() override { return &m_dst; }

[[nodiscard]] auto dst() const { return m_dst.empty() ? m_default : m_dst; }

void set_dst(T t) {
if (!m_is_multi && !m_dst.empty()) {
throw std::runtime_error(
"Multiple values provided for single value option: " + m_option);
}
m_dst.emplace_back(t);
m_dst.emplace_back(std::move(t));
}

/** Help text for option */
Expand All @@ -111,7 +109,7 @@ class ArgParser {

/** Default value for option */
auto& default_value(T t) {
m_default = {t};
m_default = {std::move(t)};
return *this;
}

Expand Down Expand Up @@ -184,7 +182,7 @@ class ArgParser {
void verify_no_duplicate_collecting() const;

std::string m_desc;
std::vector<std::unique_ptr<BaseArg>> m_options{};
std::vector<std::unique_ptr<BaseArg>> m_options;
bool m_parsed = false;

template <typename T>
Expand Down
14 changes: 8 additions & 6 deletions src/bencode.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ template <typename T>

template <typename T>
[[nodiscard]] std::string encode(const T& in) {
using src = typename ArrayToPointerDecay<T>::type;
using src = ArrayToPointerDecay<T>::type;
return encode_internal<src>(in);
}

Expand Down Expand Up @@ -122,26 +122,26 @@ class Element : public std::enable_shared_from_this<Element> {

template <typename T>
[[nodiscard]] auto to() const {
static_assert(std::is_base_of<Element, T>::value,
static_assert(std::is_base_of_v<Element, T>,
"Can only return sublasses of Element");
auto ptr = std::dynamic_pointer_cast<const T>(shared_from_this());
if (!ptr) {
throw BencodeConversionError("Could not convert to type");
}
return ptr;
return std::move(ptr);
}

template <typename T>
[[nodiscard]] auto is() const {
static_assert(std::is_base_of<Element, T>::value,
static_assert(std::is_base_of_v<Element, T>,
"Can only return sublasses of Element");
return std::dynamic_pointer_cast<const T>(shared_from_this()) != nullptr;
}

virtual std::ostream& print(std::ostream& os) = 0;

/**
* First try used T&& val, but it caoused storage of int references when we
* First try used T&& val, but it caused storage of int references when we
* want such values copied. See https://stackoverflow.com/q/17316386/11722 and
* https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers
* for details.
Expand Down Expand Up @@ -169,7 +169,9 @@ class TypedElement : public Element {
explicit TypedElement(std::add_rvalue_reference_t<T> data)
: m_data(std::forward<T>(data)) {}

[[nodiscard]] std::string encode() const override { return bencode::encode(m_data); }
[[nodiscard]] std::string encode() const override {
return bencode::encode(m_data);
}

[[nodiscard]] auto val() const { return m_data; }

Expand Down
Loading