-
Notifications
You must be signed in to change notification settings - Fork 316
util: conditionally build CGO functions #190
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
Conversation
This sounds good to me. I'm just wondering if the non-cgo stub should still implement the functions that are being moved out here, just by erroring out. This would keep the same public interface, regardless of tags. I'm not sure what is the idiomatic Go way here, @jonboulle? |
@lucab @jonboulle Can we get this merged? go-systemd build in etcd is broken. And I believe this is idiomatic, based on Go source tree.
And more
Thanks! |
// the current process is running. | ||
// This function is a wrapper around the libsystemd C library; if it cannot be | ||
// opened, an error is returned. | ||
func GetRunningSlice() (slice string, err error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function declaration and docstring should probably be retained, otherwise this part will be missing from godoc and we would get different public symbols depending on build tags. It can be simply implemented as a stub that always errors out. Same for the other functions moved out from this file.
I had another look at this, and I think that the current approach may be non-optimal: some public symbols will depend on build tags and will disappear from godoc (I guess, not sure). Thus, I'd suggest a different way this could be done, by splitting current
|
c8dab62
to
60b7021
Compare
@lucab all fixed up; I made the public functions call into private build-specific functions. It seemed weird to have the full godoc in |
"fmt" | ||
) | ||
|
||
var errNoCGO = fmt.Errorf("go-systemd built with CGO disabled") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be moved to util.go
in order to let consumers error-match on this in all situations.
I agree this is even better than my half-botched proposal, thanks! Just one final remark inline, other than that it should be ok. |
60b7021
to
6fb79a4
Compare
Some projects don't need the CGO functions in the util package; split out the functions into a separate file so CGO_ENABLED=0 works if those functions are never used. Fixes coreos#171
@lucab ok, ErrNoCGO exported |
Great, LGTM! |
Some projects don't need the CGO functions in the util package;
split out the functions into a separate file so CGO_ENABLED=0
works if those functions are never used.
Fixes #171