Skip to content

Commit 4e78a25

Browse files
committed
fix(ios):Expand iOS gopsutil stub with host and memory packages
1 parent 6fc17cd commit 4e78a25

File tree

2 files changed

+212
-23
lines changed

2 files changed

+212
-23
lines changed

openlist-lib/scripts/fix_ios_dependencies.sh

Lines changed: 192 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ EOF
5656
go mod edit -replace github.com/shoenig/go-m1cpu="$STUB_DIR/github.com/shoenig/go-m1cpu"
5757
fi
5858

59-
# Create stub for gopsutil
59+
# Create comprehensive stub for gopsutil
6060
if go list -m all | grep -q "gopsutil"; then
61-
echo "Creating stub for gopsutil..."
61+
echo "Creating comprehensive stub for gopsutil..."
62+
63+
# Create CPU package
6264
mkdir -p "$STUB_DIR/github.com/shirou/gopsutil/v3/cpu"
6365
cat > "$STUB_DIR/github.com/shirou/gopsutil/v3/cpu/cpu.go" << 'EOF'
6466
//go:build ios || mobile
@@ -83,13 +85,22 @@ type InfoStat struct {
8385
Microcode string `json:"microcode"`
8486
}
8587
86-
// Stub implementations for iOS
88+
type TimesStat struct {
89+
CPU string `json:"cpu"`
90+
User float64 `json:"user"`
91+
System float64 `json:"system"`
92+
Idle float64 `json:"idle"`
93+
Nice float64 `json:"nice"`
94+
Iowait float64 `json:"iowait"`
95+
Irq float64 `json:"irq"`
96+
Softirq float64 `json:"softirq"`
97+
Steal float64 `json:"steal"`
98+
Guest float64 `json:"guest"`
99+
GuestNice float64 `json:"guestNice"`
100+
}
101+
87102
func Info() ([]InfoStat, error) {
88-
return []InfoStat{{
89-
CPU: 0,
90-
ModelName: "iOS CPU",
91-
Cores: 1,
92-
}}, nil
103+
return []InfoStat{{CPU: 0, ModelName: "iOS CPU", Cores: 1}}, nil
93104
}
94105
95106
func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
@@ -112,20 +123,6 @@ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
112123
return Times(percpu)
113124
}
114125
115-
type TimesStat struct {
116-
CPU string `json:"cpu"`
117-
User float64 `json:"user"`
118-
System float64 `json:"system"`
119-
Idle float64 `json:"idle"`
120-
Nice float64 `json:"nice"`
121-
Iowait float64 `json:"iowait"`
122-
Irq float64 `json:"irq"`
123-
Softirq float64 `json:"softirq"`
124-
Steal float64 `json:"steal"`
125-
Guest float64 `json:"guest"`
126-
GuestNice float64 `json:"guestNice"`
127-
}
128-
129126
func Counts(logical bool) (int, error) {
130127
return 1, nil
131128
}
@@ -134,7 +131,179 @@ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
134131
return Counts(logical)
135132
}
136133
EOF
137-
134+
135+
# Create HOST package
136+
mkdir -p "$STUB_DIR/github.com/shirou/gopsutil/v3/host"
137+
cat > "$STUB_DIR/github.com/shirou/gopsutil/v3/host/host.go" << 'EOF'
138+
//go:build ios || mobile
139+
140+
package host
141+
142+
import "context"
143+
144+
type InfoStat struct {
145+
Hostname string `json:"hostname"`
146+
Uptime uint64 `json:"uptime"`
147+
BootTime uint64 `json:"bootTime"`
148+
Procs uint64 `json:"procs"`
149+
OS string `json:"os"`
150+
Platform string `json:"platform"`
151+
PlatformFamily string `json:"platformFamily"`
152+
PlatformVersion string `json:"platformVersion"`
153+
KernelVersion string `json:"kernelVersion"`
154+
KernelArch string `json:"kernelArch"`
155+
VirtualizationSystem string `json:"virtualizationSystem"`
156+
VirtualizationRole string `json:"virtualizationRole"`
157+
HostID string `json:"hostid"`
158+
}
159+
160+
type UserStat struct {
161+
User string `json:"user"`
162+
Terminal string `json:"terminal"`
163+
Host string `json:"host"`
164+
Started int `json:"started"`
165+
}
166+
167+
func Info() (*InfoStat, error) {
168+
return &InfoStat{
169+
Hostname: "iOS-Device",
170+
OS: "ios",
171+
Platform: "ios",
172+
PlatformFamily: "darwin",
173+
PlatformVersion: "17.0",
174+
KernelVersion: "23.0.0",
175+
KernelArch: "arm64",
176+
}, nil
177+
}
178+
179+
func InfoWithContext(ctx context.Context) (*InfoStat, error) {
180+
return Info()
181+
}
182+
183+
func Users() ([]UserStat, error) {
184+
return []UserStat{}, nil
185+
}
186+
187+
func UsersWithContext(ctx context.Context) ([]UserStat, error) {
188+
return Users()
189+
}
190+
191+
func Uptime() (uint64, error) {
192+
return 0, nil
193+
}
194+
195+
func UptimeWithContext(ctx context.Context) (uint64, error) {
196+
return Uptime()
197+
}
198+
199+
func BootTime() (uint64, error) {
200+
return 0, nil
201+
}
202+
203+
func BootTimeWithContext(ctx context.Context) (uint64, error) {
204+
return BootTime()
205+
}
206+
207+
func HostID() (string, error) {
208+
return "ios-device-id", nil
209+
}
210+
211+
func HostIDWithContext(ctx context.Context) (string, error) {
212+
return HostID()
213+
}
214+
EOF
215+
216+
# Create MEM package
217+
mkdir -p "$STUB_DIR/github.com/shirou/gopsutil/v3/mem"
218+
cat > "$STUB_DIR/github.com/shirou/gopsutil/v3/mem/mem.go" << 'EOF'
219+
//go:build ios || mobile
220+
221+
package mem
222+
223+
import "context"
224+
225+
type VirtualMemoryStat struct {
226+
Total uint64 `json:"total"`
227+
Available uint64 `json:"available"`
228+
Used uint64 `json:"used"`
229+
UsedPercent float64 `json:"usedPercent"`
230+
Free uint64 `json:"free"`
231+
Active uint64 `json:"active"`
232+
Inactive uint64 `json:"inactive"`
233+
Wired uint64 `json:"wired"`
234+
Laundry uint64 `json:"laundry"`
235+
Buffers uint64 `json:"buffers"`
236+
Cached uint64 `json:"cached"`
237+
WriteBack uint64 `json:"writeback"`
238+
Dirty uint64 `json:"dirty"`
239+
WriteBackTmp uint64 `json:"writebacktmp"`
240+
Shared uint64 `json:"shared"`
241+
Slab uint64 `json:"slab"`
242+
Sreclaimable uint64 `json:"sreclaimable"`
243+
Sunreclaim uint64 `json:"sunreclaim"`
244+
PageTables uint64 `json:"pagetables"`
245+
SwapCached uint64 `json:"swapcached"`
246+
CommitLimit uint64 `json:"commitlimit"`
247+
CommittedAS uint64 `json:"committedas"`
248+
HighTotal uint64 `json:"hightotal"`
249+
HighFree uint64 `json:"highfree"`
250+
LowTotal uint64 `json:"lowtotal"`
251+
LowFree uint64 `json:"lowfree"`
252+
SwapTotal uint64 `json:"swaptotal"`
253+
SwapFree uint64 `json:"swapfree"`
254+
Mapped uint64 `json:"mapped"`
255+
VmallocTotal uint64 `json:"vmalloctotal"`
256+
VmallocUsed uint64 `json:"vmallocused"`
257+
VmallocChunk uint64 `json:"vmallocchunk"`
258+
HugePagesTotal uint64 `json:"hugepagestotal"`
259+
HugePagesFree uint64 `json:"hugepagesfree"`
260+
HugePagesRsvd uint64 `json:"hugepagesrsvd"`
261+
Hugepagesize uint64 `json:"hugepagesize"`
262+
HugeTLBPages uint64 `json:"hugetlbpages"`
263+
}
264+
265+
type SwapMemoryStat struct {
266+
Total uint64 `json:"total"`
267+
Used uint64 `json:"used"`
268+
Free uint64 `json:"free"`
269+
UsedPercent float64 `json:"usedPercent"`
270+
Sin uint64 `json:"sin"`
271+
Sout uint64 `json:"sout"`
272+
PgIn uint64 `json:"pgin"`
273+
PgOut uint64 `json:"pgout"`
274+
PgFault uint64 `json:"pgfault"`
275+
PgMajFault uint64 `json:"pgmajfault"`
276+
}
277+
278+
func VirtualMemory() (*VirtualMemoryStat, error) {
279+
return &VirtualMemoryStat{
280+
Total: 1024 * 1024 * 1024, // 1GB
281+
Available: 512 * 1024 * 1024, // 512MB
282+
Used: 512 * 1024 * 1024, // 512MB
283+
UsedPercent: 50.0,
284+
Free: 512 * 1024 * 1024,
285+
}, nil
286+
}
287+
288+
func VirtualMemoryWithContext(ctx context.Context) (*VirtualMemoryStat, error) {
289+
return VirtualMemory()
290+
}
291+
292+
func SwapMemory() (*SwapMemoryStat, error) {
293+
return &SwapMemoryStat{
294+
Total: 0,
295+
Used: 0,
296+
Free: 0,
297+
UsedPercent: 0.0,
298+
}, nil
299+
}
300+
301+
func SwapMemoryWithContext(ctx context.Context) (*SwapMemoryStat, error) {
302+
return SwapMemory()
303+
}
304+
EOF
305+
306+
# Create main go.mod for gopsutil
138307
cat > "$STUB_DIR/github.com/shirou/gopsutil/v3/go.mod" << 'EOF'
139308
module github.com/shirou/gopsutil/v3
140309

