You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cabal run can run scripts, but the utility of this is limited because under the current design it recompiles on every invocation.
I propose adding the following:
fake packages for scripts to be written under ~/.local/share (or os equivalent)
specifically ~/.local/share/cabal/<abs path of script without extension>/ to avoid collisions
the option --tmp-script-artifacts (current behaviour. keep as default?)
the option --persist-script-artifacts (new behaviour)
the option --script-artifact-dir=DIR (place fake package in user supplied directory)
script support for cabal build and cabal repl
updates to the relevant docs
I have done a quick test with hard coded paths, and it works as expected without further changes. The only changes to run necessary are to add the flags and pass the correct directory based on them. I haven't scoped out the work needed to add support to build and repl, but I assume it would be very similar to how it works now in run.
the option --tmp-script-artifacts (current behaviour. keep as default?)
the option --persist-script-artifacts (new behaviour)
the option --script-artifact-dir=DIR (place fake package in user supplied directory)
bikeshedding:
no option set or -no-persist-fake-package > current behavior
persist-fake-package > save to ./local/share
persist-fake-package = dir > save to dir
Trying to generalize the behaviour for fake packages and minimize the number of flags, independently of where are being used.
Not sure if the generalization makes sense, in that case replace persist-fake-package by persist-script-build.
Otoh the proper solution should be remove the need of fake-package at all in the entire codebase (see #6977), which could open the door to other improvements
Cache folders on different OS's (please correct me if I'm wrong):
on Linux save to ~/.cache (not ~/.local/share)
on Windows save to %LOCALAPPDATA%
on OSX save to ~/Library/Caches
It probably makes sense to add a utility function (in Distribution.Simple.Utils?) to get the cache folder.
Rather than putting the fake-package directory structures directly in <cache>/cabal, it might be a better idea to put them in <cache>/cabal/fake-packages in case other uses for <cache>/cabal come up.
@fendor What's the status of the work you were doing on #6149?
@jneira re #6977: I'm not sure caching makes sense for other uses of fake package. At the very least you'd need a completely separate scheme for where to place/how to identify cached instances.
@bacchanalia: re #7393, you complain "it recompiles on every invocation", and ghc --run would be able to execute a script without producing any compilation artefacts (and without linking) at all. Therefore, it could potentially be used as, in addition to or instead of --tmp-script-artifact. If we assume scripts are never computationally intensive, perhaps it could be used instead of cabal run always? Am I missing something?
@Mikolaj running a script with cabal run allows you do have a cabal block
{- cabal:build-depends: ...-}
while ghc --run presumably just uses the global environment.
If we assume scripts are never computationally intensive
I don't think this is a good assumption. Scripts and packages have different ergonomics, and when you might prefer one over the doesn't neatly fall on that boundary, for me, anyway.
Another consideration is start-up time. On my machine running hello.hs with runghc takes 25ms, while cached cabal run only takes 15ms (and hopefully that could go lower, but that's out of scope) which is important in some applications.
Fine. And what about ghc --run (or --eval, but I don't remember the details) underlying --tmp-script-artifact? Is there a value in the temporary artifacts being written somewhere at all?
What's the status of the work you were doing on #6149?
Stalled. I don't know how much everyone else knows about this feature, so I'll repeat a bit how this currently works: The script section (which is quite literally an executable section from a .cabal file [btw, you can break it if you put main-is: SomeName.hs into the script section]) is parsed and based on it, a .cabal file is generated and written to a project file in $TMP. The source is copied to that directory as well, iirc, and then cabal build && cabal exec is basically executed on that project in $TMP.
Doing the same for v2-repl File.hs doesn't cut it, since updates to our original script file won't be noticed, we lose the current working directory, etc... I played around with workarounds, e.g. after invoking cabal v2-repl in that directory, cd to the previous working directory, and listing the full path to the script instead of copying the source script... I can't remember whether there was a blocking issue with cding and listing the full path to the source file, but it was so weird that I wondered whether I would make everything worse by applying duct-tape to this design and stopped with my experiments.
@Mikolaj That might be preferable in the --tmp-script-artifact case, but there might be some value in having consistency between the cases both in terms of implementation and use? Also a user might want to inspect the output. I don't really feel strongly about it either way.
Activity
jneira commentedon Nov 30, 2021
Related:
EDIT: Added #7393 as suggested by @Mikolaj
Mikolaj commentedon Nov 30, 2021
also #7393
jneira commentedon Nov 30, 2021
bikeshedding:
Trying to generalize the behaviour for fake packages and minimize the number of flags, independently of where are being used.
Not sure if the generalization makes sense, in that case replace
persist-fake-packagebypersist-script-build.Otoh the proper solution should be remove the need of fake-package at all in the entire codebase (see #6977), which could open the door to other improvements
bacchanalia commentedon Nov 30, 2021
When else are fake packages used other than to build scripts?
edit: This is discussed in issue #6977. I shouldn't comment before coffee.
bacchanalia commentedon Nov 30, 2021
Cache folders on different OS's (please correct me if I'm wrong):
~/.cache(not~/.local/share)%LOCALAPPDATA%~/Library/CachesIt probably makes sense to add a utility function (in Distribution.Simple.Utils?) to get the cache folder.
Rather than putting the fake-package directory structures directly in
<cache>/cabal, it might be a better idea to put them in<cache>/cabal/fake-packagesin case other uses for<cache>/cabalcome up.bacchanalia commentedon Nov 30, 2021
@Mikolaj I'm not sure I see the relevance of #7393?
@fendor What's the status of the work you were doing on #6149?
@jneira re #6977: I'm not sure caching makes sense for other uses of fake package. At the very least you'd need a completely separate scheme for where to place/how to identify cached instances.
Mikolaj commentedon Nov 30, 2021
@bacchanalia: re #7393, you complain "it recompiles on every invocation", and
ghc --runwould be able to execute a script without producing any compilation artefacts (and without linking) at all. Therefore, it could potentially be used as, in addition to or instead of--tmp-script-artifact. If we assume scripts are never computationally intensive, perhaps it could be used instead ofcabal runalways? Am I missing something?bacchanalia commentedon Nov 30, 2021
@Mikolaj running a script with
cabal runallows you do have a cabal blockwhile
ghc --runpresumably just uses the global environment.I don't think this is a good assumption. Scripts and packages have different ergonomics, and when you might prefer one over the doesn't neatly fall on that boundary, for me, anyway.
Another consideration is start-up time. On my machine running hello.hs with runghc takes 25ms, while cached cabal run only takes 15ms (and hopefully that could go lower, but that's out of scope) which is important in some applications.
Mikolaj commentedon Nov 30, 2021
Fine. And what about
ghc --run(or--eval, but I don't remember the details) underlying--tmp-script-artifact? Is there a value in the temporary artifacts being written somewhere at all?fendor commentedon Nov 30, 2021
Stalled. I don't know how much everyone else knows about this feature, so I'll repeat a bit how this currently works: The script section (which is quite literally an executable section from a .cabal file [btw, you can break it if you put
main-is: SomeName.hsinto the script section]) is parsed and based on it, a .cabal file is generated and written to a project file in $TMP. The source is copied to that directory as well, iirc, and thencabal build && cabal execis basically executed on that project in $TMP.Doing the same for
v2-repl File.hsdoesn't cut it, since updates to our original script file won't be noticed, we lose the current working directory, etc... I played around with workarounds, e.g. after invokingcabal v2-replin that directory,cdto the previous working directory, and listing the full path to the script instead of copying the source script... I can't remember whether there was a blocking issue withcding and listing the full path to the source file, but it was so weird that I wondered whether I would make everything worse by applying duct-tape to this design and stopped with my experiments.bacchanalia commentedon Nov 30, 2021
@Mikolaj That might be preferable in the
--tmp-script-artifactcase, but there might be some value in having consistency between the cases both in terms of implementation and use? Also a user might want to inspect the output. I don't really feel strongly about it either way.Mikolaj commentedon Nov 30, 2021
Sure, it's your call as the implementer and, personally, I'd not expend any extra effort (unless minimal) until users express interest.
bacchanalia commentedon Nov 30, 2021
@fendor In the thread for #6149 you mention that stack handles
:rcorrectly. Did you investigate what they do?24 remaining items
Add script support to cabal clean.
Add script support to cabal repl
Update documentation for better script support
Add support for script build caching to cabal run
Add support for scripts to cabal build.
Add script support to cabal clean.
Add script support to cabal repl
Update documentation for better script support
Add support for script build caching to cabal run
Add support for scripts to cabal build.
Add script support to cabal clean.
Add script support to cabal repl
Update documentation for better script support
Better support for running scripts. (#7851)