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

Move C files to be included by go mod #885

Closed
wants to merge 1 commit into from

Conversation

afontaine
Copy link

Fixes #832 by moving the C files into a go module directory, which means they should be included by go mod vendor.

Not sure how I should name them, let me know if you want it changed.

@afontaine
Copy link
Author

well, so much for this being easy 😞

I don't really understand the error here either, do you have any insight @shirou?

@afontaine
Copy link
Author

oh hey that did the trick. I am a touch concerned that this would somehow still not work though 🤔 but my C seems to think that this should work

@shoenig
Copy link
Contributor

shoenig commented May 29, 2020

I believe this breaks compatibility with non-darwin targets

$ uname -a
Linux nzxt 5.4.0-33-generic #37-Ubuntu SMP Thu May 21 12:53:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ cat go.mod
module foo

go 1.14

replace github.com/shirou/gopsutil => github.com/afontaine/gopsutil v2.20.5-0.20200528220053-51e143da77b3+incompatible

require (
	github.com/shirou/gopsutil v0.0.0-00010101000000-000000000000
	golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
)
$ cat foo.go
package main

import _ "github.com/shirou/gopsutil/host"
$ go build
foo.go:3:8: C source files not allowed when not using cgo or SWIG: smc.c

$ CGO_ENABLED=1 go build
foo.go:3:8: C source files not allowed when not using cgo or SWIG: smc.c

@afontaine
Copy link
Author

Ah... yes, of course it's not that simple 🤔

Lomanic added a commit to Lomanic/gopsutil that referenced this pull request May 31, 2020
Lomanic added a commit to Lomanic/gopsutil that referenced this pull request May 31, 2020
@Lomanic
Copy link
Collaborator

Lomanic commented May 31, 2020

You have to rename smc.c to smc_darwin.c and smc.h to smc_darwin.h and change the references in the source and it's then possible to go build github.com/shirou/gopsutil/hoston Linux successfully. This is what I've done in #832 (comment). Though I prefer your names (smc_darwin.{c,h} compared to my less descriptive host_darwin.{c,h}).

Though there were the same compilation warnings with these changes, I fixed them in my own branch (I'm quite sure I wouldn't be able to push to your branch) and took the occasion to rename darwin c files in the disk package.

As you spent some time on it and want some attribution maybe, I can let you fix that in your branch and merge this PR afterwards, I will rebase my PR after merging yours if you do so.

@afontaine
Copy link
Author

Ah the magic of go! Thanks @Lomanic

I'm not super concerned about the attribution, more about the fix 😁 I updated the file names, and I don't really know what I'm doing with go 😅

@afontaine
Copy link
Author

@Lomanic by all means please merge #889 instead of this, as it looks like you've captured more files that need to be moved/renamed 👍

@afontaine afontaine closed this Jun 5, 2020
@Lomanic
Copy link
Collaborator

Lomanic commented Jun 6, 2020

OK, no problem.

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

Successfully merging this pull request may close these issues.

macOS: Unable to build using Go Modules
3 participants