Repository navigation
Open
Labels
Cabal: otherre: build-toolConcerning `build-tools` and `build-tool-depends`re: preprocessorsConcerning preprocessors such as alex and happytype: enhancement
Description
I'd like to propose that Cabal support BNFC as a build tool. BNFC is a well-known, multi-language parser generator that supports Haskell via Happy & Alex.
Additional context
From what I understand, the required changes would be:
- Adding bnfc to this list here:
cabal/Cabal/Distribution/Simple/BuildToolDepends.hs
Lines 31 to 45 in 0c97920
-- The first cases matches first. desugarBuildTool :: PackageDescription -> LegacyExeDependency -> Maybe ExeDependency desugarBuildTool pkg led = if foundLocal then Just $ ExeDependency (packageName pkg) toolName reqVer else Map.lookup name whiteMap where LegacyExeDependency name reqVer = led toolName = mkUnqualComponentName name foundLocal = toolName `elem` map exeName (executables pkg) whitelist = [ "hscolour", "haddock", "happy", "alex", "hsc2hs", "c2hs" , "cpphs", "greencard", "hspec-discover" ] - Adding "fc" to "bnfc" here:
cabal/cabal-install/Distribution/Client/Init/Heuristics.hs
Lines 215 to 225 in 72d67bf
-- Unfortunately we cannot use the version exported by Distribution.Simple.Program knownSuffixHandlers :: [(String,String)] knownSuffixHandlers = [ ("gc", "greencard") , ("chs", "chs") , ("hsc", "hsc2hs") , ("x", "alex") , ("y", "happy") , ("ly", "happy") , ("cpphs", "cpp") ] - Adding bnfcProgram to this export list: and this list:
module Distribution.Simple.Program.Builtin ( , and introducing a bnfcProgram definition in that module. For bnfc, it appears that just --version is enough to detect the version number.cabal/Cabal/Distribution/Simple/Program/Builtin.hs
Lines 69 to 70 in 9537238
builtinPrograms :: [Program] builtinPrograms =
Questions:
- Would such a patch be accepted?
- If so, would those changes be enough?
- How to handle the need to arguments to bnfc (e.g.,
--haskell -p <PATH> -o <directory> <file.cf>? Would doing this immediately make cabal understand--with-bnfc,--with-bnfc-optionsandbnfc-options:?
Reacted by Andreas Källberg, Scott Santucci and Maciej Goszczycki
Metadata
Metadata
Assignees
Labels
Cabal: otherre: build-toolConcerning `build-tools` and `build-tool-depends`re: preprocessorsConcerning preprocessors such as alex and happytype: enhancement
Activity
phadej commentedon Apr 21, 2020
bnfcto known suffix preprocessors, butpackagenameandexenameis the same, which isn't:bnfcandBNFCwhich might require some bigger changes.desugarBuildToolis for legacybuild-tools, and I think shouldn't be changedMyLanguage.fcand generatedMyLanguage.hs. I guessbnfcgenerates some.xand.y(and.hs) files. I suspect the multiple output file would case architectural problems.Adding
bnfc-options:to.cabalfile syntax is a big deal, so everything else have to be figured out until we can commit to that change, we'll need to live with if forever. Note, we don't havealex-optionsnorhappy-optionsas these tools self-configure from the input file. I'd appreciate that kind of working mode.ivanperez-keera commentedon Apr 21, 2020
This assumption is correct. From one .cf file, BNFC generates:
Makes sense not to add it then.
I certainly would not expect all of these changes to happen in Cabal just for this. Is this versatility (i.e., more than one file being generated, having different package and executable names) generally desired for the future of cabal, or would this just be annoying to maintain and not provide much benefit? I see their benefit in theory, but I'm just not sure if you've every encountered this before, or expect to.
phadej commentedon Apr 22, 2020
I don't think this is big issue, it's just not done.
built-tool-dependsalready requires to specifyBNFC:bnfc (optional version range)format. But theknownSuffixHandlersis[(String, String)], where it should be[(PackageName, UnqualComponentName, Extension)]. I think it will be a good change anyway (less stringy types, evenExtensionisStringinfilepath).Is the tricky bit build-system wise.
Cabalhave to know what files are generated. I suspect one-to-one processing is very deep in howCabalis made. There are e.g. issues with ordering ofc2hsflle processing which Cabal doesn't known anything about (see #6233 for more).andreasabel commentedon Dec 21, 2020
Found this comment on situations where several files are generated:
#3545 (comment)
ivanperez-keera commentedon Sep 13, 2021
Just a comment which I don't know if/how it is related.
Currently, with cabal-3.4, adding BNFC to the setup build dependencies does not seem to be enough (or I don't know how to do it):
Instead of installing BNFC as an executable, therefore letting me run it, it installs BNFC as a library. The result is that the following setup program:
cannot find bnfc in the
PATH:although the directory src does exist in the repo. Btw, if I first install BNFC first with:
then it puts the executable in
$HOME/.cabal/binand my package compiles and installs correctly.gbaz commentedon Sep 14, 2021
Correct, as discussed in the ticket you linked,
build-tool-dependsis the correct thing to specify.ivanperez-keera commentedon Sep 14, 2021
Indeed. Unfortunately, that did not work for me on 3.6 because of #7644.