Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Build, run and install from source

This page shows how to build each part of Tetheron and run what you built, in place of an installed copy or beside it. First set up a development environment.

Build the desktop side

All Cargo commands run in desktop/.

cd desktop
cargo build --workspace

The programs are in target/debug/:

ProgramCrateWhat it is
tetherdtetherdthe daemon
tethertether-gtkthe GTK app
tether-clitether-clithe command-line client of the daemon

To build one crate, name it: cargo build -p tetherd. With --release the build is optimised and the programs are in target/release/.

Choose Cargo features

CrateFeatureDefaultEffect
tether-gtktrayonTray icon (StatusNotifierItem). Does nothing when the desktop has no tray host.
tether-gtkmirroronVideo in the phone-screen and app windows, through GStreamer. Without it the windows open and show “No video in this build”.
tether-gtkmockoffThe --mock option: the app runs against a fake daemon inside its own process.
tetherdaudioonPhone audio on the PC, through GStreamer. Without it PhoneAudioState is unsupported.
tetherdwebcamonPhone as webcam, through GStreamer. Without it WebcamSetupState is unsupported.
cargo build -p tether-gtk --features mock           # app with the fake daemon
cargo build -p tetherd --no-default-features        # daemon without GStreamer
cargo test --workspace --features tether-gtk/mock   # all tests, including the mock's

Run a debug daemon and app in place of the installed ones

Use this to try your build with your real, already paired phone. The debug daemon takes the installed daemon’s bus name and port, and reads the same settings and data in ~/.config/tether and ~/.local/share/tether.

Warning

The debug daemon works on your real data. A daemon that is newer than the installed one may move the per-phone database to a newer schema, which the installed daemon then has to open. If you are changing the database, copy ~/.local/share/tether first.

  1. Stop the installed daemon and app:

    systemctl --user stop tetherd
    pkill -x tether
    
  2. Start the debug daemon from desktop/ straight away and leave it running:

    RUST_LOG=info,tetherd=debug ./target/debug/tetherd
    

    The installed package registers the daemon for D-Bus activation. While no daemon owns org.tether.Daemon, a program that calls that name makes the session bus start the installed daemon again, and your debug daemon then fails with owning org.tether.Daemon (is another tetherd running?).

  3. In a second terminal, start the debug app:

    ./target/debug/tether
    
  4. Use ./target/debug/tether-cli for the command line. tether-cli mirror and tether-cli app start the tether program that lies next to tether-cli, so they open the debug app. Set TETHER_APP to a path to make them start a different one.

cargo run -p tetherd, cargo run -p tether-gtk and cargo run -p tether-cli -- <command> do the same and rebuild first.

Switch back to the installed ones

  1. Stop the debug app and daemon. Press Ctrl+C in their terminals, or:

    pkill -x tether
    pkill -x tetherd
    

    pkill -x matches the exact program name. Never use pkill -f: it matches whole command lines, including that of the shell that runs it.

  2. Start the installed daemon again:

    systemctl --user start tetherd
    
  3. Start the installed app from the application menu.

Run a debug daemon beside the installed one

Use this when the installed daemon should keep serving your phone while you work. The second daemon needs its own bus name, ports and directories.

VariableEffectDefault
TETHER_BUS_NAMEBus name the daemon takes. tether-cli reads the same variable to choose the daemon it talks to.org.tether.Daemon
TETHER_PORTTCP port for phones and UDP port for discovery beaconsport in config.toml, 7360
TETHER_PEER_PORTPort on which the daemon dials back a peer that connected to it. Needed only for a fake phone on a port other than 7360.7360
TETHER_ADB_PORTPort of the daemon’s private adb serveradb_server_port in config.toml, 5038
XDG_CONFIG_HOME, XDG_DATA_HOME, XDG_CACHE_HOMEWhere the settings, the identity and trusted devices, and the caches live~/.config, ~/.local/share, ~/.cache
  1. Create a directory for the second daemon:

    mkdir -p ~/tether-debug/config ~/tether-debug/data ~/tether-debug/cache
    
  2. Start the daemon with all of the variables:

    TETHER_BUS_NAME=org.tether.Debug \
    TETHER_PORT=7362 \
    TETHER_ADB_PORT=5039 \
    XDG_CONFIG_HOME=$HOME/tether-debug/config \
    XDG_DATA_HOME=$HOME/tether-debug/data \
    XDG_CACHE_HOME=$HOME/tether-debug/cache \
      ./target/debug/tetherd
    
  3. Talk to it with tether-cli:

    TETHER_BUS_NAME=org.tether.Debug ./target/debug/tether-cli devices
    

