1#!/usr/bin/env bash
2
3set -euxo pipefail
4source script/lib/sentry-upload.sh
5
6# Builds Zed and remote_server binaries and uploads debug symbols to Sentry.
7# Intended for re-uploading symbols for releases where the original upload
8# failed or the files were corrupted.
9#
10# Usage: script/upload-sentry-symbols [--verify]
11#
12# Environment:
13# SENTRY_AUTH_TOKEN (required) Sentry authentication token
14#
15# Options:
16# --verify After uploading, verify the debug IDs are resolvable on Sentry
17
18verify=false
19while [[ $# -gt 0 ]]; do
20 case $1 in
21 --verify)
22 verify=true
23 shift
24 ;;
25 *)
26 echo "Unknown option: $1" >&2
27 exit 1
28 ;;
29 esac
30done
31
32if [[ -z "${SENTRY_AUTH_TOKEN:-}" ]]; then
33 echo "Error: SENTRY_AUTH_TOKEN is required" >&2
34 exit 1
35fi
36
37if ! command -v sentry-cli >/dev/null 2>&1; then
38 echo "Error: sentry-cli is not installed" >&2
39 echo "Install with: curl -sL https://sentry.io/get-cli | bash" >&2
40 exit 1
41fi
42
43target_dir="${CARGO_TARGET_DIR:-target}"
44version_info=$(rustc --version --verbose)
45host_line=$(echo "$version_info" | grep host)
46target_triple=${host_line#*: }
47
48case "$(uname -s)" in
49 Linux)
50 musl_triple=${target_triple%-gnu}-musl
51 remote_server_triple=${REMOTE_SERVER_TARGET:-"${musl_triple}"}
52
53 echo "==> Building zed and cli (release) for ${target_triple}..."
54 cargo build --release --target "${target_triple}" --package zed --package cli
55
56 echo "==> Building remote_server (release) for ${remote_server_triple}..."
57 export RUSTFLAGS="${RUSTFLAGS:-} -C target-feature=+crt-static"
58 cargo build --release --target "${remote_server_triple}" --package remote_server
59
60 upload_paths=(
61 "${target_dir}/${target_triple}/release/zed"
62 "${target_dir}/${remote_server_triple}/release/remote_server"
63 )
64 ;;
65 Darwin)
66 echo "==> Building zed and cli (release) for ${target_triple}..."
67 cargo build --release --target "${target_triple}" --package zed --package cli
68
69 echo "==> Building remote_server (release) for ${target_triple}..."
70 cargo build --release --target "${target_triple}" --package remote_server
71
72 echo "==> Extracting DWARF debug info..."
73 dsymutil --flat "${target_dir}/${target_triple}/release/zed"
74 dsymutil --flat "${target_dir}/${target_triple}/release/remote_server"
75
76 upload_paths=(
77 "${target_dir}/${target_triple}/release/zed.dwarf"
78 "${target_dir}/${target_triple}/release/remote_server.dwarf"
79 )
80 ;;
81 *)
82 echo "Error: unsupported platform (use upload-sentry-symbols.ps1 on Windows)" >&2
83 exit 1
84 ;;
85esac
86
87echo "==> Debug files to upload:"
88for path in "${upload_paths[@]}"; do
89 ls -lh "$path"
90 sentry-cli debug-files check "$path" || true
91done
92
93echo "==> Uploading debug symbols to Sentry..."
94upload_to_sentry "${upload_paths[@]}"
95
96if [ "$verify" = true ]; then
97 echo "==> Verifying uploaded debug files..."
98 all_found=true
99 for path in "${upload_paths[@]}"; do
100 debug_id=$(sentry-cli debug-files check "$path" 2>/dev/null | grep -oP 'Debug ID:\s*\K\S+' || true)
101 if [ -n "$debug_id" ]; then
102 echo "Checking debug ID: $debug_id"
103 if sentry-cli --org zed-dev --project zed debug-files find "$debug_id" 2>&1 | grep -q "missing"; then
104 echo "WARNING: Debug ID $debug_id still reported as missing" >&2
105 all_found=false
106 else
107 echo "OK: $debug_id found on Sentry"
108 fi
109 else
110 echo "WARNING: Could not extract debug ID from $path" >&2
111 fi
112 done
113 if [ "$all_found" = false ]; then
114 echo "Some debug files could not be verified. They may need time to process." >&2
115 exit 1
116 fi
117fi
118
119echo "==> Done."