Skip to content

Commit 66f38ba

Browse files
committed
fix(ios):Simplify iOS build script and add dependency fix for iOS compatibility
1 parent 217bec2 commit 66f38ba

File tree

2 files changed

+87
-188
lines changed

2 files changed

+87
-188
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
3+
echo "Fixing iOS incompatible dependencies..."
4+
5+
# Find the module root
6+
if [ -f go.mod ]; then
7+
MODULE_ROOT="."
8+
elif [ -f ../go.mod ]; then
9+
MODULE_ROOT=".."
10+
cd ..
11+
else
12+
echo "Error: Cannot find go.mod"
13+
exit 1
14+
fi
15+
16+
echo "Working in module root: $(pwd)"
17+
18+
# Check for problematic dependencies
19+
echo "Checking for iOS incompatible dependencies..."
20+
go list -m all | grep -E "(go-m1cpu|gopsutil)" || echo "No problematic dependencies found in module list"
21+
22+
# Try to exclude problematic dependencies by replacing them with stubs
23+
echo "Attempting to exclude iOS incompatible dependencies..."
24+
25+
# Replace go-m1cpu with a no-op version if it exists
26+
if go list -m all | grep -q "go-m1cpu"; then
27+
echo "Found go-m1cpu dependency, attempting to exclude..."
28+
# Try to replace with a version that doesn't use iOS incompatible APIs
29+
go mod edit -replace github.com/shoenig/go-m1cpu=github.com/shoenig/go-m1cpu@v0.1.5 || true
30+
fi
31+
32+
# Clean and rebuild
33+
echo "Cleaning and rebuilding module..."
34+
go mod tidy
35+
go mod download
36+
37+
echo "Updated dependencies:"
38+
go list -m all | grep -E "(mobile|m1cpu|gopsutil)" || echo "No relevant dependencies found"
39+
40+
echo "iOS dependency fix completed"

openlist-lib/scripts/gobind_ios.sh

Lines changed: 47 additions & 188 deletions
Original file line numberDiff line numberDiff line change
@@ -1,217 +1,76 @@
11
#!/bin/bash
22

3-
# First check if we're in the right place
43
echo "Starting iOS build from: $(pwd)"
54

6-
# For iOS, we need to find the bindable package directory, not just go.mod
7-
# The original approach was correct - look for openlistlib directory
5+
# Find openlistlib directory
86
if [ -d ../openlistlib ]; then
9-
echo "Found openlistlib directory, using that for iOS build"
107
cd ../openlistlib || exit
8+
elif [ -d openlistlib ]; then
9+
cd openlistlib || exit
1110
else
12-
echo "Searching for bindable package directory..."
13-
cd ../ || exit
14-
15-
# Look for directories that might contain bindable packages
16-
if [ -d openlistlib ]; then
17-
echo "Found openlistlib in current directory"
18-
cd openlistlib || exit
19-
elif [ -d cmd/openlistlib ]; then
20-
echo "Found openlistlib in cmd directory"
21-
cd cmd/openlistlib || exit
22-
else
23-
echo "Error: Cannot find openlistlib directory for iOS binding"
24-
echo "Current directory: $(pwd)"
25-
echo "Directory contents:"
26-
ls -la
27-
echo "Looking for Go files that might be bindable..."
28-
find . -name "*.go" -type f | head -10
29-
exit 1
30-
fi
11+
echo "Error: Cannot find openlistlib directory"
12+
exit 1
3113
fi
3214

3315
echo "Current directory: $(pwd)"
34-
echo "Building OpenList for iOS..."
3516

3617
# Check if gomobile is available
3718
if ! command -v gomobile &> /dev/null; then
3819
echo "Error: gomobile not found. Please run init_gomobile.sh first."
3920
exit 1
4021
fi
4122

42-
# Check Go environment
4323
echo "Go version: $(go version)"
44-
echo "GOPATH: $GOPATH"
45-
echo "GOROOT: $GOROOT"
46-
47-
# Verify Go version compatibility
48-
echo "Checking Go version compatibility..."
49-
GO_VERSION=$(go version | grep -o 'go[0-9]\+\.[0-9]\+\.[0-9]\+' | sed 's/go//')
50-
echo "Current Go version: $GO_VERSION"
5124

