-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnew-rust
executable file
·84 lines (60 loc) · 1.4 KB
/
new-rust
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
function new(){
set -x
cargo new "$@"
set +x
}
function new_fab() {
p=$1
(cd "$p"; cat > fabfile.py <<- EOF
# -*- coding: utf-8 -*-
from fabric.api import *
def dev():
"""dev"""
local("cargo watch -x run")
def run():
"""run"""
local('cargo run')
def build():
"""build in release"""
local('cargo build --release')
def build_musl():
"""build musl"""
local('cargo build --release --target x86_64-unknown-linux-musl')
def build_musl_upx():
"""tip"""
build_musl()
local('du -sh target/x86_64-unknown-linux-musl/release/$p')
local('cp target/x86_64-unknown-linux-musl/release/$p target/x86_64-unknown-linux-musl/release/$p.orig')
local('upx target/x86_64-unknown-linux-musl/release/$p')
local('du -sh target/x86_64-unknown-linux-musl/release/$p')
print('try run: target/x86_64-unknown-linux-musl/release/$p')
def setup_idea():
"""setup idea"""
local('unset https_proxy http_proxy;cargo metadata --verbose --format-version 1 --all-features')
EOF
)
}
for x in "$@"; do
if [ "${x:0:1}" != "-" ]; then
project=$x
fi
done
project=${project:-"test_rust"}
if [[ -d "$project" ]]; then
echo "$project already exists"
exit 1
fi
if [ "$#" -le 1 ]; then
new "$project" --bin
else
new "$@"
fi
new_fab "$project"
echo '/target/
**/*.rs.bk
*.pyc
.idea
*.iml' >> "$project/.gitignore"
echo ""
echo "cd $project"