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

core tool could support a simple solution to the "main" vs. "library" dilemma #1381

Open
rcoreilly opened this issue Dec 18, 2024 · 3 comments
Labels
enhancement A new feature request
Milestone

Comments

@rcoreilly
Copy link
Member

Describe the feature

A constant challenge in Go is the inability to have a given directory contain both an executable and also be importable as a package for use elsewhere: https://groups.google.com/g/Golang-nuts/c/frh9zQPEjUk

If you want the executable to be named the same as the overall importable package, then you need two levels of subdirectories:

mypackage/
    mypackage.go
    ...
    cmd/
        mypackage/
            main.go
            mypackage  <- go build makes this

It would be great if you could instead just have this:

mypackage/
    mypackage.go
    ...
    cmd/
        main.go

and a core build or core run in the mypackage directory would automatically detect the presence of the cmd subdir, do a go build in that directory, and put the output back up at top level with the name mypackage.

How awesome would that be!?

This is actually a fairly urgent issue for me because I want all my sims to be accessible as imports into an overall content interactive doc space, and also available as a local executable command to run on a cluster etc.

I will implement in a PR now -- should take just a few mins.

Relevant code

No response

@rcoreilly
Copy link
Member Author

@kkoreilly pointed out that you can just do this:

mypackage/
    mypackage.go
    ...
    mypackage/
        main.go

(or the reverse, with the main at the top and package code below)

in which case the standard go build will at least make the right exe name, which is a big part of the issue. I will add tooling to cogent code to detect this situation and basically handle the rest -- it makes sense to have this be at a higher level than core build.

@rcoreilly
Copy link
Member Author

I thought that seemed too obvious to have overlooked this option before!

The problem is that I really want the exe to be in the upper level directory but then it is the same name as the subdirectory so that doesn't work at all.

@rcoreilly rcoreilly reopened this Dec 23, 2024
@kkoreilly
Copy link
Member

We still have not resolved how to do this; the commit above was reverted as it does not make sense for the core tool to do that.

@kkoreilly kkoreilly reopened this Dec 23, 2024
@kkoreilly kkoreilly added this to the v0.4 milestone Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants