@@ -19,22 +19,138 @@ echo "Working in module root: $(pwd)"
1919echo " Checking for iOS incompatible dependencies..."
2020go list -m all | grep -E " (go-m1cpu|gopsutil)" || echo " No problematic dependencies found in module list"
2121
22- # Try to exclude problematic dependencies by replacing them with stubs
23- echo " Attempting to exclude iOS incompatible dependencies..."
22+ # Create a temporary directory for stub packages
23+ STUB_DIR=" $( pwd) /ios_stubs"
24+ mkdir -p " $STUB_DIR "
2425
25- # Replace go-m1cpu with a no-op version if it exists
26+ # Create stub for go-m1cpu
2627if 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
28+ echo " Creating stub for go-m1cpu..."
29+ mkdir -p " $STUB_DIR /github.com/shoenig/go-m1cpu"
30+ cat > " $STUB_DIR /github.com/shoenig/go-m1cpu/cpu.go" << 'EOF '
31+ //go:build ios || mobile
32+
33+ package cpu
34+
35+ // Stub implementation for iOS
36+ func IsAppleSilicon() bool {
37+ return false
38+ }
39+
40+ func IsIntel() bool {
41+ return false
42+ }
43+
44+ func ModelName() string {
45+ return "iOS Device"
46+ }
47+ EOF
48+
49+ cat > " $STUB_DIR /github.com/shoenig/go-m1cpu/go.mod" << 'EOF '
50+ module github.com/shoenig/go-m1cpu
51+
52+ go 1.19
53+ EOF
54+
55+ # Replace with local stub
56+ go mod edit -replace github.com/shoenig/go-m1cpu=" $STUB_DIR /github.com/shoenig/go-m1cpu"
57+ fi
58+
59+ # Create stub for gopsutil
60+ if go list -m all | grep -q " gopsutil" ; then
61+ echo " Creating stub for gopsutil..."
62+ mkdir -p " $STUB_DIR /github.com/shirou/gopsutil/v3/cpu"
63+ cat > " $STUB_DIR /github.com/shirou/gopsutil/v3/cpu/cpu.go" << 'EOF '
64+ //go:build ios || mobile
65+
66+ package cpu
67+
68+ import "context"
69+
70+ type InfoStat struct {
71+ CPU int32 `json:"cpu"`
72+ VendorID string `json:"vendorId"`
73+ Family string `json:"family"`
74+ Model string `json:"model"`
75+ Stepping int32 `json:"stepping"`
76+ PhysicalID string `json:"physicalId"`
77+ CoreID string `json:"coreId"`
78+ Cores int32 `json:"cores"`
79+ ModelName string `json:"modelName"`
80+ Mhz float64 `json:"mhz"`
81+ CacheSize int32 `json:"cacheSize"`
82+ Flags []string `json:"flags"`
83+ Microcode string `json:"microcode"`
84+ }
85+
86+ // Stub implementations for iOS
87+ func Info() ([]InfoStat, error) {
88+ return []InfoStat{{
89+ CPU: 0,
90+ ModelName: "iOS CPU",
91+ Cores: 1,
92+ }}, nil
93+ }
94+
95+ func InfoWithContext(ctx context.Context) ([]InfoStat, error) {
96+ return Info()
97+ }
98+
99+ func Percent(interval float64, percpu bool) ([]float64, error) {
100+ return []float64{0.0}, nil
101+ }
102+
103+ func PercentWithContext(ctx context.Context, interval float64, percpu bool) ([]float64, error) {
104+ return Percent(interval, percpu)
105+ }
106+
107+ func Times(percpu bool) ([]TimesStat, error) {
108+ return []TimesStat{}, nil
109+ }
110+
111+ func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error) {
112+ return Times(percpu)
113+ }
114+
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+
129+ func Counts(logical bool) (int, error) {
130+ return 1, nil
131+ }
132+
133+ func CountsWithContext(ctx context.Context, logical bool) (int, error) {
134+ return Counts(logical)
135+ }
136+ EOF
137+
138+ cat > " $STUB_DIR /github.com/shirou/gopsutil/v3/go.mod" << 'EOF '
139+ module github.com/shirou/gopsutil/v3
140+
141+ go 1.19
142+ EOF
143+
144+ # Replace with local stub
145+ go mod edit -replace github.com/shirou/gopsutil/v3=" $STUB_DIR /github.com/shirou/gopsutil/v3"
30146fi
31147
32148# Clean and rebuild
33149echo " Cleaning and rebuilding module..."
34150go mod tidy
35151go mod download
36152
37- echo " Updated dependencies:"
153+ echo " Updated dependencies with stubs :"
38154go list -m all | grep -E " (mobile|m1cpu|gopsutil)" || echo " No relevant dependencies found"
39155
40- echo " iOS dependency fix completed"
156+ echo " iOS dependency fix completed with stubs "
0 commit comments