Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS build error: "C source files not allowed when not using cgo or SWIG: iostat_darwin.c" #1402

Open
1 of 5 tasks
simbadMarino opened this issue Jan 2, 2023 · 7 comments
Open
1 of 5 tasks

Comments

@simbadMarino
Copy link

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-release and the result of uname -a]

  • 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 -u and uname -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 .

clangwrap.txt

Any support is greatly appreciated. Thanks

@ghost
Copy link

ghost commented Feb 22, 2023

Maybe this PR #1362 can help.
Until now, iOS support is not available because the actual drive stats are still macOS only.

@simbadMarino
Copy link
Author

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...

@anatol
Copy link

anatol commented Aug 3, 2023

I am seeing the same issue when trying to compile the package with gomobile.

What is the plan with fixing this issue?

@shirou
Copy link
Owner

shirou commented Aug 3, 2023

I haven't tested it myself, but if the problem is that cgo is used, would setting CGO_ENABLED=0 solve the problem?

@simbadMarino
Copy link
Author

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

@anatol
Copy link

anatol commented Aug 4, 2023

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.

@simbadMarino
Copy link
Author

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.. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants