#tor #daemon

sys libtor-sys

Rust crate that internally compiles Tor and its dependencies

8 releases (5 stable)

Uses old Rust 2015

43.6.0+0.4.3.6 Jul 20, 2020
43.5.1+0.4.3.5 May 24, 2020
42.7.1+0.4.2.7 May 24, 2020
42.7.0+0.4.2.7 Mar 21, 2020
4.2.6-5+0.4.2.6 Mar 8, 2020

#74 in macOS APIs

Download history 17/week @ 2020-05-29 29/week @ 2020-06-05 24/week @ 2020-06-12 8/week @ 2020-06-19 4/week @ 2020-06-26 60/week @ 2020-07-03 13/week @ 2020-07-10 40/week @ 2020-07-17 16/week @ 2020-07-24 7/week @ 2020-07-31 13/week @ 2020-08-07 24/week @ 2020-08-14 20/week @ 2020-08-21 25/week @ 2020-08-28 34/week @ 2020-09-04 10/week @ 2020-09-11

80 downloads per month
Used in libtor

MIT license

15MB
343K SLoC

C 322K SLoC // 0.2% comments Shell 11K SLoC // 0.2% comments Python 5.5K SLoC // 0.3% comments Automake 3.5K SLoC // 0.1% comments Perl 400 SLoC // 0.1% comments Rust 395 SLoC // 0.1% comments Q 304 SLoC PHP 114 SLoC Lua 77 SLoC // 0.1% comments SWIG 10 SLoC // 0.2% comments

libtor-sys Build Status

This library compiles Tor and a few dependencies (zlib, libevent and openssl) into a single Rust library that can be imported like any other Rust crate into existing projects. This provides a way to use Tor without having to ship/download extra binaries - on platforms that allows running them - while for some other platforms like iOS and newer Android versions this is the only way to run Tor since the OS straight up doesn't allow exec'ing binaries.

Keep in mind that the interface exposed here is very very "low-level" (literally just what's in tor_api.h). Another crate wrapping all of these parts with a nice Rust interface will be released separately.

Supported platforms

The currently supported platforms are:

  • Linux (tested on Fedora 30 and Ubuntu Xenial)
  • Android through the NDK

Coming Soon ™️:

  • MacOS (it might even work now, but I don't have a Mac to test it)
  • iOS
  • Windows

Build gotchas

Linux

Building on a Linux pc shouldn't be too hard, a cargo build should normally work. Keep in mind that you will need all the "usual" build tools, like a compiler, automake, autoconf, make, in your PATH.

If you get an aclocal-1.15 not found or something similar, try to cd into libevent-<version> and run autoreconf --force --install. Repeat in tor-tor-<version> if you get the same issue there, and then re-cargo build.

Android

Cross-compiling for Android is a bit more complicated, there are a few things to adjust:

  1. Some libraries (zlib) are provided by the OS, but we need to link against them. So an extra environment variable SYSROOT that points to the sysroot shipped with NDK is required to let Rust know where to look for those libraries.
  2. Rust by default will look for a compiler named <arch>-linux-android-clang, but that's not how they are called in the NDK. So a CC env variable should be provided, pointing to the right compiler for the specific architecture.
  3. Rust will also look for other compiling tools, like ar. Usually the best thing is to have the NDK's bin folder in your PATH so that it can find everything it needs.

At the end, your command line will look something like this, assuming you are building for aarch64 on a linux-x86_64 pc, targeting android21:

PATH="$PATH:$NDK_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin" SYSROOT=$NDK_HOME/platforms/android-21/arch-arm64 CC="aarch64-linux-android21-clang" cargo build --target=aarch64-linux-android

Dependencies

~2.7–4.5MB
~103K SLoC