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

Ability to build a cabal script into executable #7073

Closed
ethercrow opened this issue Sep 15, 2020 · 10 comments
Closed

Ability to build a cabal script into executable #7073

ethercrow opened this issue Sep 15, 2020 · 10 comments

Comments

@ethercrow
Copy link

ethercrow commented Sep 15, 2020

When I have a haskell program in a form of a single file script like

#!/usr/bin/env cabal
{- cabal:
build-depends: base, lens, shake, ...
-}
main = putStrLn "All done."

I'd like to be able to build it into a standalone executable.

Currently it seems like you can only build something with cabal v2-build if there is a cabal file and/or a project file, but building single file scripts is not supported:

> cabal v2-build Main.hs
No cabal.project file or cabal file matching the default glob './*.cabal' was found.
Please create a package description file ...

Creating a package description file is exactly what I'd like to avoid for small programs, since all the necessary information is already contained in the source file.

@jneira
Copy link
Member

jneira commented Sep 16, 2020

In fact cabal generates an executable when you does a cabal v2-run whatever.hs, it is under dist-newstyle\build\x86_64-windows\ghc-x.x.x\fake-package-0\x\script\build\script\script.exe in my windows system (the precise path can be different in other os). Maybe it would not be a final solution but maybe a working workaround.

@phadej
Copy link
Collaborator

phadej commented Sep 16, 2020

@jneira as if I remembered that cabal script should just use runghc. Whether it should first compiler and run executable, or just interpret is better left to the choice of user. (I think that interpreting is more reasonable default for scripts).

@bacchanalia
Copy link
Collaborator

I think #7851 resolved this issue.

@Mikolaj
Copy link
Member

Mikolaj commented Jan 21, 2022

It seems so. @ethercrow (and other interested parties), could you kindly confirm if it solves your use case? Ideally by compiling the master branch and trying it out.

@georgefst
Copy link

#7851 certainly improves the situation. But there's no easy way to find the resulting binary. It would be great if list-bin worked for scripts (and/or install, but I've always had issues with that one).

@bacchanalia
Copy link
Collaborator

There are so many cabal sub commands I didn't even realize list-bin was a thing. Adding list-bin support for scripts seems reasonable. I think installing a script going against the spirit of a script, though.

@georgefst
Copy link

There are so many cabal sub commands I didn't even realize list-bin was a thing.

Not unreasonably: #7774.

Adding list-bin support for scripts seems reasonable. I think installing a script going against the spirit of a script, though.

Well, if you have list-bin then I was thinking cabal install Script.hs is just a shortcut for (roughly) cabal build Script.hs && cabal list-bin Script.hs | cp ~/.local/bin. But I seem to remember that install isn't defined like that, and I've never understood why.

bacchanalia added a commit to bacchanalia/cabal that referenced this issue Jan 23, 2022
bacchanalia added a commit to bacchanalia/cabal that referenced this issue Jan 28, 2022
bacchanalia added a commit to bacchanalia/cabal that referenced this issue Jan 28, 2022
@bacchanalia
Copy link
Collaborator

can we close this?

@georgefst
Copy link

can we close this?

I'm happy. Thanks for #7925!

@Mikolaj
Copy link
Member

Mikolaj commented Feb 15, 2022

Tada!

@Mikolaj Mikolaj closed this as completed Feb 15, 2022
Kleidukos pushed a commit to Kleidukos/cabal that referenced this issue Mar 30, 2022
andreabedini pushed a commit to andreabedini/cabal that referenced this issue May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants