Skip to content

Commit

Permalink
build: add tor_expert_bundle_target which downloads and extracts PTs …
Browse files Browse the repository at this point in the history
…from Tor Browser's tor-expert-bundle
  • Loading branch information
Richard Pospesel committed Jun 22, 2024
1 parent 19ce366 commit 13a854a
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 8 deletions.
27 changes: 19 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@ jobs:
cxxflags: -m32
rust-target: i686-unknown-linux-gnu
cmake-find-root-path: /usr/lib/i386-linux-gnu
teb-target: linux-i686
arch: i386
- debian-arch: amd64
rust-target: x86_64-unknown-linux-gnu
cmake-find-root-path: /usr/lib/x86_64-linux-gnu
teb-target: linux-x86_64
arch: x86_64
runs-on: ubuntu-latest
steps:
Expand All @@ -36,7 +38,7 @@ jobs:
rustup default stable-${{ matrix.rust-target }}
- name: Build Debug
run: |
cmake -S . -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DCMAKE_C_FLAGS="${{ matrix.cflags }}" -DCMAKE_CXX_FLAGS="${{ matrix.cxxflags }}" -DCMAKE_FIND_ROOT_PATH=${{ matrix.cmake-find-root-path }}
cmake -S . -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DCMAKE_C_FLAGS="${{ matrix.cflags }}" -DCMAKE_CXX_FLAGS="${{ matrix.cxxflags }}" -DCMAKE_FIND_ROOT_PATH=${{ matrix.cmake-find-root-path }} -DENABLE_TOR_EXPERT_BUNDLE=ON -DTEB_TARGET=${{ matrix.teb-target }}
cmake --build build
cmake --install build
- name: Archive Debug
Expand All @@ -50,7 +52,7 @@ jobs:
path: dist/gosling-linux-gnu-${{ matrix.arch }}-debug.tar
- name: Build Release
run: |
cmake -S . -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DCMAKE_C_FLAGS="${{ matrix.cflags }}"
cmake -S . -B build -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DCMAKE_C_FLAGS="${{ matrix.cflags }}" -DENABLE_TOR_EXPERT_BUNDLE=ON -DTEB_TARGET=${{ matrix.teb-target }}
cmake --build build
cmake --install build
- name: Archive Release
Expand All @@ -71,18 +73,23 @@ jobs:
- msystem: ucrt64
msys-env: ucrt-x86_64
java-arch: x64
teb-target: windows-x86_64
- msystem: clang64
msys-env: clang-x86_64
java-arch: x64
teb-target: windows-x86_64
- msystem: clang32
msys-env: clang-i686
java-arch: x86
teb-target: windows-i686
- msystem: mingw64
msys-env: x86_64
java-arch: x86_64
teb-target: windows-x86_64
- msystem: mingw32
msys-env: i686
java-arch: x86
teb-target: windows-i686
runs-on: windows-latest
defaults:
run:
Expand Down Expand Up @@ -116,7 +123,7 @@ jobs:
export PATH=$(cygpath -u ${JAVA_HOME})/bin:$PATH
mkdir -p build/debug
cd build/debug
cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_MSYS2_PKGBUILD=ON
cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_MSYS2_PKGBUILD=ON -DENABLE_TOR_EXPERT_BUNDLE=ON -DTEB_TARGET=${{ matrix.teb-target }}
make
make install
- name: Archive Debug
Expand All @@ -134,7 +141,7 @@ jobs:
export PATH=$(cygpath -u ${JAVA_HOME})/bin:$PATH
mkdir -p build/release
cd build/release
cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_MSYS2_PKGBUILD=ON
cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_MSYS2_PKGBUILD=ON -DENABLE_TOR_EXPERT_BUNDLE=ON -DTEB_TARGET=${{ matrix.teb-target }}
make
make install
- name: Archive Release
Expand All @@ -155,9 +162,11 @@ jobs:
- java-arch: x64
platform: x64
rust-target: x86_64-pc-windows-msvc
teb-target: windows-x86_64
- java-arch: x86
platform: Win32
rust-target: i686-pc-windows-msvc
teb-target: windows-x86_64
runs-on: windows-latest
steps:
- name: Checkout Gosling
Expand Down Expand Up @@ -185,7 +194,7 @@ jobs:
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
run: |
cmake -S . -B build/debug -DCMAKE_BUILD_TYPE=Debug -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON
cmake -S . -B build/debug -DCMAKE_BUILD_TYPE=Debug -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DENABLE_TOR_EXPERT_BUNDLE=ON -DTEB_TARGET=${{ matrix.teb-target }}
cmake --build build/debug --config Debug
cmake --install build/debug --config Debug
- name: Upload Debug
Expand All @@ -197,7 +206,7 @@ jobs:
env:
BOOST_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}
run: |
cmake -S . -B build/release -DCMAKE_BUILD_TYPE=Release -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON
cmake -S . -B build/release -DCMAKE_BUILD_TYPE=Release -A ${{ matrix.platform }} -DCMAKE_INSTALL_PREFIX=dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DENABLE_TOR_EXPERT_BUNDLE=ON -DTEB_TARGET=${{ matrix.teb-target }}
cmake --build build/release --config Release
cmake --install build/release --config Release
- name: Upload Release
Expand All @@ -213,8 +222,10 @@ jobs:
include:
- runs-on: macos-12
arch: x86_64
teb-target: macos-x86_64
- runs-on: macos-14
arch: aarch64
teb-target: macos-aarch64
runs-on: ${{ matrix.runs-on }}
steps:
- name: Checkout Gosling
Expand All @@ -228,7 +239,7 @@ jobs:
run: |
mkdir -p build/debug
cd build/debug
cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_HOMEBREW_FORMULA=ON
cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=../../dist/debug -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_HOMEBREW_FORMULA=ON -DENABLE_TOR_EXPERT_BUNDLE=ON -DTEB_TARGET=${{ matrix.teb-target }}
make
make install
- name: Archive Debug
Expand All @@ -244,7 +255,7 @@ jobs:
run: |
mkdir -p build/release
cd build/release
cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_HOMEBREW_FORMULA=ON
cmake ../.. -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=../../dist/release -DBUILD_PYTHON_BINDINGS=ON -DBUILD_JAVA_BINDINGS=ON -DBUILD_EXAMPLES=ON -DBUILD_HOMEBREW_FORMULA=ON -DENABLE_TOR_EXPERT_BUNDLE=ON -DTEB_TARGET=${{ matrix.teb-target }}
make
make install
- name: Archive Release
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ if (ENABLE_TESTS OR ENABLE_FUZZ_TESTS)
enable_testing()
endif()

