Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GHC 7.10.3 build fails with cpphs
/* DO NOT EDIT: This file is automatically generated by Cabal */
/* package rts-1.0 */
#define VERSION_rts "1.0"
#define MIN_VERSION_rts(major1,major2,minor) (\
(major1) < 1 || \
(major1) == 1 && (major2) < 0 || \
(major1) == 1 && (major2) == 0 && (minor) <= 0)
/* package ghc-prim-0.4.0.0 */
#define VERSION_ghc_prim "0.4.0.0"
#define MIN_VERSION_ghc_prim(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 4 || \
(major1) == 0 && (major2) == 4 && (minor) <= 0)
/* package integer-gmp-1.0.0.0 */
#define VERSION_integer_gmp "1.0.0.0"
#define MIN_VERSION_integer_gmp(major1,major2,minor) (\
(major1) < 1 || \
(major1) == 1 && (major2) < 0 || \
(major1) == 1 && (major2) == 0 && (minor) <= 0)
/* tool cpphs-1.19.3 */
#define TOOL_VERSION_cpphs "1.19.3"
#define MIN_TOOL_VERSION_cpphs(major1,major2,minor) (\
(major1) < 1 || \
(major1) == 1 && (major2) < 19 || \
(major1) == 1 && (major2) == 19 && (minor) <= 3)
/* tool gcc-4.8 */
#define TOOL_VERSION_gcc "4.8"
#define MIN_TOOL_VERSION_gcc(major1,major2,minor) (\
(major1) < 4 || \
(major1) == 4 && (major2) < 8 || \
(major1) == 4 && (major2) == 8 && (minor) <= 0)
/* tool ghc-7.10.3 */
#define TOOL_VERSION_ghc "7.10.3"
#define MIN_TOOL_VERSION_ghc(major1,major2,minor) (\
(major1) < 7 || \
(major1) == 7 && (major2) < 10 || \
(major1) == 7 && (major2) == 10 && (minor) <= 3)
/* tool ghc-pkg-7.10.3 */
#define TOOL_VERSION_ghc_pkg "7.10.3"
#define MIN_TOOL_VERSION_ghc_pkg(major1,major2,minor) (\
(major1) < 7 || \
(major1) == 7 && (major2) < 10 || \
(major1) == 7 && (major2) == 10 && (minor) <= 3)
/* tool haddock-2.14.3 */
#define TOOL_VERSION_haddock "2.14.3"
#define MIN_TOOL_VERSION_haddock(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 14 || \
(major1) == 2 && (major2) == 14 && (minor) <= 3)
/* tool hpc-0.67 */
#define TOOL_VERSION_hpc "0.67"
#define MIN_TOOL_VERSION_hpc(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 67 || \
(major1) == 0 && (major2) == 67 && (minor) <= 0)
/* tool hsc2hs-0.67 */
#define TOOL_VERSION_hsc2hs "0.67"
#define MIN_TOOL_VERSION_hsc2hs(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 67 || \
(major1) == 0 && (major2) == 67 && (minor) <= 0)
/* tool pkg-config-0.26 */
#define TOOL_VERSION_pkg_config "0.26"
#define MIN_TOOL_VERSION_pkg_config(major1,major2,minor) (\
(major1) < 0 || \
(major1) == 0 && (major2) < 26 || \
(major1) == 0 && (major2) == 26 && (minor) <= 0)
/* tool strip-2.24 */
#define TOOL_VERSION_strip "2.24"
#define MIN_TOOL_VERSION_strip(major1,major2,minor) (\
(major1) < 2 || \
(major1) == 2 && (major2) < 24 || \
(major1) == 2 && (major2) == 24 && (minor) <= 0)
#define CURRENT_PACKAGE_KEY "base_HQfYBxpPvuw8OunzQu6JGM"
@AlainODea
Copy link
Author

AlainODea commented Jan 10, 2016

GHC 7.10.3's build fails when cpphs is the configured hs-cpp. It runs into an error when preprocessing libraries/base/GHC/Natural.hs.

Prep on either SmartOS or Ubuntu:

Install a 7.8+ GHC and then run:

cabal update
cabal install cabal-install
cabal install cpphs alex happy binary
export PATH=~/.cabal/bin:$PATH
tar xf ghc-7.10.3-src.tar.bz2
cd ghc-7.10.3/
./configure --with-hs-cpp=$(which cpphs) --with-hs-cpp-flags="--cpp"
make -j8

On SmartOS:

