Skip to content

Commit 042d7bc

Browse files
committed
Fix libtorrent integration: remove hardcoded paths, fix code style
- Remove hardcoded /opt/homebrew/include paths from meson.build that would break CI on non-macOS platforms - Add proper GPL copyright header to libtorrent.h and libtorrent.cpp - Fix forward declaration of libtorrent::session (use struct not class) - Rename member variable to mp_session following kiwix naming convention - Fix namespace comment style to match existing codebase - Simplify test file by removing redundant test case and fixing include order libtorrent-rasterbar IS the official libtorrent library from github.com/arvidn/libtorrent - the 'rasterbar' name comes from the project's origins. This is the correct pkg-config name.
1 parent 892647f commit 042d7bc

File tree

4 files changed

+56
-46
lines changed

4 files changed

+56
-46
lines changed

meson.build

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,10 @@ zlib_dep = dependency('zlib', static:static_deps)
6363
xapian_dep = dependency('xapian-core', static:static_deps)
6464
libtorrent_dep = dependency('libtorrent-rasterbar', static:static_deps)
6565

66-
6766
if compiler.has_header('mustache.hpp')
6867
extra_include = []
6968
elif compiler.has_header('mustache.hpp', args: '-I/usr/include/kainjow')
7069
extra_include = ['/usr/include/kainjow']
71-
elif compiler.has_header('mustache.hpp', args: '-I/opt/homebrew/include')
72-
extra_include = []
7370
else
7471
error('Cannot found header mustache.hpp')
7572
endif
@@ -103,10 +100,7 @@ all_deps = [thread_dep, libzim_dep, pugixml_dep, libcurl_dep, microhttpd_dep, zl
103100
# Dependencies as array
104101
all_deps += libicu_deps
105102

106-
# Add boost include path for libtorrent
107-
boost_include = include_directories('/opt/homebrew/include')
108-
109-
inc = include_directories('include', extra_include, '/opt/homebrew/include')
103+
inc = include_directories('include', extra_include)
110104

111105
conf = configuration_data()
112106
conf.set('LIBKIWIX_VERSION', '"@0@"'.format(meson.project_version()))

src/libtorrent.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
1-
1+
/*
2+
* Copyright 2025 Kiwix developers
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
219

320
#include "libtorrent.h"
421

@@ -8,20 +25,16 @@
825
namespace kiwix
926
{
1027

11-
LibTorrent::LibTorrent() : m_session(new libtorrent::session())
28+
LibTorrent::LibTorrent()
29+
: mp_session(new libtorrent::session())
1230
{
13-
// Create a basic libtorrent session
14-
// This ensures we can successfully link against libtorrent
1531
}
1632

17-
LibTorrent::~LibTorrent()
18-
{
19-
// Cleanup is handled automatically by unique_ptr
20-
}
33+
LibTorrent::~LibTorrent() = default;
2134

2235
std::string LibTorrent::getVersion() const
2336
{
2437
return LIBTORRENT_VERSION;
2538
}
2639

27-
} // end namespace kiwix
40+
} // namespace kiwix

src/libtorrent.h

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,24 @@
1+
/*
2+
* Copyright 2025 Kiwix developers
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 3 of the License, or
7+
* any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the Free Software
16+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17+
* MA 02110-1301, USA.
18+
*/
119

2-
3-
#ifndef KIWIXLIB_LIBTORRENT_H_
4-
#define KIWIXLIB_LIBTORRENT_H_
20+
#ifndef KIWIX_LIBTORRENT_H
21+
#define KIWIX_LIBTORRENT_H
522

623
#include <memory>
724
#include <string>
@@ -15,27 +32,28 @@ namespace kiwix
1532
{
1633

1734
/**
18-
* @brief A minimal wrapper class around libtorrent-rasterbar
35+
* A minimal wrapper class around libtorrent.
1936
*
2037
* This is a stub implementation to verify that libkiwix can successfully
21-
* compile and link against libtorrent-rasterbar library.
38+
* compile and link against libtorrent library.
2239
*/
2340
class LibTorrent
2441
{
25-
private:
26-
std::unique_ptr<libtorrent::session> m_session;
27-
2842
public:
2943
LibTorrent();
30-
virtual ~LibTorrent();
44+
~LibTorrent();
3145

3246
/**
33-
* @brief Get the version of libtorrent being used
34-
* @return Version string of libtorrent-rasterbar
47+
* Get the version of libtorrent being used.
48+
*
49+
* @return Version string of libtorrent
3550
*/
3651
std::string getVersion() const;
52+
53+
private:
54+
std::unique_ptr<libtorrent::session> mp_session;
3755
};
3856

39-
} // end namespace kiwix
57+
} // namespace kiwix
4058

41-
#endif // KIWIXLIB_LIBTORRENT_H_
59+
#endif // KIWIX_LIBTORRENT_H

test/libtorrent.cpp

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
#include "gtest/gtest.h"
12
#include "../src/libtorrent.h"
23

34
#include <string>
45

5-
#include "gtest/gtest.h"
6-
76
namespace
87
{
98

@@ -24,18 +23,4 @@ TEST(LibTorrentTest, CanGetVersion)
2423
EXPECT_NE(version.find_first_of("0123456789"), std::string::npos);
2524
}
2625

27-
TEST(LibTorrentTest, CanIncludeLinkLibtorrent)
28-
{
29-
// This test verifies that we can successfully:
30-
// 1. Include libtorrent headers (done in libtorrent.h/cpp)
31-
// 2. Link against libtorrent library (verified by instantiation)
32-
// 3. Call basic libtorrent functions (getVersion uses LIBTORRENT_VERSION)
33-
34-
kiwix::LibTorrent lt;
35-
std::string version = lt.getVersion();
36-
37-
// If we can create an instance and get version, linking works
38-
EXPECT_TRUE(true);
39-
}
40-
41-
} // unnamed namespace
26+
} // unnamed namespace

0 commit comments

Comments
 (0)