Repository navigation
Expand file tree
/
Copy pathbuild-package
More file actions
executable file
·76 lines (71 loc) · 3.81 KB
/
Copy pathbuild-package
File metadata and controls
executable file
·76 lines (71 loc) · 3.81 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
#!/usr/bin/env bash
# Build a Vis runtime package. Published builds use the archive in native.lock.
set -euo pipefail
fail() { printf 'build-package: %s\n' "$*" >&2; exit 1; }
sha256() {
if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1"; else shasum -a 256 "$1"; fi | cut -d' ' -f1
}
archive=0
if [[ "${1:-}" == --archive ]]; then archive=1; shift; fi
[[ $# == 2 ]] || { echo "Usage: build-package [--archive] PLATFORM OUTPUT" >&2; exit 2; }
platform="$1"
output="$(cd -P -- "$(dirname -- "$2")" && pwd)/$(basename -- "$2")"
[[ ! -e "$output" && ! -L "$output" ]] || fail "Output already exists: $output"
cd -P -- "$(dirname -- "${BASH_SOURCE[0]}")"
lock=package/session/native.lock
version="$(awk '!/^#/ && NF == 1 { print; exit }' "$lock")"
case "$platform" in
macos-arm64) native=darwin-arm64; library=libvispython.dylib; rust_target=aarch64-apple-darwin ;;
macos-x64) native=darwin-x64; library=libvispython.dylib; rust_target=x86_64-apple-darwin ;;
linux-arm64) native=linux-arm64; library=libvispython.so; rust_target=aarch64-unknown-linux-gnu ;;
linux-x64) native=linux-x64; library=libvispython.so; rust_target=x86_64-unknown-linux-gnu ;;
windows-x64) native=windows-x64; library=vispython.dll; rust_target=x86_64-pc-windows-msvc ;;
*) fail "Unknown platform: $platform" ;;
esac
worker=vis-python-session
if [[ "$platform" == windows-x64 ]]; then worker+=.exe; fi
umask 022
export COPYFILE_DISABLE=1
scratch="$(mktemp -d "$(dirname -- "$output")/.vis-package.XXXXXX")"
trap 'rm -rf -- "$scratch"' EXIT
package="$scratch/package"
mkdir -p "$package/native" "$scratch/native"
if [[ -n "${VIS_PYTHON_PACKAGE_NATIVE_TREE:-}" ]]; then
# Tests can stage a native build before a release publishes its archive.
native_tree="$(cd -P -- "$VIS_PYTHON_PACKAGE_NATIVE_TREE" && pwd)"
else
digest="$(awk -v platform="$native" '$1 == platform { print $2 }' "$lock")"
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ && "$digest" =~ ^[0-9a-f]{64}$ ]] || fail "No archive pin for $platform"
asset="vis-python-runtime-$native-$version.tar.gz"
curl --retry 3 -fsSL "https://github.com/Blockether/vis-python-runtime/releases/download/v$version/$asset" -o "$scratch/$asset"
[[ "$(sha256 "$scratch/$asset")" == "$digest" ]] || fail "Checksum does not match: $asset"
tar -xzf "$scratch/$asset" -C "$scratch/native"
native_tree="$scratch/native"
fi
# Copy the library and interpreter, not the old release worker. Resolve the
# archive's local links before transport. The package store does not allow links.
for entry in python licenses; do
dir="$native_tree/$entry"
while IFS= read -r -d '' link; do
target="$(readlink "$link")"
[[ "$target" != /* ]] || fail "Absolute link in $entry: $link"
resolved="$(cd -P -- "$(dirname -- "$link")/$(dirname -- "$target")" && pwd)/$(basename -- "$target")"
[[ "$resolved" == "$dir/"* && -f "$resolved" && ! -L "$resolved" ]] || fail "Link is not to a regular file in $entry: $link"
done < <(find "$dir" -type l -print0)
cp -pRL -- "$dir" "$package/native/$entry"
done
[[ -f "$native_tree/$library" && ! -L "$native_tree/$library" ]] || fail "Missing library: $library"
cp -p "$native_tree/$library" "$package/native/"
cp LICENSE "$package/"
cargo build --manifest-path native/session-worker/Cargo.toml --locked --release --target "$rust_target" --target-dir native/session-worker/target
cp -p "native/session-worker/target/$rust_target/release/$worker" "$package/"
"${PYTHON:-python3}" -I scripts/stage-session-data.py --guest-sources "$package"
[[ -x "$package/$worker" ]] || fail "The package has no session worker"
bad="$(find "$package" ! -type f ! -type d -print -quit)"
[[ -z "$bad" ]] || fail "The package contains a link or a special file: $bad"
if (( archive )); then
tar -C "$package" -czf "$scratch/package.tar.gz" .
mv -n -- "$scratch/package.tar.gz" "$output"
else
mv -n -- "$package" "$output"
fi