elastic / gosigar

Gathers system and per process statistics
Apache License 2.0
105 stars 76 forks source link

Fix build on iOS #134

Closed jeanregisser closed 4 years ago

jeanregisser commented 4 years ago

This PR fixes a compilation error on iOS as seen in https://github.com/ethereum/go-ethereum/issues/20160

Unfortunately libproc.h is not included in the iOS SDK. The missing headers were taken from Xcode 11.3.1 (/Applications/Xcode11.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/).

Let me know what you think. Thanks.

cla-checker-service[bot] commented 4 years ago

❌ Author of the following commits did not sign a Contributor Agreement: 8818624d7cd4a9e069a68efb8b44216e32d6c91f, 8d0b88ce06808ffb66202b325454ee05dd0e4c97, bce15e6cb89669f1a4aeff6297f3ded5794d7377, 73c1cd0ddd1c9663a4897466dd3d16b48a8477ad

Please, read and sign the above mentioned agreement if you want to contribute to this project

holiman commented 4 years ago

ping @jeanregisser would you be open to signing that CLA? I guess this PR is blocked for that reason

jeanregisser commented 4 years ago

Yes I did follow the process and signed the document on DocuSign but somehow the bot didn’t update the status.

I’ll retry today.

arnaubennassar commented 4 years ago

Is there any update on this?

andrewkroh commented 4 years ago

We don't want to include and maintain Apple's headers in this project. Apple should add the necessary headers to their IOS SDK if they are meant to be used to IOS projects. I recommend using tags to exclude the use of gosigar from projects that need to compile for mobile.

I think we would accept a patch to include sigar_stub.go for IOS. It would need to be accompanied by tests on Travis CI that verify builds work for gomobile build -target=ios -x ., GOOS=darwin GOARCH=amd64 build, and GOOS=darwin GOARCH=386 go build ..

I did check if the MacOS SDK would work unmodified, but, no, it did not work without cherry-picking particular files as this PR has done. Specifically some of the headers complain that architecture not supported due to ARM.

The other issue I encountered is that gomobile doesn't support -gccgoflags or CGO_CFLAGS. So you cannot pass through the CFLAGS option. The only way I could set the value was by adding a source file with a CGO "comment" that set CFLAGS. From gomobile help build:

The build flags -a, -i, -n, -x, -gcflags, -ldflags, -tags, -trimpath, and -work are shared with the build command. For documentation, see 'go help build'.

user1121114685 commented 1 year ago

感谢你的支持,成功的解决了编译错误的问题,这个修复在 https://github.com/shirou/gopsutil 中支持良好,一次性解决了编译问题,非常感谢。