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

start to using CGO on cpu/cpu_darwin #66

Open
shirou opened this issue Aug 28, 2015 · 8 comments
Open

start to using CGO on cpu/cpu_darwin #66

shirou opened this issue Aug 28, 2015 · 8 comments

Comments

@shirou
Copy link
Owner

shirou commented Aug 28, 2015

I know there are many people who want to get CPUTimes on darwin using CGO. I had rejected because of easy cross-compiling. I had wrote using helper process. But yes, this is bad approach. And I think there is no way to get host_processer_info from pure Go because this is belongs to Mach part of darwin.

So, now, I have changed my mind.

Since 47f6760, cpu_darwin uses CGO. Current code is borrowed from influxdb/telegraf. Thank you using gopsutil!)

If someone want to remove CGO dependency, please write comments for this issue. I will remove quickly.

I always grateful to such a many people using, discussing, and contributing gopsutil.

reference

@vrecan
Copy link
Contributor

vrecan commented Aug 31, 2015

👍

@dadgar
Copy link

dadgar commented Oct 5, 2015

I would prefer this removed because as you said it makes cross compiling difficult. Using tools like gox is much harder with this now.

@shirou
Copy link
Owner Author

shirou commented Oct 8, 2015

@dadgar thank you for the 👎

I have an idea about to use a build tag to easy cross compiling. It means, make two kind of files about darwin.

  • cpu_darwin_cross.go
    • // +build darwin cross
    • no CGO, just return NotImplementedError on CPUTimes()
  • cpu_darwin.go
    • // +build darwin !cross
    • use CGO

If you want to cross compile (and can accept could not get CPUTimes on darwin), type go build -tags=cross. Then, cpu_darwin_cross.go is used for cross-compile.

How do you feel it? Thank you.

@dadgar
Copy link

dadgar commented Oct 9, 2015

Yeah I like your thinking. You could probably use the cgo tag right?
`

@shirou
Copy link
Owner Author

shirou commented Oct 10, 2015

Ah! cgo build tag is the right way. Totaly agree.
I made a PR #89. could you check it out?

@Comdex
Copy link

Comdex commented May 31, 2016

Let user to choose use cgo or not when compile the code is a good idea

@shirou
Copy link
Owner Author

shirou commented May 31, 2016

@Comdex You can change CGO_ENABLE environment variable.

@jesse-c
Copy link

jesse-c commented Jun 16, 2017

Quick tip for anyone wondering, it's CGO_ENABLED. See: https://golang.org/cmd/cgo/.

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

No branches or pull requests

6 participants