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
Summary by @ezyang. There is no way to ask Setup to just typecheck a package. It sort of works if you pass -fno-code via --ghc-options but that's purely accidental.
I use cabal build --ghc-options="-Wall -fno-code" to quickly get all errors/warnings from a project and show them in an editor.
in my cabal file that only builds a shared object, I get:
Warning: the following files would be used as linker inputs, but linking is not being done: dist/build/...
ghc: no input files
Usage: For basic information, try the `--help' option.
Should we get this warning although we explicitly said -fno-code?
If yes, can we add an option to disable this kind of warning so that it does not clutter the warnings I am actually interested in (to show in the editor)?
Update:
(The original title was Add option to disable non-linking warnings with -fno-code.)
I just realized that there is an actual bug in this:
After the warning, due to the ghc error cabal will just stop and build no further. This should not happen as there is no code to build!
Reacted by Imants Čekušins, Spiros Boosalis, Poscat, Andreas Abel, Emily, 霧雨魔理沙, Julius Marozas, George Thomas, Manuel Bärenz, Laurent P. René de Cotret and 3 more
This even happens when you don't have a configuration as above, but a way more normal one, like hspec's cabal file.
A normal build looks like this:
Building hspec-1.4.3...
Preprocessing library hspec-1.4.3...
[ 1 of 14] Compiling Test.Hspec.Compat ( src/Test/Hspec/Compat.hs, dist/build/Test/Hspec/Compat.o )
...
[14 of 14] Compiling Test.Hspec.QuickCheck ( src/Test/Hspec/QuickCheck.hs, dist/build/Test/Hspec/QuickCheck.o )
In-place registering hspec-1.4.3...
Preprocessing executable 'hspec-discover' for hspec-1.4.3...
[1 of 2] Compiling Run ( hspec-discover/src/Run.hs, dist/build/hspec-discover/hspec-discover-tmp/Run.o )
[2 of 2] Compiling Main ( hspec-discover/src/Main.hs, dist/build/hspec-discover/hspec-discover-tmp/Main.o )
Linking dist/build/hspec-discover/hspec-discover ...
But cabal build --ghc-options="-fno-code" gives:
Building hspec-1.4.3...
Preprocessing library hspec-1.4.3...
[ 1 of 14] Compiling Test.Hspec.Compat ( src/Test/Hspec/Compat.hs, nothing )
...
[14 of 14] Compiling Test.Hspec.QuickCheck ( src/Test/Hspec/QuickCheck.hs, nothing )
/usr/bin/ar: dist/build/Test/Hspec.o: No such file or directory
Note this only breaks if the code hasn't been built yet (e.g. after cabal clean). If it has been built before, cabal build --ghc-options="-fforce-recomp -fno-code" correctly yields:
Building hspec-1.4.3...
Preprocessing library hspec-1.4.3...
[ 1 of 14] Compiling Test.Hspec.Compat ( src/Test/Hspec/Compat.hs, nothing )
...
[14 of 14] Compiling Test.Hspec.QuickCheck ( src/Test/Hspec/QuickCheck.hs, nothing )
In-place registering hspec-1.4.3...
Preprocessing executable 'hspec-discover' for hspec-1.4.3...
[1 of 2] Compiling Run ( hspec-discover/src/Run.hs, nothing )
[2 of 2] Compiling Main ( hspec-discover/src/Main.hs, nothing )
I think this is a bug - cabal build --ghc-options="-fno-code" should always work, no matter if code had been generated before!
I was thinking into this direction (nh2@0c51929) but then realized that what I want is not that easy: You could perform a "read-only" typecheck with cabal to build the library, but as soon as you want to typecheck an executable (that depends on your own library and is in a different directory to avoid repeated compilation), you actually need the result of the library compilation.
In the mean time, an easy work around would be #1177 - making a full cabal build instant by skipping linking if not necessary. (This could also be accomplished with -c, but that still performs unnecessary registering and unnecessarily links .so files.) On success (otherwise we have an error anyway), we can immediately run cabal build --ghc-options="-fforce-recomp -Wall -fno-code" which will work now since all necesssary files already exist.
However, this doesn't work as described in my original bug report: ghc reports ghc: no input files and terminates before the remaining warnings can be generated.
I just added an option -fwrite-interface, to dump interface files precisely when you want to do something like typecheck a library, and then typecheck a dependent executable.
If you are planning on doing only typechecking cycles, and you have a library + executable Cabal file, run -fno-code and -fwrite-interface to typecheck the library, and then you will be able to type check the executable (because the library hi files are available.) Needs some UI polish, obviously!
I also see this error when building even static libraries or executables. Would be happy to hack on it if that's helpful, although I haven't looked at cabal's code before. Not sure if this is a beginner-level problem or not.
This issue seems to persist, and is currently causing minor frustration in using SublimeHaskell, whose default build mechanism uses two builds: first a standard cabal build and then cabal build -v0 --ghc-options="-fforce-recomp -Wall -fno-code" to gather warnings. This issue is causing SublimeHaskell to display a bothersome error pane every time a project is recompiled (which happens every save). It's a minor issue, but a fix would be appreciated.
The command toonly typecheck suggested by @andreasabel: cabal v2-build --ghc-options=-fno-code --ghc-options=-fwrite-interface
is more useful after #7973, cause now ghc-options applies only to all local packages. So change it does not trigger the recompilation of dependencies (aka remote packages).
@nh2 would be it enough for your use case? how could be it improved to fit it? create a new command would be difficult to get done
This is a long awaited improvement. I built a shiny new Cabal executable and tried it out today.
+
It works for a single component:
% ~/.cabal/bin/cabal init --non-interactive
Warning: this is a debug build with assertions enabled.
[Log] Guessing dependencies...
[Log] Using cabal specification: 3.6
[Warning] unknown license type, you must put a copy in LICENSE yourself.
[Log] Creating fresh file CHANGELOG.md...
[Log] Creating fresh directory ./app...
[Log] Creating fresh file app/Main.hs...
[Log] Creating fresh file x.cabal...
[Warning] No synopsis given. You should edit the .cabal file and add one.
[Info] You may want to edit the .cabal file and add a Description field.
% ~/.cabal/bin/cabal build --ghc-options=-fno-code --ghc-options=-fwrite-interface
Warning: this is a debug build with assertions enabled.
Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
- x-0.1.0.0 (exe:x) (first run)
Warning: this is a debug build with assertions enabled.
Configuring executable 'x' for x-0.1.0.0..
Warning: this is a debug build with assertions enabled.
Preprocessing executable 'x' for x-0.1.0.0..
Building executable 'x' for x-0.1.0.0..
[1 of 1] Compiling Main ( app/Main.hs, nothing )
% echo $?
0
−
It does not work when there are multiple interdependent components:
% ~/.cabal/bin/cabal init --non-interactive --libandexe
Warning: this is a debug build with assertions enabled.
[Log] Guessing dependencies...
[Log] Guessing dependencies...
[Log] Using cabal specification: 3.6
[Warning] unknown license type, you must put a copy in LICENSE yourself.
[Log] Creating fresh file CHANGELOG.md...
[Log] Creating fresh directory ./src...
[Log] Creating fresh file src/MyLib.hs...
[Log] Creating fresh directory ./app...
[Log] Creating fresh file app/Main.hs...
[Log] Creating fresh file x.cabal...
[Warning] No synopsis given. You should edit the .cabal file and add one.
[Info] You may want to edit the .cabal file and add a Description field.
% ~/.cabal/bin/cabal build --ghc-options=-fno-code --ghc-options=-fwrite-interface
Warning: this is a debug build with assertions enabled.
Resolving dependencies...
Build profile: -w ghc-8.10.7 -O1
In order, the following will be built (use -v for more details):
- x-0.1.0.0 (lib) (first run)
- x-0.1.0.0 (exe:x) (first run)
Warning: this is a debug build with assertions enabled.
Configuring library for x-0.1.0.0..
Warning: this is a debug build with assertions enabled.
Preprocessing library for x-0.1.0.0..
Building library for x-0.1.0.0..
[1 of 1] Compiling MyLib ( src/MyLib.hs, nothing, /tmp/x/dist-newstyle/build/x86_64-linux/ghc-8.10.7/x-0.1.0.0/build/MyLib.dyn_o )
/usr/bin/ar: dist-newstyle/build/x86_64-linux/ghc-8.10.7/x-0.1.0.0/build/MyLib.o: No such file or directory
Error: cabal: Failed to build x-0.1.0.0 (which is required by exe:x from
x-0.1.0.0).
% echo $?
1
It seems that Cabal tries to link the dependent components (such as internal libraries), but there is nothing to link because nothing was built!
I cannot wait for this improvement to be released!
Reacted by Javier Neira , Artem Pelenitsyn, Tesla Zhang and Laurent P. René de Cotret
If adding a new command cabal typecheck(or a special flag cabal build --typecheck) is still on the table, I say it should behave like this:
Accept the same options as cabal build. (So that the one can be easily swapped for the other.)
Produce the same standard error as cabal build. (So that it calls out all errors.)
Produce no object files.
Run faster.
Even though thanks to haskell-language-server one needs to call Cabal only rarely, it is still a good sanity check for when one is about to commit some code, for continuous integration or whenever haskell-language-server gets stuck or cannot start.
@andreasabel sorry for a basic question, but why do you need to store -no-code artifacts separately? For -O0, a separate directory is needed so that you don't rebuild every time you switch configuration, but that shouldn't apply to -no-code as it shouldn't, in theory, generate any different artifacts?
it shouldn't, in theory, generate any different artifacts?
The typechecking-only build tree contains the cabal configuration, interface files, and even some object files (e.g. Paths_*.o, setup/Main.o, modules using TemplateHaskell). Until evidence to the contrary is produced, I must assume there are differences.
@Mikolaj you added this issue to the project about replacing v1-commands, but I don't quite see which v1 functionality this would replace. At least, I don't think there's anything better in v1 than already shown here --no-code, which works perfectly with v2. The issue is about wrapping it into a prettier interface, but that's unrelated to v1 I think?
The Stack project would be interested in Cabal (the library) supporting this. The context is 'nimble workflows', where people seek to have the benefit of type-checking without bearing the 'cost' of compilation. EDIT: Adding for context some discussions at the Haskell Community:
Activity
nh2 commentedon Jan 13, 2013
This even happens when you don't have a configuration as above, but a way more normal one, like hspec's cabal file.
A normal build looks like this:
But
cabal build --ghc-options="-fno-code"gives:Note this only breaks if the code hasn't been built yet (e.g. after
cabal clean). If it has been built before,cabal build --ghc-options="-fforce-recomp -fno-code"correctly yields:I think this is a bug -
cabal build --ghc-options="-fno-code"should always work, no matter if code had been generated before!nh2 commentedon Jan 13, 2013
@23Skidoo Can you reproduce this with some of your packages (or hspec as above)?
23Skidoo commentedon Jan 13, 2013
@nh2 I'm a bit swamped right now, will look at this later.
nh2 commentedon Jan 13, 2013
I was thinking into this direction (nh2@0c51929) but then realized that what I want is not that easy: You could perform a "read-only" typecheck with cabal to build the library, but as soon as you want to typecheck an executable (that depends on your own library and is in a different directory to avoid repeated compilation), you actually need the result of the library compilation.
Actually, you only need the *.hi files; it should be possible to generate them without further code generation, but I don't know how (see http://stackoverflow.com/questions/14306934/haskell-how-to-only-generate-hi-file-with-ghc).
nh2 commentedon Jan 13, 2013
In the mean time, an easy work around would be #1177 - making a full
cabal buildinstant by skipping linking if not necessary. (This could also be accomplished with-c, but that still performs unnecessary registering and unnecessarily links.sofiles.) On success (otherwise we have an error anyway), we can immediately runcabal build --ghc-options="-fforce-recomp -Wall -fno-code"which will work now since all necesssary files already exist.However, this doesn't work as described in my original bug report: ghc reports
ghc: no input filesand terminates before the remaining warnings can be generated.nh2 commentedon Jan 13, 2013
https://github.com/nh2/cabal/compare/no-code-link-shared is a proposal to skip linking on
-fno-code. It fixes the error described.An explicit cabal option to disable this step might be better, though.
ezyang commentedon Jun 27, 2014
I just added an option -fwrite-interface, to dump interface files precisely when you want to do something like typecheck a library, and then typecheck a dependent executable.
nh2 commentedon Jul 15, 2014
@ezyang Can you explain a bit more how this is intended to be used?
ezyang commentedon Jul 15, 2014
If you are planning on doing only typechecking cycles, and you have a library + executable Cabal file, run -fno-code and -fwrite-interface to typecheck the library, and then you will be able to type check the executable (because the library hi files are available.) Needs some UI polish, obviously!
asivitz commentedon Sep 4, 2014
I also see this error when building even static libraries or executables. Would be happy to hack on it if that's helpful, although I haven't looked at cabal's code before. Not sure if this is a beginner-level problem or not.
alilleybrinker commentedon Feb 3, 2015
This issue seems to persist, and is currently causing minor frustration in using SublimeHaskell, whose default build mechanism uses two builds: first a standard
cabal buildand thencabal build -v0 --ghc-options="-fforce-recomp -Wall -fno-code"to gather warnings. This issue is causing SublimeHaskell to display a bothersome error pane every time a project is recompiled (which happens every save). It's a minor issue, but a fix would be appreciated.Here is the relevant SublimeHaskell issue: SublimeHaskell/SublimeHaskell#158
22 remaining items
fgaz commentedon Aug 28, 2021
@andreasabel I think the issue you mention is #3579: ghc-options is not available in top-level local options (but it still is in per-package options)
jneira commentedon May 1, 2022
The command toonly typecheck suggested by @andreasabel:
cabal v2-build --ghc-options=-fno-code --ghc-options=-fwrite-interfaceis more useful after #7973, cause now
ghc-optionsapplies only to all local packages. So change it does not trigger the recompilation of dependencies (aka remote packages).@nh2 would be it enough for your use case? how could be it improved to fit it? create a new command would be difficult to get done
kindaro commentedon Jul 10, 2022
This is a long awaited improvement. I built a shiny new Cabal executable and tried it out today.
+
It works for a single component:
−
It does not work when there are multiple interdependent components:
It seems that Cabal tries to link the dependent components (such as internal libraries), but there is nothing to link because nothing was built!
I cannot wait for this improvement to be released!
kindaro commentedon Jul 10, 2022
If adding a new command
cabal typecheck(or a special flagcabal build --typecheck) is still on the table, I say it should behave like this:cabal build. (So that the one can be easily swapped for the other.)cabal build. (So that it calls out all errors.)Even though thanks to
haskell-language-serverone needs to call Cabal only rarely, it is still a good sanity check for when one is about to commit some code, for continuous integration or wheneverhaskell-language-servergets stuck or cannot start.andreasabel commentedon Jul 11, 2022
Yes, it should be like
-O0, in particular, use its own build directory.The main annoyance with the current workaround (a separate
cabal.projectfile with suitableghc-options) is thatbuilddirisn't accepted incabal.project, and has to be passed on the command line manually all the time, like in https://github.com/agda/agda/blob/a47f8762978e878ecf6ed6081fa3772acc3499d1/Makefile#L238 .In contrast
-O0stores build artefacts in its own.../noopt/...folders so that the regular build artefacts (-O1) are not overwritten.ulysses4ever commentedon Jul 11, 2022
@andreasabel sorry for a basic question, but why do you need to store
-no-codeartifacts separately? For -O0, a separate directory is needed so that you don't rebuild every time you switch configuration, but that shouldn't apply to-no-codeas it shouldn't, in theory, generate any different artifacts?andreasabel commentedon Jul 12, 2022
The typechecking-only build tree contains the cabal configuration, interface files, and even some object files (e.g.
Paths_*.o,setup/Main.o, modules usingTemplateHaskell). Until evidence to the contrary is produced, I must assume there are differences.ulysses4ever commentedon Jul 11, 2023
@Mikolaj you added this issue to the project about replacing
v1-commands, but I don't quite see whichv1functionality this would replace. At least, I don't think there's anything better inv1than already shown here--no-code, which works perfectly withv2. The issue is about wrapping it into a prettier interface, but that's unrelated tov1I think?So, how about we remove this from the project?
Mikolaj commentedon Jul 11, 2023
Yes, I guess the workaround is good enough not to make this issue a blocker (though probably not to close the issue and, in any case, that's for the affected users to opine on). Let me remove this ticket from the https://github.com/haskell/cabal/projects/12 project. Thanks.
mpilgrem commentedon Jul 16, 2026
The Stack project would be interested in Cabal (the library) supporting this. The context is 'nimble workflows', where people seek to have the benefit of type-checking without bearing the 'cost' of compilation. EDIT: Adding for context some discussions at the Haskell Community: