-
Notifications
You must be signed in to change notification settings - Fork 24
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
Remove Cgo dependency on Windows #102
Conversation
friendly ping |
That's really sad that there has not been any feedback in the last 22 days. This change is really important (at least to me) e.g. in order to make compiling time shorten on Windows. |
Hi @hajimehoshi, thanks very much for your contribution. Sorry it is taking time, but please be aware that no one is paid to maintain these packages. It's a best effort in our spare time and we can only give so much. Please have patience and faith that we will get to it. Feel free to continue to send pings! |
This is a temporal fix until go-gl/glow#102 is applied.
type.go
Outdated
return fmt.Sprintf("uintptr(math.Float64bits(%s))", name) | ||
} | ||
case "GLDEBUGPROC", "GLDEBUGPROCARB", "GLDEBUGPROCKHR": | ||
return fmt.Sprintf("syscall.NewCallback(%s)", name) |
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.
Should this be NewCallbackCDecl?
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.
Done.
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.
Just a quick first pass...
} | ||
|
||
// Syscall returns a syscall expression for Windows. | ||
func (f Function) Syscall() string { |
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.
I wonder if this would be more idiomatic/clear if it returned an error when !IsImplementedForSyscall (rather than having a separate func that needs to be called)?
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 is called at templates to generate Syscall
calling, then returning error here would not make sense.
@@ -0,0 +1,110 @@ | |||
//glow:keepspace |
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.
It's not clear to me why this conversion code, or the debug code, needs to be forked across Windows/not-Windows.
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.
#102 (comment) is the reason: using this conversions_windows.tmpl
version at Cgo caused errors.
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.
Is there any way we can reduce the duplication by factoring out the parts that are the same? (Or am I misreading and all the implementations are subtly different?)
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.
Done (created the common conversion.tmpl
)
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.
Getting back to this now (finally, sorry for the delay)...
- Are the changes to conversions.tmpl platform agnostic and should be used everywhere?
- I still don't quite understand why debug needs to be forked.
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.
Quick reply: go-gl/gl#80 might be related, but I am not sure. I'll take a look later.
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.
I feel like if we can make conversions.tmpl pure Go first, we should do this before merging this PR. Wdyt?
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.
Yeah, I'm all for updating conversions to work across the board.
@@ -68,14 +68,29 @@ func (pkg *Package) GeneratePackage(dir string) error { | |||
if err := pkg.generateFile("package", dir); err != nil { | |||
return err | |||
} | |||
if err := pkg.generateFile("conversions", dir); err != nil { | |||
if err := pkg.generateFile("package_notwindows", dir); err != nil { |
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.
Having all these files is super unfortunate, but I'm not sure whether there is anything to be done for it.
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.
Perhaps something like:
for _, v := range []string{"package", "package_notwindows", "package_windows",
"conversions", "conversions_notwindows", "conversions_windows",
"procaddr_notwindows", "procaddr_windows"} {
if err := pkg.generateFile(v, dir); err != nil {
return err
}
}
tmpl/package_notwindows.tmpl
Outdated
// #cgo linux freebsd LDFLAGS: -lGL | ||
// #cgo windows LDFLAGS: -lopengl32 | ||
// | ||
// #if defined(_WIN32) && !defined(APIENTRY) && !defined(__CYGWIN__) && !defined(__SCITECH_SNAP__) |
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.
presumably these windows-specific bits are no longer necessary in the not-windows files?
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.
True.
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.
Done.
I think I have addressed all the issues. Please take a look. Thank you! |
Oops, I need to rebase this |
Done. PTAL |
// in order to free the memory. | ||
// | ||
// If no strings are provided as a parameter this function will panic. | ||
func Strs(strs ...string) (cstrs **uint8, free func()) { |
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.
@errcw My concern was that **uint8
would be a Go pointer to a Go pointer, which is not allowed to pass to C world. (This is fine to pass this to Syscall
on Windows as long as we care the lifetime of the object). That's why I separated the implementation for Windows and non-Windows. Do you have any suggestions?
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.
ping
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.
I'm so sorry for the slow responses here. The amount of free time I have is vanishingly small these days. The cstrs **unit8
return value is actually a set of pointers into malloc'ed C memory, which I believe is safe?
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.
Thank you for responding! Our plan is to make this function in pure Go (no cgo in any environment), right? If so, we would not be able to use C allocator.
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.
Right, right, of course. So I'm clear, on Windows, we're using Syscall
which is inherently safe to accept values that are Go pointers to Go pointers? Whereas on other platforms those same values are unsafe because they cross the Cgo boundary? If so, sounds good.
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.
on Windows, we're using Syscall which is inherently safe to accept values that are Go pointers to Go pointers?
Yes, there is no warning, and we can assure the lifetime of the objects (by runtime.KeepAlive
).
Whereas on other platforms those same values are unsafe because they cross the Cgo boundary?
This is unsafe, and unfortunately Go runtime suspends the execution with warning messages. That's the problem.
Then, I think it would be inevitable to split the implementation for Windows and non-Windows. My suggestion is to split the allocation part to minimize the split code. What do you think?
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.
If so, sounds good.
So, you are fine with splitting the code? :-)
@hajimehoshi thank you very much for this. I can't understand why it has been abandoned. I created a pull request on your nocgo branch to sync with master, implementing overloads. Moreover, I found a bug, not linked to overloads, in function:
This happens while creating a debug context with glfw 3.3; it works fine with cgo version. If I succeed in fixing it, I will make another pull request on your branch. |
I would like everyone to take notice that using syscall will double the call overhead, because syscall always calls |
Does this change limit glow only to generating Golang GL bindings using desktop OpenGL? Thanks |
Oh I forgot I created this PR... I was waiting for the reviews but reviewers seemed pretty busy. If there are reviewers, I'm fine to continue this PR. |
We at Fyne would certainly be interested at testing this once it is ready. It has been suggested a few times in the past that we should remove CGo on Windows (see fyne-io/fyne#911). |
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.
Not really much of a review. Just a small note on a comment :)
@@ -10,6 +13,33 @@ type Function struct { | |||
Return Type | |||
} | |||
|
|||
// IsImplementedForSyscall reports whether the function is implemented for syscall or not. | |||
func (f Function) IsImplementedForSyscall() bool { | |||
// TODO: Use syscall.Syscall18 when Go 1.12 is the minimum supported version. |
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.
Looks like Go 1.12 is the lowest supported version now.
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.
At least in glow. The gl package's mod file still says 1.9. Also, in 1.18 all the syscall functions except SyscallN are deprecated.
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.
Sure, go-gl/gl#144
Friedly ping ... |
I'm quite busy to work on this. I'm fine if someone takes over this |
Fixes go-gl/gl#109
Design Document
https://docs.google.com/document/d/1mqquznil9fR2amtb3eTC2ObCx3A8Af_5INqKjO-pKDg/edit?usp=sharing
tl;dr
I propose to eliminate Cgo usages on Windows from go-gl/gl by fixing go-gl/glow to generate code using syscall.Syscall.