52-
# Check if this directory has Go files suitable for binding
53-
if ! ls *.go 1> /dev/null 2>&1; then
54-
echo "Warning: No Go files found in current directory"
55-
echo "Directory contents:"
56-
ls -la
57-
fi
58-
59-
# Verify gomobile tools are available
60-
echo "Verifying gomobile tools..."
61-
echo "gomobile path: $(which gomobile 2>/dev/null || echo 'NOT FOUND')"
62-
echo "gobind path: $(which gobind 2>/dev/null || echo 'NOT FOUND')"
63-
64-
# Check if we need to work with go modules
65-
if [ -f go.mod ]; then
66-
echo "Go module info:"
67-
go mod tidy
68-
go list -m all | head -10
25+
# Work from module root if go.mod exists in parent
26+
if [ -f ../go.mod ]; then
27+
echo "Found go.mod in parent directory"
28+
cd ..
6929

70-
# Ensure dependencies are downloaded
71-
echo "Downloading dependencies..."
72-
go mod download
73-
else
74-
echo "No go.mod in current directory, checking parent..."
75-
if [ -f ../go.mod ]; then
76-
echo "Found go.mod in parent directory"
77-
PARENT_DIR=$(pwd)/..
78-
cd ..
79-
80-
# Force update mobile packages to latest version
81-
echo "Updating mobile packages to latest version..."
82-
go mod edit -replace golang.org/x/mobile=golang.org/x/mobile@v0.0.0-20250711185624-d5bb5ecc55c0
83-
go get golang.org/x/mobile@v0.0.0-20250711185624-d5bb5ecc55c0
84-
go get golang.org/x/mobile/bind@v0.0.0-20250711185624-d5bb5ecc55c0
85-
go get golang.org/x/mobile/bind/objc@v0.0.0-20250711185624-d5bb5ecc55c0
86-
87-
# Clean and rebuild everything
88-
echo "Cleaning and rebuilding module cache..."
89-
go clean -cache
90-
go clean -modcache
91-
go mod tidy
92-
go mod download
93-
94-
# Verify bind packages are in module with correct version
95-
echo "Verifying bind packages in module:"
96-
go list -m golang.org/x/mobile
97-
98-
# Reinstall gomobile tools with the correct version
99-
echo "Reinstalling gomobile tools with correct version..."
100-
go get -u golang.org/x/mobile/...
101-
go install golang.org/x/mobile/cmd/gobind@latest
102-
go install golang.org/x/mobile/cmd/gomobile@latest
103-
104-
# Reinitialize gomobile
105-
echo "Reinitializing gomobile..."
106-
gomobile clean || true
107-
gomobile init
108-
109-
# Return to openlistlib but stay in module context
110-
cd openlistlib
111-
112-
# Try to build from parent context
113-
echo "Building from parent module context..."
114-
cd ..
115-
116-
# Build the openlistlib package from module root
117-
echo "Current directory for iOS build: $(pwd)"
118-
echo "Building package: ./openlistlib"
119-
120-
# Set CGO environment for iOS
121-
export CGO_ENABLED=1
30+
# Fix iOS incompatible dependencies
31+
echo "Fixing iOS incompatible dependencies..."
32+
chmod +x scripts/fix_ios_dependencies.sh
33+
./scripts/fix_ios_dependencies.sh
34+
35+
# Set CGO environment for iOS
36+
export CGO_ENABLED=1
37+
38+
# Build for iOS with iOS-specific build tags to exclude incompatible packages
39+
echo "Starting iOS build from module root..."
40+
echo "CGO_ENABLED: $CGO_ENABLED"
41+
42+
# Use build tags to exclude problematic packages on iOS
43+
gomobile bind -ldflags "-s -w" -v -target="ios" -tags="ios mobile" ./openlistlib 2>&1 | tee ios_build.log || {
44+
echo "Error: gomobile bind failed"
45+
echo "Build log:"
46+
cat ios_build.log 2>/dev/null || echo "No build log available"
12247

123-
# Build for iOS with more verbose output
124-
echo "Starting iOS build from module root..."
125-
echo "CGO_ENABLED: $CGO_ENABLED"
126-
gomobile bind -ldflags '-w -s' --target=ios ./openlistlib 2>&1 | tee ios_build.log || {
127-
echo "Error: gomobile bind failed"
128-
echo "Build log:"
129-
cat ios_build.log 2>/dev/null || echo "No build log available"
130-
131-
# Try to get more specific error information
132-
echo "Checking for common issues..."
133-
echo "Go environment:"
134-
go env
135-
echo "Available targets:"
136-
gomobile version 2>/dev/null || echo "gomobile version failed"
137-
48+
# Try with different build tags to exclude problematic dependencies
49+
echo "Retrying with different build tags..."
50+
gomobile bind -ldflags "-s -w" -v -target="ios" -tags="ios,mobile,!darwin,!cgo" ./openlistlib 2>&1 | tee ios_build_retry.log || {
51+
echo "Retry also failed"
52+
cat ios_build_retry.log 2>/dev/null || echo "No retry log available"
13853
exit 1
13954
}
140-
141-
echo "Listing generated files:"
142-
ls -la *.xcframework 2>/dev/null || echo "No .xcframework files found"
143-
144-
echo "Moving xcframework to ios/Frameworks"
145-
mkdir -p ios/Frameworks
146-
147-
# Check if xcframework files exist before moving
148-
if ls *.xcframework 1> /dev/null 2>&1; then
149-
mv -f ./*.xcframework ios/Frameworks/
150-
echo "iOS framework build completed successfully"
151-
echo "Files in ios/Frameworks:"
152-
ls -la ios/Frameworks/
153-
exit 0
154-
else
155-
echo "Warning: No .xcframework files were generated"
156-
exit 1
157-
fi
158-
else
159-
echo "Warning: No go.mod found, proceeding without module operations"
160-
fi
161-
fi
162-
163-
# Set CGO environment for iOS
164-
export CGO_ENABLED=1
165-
166-
# Clean any previous builds
167-
echo "Cleaning previous builds..."
168-
go clean -cache
169-
go clean -modcache || true
170-
171-
# Try a simple build first to check for issues
172-
echo "Testing basic build..."
173-
go build -v . || {
174-
echo "Error: Basic go build failed"
175-
echo "Trying to build from parent directory with module path..."
176-
cd ..
177-
go build -v ./openlistlib || {
178-
echo "Error: Build failed from parent directory too"
179-
exit 1
18055
}
181-
cd openlistlib
182-
}
183-
184-
# Build for iOS with more verbose output
185-
echo "Starting iOS build..."
186-
echo "CGO_ENABLED: $CGO_ENABLED"
187-
gomobile bind -ldflags "-s -w" -v -target="ios" 2>&1 | tee ios_build.log || {
188-
echo "Error: gomobile bind failed"
189-
echo "Build log:"
190-
cat ios_build.log 2>/dev/null || echo "No build log available"
19156

192-
# Try to get more specific error information
193-
echo "Checking for common issues..."
194-
echo "Go environment:"
195-
go env
196-
echo "Available targets:"
197-
gomobile version 2>/dev/null || echo "gomobile version failed"
57+
echo "Listing generated files:"
58+
ls -la *.xcframework 2>/dev/null || echo "No .xcframework files found"
19859

199-
exit 1
200-
}
201-
202-
echo "Listing generated files:"
203-
ls -la *.xcframework 2>/dev/null || echo "No .xcframework files found"
204-
205-
echo "Moving xcframework to ios/Frameworks"
206-
mkdir -p ../../ios/Frameworks
207-
208-
# Check if xcframework files exist before moving
209-
if ls *.xcframework 1> /dev/null 2>&1; then
210-
mv -f ./*.xcframework ../../ios/Frameworks/
211-
echo "iOS framework build completed successfully"
212-
echo "Files in ios/Frameworks:"
213-
ls -la ../../ios/Frameworks/
60+
echo "Moving xcframework to ios/Frameworks"
61+
mkdir -p ios/Frameworks
62+
63+
# Check if xcframework files exist before moving
64+
if ls *.xcframework 1> /dev/null 2>&1; then
65+
mv -f ./*.xcframework ios/Frameworks/
66+
echo "iOS framework build completed successfully"
67+
echo "Files in ios/Frameworks:"
68+
ls -la ios/Frameworks/
69+
else
70+
echo "Warning: No .xcframework files were generated"
71+
exit 1
72+
fi
21473
else
215-
echo "Warning: No .xcframework files were generated"
74+
echo "Error: No go.mod found in parent directory"
21675
exit 1
21776
fi

0 commit comments

Comments
 (0)