tempdir=$(mktemp --tmpdir --directory ghcXXXXX_0)
tempfile="$tempdir/ghc_1.hscpp"
touch $tempfile
/opt/local/bin/cpphs --cpp -DOPTIMISE_INTEGER_GCD_LCM -include libraries/base/dist-install/build/autogen/cabal_macros.h -I libraries/base/dist-install/build -I libraries/base/dist-install/build -I libraries/base/dist-install/build/autogen -I libraries/base/include -I /root/ghc-7.10.3/libraries/integer-gmp2/include -I /root/ghc-7.10.3/rts/dist/build -I /root/ghc-7.10.3/includes -I /root/ghc-7.10.3/includes/dist-derivedconstants/header -D__GLASGOW_HASKELL__=710 -include /root/ghc-7.10.3/includes/ghcversion.h -Dsolaris2_BUILD_OS=1 -Di386_BUILD_ARCH=1 -Dsolaris2_HOST_OS=1 -Di386_HOST_ARCH=1 -D__GLASGOW_HASKELL_TH__=NO -x assembler-with-cpp libraries/base/GHC/Natural.hs -o $tempfile

On Ubuntu:

tempdir=$(mktemp --tmpdir --directory ghcXXXXX_0)
tempfile="$tempdir/ghc_1.hscpp"
touch $tempfile
~/.cabal/bin/cpphs --cpp -DOPTIMISE_INTEGER_GCD_LCM -include libraries/base/dist-install/build/autogen/cabal_macros.h -I libraries/base/dist-install/build -I libraries/base/dist-install/build -I libraries/base/dist-install/build/autogen -I libraries/base/include -I /home/alain_odea/Documents/haskell/ghc-7.10.3/libraries/integer-gmp2/include -I /home/alain_odea/Documents/haskell/ghc-7.10.3/rts/dist/build -I /home/alain_odea/Documents/haskell/ghc-7.10.3/includes -I /home/alain_odea/Documents/haskell/ghc-7.10.3/includes/dist-derivedconstants/header -D__GLASGOW_HASKELL__=710 -include /home/alain_odea/Documents/haskell/ghc-7.10.3/includes/ghcversion.h -Dlinux_BUILD_OS=1 -Di386_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Di386_HOST_ARCH=1 -D__GLASGOW_HASKELL_TH__=NO -x assembler-with-cpp libraries/base/GHC/Natural.hs -o $tempfile

Both result in this error:

cpphs: macro MIN_VERSION_integer_gmp expected 3 arguments, but was given 0

In either case removing -include libraries/base/dist-install/build/autogen/cabal_macros.h from the cpphs arguments makes the error go away.

Using cpphs on cabal-macros.h alone has no error messages:

cpphs --cpp libraries/base/dist-install/build/autogen/cabal_macros.h

@AlainODea
Copy link
Author

AlainODea commented Jan 10, 2016

Isolating this somewhat I can create minfail-cpphs.hs:

