/
build.xsh
executable file
·78 lines (56 loc) · 1.56 KB
/
build.xsh
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
#!/usr/bin/env xonsh
import tomli
from os.path import dirname,abspath,exists
from fire import Fire
import platform
from humanize import naturalsize
from os import stat,makedirs,replace
import tarfile
PWD = dirname(abspath(__file__))
cd @(PWD)
p".xonshrc".exists() && source .xonshrc
@Fire
def main():
system = platform.system().lower()
ext = ''
if system == 'windows':
os_name = 'win'
machine = 'x86_64'
os = f'{machine}-pc-windows-msvc'
ext = '.exe'
else:
machine = platform.machine()
if system == 'darwin':
os_name = 'osx'
os = f'{machine}-apple-{system}'
elif system == 'linux':
os_name = 'linux'
os = f'{machine}-unknown-linux-gnu'
$RUSTFLAGS="-C target-feature=+crt-static -C link-self-contained=yes"
# -l static=stdc++"
TARGET=f'{os}'
with open(join(PWD,"Cargo.toml"),"rb") as f:
toml = tomli.load(f)
pkg = toml['package']
app = pkg['name']
exe = app+ext
version = pkg['version']
cargo build \
--release \
--target @(TARGET) \
-Z build-std=std,panic_abort \
-Z build-std-features=panic_immediate_abort # 这一句有时候会导致问题,出问题了可以注释掉
out=f"target/{TARGET}/release/{exe}"
strip @(out)
if system!='windows':
./sh/upx.sh
upx --best --lzma @(out)
print(naturalsize(stat(out).st_size))
dir = 'target/txz'
makedirs(join(PWD,dir),exist_ok=True)
if machine == 'x86_64':
machine = 'x64'
txz = join(dir,app+f".{version}.{os_name}.{machine}.txz")
with tarfile.open(txz, "w:xz") as tar:
tar.add(out,arcname=exe)
print(txz)