diff --git a/README.md b/README.md index e04bbbfd..1f0ad63b 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ shadowsocks is a fast tunnel proxy that helps you bypass firewalls. ## Usage +### **crates.io** + Install from [crates.io](https://crates.io/crates/shadowsocks-rust): ```bash @@ -24,7 +26,7 @@ cargo install shadowsocks-rust then you can find `sslocal` and `ssserver` in `$CARGO_HOME/bin`. -or you can also build with [Cargo](http://doc.crates.io): +### **Build from source** ```bash cargo build @@ -33,6 +35,19 @@ cargo build Then `sslocal` and `ssserver` will appear in `./target`, it works similarly as the two binaries in the official ShadowSocks' implementation. +### **Build standalone binaries** + +Requirements: + +* Linux x86_64 +* Docker + +```bash +./build/build-release +``` + +Then `sslocal`, `ssserver` and `ssurl` will be packaged in `./build/shadowsocks-latest-release.x86_64-unknown-linux-musl.tar.gz`. + Read `Cargo.toml` for more details. ## Getting Started diff --git a/build/README.md b/build/README.md index 936df429..77b10794 100644 --- a/build/README.md +++ b/build/README.md @@ -2,10 +2,18 @@ Compile static-linked binaries with [`rust-musl-builder`](https://github.com/emk ```sh # build image use Dockerfile in build dir. -docker build -t shadowsocks_rust:0.0.1 . +docker build -t shadowsocks-rust:latest . # run command in project root. -alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src shadowsocks_rust:0.0.1' +alias rust-musl-builder='docker run --rm -it -v "$(pwd)":/home/rust/src shadowsocks-rust:latest' rust-musl-builder cargo build --release ``` -At the moment, it doesn't attempt to cache libraries between builds, so this is best reserved for making final release builds. \ No newline at end of file +At the moment, it doesn't attempt to cache libraries between builds, so this is best reserved for making final release builds. + +## Helpful Scripts + +* `build-release` on *nix environment + +```bash +./build-release +``` diff --git a/build/build-release b/build/build-release new file mode 100755 index 00000000..e204e7b1 --- /dev/null +++ b/build/build-release @@ -0,0 +1,30 @@ +#!/bin/sh + +IMAGE='shadowsocks-rust:latest' +CUR_DIR=$( cd $( dirname $0 ) && pwd ) + +docker build -t "${IMAGE}" "$CUR_DIR" + +SRC_PATH="/home/rust/src" +CARGO_TARGET_DIR="${SRC_PATH}/build/target" +LOCAL_USER=$( id -u "$USER" ):$( id -g "$USER" ) + +docker run \ + --rm \ + -it \ + -e CARGO_TARGET_DIR="${CARGO_TARGET_DIR}" \ + -v "${CUR_DIR}"/..:"$SRC_PATH" \ + "${IMAGE}" \ + /bin/bash -c \ + "sudo mkdir -p $CARGO_TARGET_DIR \ + && sudo chown -R rust:rust $CARGO_TARGET_DIR \ + && cargo build --release \ + && sudo chown -R $LOCAL_USER $CARGO_TARGET_DIR" + +TARGET_NAME="x86_64-unknown-linux-musl" +TARGET_DIR="$CUR_DIR/target/$TARGET_NAME/release/" +cd "$TARGET_DIR" +tar -czf "${CUR_DIR}/shadowsocks-latest-release.${TARGET_NAME}.tar.gz" \ + "sslocal" \ + "ssserver" \ + "ssurl"