-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathpyoxidizer
More file actions
executable file
·86 lines (71 loc) · 2.46 KB
/
pyoxidizer
File metadata and controls
executable file
·86 lines (71 loc) · 2.46 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
#!/bin/bash
set -euo pipefail
shopt -s extglob failglob
devel="$(dirname "$0")"
build="$(dirname "$0")/../build"
main() {
local pyoxidizer
if pyoxidizer="$(locate 2>/dev/null)"; then
echo "--> Located existing PyOxidizer binary at $pyoxidizer" >&2
else
echo "--> Downloading PyOxidizer binary…" >&2
pyoxidizer="$(download)"
echo "--> Downloaded PyOxidizer binary to $pyoxidizer" >&2
fi
# On Linux, exec into a manylinux container with an old glibc version.
# These manylinux images are used in the Python packaging ecosystem to
# build widely-compatible binary packages (wheels).
#
# https://github.com/pypa/manylinux#readme
if [[ "$(platform-system)" == Linux ]]; then
mkdir -p "$build"/cache/{pyoxidizer,pip,cargo}
exec "$devel"/within-container \
--volume "$build/cache/pyoxidizer:/tmp/.cache/pyoxidizer" \
--volume "$build/cache/pip:/tmp/.cache/pip" \
--volume "$build/cache/cargo:/tmp/.cargo" \
quay.io/pypa/manylinux2014_"$(platform-machine)" "$pyoxidizer" "$@"
else
exec "$pyoxidizer" "$@"
fi
}
locate() {
# Locate existing local copy of pyoxidizer.
printf '%s\n' "$devel"/pyoxidizer-[0-9]*_"$(platform-machine)"?(.exe) | sort --reverse --version-sort | head -n1
}
download() {
# Download pyoxidizer and return the path to it.
#
# Even though it's a Rust project, the easiest cross-platform way to
# download it is via pip since they publish wheels with the binaries. :-)
# Using Pip also allows us to piggy back on the version specification
# system and platform-specific bits of a package manager/registry
# ecosystem.
local tmp
tmp="$(mktemp -d)"
# shellcheck disable=SC2064
trap "rm -rf \"$tmp\"" EXIT
python3 -m pip download \
--disable-pip-version-check \
--quiet \
--no-deps \
--dest "$tmp" \
'pyoxidizer !=0.23.0' \
>&2
local wheels wheel binary
wheels=("$tmp"/pyoxidizer-[0-9]*.whl)
wheel="${wheels[0]}"
binary="$(basename "$wheel" .whl)"
if [[ "$(platform-system)" == Windows ]]; then
binary+=.exe
fi
unzip -p "$wheel" '*/scripts/pyoxidizer*' > "$devel/$binary"
chmod +x "$devel/$binary"
echo "$devel/$binary"
}
platform-machine() {
python3 -c 'import platform; print(platform.machine())'
}
platform-system() {
python3 -c 'import platform; print(platform.system())'
}
main "$@"