Add helpful build script

This commit is contained in:
Y. T. Chung
2017-07-29 00:59:03 +08:00
parent 5663623f59
commit 2dfd94dac1
3 changed files with 57 additions and 4 deletions

View File

@@ -16,6 +16,8 @@ shadowsocks is a fast tunnel proxy that helps you <del>bypass firewalls</del>.
## 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

View File

@@ -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.
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
```

30
build/build-release Executable file
View File

@@ -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"