-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·162 lines (143 loc) · 5.54 KB
/
configure
File metadata and controls
executable file
·162 lines (143 loc) · 5.54 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/bin/bash
set -euo pipefail
# SwiftOpenUI configure script
# Sets up the open-source Swift toolchain and Wasm SDK for cross-platform builds.
SWIFT_VERSION="6.2.4"
WASM_SDK_URL="https://download.swift.org/swift-${SWIFT_VERSION}-release/wasm-sdk/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE_wasm.artifactbundle.tar.gz"
WASM_SDK_CHECKSUM="32fdb8772d73bb174f77b5c59bc88a0d55003d75712832129394d3465158fb43"
WASM_SDK_NAME="swift-${SWIFT_VERSION}-RELEASE_wasm"
SWIFTLY_HOME="${SWIFTLY_HOME_DIR:-$HOME/.swiftly}"
# Source swiftly env if available (ensures swiftly-managed swift is on PATH)
if [ -f "$SWIFTLY_HOME/env.sh" ]; then
# shellcheck disable=SC1091
source "$SWIFTLY_HOME/env.sh"
fi
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
CYAN='\033[0;36m'
NC='\033[0m'
info() { echo -e "${CYAN}[info]${NC} $1"; }
ok() { echo -e "${GREEN}[ok]${NC} $1"; }
warn() { echo -e "${YELLOW}[warn]${NC} $1"; }
fail() { echo -e "${RED}[error]${NC} $1"; exit 1; }
echo ""
echo "SwiftOpenUI — configure"
echo "======================="
echo ""
# --------------------------------------------------------------------------
# 1. Check / install swiftly
# --------------------------------------------------------------------------
if command -v swiftly &>/dev/null; then
ok "swiftly found: $(swiftly --version 2>&1 | head -1)"
else
info "swiftly not found. Installing..."
SWIFTLY_PKG=$(mktemp /tmp/swiftly.XXXXXX.pkg)
curl -fSL https://download.swift.org/swiftly/darwin/swiftly.pkg -o "$SWIFTLY_PKG"
installer -pkg "$SWIFTLY_PKG" -target CurrentUserHomeDirectory
rm -f "$SWIFTLY_PKG"
# Init swiftly (non-interactive)
"$SWIFTLY_HOME/bin/swiftly" init --quiet-shell-followup 2>/dev/null || true
# Source env for this session
if [ -f "$SWIFTLY_HOME/env.sh" ]; then
# shellcheck disable=SC1091
source "$SWIFTLY_HOME/env.sh"
fi
hash -r 2>/dev/null || true
if command -v swiftly &>/dev/null; then
ok "swiftly installed successfully"
else
warn "swiftly installed but not on PATH yet."
echo " Run: source \"$SWIFTLY_HOME/env.sh\""
echo " Then re-run ./configure"
exit 1
fi
fi
# --------------------------------------------------------------------------
# 2. Check / install open-source Swift toolchain
# --------------------------------------------------------------------------
check_toolchain() {
local ver
ver=$(swift --version 2>&1 | head -1)
# Xcode's Swift: "Apple Swift version 6.2.4 (swiftlang-6.2.4.1.4 clang-...)"
# Open-source: "Apple Swift version 6.2.4 (swift-6.2.4-RELEASE)"
if echo "$ver" | grep -q "swiftlang-"; then
return 1 # Xcode toolchain (no Wasm backend)
fi
return 0 # Open-source toolchain
}
if check_toolchain; then
ok "Open-source Swift toolchain active: $(swift --version 2>&1 | head -1)"
else
warn "Xcode's Swift is active (lacks Wasm backend)."
info "Installing open-source Swift $SWIFT_VERSION via swiftly..."
if swiftly list 2>/dev/null | grep -q "$SWIFT_VERSION"; then
info "Swift $SWIFT_VERSION already installed, switching..."
swiftly use "$SWIFT_VERSION"
else
swiftly install --use "$SWIFT_VERSION"
fi
# Re-source env to pick up the new toolchain PATH
if [ -f "$SWIFTLY_HOME/env.sh" ]; then
source "$SWIFTLY_HOME/env.sh"
fi
hash -r 2>/dev/null || true
if check_toolchain; then
ok "Switched to open-source Swift: $(swift --version 2>&1 | head -1)"
else
fail "Failed to switch to open-source toolchain. Xcode's Swift is still active."
fi
fi
# --------------------------------------------------------------------------
# 3. Check / install Wasm SDK
# --------------------------------------------------------------------------
if swift sdk list 2>/dev/null | grep -q "$WASM_SDK_NAME"; then
ok "Wasm SDK already installed: $WASM_SDK_NAME"
else
info "Installing Wasm SDK ($WASM_SDK_NAME)..."
swift sdk install "$WASM_SDK_URL" --checksum "$WASM_SDK_CHECKSUM"
if swift sdk list 2>/dev/null | grep -q "$WASM_SDK_NAME"; then
ok "Wasm SDK installed: $WASM_SDK_NAME"
else
fail "Wasm SDK installation failed."
fi
fi
# --------------------------------------------------------------------------
# 4. Verify builds
# --------------------------------------------------------------------------
echo ""
info "Verifying macOS build..."
if swift build 2>&1 | tail -1 | grep -q "Build complete"; then
ok "macOS build OK"
else
warn "macOS build had issues (may be expected if not on macOS)"
fi
info "Verifying Wasm build..."
WASM_OUTPUT=$(swift build --swift-sdk "$WASM_SDK_NAME" 2>&1)
if echo "$WASM_OUTPUT" | grep -q "Build complete"; then
ok "Wasm build OK"
else
warn "Wasm build failed:"
echo "$WASM_OUTPUT" | grep -E "error:" | head -5
fi
# --------------------------------------------------------------------------
# Done
# --------------------------------------------------------------------------
echo ""
echo "======================="
echo "Configuration complete."
echo ""
echo "Build commands:"
echo " swift build # macOS (native SwiftUI)"
echo " swift build --swift-sdk $WASM_SDK_NAME # WebAssembly"
echo " swift test # Run tests"
echo ""
echo "Run examples:"
echo " swift run HelloWorld"
echo " swift run Counter"
echo " swift run Showcase1"
echo " swift run Showcase2"
echo ""
echo "Note: To use the open-source toolchain in new shells, ensure"
echo "swiftly's env is sourced: source \"$SWIFTLY_HOME/env.sh\""
echo ""