Set every variable. Without TETHER_ADB_PORT, both daemons use the adb server on port 5038, and the debug daemon stops that server when it exits. Without the XDG_ variables, both daemons write the same files.

The second daemon has its own identity, so to a phone it is another computer. It announces itself on the network unless its config.toml says discoverable = false.

The GTK app does not read TETHER_BUS_NAME. It always talks to org.tether.Daemon, and a second tether process hands over to the one that is already running. Drive a second daemon with tether-cli or with a fake phone. The tutorial is a complete example of this set-up.

Run the app against its fake daemon

cargo run -p tether-gtk --features mock -- --mock

The mock app has its own application id (org.tether.Tether.Mock) and runs beside the real app. It shares the real app’s settings file (~/.config/tether/gtk.toml), its autostart switch, and the launcher entries that “Pin to desktop” writes. Point it at scratch directories to keep those apart:

XDG_CONFIG_HOME=/tmp/tether-mock/config XDG_DATA_HOME=/tmp/tether-mock/data \
  cargo run -p tether-gtk --features mock -- --mock

The mock’s options are in Test your changes.

Build and install the Android app

All Gradle commands run in android/.

Debug APK

  1. Build it:

    cd android
    ./gradlew :app:assembleDebug
    

    The APK is app/build/outputs/apk/debug/app-debug.apk.

  2. Install it on the phone that is connected over adb, and start it:

    adb install -r app/build/outputs/apk/debug/app-debug.apk
    adb shell am start -n org.tether.android/.ui.MainActivity
    

adb install -r replaces the app and keeps its data, so a debug APK installed over an earlier debug APK from the same computer keeps the phone’s identity and its pairing.

The debug and the release build have the same application id, org.tether.android, and different signing keys. Android refuses to install one over the other. Uninstall the app first. That removes the app’s data, so you pair again afterwards.

Release APK

./gradlew :app:assembleRelease

The release build is minified with R8. It is signed only if the build finds a keystore, through four TETHER_* environment variables or android/keystore.properties (see “Sign the APK” in Package and release). Without one the APK is unsigned, and Android does not install an unsigned APK.

A release APK that you sign with your own key cannot replace the project’s released APK on a phone, because the keys differ.

Build and install the Debian package

  1. Install cargo-deb once:

    cargo install cargo-deb --locked
    
  2. Build the release programs and the package:

    desktop/packaging/build-deb.sh
    

    The script runs cargo build --release --workspace and then cargo deb -p tetherd --no-build. The package is one file, desktop/target/debian/tether_<version>-1_<arch>.deb, and contains the daemon, the app and tether-cli.

  3. Inspect it if you changed the packaging:

    dpkg-deb -c desktop/target/debian/tether_*.deb
    lintian desktop/target/debian/tether_*.deb
    
  4. Install it and restart the daemon:

    sudo apt install ./desktop/target/debian/tether_*.deb
    systemctl --user restart tetherd
    

Build the tarball for other distributions

desktop/packaging/build-tarball.sh

The script builds the release programs and writes desktop/target/tarball/tether-<version>-linux-<arch>.tar.gz. Unpack it and run sudo ./install.sh to install your build under /usr/local, as Install Tetheron on Linux describes for a release. The programs need the GTK, libadwaita and glibc versions of the machine that built them, or newer.

The package layout and the maintainer scripts are described in desktop/packaging/README.md. Releases are covered in Package and release.