-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
proposal: cmd/cgo: create temporary objdir by default #64621
Comments
I also (prematurely) created PR #64591 for this. |
|
I think that, regardless of this, it would be a better default. The fact that it's racy by default does not seem to be documented anywhere for people that aren't typical Go users, and there are various workarounds to the left-over If this proposal is not accepted, then two potentially less controversial fixes (which would be addressed by this) still pop to mind:
|
I have file like this :
I do that because after 6 years, my IDE (GoLand) still doesn't offers completion to C structs. (neither on C.struct_* nor on their type aliases) So I workaround this sorry state by And instead I call Doing so leaves a (not temporary) _obj/ + _obj/cgo.o file, which I So, anyway, that's an use case for possibly not having a (persistent by default) _obj/ directory placed in the source tree. Best Regards, |
I had a similar issue and a similar solution, though with a dedicated code parsing tool. Though gopls under VS Code seems to understand cgo definitions just fine, and I never really thought to look into how it did it... |
Change https://go.dev/cl/548076 mentions this issue: |
It is hard to understand how it is working, can you consider to create some example project on github to share the idea with community? Thanks in advance! |
Proposal Details
As a part of an invocation of
go tool cgo
, temporary files are created and placed in an "object directory". This directory can be specified with the -objdir flag, and it defaults to _obj within the current directory.There are some issues with this:
os.Mkdir
is not verified)I believe that creating a temporary directory and removing it afterwards would be a better default, as it would avoid these issues.
Anything that explicitly sets the
-objdir
flag would be left unchanged, and the current default behaviour could be restored simply by explicitly setting-objdir
to_obj
This would break anything that runs
go tool cgo
without explicitly setting-objdir
and assumes that the_obj
directory is left over afterwards. In the golang/go repository, there is no occurrence of this, aside from one behaviour test for cmd/goThe text was updated successfully, but these errors were encountered: