-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathjustfile
More file actions
206 lines (155 loc) · 4.83 KB
/
justfile
File metadata and controls
206 lines (155 loc) · 4.83 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
cargo := if env_var_or_default('USE_CROSS', 'false') == "true" { "cross" } else { "cargo" }
alias b := build
alias c := clippy
alias t := test
alias pack := package
set positional-arguments
name := "smartdns"
target := `rustc -vV | grep host | cut -d ' ' -f2`
version := `cargo pkgid | cut -d@ -f2`
diagnostic := ""
bin_name := if os_family() == "windows" { name + ".exe" } else { name }
dist_dir := "dist"
dist_name := name + "-" + target
dist_zip := if os() == "windows" { dist_name + "-v" + version + ".zip" } else if os() == "macos" { dist_name + "-v" + version + ".zip" } else { dist_name + "-v" + version + ".tar.gz" }
#------------#
# versioning #
#------------#
# Increment manifest version: major, minor, patch, rc, beta, alpha
bump +args: require_set-version
@cargo set-version --bump {{args}}
# Print current version
version:
@echo "{{version}}"
#----------#
# building #
#----------#
# Build
build *args: patch
#!/usr/bin/env sh
if [ ! -z {{diagnostic}} ] ; then
echo "{{cargo}} build --features "future-diagnostic" {{args}}"
RUSTFLAGS="--cfg tokio_unstable" {{cargo}} build --features "future-diagnostic" {{args}}
else
echo "{{cargo}} build {{args}}"
{{cargo}} build {{args}}
fi
# Build Windows installer
[windows]
wix: && wix-sha256sum
#!/usr/bin/env sh
# set -euxo pipefail
wix --version >/dev/null 2>&1 || { echo "wix not installed"; exit 1; } # check if wix is installed
TARGET="{{target}}"
if [[ "$TARGET" != *windows* ]]; then
exit 0
fi
ARCH="${TARGET%%-*}"
case "$ARCH" in
x86_64) ARCH="x64" ;;
aarch64) ARCH="arm64" ;;
i[3-6]86|x86) ARCH="x86" ;;
thumbv7a|armv7) ARCH="arm" ;;
arm64|arm64ec) ARCH="arm64ec" ;;
*)
exit 0
;;
esac
VERSION="{{version}}"
SOURCE_DIR="{{dist_dir}}/{{dist_name}}"
OUTPUT="{{dist_dir}}/{{dist_name}}-v{{version}}.msi"
echo "Building Windows installer for $ARCH..."
# echo "TARGET=$TARGET"
# echo "ARCH=$ARCH"
# echo "VERSION=$VERSION"
VERSION="$VERSION" TARGET="$TARGET" SOURCE_DIR="$SOURCE_DIR" wix build -acceptEula wix7 -arch $ARCH ./wix.wxs -o $OUTPUT
echo "Saved to: $OUTPUT"
# Publish to Crates.io
publish *args: patch
{{cargo}} publish --no-verify
# Package the binary for distribution
[unix]
package: patch package-clean package-prepare && zip package-list
cp target/{{target}}/release/{{bin_name}} {{dist_dir}}/{{dist_name}}
# Package the binary for distribution
[windows]
package: patch package-clean package-prepare && zip wix package-list
cp target/{{target}}/release/{{bin_name}} {{dist_dir}}/{{dist_name}}
[private]
package-prepare:
@mkdir -p {{dist_dir}}/{{dist_name}}
cp LICENSE README*.md etc/smartdns/smartdns.conf {{dist_dir}}/{{dist_name}}
echo "Version: {{version}}" > {{dist_dir}}/{{dist_name}}/version
echo "Build date: $(date)" >> {{dist_dir}}/{{dist_name}}/version
echo "Branch: $(git rev-parse --abbrev-ref HEAD)" >> {{dist_dir}}/{{dist_name}}/version
echo "Commit: $(git rev-parse HEAD)" >> {{dist_dir}}/{{dist_name}}/version
[private]
package-clean:
@rm -rf {{dist_dir}}/{{dist_name}}*
[private]
package-list:
@ls -lh dist
[private]
[windows]
zip: && zip-sha256sum
cd {{dist_dir}} && 7z a -tzip {{dist_zip}} {{dist_name}}
[private]
[macos]
zip: && zip-sha256sum
cd {{dist_dir}} && zip -9r {{dist_zip}} {{dist_name}}
[private]
[linux]
zip: && zip-sha256sum
cd {{dist_dir}} && tar -zcvf {{dist_zip}} {{dist_name}}
[private]
zip-sha256sum:
echo {{sha256_file(dist_dir + "/" + dist_zip)}} > {{dist_dir}}/{{dist_zip}}-sha256sum.txt
[private]
[windows]
wix-sha256sum:
echo {{sha256_file(dist_dir + "/" + dist_name + "-v" + version + ".msi" )}} > {{dist_dir}}/{{dist_name}}-v{{version}}.msi-sha256sum.txt
# cleanup the workspace
clean:
cargo clean
#---------------#
# running tests #
#---------------#
# Run tests
test *args: patch
{{cargo}} test {{args}}
#-----------------------#
# code quality and misc #
#-----------------------#
# Analyze the package and report errors, but don't build object files
check *args: patch
{{cargo}} check --workspace --tests --benches --examples {{args}}
# Run clippy fix
clippy: patch
{{cargo}} clippy --fix --all
# Format the code
fmt: patch
{{cargo}} fmt --all
# Check the clippy and format.
cleanliness: patch
cargo clippy
cargo fmt --all -- --check
#-------#
# tools #
#-------#
# Set cap for smartdns binary
setcap:
sudo find ./target -type f -name smartdns -exec setcap CAP_SYS_ADMIN,CAP_NET_ADMIN,CAP_NET_RAW,CAP_NET_BIND_SERVICE+eip {} \;
@find ./target -type f -name smartdns
# Apply patch
[private]
patch: # require_patch-crate
@#cargo patch-crate -f
#------------#
# dependency #
#------------#
[private]
@require_patch-crate:
cargo patch-crate --version >/dev/null 2>&1 || cargo install patch-crate
[private]
@require_set-version:
cargo set-version --version >/dev/null 2>&1 || cargo install cargo-edit > /dev/null