Embed Tor executable for static Mac OS builds

This commit is contained in:
dsc 2020-10-09 23:22:02 +02:00
parent 18543ad33b
commit 1337c1708d
5 changed files with 36 additions and 3 deletions

View file

@ -172,12 +172,23 @@ endif()
# Tor/torsocks # Tor/torsocks
set(TOR_TAG "tor-0.4.3.5") set(TOR_TAG "tor-0.4.3.5")
set(TOR_DIR "${CMAKE_SOURCE_DIR}/contrib/tor") set(TOR_DIR "${CMAKE_SOURCE_DIR}/contrib/tor")
if(BUILD_TOR AND APPLE)
execute_process(COMMAND bash -c "touch ${CMAKE_SOURCE_DIR}/src/tor/libevent-2.1.7.dylib")
ENDIF()
if(UNIX AND NOT APPLE) if(UNIX AND NOT APPLE)
set(TOR_LIB "libtorsocks.so") set(TOR_LIB "libtorsocks.so")
elseif(APPLE) elseif(APPLE)
set(TOR_LIB "libtorsocks.dylib") set(TOR_LIB "libtorsocks.dylib")
endif() endif()
if("$ENV{DRONE}" STREQUAL "true" AND STATIC AND BUILD_TOR)
if("$ENV{DRONE}" STREQUAL "true" AND APPLE)
message(STATUS "We are inside a static compile with Drone CI")
# @TODO: taken from Tor Browser official release for now
execute_process(COMMAND bash -c "cp ~/tor/libevent-2.1.7.dylib ${CMAKE_SOURCE_DIR}/src/tor/libevent-2.1.7.dylib")
execute_process(COMMAND bash -c "cp ~/tor/tor ${CMAKE_SOURCE_DIR}/src/tor/tor")
elseif("$ENV{DRONE}" STREQUAL "true" AND BUILD_TOR)
message(STATUS "We are inside a static compile with Drone CI") message(STATUS "We are inside a static compile with Drone CI")
if(MINGW) if(MINGW)
execute_process(COMMAND bash -c "cp /mxe/usr/x86_64-w64-mingw32.static/bin/tor.exe ${CMAKE_SOURCE_DIR}/src/tor/tor.exe") execute_process(COMMAND bash -c "cp /mxe/usr/x86_64-w64-mingw32.static/bin/tor.exe ${CMAKE_SOURCE_DIR}/src/tor/tor.exe")

View file

@ -42,7 +42,7 @@ file(GLOB SOURCE_FILES
"dialog/*.cpp" "dialog/*.cpp"
) )
if(APPLE AND BUILD_TOR) if((APPLE AND BUILD_TOR) OR (APPLE AND "$ENV{DRONE}" STREQUAL "true"))
set(ASSETS_OS "assets_macos_tor.qrc") set(ASSETS_OS "assets_macos_tor.qrc")
elseif(UNIX AND NOT APPLE AND BUILD_TOR) elseif(UNIX AND NOT APPLE AND BUILD_TOR)
set(ASSETS_OS "assets_linux_tor.qrc") set(ASSETS_OS "assets_linux_tor.qrc")
@ -138,6 +138,10 @@ if(STATIC)
target_compile_definitions(feather PRIVATE STATIC=1) target_compile_definitions(feather PRIVATE STATIC=1)
endif() endif()
if("$ENV{DRONE}" STREQUAL "true")
target_compile_definitions(feather PRIVATE DRONE=1)
endif()
if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug") if (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(feather PRIVATE QT_NO_DEBUG=1) target_compile_definitions(feather PRIVATE QT_NO_DEBUG=1)
endif() endif()

View file

@ -1,5 +1,6 @@
<!DOCTYPE RCC><RCC version="1.0"> <!DOCTYPE RCC><RCC version="1.0">
<qresource prefix="/"> <qresource prefix="/">
<file>tor/tor</file> <file>tor/tor</file>
<file>tor/libevent-2.1.7.dylib</file>
</qresource> </qresource>
</RCC> </RCC>

View file

@ -174,6 +174,22 @@ void Tor::handleProcessError(QProcess::ProcessError error) {
bool Tor::unpackBins() { bool Tor::unpackBins() {
QString torFile; QString torFile;
// @TODO: refactor for Mac OS - should compile Tor statically.
#if defined(Q_OS_MAC) && defined(DRONE)
// Tor on Mac requires libevent.dylib, borrowed the executable from
// the official Tor Browser release for now.
QString libEvent = ":/tor/libevent-2.1.7.dylib";
if (Utils::fileExists(libEvent)) {
QFile e(libEvent);
QFileInfo eventInfo(e);
auto libEventPath = QDir(this->torDir).filePath(eventInfo.fileName());
qDebug() << libEventPath;
e.copy(libEventPath);
e.close();
}
#endif
#if defined(Q_OS_MAC) || defined(Q_OS_LINUX) #if defined(Q_OS_MAC) || defined(Q_OS_LINUX)
torFile = ":/tor/tor"; torFile = ":/tor/tor";
#elif defined(Q_OS_WIN) #elif defined(Q_OS_WIN)

View file

@ -3,11 +3,12 @@
HASH="$1" HASH="$1"
echo "[+] hash: $HASH" echo "[+] hash: $HASH"
export DRONE=true
echo "[+] Building" echo "[+] Building"
rm ~/feather.zip 2>&1 >/dev/null rm ~/feather.zip 2>&1 >/dev/null
cd ~/feather cd ~/feather
git fetch git fetch --all
git reset --hard "$HASH" git reset --hard "$HASH"
git submodule update --init --depth 50 contrib/tor git submodule update --init --depth 50 contrib/tor
git submodule update --init --depth 50 contrib/torsocks git submodule update --init --depth 50 contrib/torsocks