#
# Addditional Tools
#

# Run rust's clippy for Rust targets and cppcheck for C++ targets
option(ENABLE_LINTING "Enable lint make target" OFF)
if (ENABLE_LINTING)
find_program(JQ_EXECUTABLE NAMES jq)
Expand Down Expand Up @@ -49,6 +53,7 @@ if (ENABLE_LINTING)
add_dependencies(linting cppcheck_target)
endif()

#
option(ENABLE_FORMATTING "Enable format make target" OFF)
if (ENABLE_FORMATTING)
find_program(CLANG_FORMAT_EXECUTABLE NAMES clang-format)
Expand All @@ -66,6 +71,9 @@ if (ENABLE_FORMATTING)
add_custom_target(format)
endif()


option(ENABLE_TOR_EXPERT_BUNDLE "Enable and fetch tor-expert-bundle" OFF)

# Bindings options
option(BUILD_PYTHON_BINDINGS "Build cpython.py Python bindings" OFF)
option(BUILD_JAVA_BINDINGS "Build JNI and jar Java bindings" OFF)
Expand Down
4 changes: 4 additions & 0 deletions source/extern/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/json/CMakeLists.txt)
set(JSON_Install OFF CACHE INTERNAL "")
add_subdirectory(json)
endif()

if (ENABLE_TOR_EXPERT_BUNDLE)
add_subdirectory(tor-expert-bundle)
endif()
80 changes: 80 additions & 0 deletions source/extern/tor-expert-bundle/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# TEB shorthand for tor-expert-bundle
if (NOT TEB_VERSION)
set(TEB_VERSION 13.5)
endif()