{-# LANGUAGE CPP #-}

#if defined(MIN_VERSION_integer_gmp)
#endif

And attempt to preprocess it:

tempdir=$(mktemp --tmpdir --directory ghcXXXXX_0)
tempfile="$tempdir/ghc_1.hscpp"
touch $tempfile
~/.cabal/bin/cpphs --cpp -DOPTIMISE_INTEGER_GCD_LCM -include libraries/base/dist-install/build/autogen/cabal_macros.h -I libraries/base/dist-install/build -I libraries/base/dist-install/build -I libraries/base/dist-install/build/autogen -I libraries/base/include -I /home/alain_odea/Documents/haskell/ghc-7.10.3/libraries/integer-gmp2/include -I /home/alain_odea/Documents/haskell/ghc-7.10.3/rts/dist/build -I /home/alain_odea/Documents/haskell/ghc-7.10.3/includes -I /home/alain_odea/Documents/haskell/ghc-7.10.3/includes/dist-derivedconstants/header -D__GLASGOW_HASKELL__=710 -include /home/alain_odea/Documents/haskell/ghc-7.10.3/includes/ghcversion.h -Dlinux_BUILD_OS=1 -Di386_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Di386_HOST_ARCH=1 -D__GLASGOW_HASKELL_TH__=NO -x assembler-with-cpp libraries/base/GHC/minfail-cpphs.hs -o $tempfile

And get the same error:

cpphs: macro MIN_VERSION_integer_gmp expected 3 arguments, but was given 0

It appears to be a bug in handling if defined(MACRODEF) constructs.

@AlainODea
Copy link
Author

AlainODea commented Jan 10, 2016

Notably the equivalent ifdef construct does not fail.

minpass-cpphs.hs:

{-# LANGUAGE CPP #-}

#ifdef MIN_VERSION_integer_gmp
#endif

And preprocess it:

tempdir=$(mktemp --tmpdir --directory ghcXXXXX_0)
tempfile="$tempdir/ghc_1.hscpp"
touch $tempfile
~/.cabal/bin/cpphs --cpp -DOPTIMISE_INTEGER_GCD_LCM -include libraries/base/dist-install/build/autogen/cabal_macros.h -I libraries/base/dist-install/build -I libraries/base/dist-install/build -I libraries/base/dist-install/build/autogen -I libraries/base/include -I /home/alain_odea/Documents/haskell/ghc-7.10.3/libraries/integer-gmp2/include -I /home/alain_odea/Documents/haskell/ghc-7.10.3/rts/dist/build -I /home/alain_odea/Documents/haskell/ghc-7.10.3/includes -I /home/alain_odea/Documents/haskell/ghc-7.10.3/includes/dist-derivedconstants/header -D__GLASGOW_HASKELL__=710 -include /home/alain_odea/Documents/haskell/ghc-7.10.3/includes/ghcversion.h -Dlinux_BUILD_OS=1 -Di386_BUILD_ARCH=1 -Dlinux_HOST_OS=1 -Di386_HOST_ARCH=1 -D__GLASGOW_HASKELL_TH__=NO -x assembler-with-cpp libraries/base/GHC/minpass-cpphs.hs -o $tempfile


It works correctly.

@AlainODea
Copy link
Author

AlainODea commented Jan 10, 2016

Iterative narrowing.

broken1.hs:

{-# LANGUAGE CPP #-}

#define MIN_VERSION_integer_gmp(major1,major2,minor) (\
  (major1) <  1 || \
  (major1) == 1 && (major2) <  0 || \
  (major1) == 1 && (major2) == 0 && (minor) <= 0)

#if defined(MIN_VERSION_integer_gmp)
#endif

Can't be preprocessed correctly:

$ cpphs --cpp broken1.hs -o $tempfile
cpphs: macro MIN_VERSION_integer_gmp expected 3 arguments, but was given 0
$

working1.hs:

{-# LANGUAGE CPP #-}

#define EXAMPLE_MACRO(arg) (\
                               arg)

#if defined(EXAMPLE_MACRO)
#endif

can be preprocessed correctly:

$ cpphs --cpp working1.hs -o $tempfile
$

@AlainODea
Copy link
Author

AlainODea commented Jan 10, 2016

Iterative narrowing.

broken2.hs:

{-# LANGUAGE CPP #-}

#define EXAMPLE_MACRO(arg1,arg2) (\
                               arg1 > arg2)

#if defined(EXAMPLE_MACRO)
#endif

can't be preprocessed correctly:

$ cpphs --cpp broken2.hs -o $tempfile
cpphs: macro EXAMPLE_MACRO expected 2 arguments, but was given 0
$

@AlainODea
Copy link
Author

AlainODea commented Jan 10, 2016

Iterative narrowing.

working2.hs:

{-# LANGUAGE CPP #-}

#define EXAMPLE_MACRO(arg1,arg2) (\
                               arg1 > arg2)

#ifdef EXAMPLE_MACRO
#endif

can be preprocessed correctly:

$ cpphs --cpp working2.hs -o $tempfile
$

@AlainODea
Copy link
Author

AlainODea commented Jan 10, 2016

I've isolated the issue to the handling of if defined on multi-argument macros.

if defined works on single-argument macros.

working1.hs:

{-# LANGUAGE CPP #-}

#define EXAMPLE_MACRO(arg) (\
                               arg)

#if defined(EXAMPLE_MACRO)
#endif

preprocess it (it works!):

$ cpphs --cpp working1.hs -o $tempfile
$

ifdef works on multiple-argument macros.

working2.hs:

{-# LANGUAGE CPP #-}

#define EXAMPLE_MACRO(arg1,arg2) (\
                               arg1 > arg2)

#ifdef EXAMPLE_MACRO
#endif

preprocess it (it works!):

$ cpphs --cpp working2.hs -o $tempfile
$

if defined fails on multi-argument macros.

broken2.hs:

{-# LANGUAGE CPP #-}

#define EXAMPLE_MACRO(arg1,arg2) (\
                               arg1 > arg2)

#if defined(EXAMPLE_MACRO)
#endif

preprocess it (it fails!):

$ cpphs --cpp broken2.hs -o $tempfile
cpphs: macro EXAMPLE_MACRO expected 2 arguments, but was given 0
$

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment