Repository navigation
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·151 lines (134 loc) · 5.79 KB
/
Copy pathconfigure
File metadata and controls
executable file
·151 lines (134 loc) · 5.79 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
#!/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 is on PATH)
if [ -f "$SWIFTLY_HOME/env.sh" ]; then
# shellcheck disable=SC1091
source "$SWIFTLY_HOME/env.sh"
fi
# Run the open-source toolchain explicitly. A bare `swift` may resolve to
# Xcode's (when /usr/bin precedes swiftly on PATH), and `swiftly use` would
# rewrite .swift-version, so neither is relied on here.
oss_swift() { swiftly run swift "$@" "+$SWIFT_VERSION"; }
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
# --------------------------------------------------------------------------
# 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)"
# Only the open-source toolchain has the Wasm backend.
if ! swiftly list 2>/dev/null | grep -q "Swift $SWIFT_VERSION"; then
info "Installing open-source Swift $SWIFT_VERSION via swiftly..."
swiftly install "$SWIFT_VERSION"
fi
if oss_swift --version 2>&1 | grep -q "swift-$SWIFT_VERSION-RELEASE"; then
ok "Open-source Swift toolchain available: $(oss_swift --version 2>&1 | head -1)"
else
fail "Open-source Swift $SWIFT_VERSION is not available through swiftly."
fi
# --------------------------------------------------------------------------
# 3. Check / install Wasm SDK
# --------------------------------------------------------------------------
if oss_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)..."
oss_swift sdk install "$WASM_SDK_URL" --checksum "$WASM_SDK_CHECKSUM"
if oss_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 (Xcode's Swift)..."
if xcrun 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
# Built per product: a blanket Wasm build tries to link the BackendAndroid
# dynamic library, which wasm32 does not support.
info "Verifying Wasm build (HelloWorld)..."
WASM_OUTPUT=$(oss_swift build --swift-sdk "$WASM_SDK_NAME" --product HelloWorld 2>&1 || true)
if echo "$WASM_OUTPUT" | grep -q "complete!"; then
ok "Wasm build OK"
else
warn "Wasm build failed:"
echo "$WASM_OUTPUT" | grep -E "error:" | sort -u | cut -c1-160 | head -5
if echo "$WASM_OUTPUT" | grep -q "target-arch-variant"; then
echo ""
warn "Swift $SWIFT_VERSION cannot use this Xcode's macOS SDK."
echo " Point DEVELOPER_DIR at an older Xcode for Wasm builds, e.g.:"
echo " DEVELOPER_DIR=/Applications/Xcode-26.6.0.app/Contents/Developer ./configure"
fi
fi
# --------------------------------------------------------------------------
# Done
# --------------------------------------------------------------------------
echo ""
echo "======================="
echo "Configuration complete."
echo ""
echo "Build commands:"
echo " swift build # macOS (native SwiftUI)"
echo " swift test # Run tests"
echo " swiftly run swift build --swift-sdk $WASM_SDK_NAME --product HelloWorld +$SWIFT_VERSION # WebAssembly"
echo ""
echo "Run examples:"
echo " swift run HelloWorld"
echo " swift run Stopwatch"
echo " swift run ColorMixer"
echo ""
echo "Note: Wasm builds need the open-source toolchain. \`swiftly run swift … +$SWIFT_VERSION\`"
echo "selects it without changing your default toolchain or .swift-version."
echo ""