if (NOT TEB_TARGET)
# get the CPU arch we are building for
if (WINDOWS)
set(TEB_OS "windows")
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "AMD64")
set(TEB_ARCH "x86_64")
elseif( CMAKE_SYSTEM_PROCESSOR STREQUAL "X86")
set(TEB_ARCH "i686")
else()
message(FATAL_ERROR "Unsupported Windows cpu architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
elseif(MACOS)
set(TEB_OS "macos")
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(TEB_ARCH "x86_64")
elseif( CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
set(TEB_ARCH "aarch64")
else()
message(FATAL_ERROR "Unsupported macOS cpu architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
elseif(LINUX)
set(TEB_OS "linux")
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
set(TEB_ARCH "x86_64")
elseif( CMAKE_SYSTEM_PROCESSOR STREQUAL "x86")
set(TEB_ARCH "i686")
else()
message(FATAL_ERROR "Unsupported Linux cpu architecture: ${CMAKE_SYSTEM_PROCESSOR}")
endif()
else()
message(FATAL_ERROR "Unsupported operating system")
endif()

set(TEB_TARGET "${TEB_OS}-${TEB_ARCH}")
message(WARNING
"User did not define TEB_TARGET, supported values:\n"
" - windows-i686\n"
" - windows-x86_64\n"
" - macos-x86_64\n"
" - macos-aarch64\n"
" - linux-i686\n"
" - linux-x86_64\n"
"Guessing ${TEB_TARGET}"
)
endif()

set(TEB_ARCHIVE "tor-expert-bundle-${TEB_TARGET}-${TEB_VERSION}.tar.gz")
set(TEB_ARCHIVE_URL "https://archive.torproject.org/tor-package-archive/torbrowser/${TEB_VERSION}/${TEB_ARCHIVE}")

message(STATUS "Downloading ${TEB_ARCHIVE_URL}")
file(DOWNLOAD "${TEB_ARCHIVE_URL}" "${CMAKE_CURRENT_BINARY_DIR}/${TEB_ARCHIVE}" SHOW_PROGRESS)
# TODO: verify gpg signature

set(pluggable_transport_binaries
${CMAKE_CURRENT_BINARY_DIR}/lyrebird${CMAKE_EXECUTABLE_SUFFIX}
${CMAKE_CURRENT_BINARY_DIR}/snowflake-client${CMAKE_EXECUTABLE_SUFFIX}
${CMAKE_CURRENT_BINARY_DIR}/conjure-client${CMAKE_EXECUTABLE_SUFFIX}
)

add_custom_command(
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${TEB_ARCHIVE}
OUTPUT ${pluggable_transport_binaries}
# extract tor expert bundle
COMMAND ${CMAKE_COMMAND} -E make_directory tor-expert-bundle
COMMAND ${CMAKE_COMMAND} -E chdir tor-expert-bundle ${CMAKE_COMMAND} -E tar xvf ${CMAKE_CURRENT_BINARY_DIR}/${TEB_ARCHIVE}
# copy each pt
COMMAND ${CMAKE_COMMAND} -E copy tor-expert-bundle/tor/pluggable_transports/lyrebird${CMAKE_EXECUTABLE_SUFFIX} .
COMMAND ${CMAKE_COMMAND} -E copy tor-expert-bundle/tor/pluggable_transports/snowflake-client${CMAKE_EXECUTABLE_SUFFIX} .
COMMAND ${CMAKE_COMMAND} -E copy tor-expert-bundle/tor/pluggable_transports/conjure-client${CMAKE_EXECUTABLE_SUFFIX} .
# cleanup exttra stuff
COMMAND ${CMAKE_COMMAND} -E rm -rf tor-expert-bundle
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
)
add_custom_target(tor_expert_bundle_target
DEPENDS ${pluggable_transport_binaries})

0 comments on commit 13a854a

Please sign in to comment.