Skip to content

proposal: cmd/cgo: create temporary objdir by default #64621

@monoidic

Description

@monoidic

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:

  1. It is racy in conditions where this tool is invoked in parallel within the same directory
  2. it creates unexpected clutter (the objdir is not cleaned up at all post-invocation)
  3. it fails when the current directory is not writable (with a somewhat misleading error, e.g "Fatal error: can't create _obj/cgo.o: No such file or directory"; the success of 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/go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions