-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
115 lines (101 loc) · 3.36 KB
/
Copy pathbuild.sh
File metadata and controls
115 lines (101 loc) · 3.36 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
#!/bin/bash
set -e
PROJECT="src/officecli/officecli.csproj"
ALL_TARGETS="osx-arm64:officecli-mac-arm64 osx-x64:officecli-mac-x64 linux-x64:officecli-linux-x64 linux-arm64:officecli-linux-arm64 linux-musl-x64:officecli-linux-alpine-x64 linux-musl-arm64:officecli-linux-alpine-arm64 win-x64:officecli-win-x64.exe win-arm64:officecli-win-arm64.exe"
# Detect current platform RID
detect_local_rid() {
local OS=$(uname -s | tr '[:upper:]' '[:lower:]')
local ARCH=$(uname -m)
local LIBC="gnu"
if [ "$OS" = "linux" ]; then
if command -v ldd >/dev/null 2>&1 && ldd --version 2>&1 | grep -qi musl; then
LIBC="musl"
elif [ -f /etc/alpine-release ]; then
LIBC="musl"
fi
fi
case "$OS" in
darwin)
case "$ARCH" in
arm64) echo "osx-arm64" ;;
x86_64) echo "osx-x64" ;;
esac ;;
linux)
case "$ARCH" in
x86_64)
if [ "$LIBC" = "musl" ]; then echo "linux-musl-x64"; else echo "linux-x64"; fi ;;
aarch64|arm64)
if [ "$LIBC" = "musl" ]; then echo "linux-musl-arm64"; else echo "linux-arm64"; fi ;;
esac ;;
esac
}
# Find target entry by RID
find_target() {
local RID="$1"
for target in $ALL_TARGETS; do
if [ "${target%%:*}" = "$RID" ]; then
echo "$target"
return
fi
done
}
build_config() {
local CONFIG="$1"
local TARGETS="$2"
local OUTPUT="bin/$(echo "$CONFIG" | tr '[:upper:]' '[:lower:]')"
rm -rf "$OUTPUT"
mkdir -p "$OUTPUT"
for target in $TARGETS; do
RID="${target%%:*}"
NAME="${target##*:}"
TMPDIR=$(mktemp -d)
echo "[$CONFIG] Building $RID -> $NAME"
dotnet publish "$PROJECT" -c "$CONFIG" -r "$RID" -o "$TMPDIR" --nologo -v quiet
if [ -f "$TMPDIR/officecli.exe" ]; then
cp "$TMPDIR/officecli.exe" "$OUTPUT/$NAME"
else
cp "$TMPDIR/officecli" "$OUTPUT/$NAME"
fi
# Ad-hoc codesign on macOS (required by AppleSystemPolicy)
if [ "$(uname -s)" = "Darwin" ] && [[ "$RID" == osx-* ]]; then
codesign -s - -f "$OUTPUT/$NAME" 2>/dev/null || true
fi
cp "$TMPDIR/officecli.pdb" "$OUTPUT/${NAME%.*}.pdb"
rm -rf "$TMPDIR"
done
rm -rf src/officecli/bin src/officecli/obj
echo ""
echo "$CONFIG build complete:"
ls -lh "$OUTPUT"
}
CONFIG="${1:-release}"
case "$CONFIG" in
release|Release)
LOCAL_RID=$(detect_local_rid)
TARGET=$(find_target "$LOCAL_RID")
if [ -z "$TARGET" ]; then
echo "Unsupported platform: $(uname -s) $(uname -m)"
exit 1
fi
build_config "Release" "$TARGET"
;;
debug|Debug)
LOCAL_RID=$(detect_local_rid)
TARGET=$(find_target "$LOCAL_RID")
if [ -z "$TARGET" ]; then
echo "Unsupported platform: $(uname -s) $(uname -m)"
exit 1
fi
build_config "Debug" "$TARGET"
;;
all)
build_config "Release" "$ALL_TARGETS"
;;
*)
echo "Usage: ./build.sh [release|debug|all]"
echo " release - Build Release for current platform (default)"
echo " debug - Build Debug for current platform"
echo " all - Build Release for all platforms"
exit 1
;;
esac