Replace the compiler when creating a Haskell project using Cabal

Is it possible to somehow configure the cabal project to use a different compiler than GHC? Can this be controlled by some flags?

I want to compile my project using GHC or Haste (in JavaScript) based on some compilation flags.

It would be ideal if I could customize my cabal configuration or my custom script to do something like:

-- target JS cabal configure --target=js cabal build -- target Native cabal configure --target=native cabal build 
+6
source share
2 answers

To create a Cabal project using GHC or Haste, use the cabal binary for the former and haste-inst (comes in a hurry) for the latter.

To have conditional code in your modules, add {-# LANGUAGE CPP #-} and use #ifdef __HASTE__ , which will be determined only by haste, but not by GHC. Note that __GLASGOW_HASKELL__ is defined in both cases (which makes sense since rush builds on GHC for large parts of compilation). Therefore you would use it as

 {-# LANGUAGE CPP #-} module Module where compiler :: String #ifdef __HASTE__ compiler = "haste" #else compiler = "GHC" #endif 

Theoretically, for conditional settings in the Cabal file, something like this should work:

 library exposed-modules: Module if impl(ghc) exposed-modules: Module.GHC if impl(haste) exposed-modules: Module.GHC build-depends: base ==4.6.* 

but it seems that even with haste-inst , impl(ghc) true; error report .

+5
source

It is currently not possible to use impl(haste) in your cabal files, now you can check flag(haste-inst) to see if your package is built using haste-inst .

0
source

Source: https://habr.com/ru/post/949326/


All Articles