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

cmd/cgo: CFLAGS not passed in godefs mode #41072

Open
Helflym opened this issue Aug 27, 2020 · 3 comments
Open

cmd/cgo: CFLAGS not passed in godefs mode #41072

Helflym opened this issue Aug 27, 2020 · 3 comments
Labels
Milestone

Comments

@Helflym
Copy link
Contributor

@Helflym Helflym commented Aug 27, 2020

What version of Go are you using (go version)?

Master, 1.15, 1.14.7 and 1.13.13

What operating system and processor architecture are you using (go env)?

Found on aix/ppc64, but same on linux/amd64

What did you do?

The #cgo CFLAGS directive is ignored when using -godefs mode.
The following example shows it with a define. Of course, #cgo CFLAGS: -D_D1 can be replaced by #define _D1 and it will work. But that's not possible, AFAIK, for gcc flags like "-fms-extensions" which I need to pass for another code.

package p

/*
#cgo CFLAGS: -D_D1

#ifdef _D1
typedef struct S1 {
        int a;
} S1_t;
#endif
*/
import "C"

type S1 C.struct_S1

What did you expect to see?

$ go tool cgo -godefs  godefs.go 
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs godefs.go

package p

type S1 struct {
	A int32
}

What did you see instead?

$ go tool cgo -godefs  godefs.go 
// Code generated by cmd/cgo -godefs; DO NOT EDIT.
// cgo -godefs godefs.go

package p

type S1 struct{}
@Helflym Helflym changed the title cmd/cgo: CGLAFS not taken in godefs mode cmd/cgo: CFLAGS not passed in godefs mode Aug 27, 2020
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 27, 2020

The only way to use -godefs mode is via go tool cgo, and when you run go tool cgo you can pass C compiler options on the command line. Do we need to also support #cgo CFLAGS?

@Helflym
Copy link
Contributor Author

@Helflym Helflym commented Aug 28, 2020

I wasn't aware you can pass compiler options directly to go tool cgo. Maybe, it should be said in cgo doc, at least that #cgo directives don't work with it.

Anyway, it's up to you, adding #cgo CFLAGS support can be useful in some cases. As you can record which flags to add, it would help if you want to have the same godefs file for different OS without wondering each time which flags are needed. But as there is a way to achieve the same behavior already it's not mandatory, I guess.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 28, 2020

I suppose I'm OK with having -godefs honor #cgo CFLAGS, but it's not something I plan to work on myself.

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.