AC-BuildPlatform
version 1.0.0: Read me
Due to Cabal bug #303, under Windows you can't do “cabal clean
”. In this instance, please use “runhaskell Setup clean
” instead.
(Apparently Unix has some weird mis-feature whereby deleting a running executable file is not an error. Apparently cabal-install relies on this flaw. Obviously this means that on operating systems that actually support the concept of file locking, it doesn't work. In fairness, it's not obvious how to solve this little problem.)
{-# LANGUAGE CPP #-}
pragma works. (If not, you'll likely get random syntax errors.)This package allows you to query at run-time what operating system and compiler are in use. This information is not easy to discover — hence why this package exists in the first place. The package runs some custom code during the “configure” stage. This code attempts to detect what platform it's running under. Note that the script prints out the values detected, so you don't have to actually build and install the package just to find out if platform detection is working right.
The platform detection code makes a number of assumptions, which are documented here. If these assumptions fail, it may not be possible to detect some or all of the platform values. Note that if the OS type cannot be detected, the configure step will fail, preventing the package from being built and installed.
There is a small utility called Manual.hs
. If you run this, it will let you set the platform values to whatever you like. This kludge lets you specify that your compiler is Fred's Haskell Compiler or whatever.
You must run this before the “build” and/or “haddock” stages, but you can run it before or after the “configure” stage. So if you run a “configure” and it fails, and you can't correct the failure, you can use a manual override to specify the correct values and then run “configure” again.
Note that performing a manual override turns off the auto-detection logic in “configure”. To turn it back on again, just perform a “clean” (which removes any manual values you specified). See the notes above about performing a “clean” operation though.
The platform detection logic makes a number of assumptions. The first two are the only ones that most users need to worry about.
You configure the package using “cabal configure
”, not “runhaskell Setup configure
”.
If this is not the case, no information is detected [and therefore configure fails].
Your compiler is GHC, version 6.8.1 or newer.
If this is not the case, most likely no information will be detected [and therefore configure will fail].
I realise that being able to query the compiler is a bit pointless when only one possible compiler is supported. Note though that if the compiler is not GHC, it will not be reported as GHC. So there is some small information content there.
The cabal-install tool compiles Setup.hs
before running it.
(And, additionally, stores it in ./dist/setup/Setup[.exe]
. And, additionally, runs it with the package root folder as the current working folder.)
In theory, the path might change in future, breaking the detection code.
The compiler used for configuring is the same as the one used for building.
As far as I know, Cabal does not allow you to violate this assumption. But if you did, the detected information would refer to the compiler used for configuring and not the one used for building.
The GHC “+RTS --info
” option is available.
This option was added in GHC 6.8.1; older versions do not support it. Additionally, as of GHC 7.0.1, most RTS options are disabled by default (but not this one). If in future this option is disabled as well, detection will break.
As far as I know, no other compilers support this option. But if they did, the existing detection logic is intended to respond gracefully. The detection script looks for only two keys: “GHC version
” and “Target platform
”. The latter might plausibly be available from other implementations, in which case OS detection would work.
GHC for Windows uses MinGW.
This has always been the case in the past, but it could potentially change in future. (Here's to hoping, anyway!)
Of course, the detection logic doesn't really care whether MinGW is in use or not. It only cares whether the target platform is reported as “mingw32
”. If yes, it assumes the platform is MS_Windows
. For any other value it assumes Unix
. So if some day GHC actually reports Windows as being “Windows
”, the detection logic will need updating.
In summary: The detection algorithm depends on precise details of GHC, the GHC RTS, the Cabal library, and the cabal-install tool. If any of these tools change in particularly unusual ways in the future, the detection code might break.