openlist-lib/scripts/gobind_ios.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,26 @@ if [ -f ../go.mod ]; then
6969
go build -v ./openlistlib || {
7070
echo "Basic build failed, checking for issues..."
7171
go list -f '{{.ImportPath}}: {{.Error}}' ./openlistlib || true
72+
73+
# Check if it's a missing gopsutil package issue
74+
if go build -v ./openlistlib 2>&1 | grep -q "no required module provides package.*gopsutil"; then
75+
echo "Detected missing gopsutil packages, adding them..."
76+
go get github.com/shirou/gopsutil/v3/host
77+
go get github.com/shirou/gopsutil/v3/mem
78+
go get github.com/shirou/gopsutil/v3/cpu
79+
go mod tidy
80+
81+
# Re-run dependency fix after adding packages
82+
echo "Re-running dependency fix after adding gopsutil packages..."
83+
./scripts/fix_ios_dependencies.sh
84+
85+
# Try build again
86+
echo "Retrying basic build..."
87+
go build -v ./openlistlib || {
88+
echo "Build still failing after adding gopsutil packages"
89+
go list -f '{{.ImportPath}}: {{.Error}}' ./openlistlib || true
90+
}
91+
fi
7292
}
7393

7494
# Use build tags to exclude problematic packages on iOS

0 commit comments

Comments
 (0)