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
{{ message }}
Repository navigation
cabal install run immediately after cabal build unnecessarily rebuilds the project #6919
I notice that, if I cabal build exe:propellor, the cabal install does not re-build.
The default cabal build of both executables and the library differing from what's it's being asked to install seem to be what causes the re-build. I think it should be possible to build everything and then only install part of what was build, without a rebuild.
System information
cabal-install version 3.0.0.0
compiled using version 3.0.1.0 of the Cabal library
Reacted by Andreas Abel, John MacFarlane, Artem Pelenitsyn, Julius Marozas, Lua Viana Reis , Mouse, Mitchell Dalvi Rosen, Jonathan Moore and Ilya Baryshnikov
I should mention that, while the above seems like suboptimal behavior, what I'm really wanting to do -- inexpensively symlinking the executable cabal has built to a place I need it -- is something cabal install seems ill-suited to.
Other performance problems include it loading the cabal package list, building the sdist (a 1.7 mb compressed tarball in my case), probably more.
What I'm probably going to use instead is cabal exec -- sh -c 'command -v propellor'
to get the path to the binary and symlink it myself.
Context:
While v1- was "autotools-like", v2- does not follow that model anymore and is more declarative instead. v2-install tries to be as reproducible as possible by doing a sdist before building and installing (and anecdotally this has helped people catch some bugs in their cabal files). This also has a simpler implementation, = less bugs.
@andreasabel
So the sequence of commands for installing an executable is just
cabal install TARGET
Which builds the package one time only. build (and configure, which is optional) is only useful if you want to develop the package.
@joeyh
for your usecase, the upcoming cabal 3.4 provides a list-bin command that inexpensively prints the paths of local executables, so you can do whatever you want with them without fragile exec hacks. Does that solve the issue?
in the working directory to get Agda to build and be installed. Of course, I will have to invoke this command several times until all the compilation error are fixed.
How do I proceed in v2?
I would run cabal build several times until my compilation errors are fixed, and then how to install the executables? cabal install is forbiddingly expensive, since compiling the 400 modules from scratch with aggressive optimization takes 30 minutes.
For me, the v1-install functionality works best. To port it to v2, could we have something like
cabal build --install-executables
that performs the installation with binaries built by build?
I should mention that we don't test any of v1- commands anymore.
The code is there, and if it works it is good, but if it doesn't,
we wont actively pursue fixing it (rather concentrating on whatever
issues are holding you from migration to v1-build).
the present issue is one that makes us stick to v1 in the Agda development.
My feature request would be to have this option of stack build:
--[no-]copy-bins Enable/disable copying binaries to the local-bin-path
(see 'stack path') (default: disabled)
In the meantime, I have awked a workaround. I write
cabal build | tee >(copy-bins.awk)
which picks up the executable name from the Linking foo ... message of cabal build and links this executable in .cabal/bin.
copy-bins.awk:
#!/usr/local/bin/gawk --file# To use with "cabal v2-build", e.g.## cabal build | tee >(copy-bins.awk)## When "cabal build" outputs "Linking path/.../x/.../to/exe ..."# we symlink this executable from our ".cabal/bin" directory.match ($0, /^Linking (.+\/x\/.+) ...$/, res) {
# CONFIGURE ME
installdir ="~/.cabal/bin";
# Capture the regex group (...) in src
src = res[1];
# Create the symlink
ln_cmd ="ln -s -f "src""installdir"/";
print("[COPY-BINS]", ln_cmd); # Tell what you are doing.system(ln_cmd);
}
If the exec and list-bin+ ln -s workarounds aren't enough, we could consider accepting a pr that implements the conversion from local to store package, but there are a lot of details to think about (ex. rpath/relinking, data files, dependencies...). Even so, such a conversion has a fundamental problem over the above workarounds when doing iterative development: it would quickly increase the size of the store, and we have no garbage collection yet. I think list-bin plus ln -s is the best solution in this case.
After the info posted in #7297 (comment) and my tests in #7745 about the differences between build local packages and installing them
cannot be completely true, unit-ids (of local libraries) are different, Paths_ point to different directories, maybe something else I forget.
i would say that
cabal install should behave as is (therefore continue rebuilding the local packages as remote ones), not only to reuse the code for cabal install local.or.remote.tar but to have a consistent behaviour across all target types.
it will make local libraries available in the store for other projects f.e.
still i think we should add a cabal build --copy-bins to copy executables, tests and benches (and dynamic libs?) outside the build directory and make available the pattern cp $(cabal list-bin my exe) /some/path to users
First, yes - to be useful, --copy-bins must copy dynamic libraries in addition to copying the executables themselves. Otherwise, those executables would have zero chance to run.
Second, right now cabal list-bin appears broken. So, I assume cabal as-is would be unable to even locate the binaries to copy. cabal-plan does list the executables correctly - but it seems to have no idea about dynamic libs those executables depend on.
What are the effects of --enable-tests? Why cannot cabal v2-install build whatever it's (re-) building with that flag, and merely skip copying the <target>:test executables to the global store?
No, an attempt to find a solution or a "working" workaround for this problem - when you build with --enable-tests, there's no way to avoid re-building a lot of dependencies during install. Based on this ticket, it looks like --enable-tests is not the only case when cabal rebuilds just-built stuff during install.
I agree that --copy-bins would've been a good workaround, if not a "total" solution - if it worked.
changed the title [-]cabal install run immediately after cabal build unncessarily rebuilds the project[/-][+]cabal install run immediately after cabal build unnecessarily rebuilds the project[/+]on Jan 29, 2022
@mouse07410: I'm afraid we haven't made any progress with designing --copy-bins nor splitting install or even incorporating cabal-env. That's my report for now. Do you have anything to report? Any new ideas?
Alas, nothing new. :-(
Frankly, I doubt I'm in the league - not enough Haskell or general FP experience or expertise. But it would be great if somebody figured how to fix --copy-bins and splitting install.
cabal install forces rebuild of several dependencies even when run immediately after a successful cabal build.
cabal --copy-bins omits dynamic libraries, thus ensuring that the copied executables become useless/broken (unable to run, being unable to load dynamic libraries they need).
I'm not aware of any progress, but I might have easily missed something. If you find any relevant ticket or a comment in another ticket, please kindly link here.
@mpickering: This issue is still a blocker for removing the v1 interface.
E.g. it makes bisection of large projects much slower if you need to install rather than just build.
I understand that developers and maintainers are volunteers, and choose to invest their time as they see fit. But since they are involved with this project - they probably care for Cabal to be more usable, and exhibit fewer problems.
An acceptable workaround would be if --copy-bins could either figure that that there are dynamic libraries and copy them along with executables, or have another sub-flag --with-libs or such - upon which it would locate and copy dynamic libraries...
Activity
joeyh commentedon Jun 18, 2020
I should mention that, while the above seems like suboptimal behavior, what I'm really wanting to do -- inexpensively symlinking the executable cabal has built to a place I need it -- is something cabal install seems ill-suited to.
Other performance problems include it loading the cabal package list, building the sdist (a 1.7 mb compressed tarball in my case), probably more.
What I'm probably going to use instead is
cabal exec -- sh -c 'command -v propellor'to get the path to the binary and symlink it myself.
andreasabel commentedon Jan 16, 2021
Same here. This behavior makes me hesitant to embrace v2-cabal yet, still preferring v1-cabal.
What would be a good workflow with v2-cabal?
This looks natural:
but does not fly because the last step rebuilds everything---needlessly, it seems, isn't often copying/linking the executable all that is left to do?
fgaz commentedon Jan 16, 2021
Context:
While v1- was "autotools-like", v2- does not follow that model anymore and is more declarative instead. v2-install tries to be as reproducible as possible by doing a sdist before building and installing (and anecdotally this has helped people catch some bugs in their cabal files). This also has a simpler implementation, = less bugs.
@andreasabel
So the sequence of commands for installing an executable is just
Which builds the package one time only.
build(andconfigure, which is optional) is only useful if you want to develop the package.@joeyh
for your usecase, the upcoming
cabal3.4 provides alist-bincommand that inexpensively prints the paths of local executables, so you can do whatever you want with them without fragileexechacks. Does that solve the issue?andreasabel commentedon Jan 27, 2021
@fgaz
Indeed I develop https://github.com/agda/agda and want to install the executables after each build in order to test interactive Agda development with the newest bug-fixes in emacs.
The v1 workflow was to run
in the working directory to get Agda to build and be installed. Of course, I will have to invoke this command several times until all the compilation error are fixed.
How do I proceed in v2?
I would run
cabal buildseveral times until my compilation errors are fixed, and then how to install the executables?cabal installis forbiddingly expensive, since compiling the 400 modules from scratch with aggressive optimization takes 30 minutes.For me, the
v1-installfunctionality works best. To port it to v2, could we have something likethat performs the installation with binaries built by
build?@phadej Since you ask what is holding me back from v2
the present issue is one that makes us stick to v1 in the Agda development.
andreasabel commentedon Feb 23, 2021
My feature request would be to have this option of
stack build:In the meantime, I have
awked a workaround. I writewhich picks up the executable name from the
Linking foo ...message ofcabal buildand links this executable in.cabal/bin.copy-bins.awk:fgaz commentedon Apr 2, 2021
If the
execandlist-bin+ln -sworkarounds aren't enough, we could consider accepting a pr that implements the conversion from local to store package, but there are a lot of details to think about (ex. rpath/relinking, data files, dependencies...). Even so, such a conversion has a fundamental problem over the above workarounds when doing iterative development: it would quickly increase the size of the store, and we have no garbage collection yet. I thinklist-binplusln -sis the best solution in this case.fgaz commentedon Oct 10, 2021
Some discussion in #7297 (comment) and partially in #7693 (but please let's use this ticket for this topic)
mouse07410 commentedon Oct 13, 2021
Please take a look at #7693 (comment), and feel free to respond here. Thanks!
jneira commentedon Oct 13, 2021
After the info posted in #7297 (comment) and my tests in #7745 about the differences between build local packages and installing them
i would say that
cabal installshould behave as is (therefore continue rebuilding the local packages as remote ones), not only to reuse the code forcabal install local.or.remote.tarbut to have a consistent behaviour across all target types.cabal build --copy-binsto copy executables, tests and benches (and dynamic libs?) outside the build directory and make available the patterncp $(cabal list-bin my exe) /some/pathto usersmouse07410 commentedon Oct 13, 2021
First, yes - to be useful,
--copy-binsmust copy dynamic libraries in addition to copying the executables themselves. Otherwise, those executables would have zero chance to run.Second, right now
cabal list-binappears broken. So, I assumecabalas-is would be unable to even locate the binaries to copy.cabal-plandoes list the executables correctly - but it seems to have no idea about dynamic libs those executables depend on.What are the effects of
--enable-tests? Why cannotcabal v2-installbuild whatever it's (re-) building with that flag, and merely skip copying the<target>:testexecutables to the global store?Mikolaj commentedon Oct 13, 2021
Could you elaborate? (Best just point to ticket about that or open one).
Wrong ticket?
mouse07410 commentedon Oct 13, 2021
#7679
No, an attempt to find a solution or a "working" workaround for this problem - when you build with
--enable-tests, there's no way to avoid re-building a lot of dependencies during install. Based on this ticket, it looks like--enable-testsis not the only case whencabalrebuilds just-built stuff during install.I agree that
--copy-binswould've been a good workaround, if not a "total" solution - if it worked.jneira commentedon Nov 11, 2021
jneira commentedon Nov 11, 2021
ugh i missed rebuild the project, sorry
[-]cabal install run immediately after cabal build unncessarily rebuilds the project[/-][+]cabal install run immediately after cabal build unnecessarily rebuilds the project[/+]mouse07410 commentedon Feb 23, 2022
Ping?
Mikolaj commentedon Feb 23, 2022
@mouse07410: I'm afraid we haven't made any progress with designing
--copy-binsnor splittinginstallor even incorporatingcabal-env. That's my report for now. Do you have anything to report? Any new ideas?mouse07410 commentedon Feb 24, 2022
Alas, nothing new. :-(
Frankly, I doubt I'm in the league - not enough Haskell or general FP experience or expertise. But it would be great if somebody figured how to fix
--copy-binsand splittinginstall.mouse07410 commentedon Oct 6, 2022
It seems that two problems are brought up here:
cabal installforces rebuild of several dependencies even when run immediately after a successfulcabal build.cabal --copy-binsomits dynamic libraries, thus ensuring that the copied executables become useless/broken (unable to run, being unable to load dynamic libraries they need).Is there any progress in either of these two?
Mikolaj commentedon Oct 24, 2022
I'm not aware of any progress, but I might have easily missed something. If you find any relevant ticket or a comment in another ticket, please kindly link here.
use cabal exec to find path of propellor binary
andreasabel commentedon Oct 11, 2025
@mpickering: This issue is still a blocker for removing the
v1interface.E.g. it makes bisection of large projects much slower if you need to install rather than just build.
cabal installdoes unnecessary recompilations,cabal buildis fine, why the difference? #11474 as a duplicate of this issuemouse07410 commentedon Feb 12, 2026
Guys, any chance this could get fixed?
I understand that developers and maintainers are volunteers, and choose to invest their time as they see fit. But since they are involved with this project - they probably care for Cabal to be more usable, and exhibit fewer problems.
An acceptable workaround would be if
--copy-binscould either figure that that there are dynamic libraries and copy them along with executables, or have another sub-flag--with-libsor such - upon which it would locate and copy dynamic libraries...