iOS build error: "C source files not allowed when not using cgo or SWIG: iostat_darwin.c"
Describe the bug I'm getting a "C source files not allowed when not using cgo or SWIG: iostat_darwin.c" error when compiling when trying to compile go-btfs which has a dependency on go-sutil. I need to use CGO so CGO=0 is not doable for me, issue is happening for arm64 and x86_64 as well.
Exact output error:
package github.com/bittorrent/go-btfs/cmd/btfs imports github.com/bittorrent/go-btfs/chain imports github.com/bittorrent/go-btfs/core/commands/storage/path imports github.com/shirou/gopsutil/v3/disk: C source files not allowed when not using cgo or SWIG: iostat_darwin.c make: *** [ios-arm64] Error 1
To Reproduce
v3.22.12
CGO_ENABLED=1 \
GOOS=darwin \
GOARCH=arm64 \
SDK=iphoneos \
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk \
CC=$(PWD)/clangwrap.sh \
CGO_CFLAGS="-fembed-bitcode -Wno-undef-prefix" \
go build -buildmode=c-archive -tags ios -o $(IOS_OUT)/arm64.a .
Expected behavior Compiling completed with no issues
Environment (please complete the following information):
-
[ ] Windows: [paste the result of
ver] -
[ ] Linux: [paste contents of
/etc/os-releaseand the result ofuname -a] -
[X] Mac OS: ProductName: macOS ProductVersion: 13.1 BuildVersion: 22C65 Darwin Simbads-MacBook-Air.local 22.2.0 Darwin Kernel Version 22.2.0: Fri Nov 11 02:04:44 PST 2022; root:xnu-8792.61.2~4/RELEASE_ARM64_T8103 arm64
-
[ ] FreeBSD: [paste the result of
freebsd-version -k -r -uanduname -a] -
[ ] OpenBSD: [paste the result of
uname -a]
Additional context
[Cross-compiling? Paste the command you are using to cross-compile and the result of the corresponding go env]
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/simbadmarino/Library/Caches/go-build"
GOENV="/Users/simbadmarino/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/simbadmarino/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/simbadmarino/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/simbadmarino/Documents/btfs-sharedLib/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/89/7_dkrhfd345107kdvp3gk4p40000gn/T/go-build1188434045=/tmp/go-build -gno-record-gcc-switches -fno-common"
MakeFile:
CGO_ENABLED=1 \
GOOS=darwin \
GOARCH=arm64 \
SDK=iphoneos \
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk \
CC=$(PWD)/clangwrap.sh \
CGO_CFLAGS="-fembed-bitcode -Wno-undef-prefix" \
go build -buildmode=c-archive -tags ios -o $(IOS_OUT)/arm64.a .
Any support is greatly appreciated. Thanks
Maybe this PR https://github.com/shirou/gopsutil/pull/1362 can help. Until now, iOS support is not available because the actual drive stats are still macOS only.
Maybe this PR #1362 can help. Until now, iOS support is not available because the actual drive stats are still macOS only.
That actually worked but the work around I used was to remove all C files in the directory, otherwise CGO understands it needs to use CGO instead of nonCGO. Not sure if its possible to somehow tell Go not to use CGO on a particular package and having C files at the same time...
I am seeing the same issue when trying to compile the package with gomobile.
What is the plan with fixing this issue?
I haven't tested it myself, but if the problem is that cgo is used, would setting CGO_ENABLED=0 solve the problem?
I am seeing the same issue when trying to compile the package with
gomobile.What is the plan with fixing this issue?
The problem is that if you keep CGO enabled ,go detects C / header files in this library directory and rise this issue. What I did as a work around is just to remove the library C files and header files and compile again. I know its not elegant but works in the mean time
Removing the C files helps to compile the library for iOS with gomobile. But now it does not work with regular go build at MacOS.
I've been using the same gomobile binary to use it on m1 chip without issues, but for sure wont work for non arm64 chips. In summary didn't test it for x64 Mac, you'll need to get a better workaroud for your use cae unfortunately... let us know if you find a better workaround.. :)