Re: Avoiding linking final executable to TH
Lemmih <[email protected]> Mon, 4 Jul 2005 22:45:03 +0200
| Newsgroups | gmane.comp.lang.haskell.template |
|---|---|
| Message-ID | <[email protected]> |
On 7/4/05, Einar Karttunen <[email protected]> wrote: > Hello > > Are there currently any plans to avoid linking the final executable with > TH? As far as I understand currently the situation is as follows: > > Module M uses TH code defined in MTH. > Module MTH imports TH modules and thus needs to be linked with template-haskell. > > The simplest way to deal with this could be to use a special > compile-time import construct between M and MTH - so that MTH would > not need to be linked with M (and thus template-haskell would not be > needed either). > > Are there any plans regarding something like this or an another solution? I hacked up Zeroth to overcome the linking problem. Zeroth is a preprocessor which scans Haskell source files (using haskell-src-exts) for top level splices and evaluates them. For example: > module TestTH where > #ifdef HASTH > -- import TH modules here. > #endif > -- Simple declaration > $( [d| x = "test" |] ) becomes > module TestTH > -- Simple declaration > x = "test" However, Zeroth is hardly more than a dirty fix so use with care. Darcs repository: http://www.scannedinavian.org/~lemmih/zerothHead Haskell-src-exts: http://www.cs.chalmers.se/%7Ed00nibro/haskell-src-exts/ I've attached a patch with Cabal support for zeroth. -- Friendly, Lemmih _______________________________________________ template-haskell mailing list [email protected] http://www.haskell.org/mailman/listinfo/template-haskell
zeroth.patch
(text/x-patch, 14.1 KB)
New patches: [Zeroth support. [email protected]**20050704202406] { hunk ./Distribution/PreProcess.hs 43 - ppCpp, ppCpp', ppGreenCard, ppC2hs, ppHsc2hs, + ppZeroth, ppZeroth', ppCpp, ppCpp', ppGreenCard, + ppGreenCard', ppC2hs, ppHsc2hs, hunk ./Distribution/PreProcess.hs 54 +import Distribution.Package ( showPackageId, PackageIdentifier ) + hunk ./Distribution/PreProcess.hs 59 +import Distribution.Extension ( extensionsToGHCFlag ) + hunk ./Distribution/PreProcess.hs 64 -import Data.List (nub) +import Data.List ( nub, intersperse ) hunk ./Distribution/PreProcess.hs 192 +ppZeroth :: BuildInfo -> LocalBuildInfo -> PreProcessor +ppZeroth = ppZeroth' [] [] + +ppZeroth' :: [PackageIdentifier] -> [String] -> BuildInfo -> LocalBuildInfo -> PreProcessor +ppZeroth' extraPkgs inputArgs bi lbi + = maybe (ppNone "zeroth") pp (withZeroth lbi) + where pp zeroth inFile outFile verbose + = rawSystemVerbose verbose zeroth (["--ghc="++compilerPath (compiler lbi) + ,"--output="++outFile,"--input="++ inFile + ,"--ghc-args="++ghcArgs] ++ cpphsArg ++ inputArgs) + ghcArgs = "-i.:"++concat (intersperse ":" (hsSourceDirs bi)) ++ " " ++ unwords (snd (extensionsToGHCFlag (extensions bi))) + -- unwords $ map (\pkg -> unwords ["-package",showPackageId pkg]) (packageDeps lbi ++ extraPkgs) + cpphsArg = case withCpphs lbi of + Nothing -> [] + Just cpphs -> ["--cpphs="++cpphs] + hunk ./Distribution/PreProcess.hs 305 --- |Standard preprocessors: GreenCard, c2hs, hsc2hs, happy, alex and cpphs. +-- |Standard preprocessors: zeroth, GreenCard, c2hs, hsc2hs, happy, alex and cpphs. hunk ./Distribution/PreProcess.hs 308 - [ ("gc", ppGreenCard) + [ ("th", ppZeroth) + , ("gc", ppGreenCard) hunk ./Distribution/Setup.hs 105 + configZeroth :: Maybe FilePath, -- ^Zeroth path hunk ./Distribution/Setup.hs 128 + configZeroth = Nothing, hunk ./Distribution/Setup.hs 139 - | WithGreencard FilePath + | WithGreencard FilePath | WithZeroth FilePath hunk ./Distribution/Setup.hs 264 + Option "" ["with-zeroth"] (ReqArg WithZeroth "PATH") + "give the path to zeroth", hunk ./Distribution/Setup.hs 297 + updateCfg t WithZeroth path = t { configZeroth = Just path } hunk ./Distribution/Simple/Configure.hs 150 + zeroth <- findProgram "zeroth" (configZeroth cfg) hunk ./Distribution/Simple/Configure.hs 164 + reportProgram "zeroth" zeroth hunk ./Distribution/Simple/Configure.hs 178 + withZeroth=zeroth, hunk ./Distribution/Simple/LocalBuildInfo.hs 71 + withZeroth :: Maybe FilePath, -- ^Might be the location of the Zeroth executable. } Context: [added dist.compiler, from ross [email protected]**20050628154025] [prof-options -> ghc-prof-options [email protected]**20050628063036] [wibble 2 [email protected]**20050628060925] [wibble [email protected]**20050628060756] [clean up conflicts, temp fix for test cases [email protected]**20050628055527] [from ross, added language.haskell.extension [email protected]**20050628052426] [lots of changes, mostly from ross [email protected]**20050628051544 documentation updates from ross paterson - more accurate specification of package names - hs-source-dir -> hs-source-dirs in examples - setup clean removes a bit more - rearrange description of fields Version.hs: allow more spaces in version constraints Install.hs: add the exe extension when installing executables (reported by Brian Smith) test directory: add explicit dependencies on base Misc: Prefix error messages and warnings with the program name, and send them to stderr. (Also moved some stuff from Distribution.Simple.Utils to Distribution.Simple.Build to avoid circular dependencies.) refactoring only: split Compiler type from Distribution.Setup, to reduce dependencies. Exclude DefaultSetup.lhs from the GHC build add JHC to the Compiler type refactored argument processing setup sdist --snapshot: append YYYYMMDD to the version for the bundle improved error messages (from Brian Smith): * attach source locations to messages when available * change some remaining error's do die. refactor defaultMainWorker split Distribution.Extension between Language.Haskell.Extension (just the type, which will also be useful when haskell-src-exts is merged) and Distribution.Compiler (mappings to compiler options). add Language.Haskell.Extension Simon marlow: update defaults for prefix/libdir/bindir ] [comments and small docs [email protected]**20050604183800] [added the cabal-setup executable which is defaultMain [email protected]**20050517060532] [s/rawSystemPath/rawSystemVerbose/ typo. [email protected]**20050609164509] [Make HUnit happy with the new profiling support. [email protected]**20050604191435] [Previous prof-libraries are removed before building the new one. [email protected]**20050530150253] [Fixed bug which caused Cabal to guess the wrong HC-PKG path. [email protected]**20050530121044] [Using 'reads' instead of 'read' in Simple.Configure.getPersistBuildConfig [email protected]**20050530120947] [Added --with-greencard. [email protected]**20050530120830] [Support for building libraries and executables with profiling enabled. [email protected]**20050527173144] [from Krasimir: -fhide-all-packages should be -hide-all-packages [email protected]**20050516165147] [fixed bug: executable build location had changed [email protected]**20050515074133 Since we don't have hs-source-dir anymore, the location for building executables had changed. However, install was still looking in the old location. Fixed this. Fixed another bug where hs-source-dir for executables was [".","."] where this duplication caused a problem in locating the Main module. Not sure quite where this came from, but now for combining fields, we always nub, so this should be a robust fix. Fixed build failures in testing code. ] [hs-source-dirs, other-files [email protected]**20050515061253 Krasimir: added hs-source-dirs (ross added docs) Add other-files field to PackageDescription. This is a list files which belong to the package but aren't compiled. These files are copied and packaged from sdist command. Ross: fixes to buildHugs and sdist after hs-source-dirs changes. Also simplified smartCopySources a bit. document sdist and new other-files field. ] [adding -fhide-all-packages for ghc > 6.4 [email protected]**20050512043302] [updating changelog and release notes for release [email protected]**20050512043237] [untabify cabal file [email protected]**20050510051920] [resolved confligs with hackage version [email protected]**20050510051615] [cabal version and test case for ghc 6.4 recursive mods [email protected]**20050510045613] [Cabal-get is not using Distribution.GetOps anymore. [email protected]**20050421211447] [Various changed needed by hackage/cabal-get. [email protected]**20050421013739 * Exporting Distribution.Compat.FilePath and Distribution.GetOpt. I'm using GetOpt from Cabal 'cause I fixed a bug in it which I haven't commited to CVS yet. In Distribution.Simple.Config: * Made 'getInstalledPackagesAux' and 'configCompilerAux' which aren't using ConfigFlags since cabal-get defines it own ConfigFlags. * Changed 'configCompilerVersion' to take a verbose argument instead of a ConfigFlags. * Exported those functions. ] [Now exporting getInstalledPackages from Distribution.Simple.Configure since it's needed by cabal-get. [email protected]**20050418173622] [CVS pull from Simon Marlow: [email protected]**20050510043142 getInstalledPackages: ignore lines beginning with "Creating", so that we can understand this ghc-pkg output from 6.4: Creating user package database in /home/simonmar/.ghc/i386-linux-6.4/package.conf /home/simonmar/fp/lib/i386-unknown-linux/ghc-6.4/package.conf: rts-1.0, base-1.0, haskell98-1.0, template-haskell-1.0, unix-1.0, Cabal-1.0, parsec-1.0, haskell-src-1.0, network-1.0, QuickCheck-1.0, HUnit-1.1, mtl-1.0, fgl-5.2, X11-1.1, HGL-3.1, OpenGL-2.0, GLUT-2.0, stm-1.0, readline-1.0, (lang-1.0), (concurrent-1.0), (posix-1.0), (util-1.0), (data-1.0), (text-1.0), (net-1.0), (hssource-1.0) /home/simonmar/.ghc/i386-linux-6.4/package.conf: ] [adding some haddock [email protected]**20050508215248] [CVS pull from Ross [email protected]**20050508212926 add with-c2hs option to configure, pass cpp options to c2hs, plus a little refactoring. This involves interface changes: changed type of ppC2hs, extra fields in ConfigFlags and LocalBuildInfo. ] [renamed getInstalledPackages{,Aux} [email protected]**20050503171755] [implemented ranlib execution during installation [email protected]**20050502050154 This is necessary in Mac OS X and on Solaris. It is possible that this might cause problems for systems that use setup copy to build and then use cp to install files, since the library modification time will change. I think this is only the case on Mac OS X and Solaris. ] [working on changelogs; bumped version number [email protected]**20050502042039] [tweaks to lemmih's patch to rename functions [email protected]**20050502031647] [fixed bug in c2hs preprocessor [email protected]**20050502024024] [formatting changes and untabify [email protected]**20050418052517] [Added pattern guards as a language extension Josef Svenningsson <[email protected]>**20050416204612] [Changes needed by cabal-get. [email protected]**20050426230537 [from Distribution.Simple.Configure] * Exporting getInstalledPackagesAux and configCompilerAux. * Refactored ConfigFlags out of configCompilerAux, findCompiler, configCompilerVersion and guessPkgToolFromHcPath. * Changed the verbosity of getInstalledPackages, findCompiler, configCompilerVersion and guessPkgToolFromHcPath. ] [cleanup from Ross. no change in behavior [email protected]**20050416200553] [implemented handling of _stub.{c,h,o} files [email protected]**20050416195824 Including a test case from Jérémy Bobbio. Previously, we weren't linking in _stub.o files to the library, though they are produced by the build. Now we link them in. I assume that ghc --make does the right thing for executables, haven't tested this. Also implemented ./setup clean for getting rid of Foo_stub.{h,c} files for both executables and libraries. These files aren't put into the dist/build directory (can they be?) so I had to add a bit of extra logic here. ] [./setup clean now removes dist/doc, which is produced by ./setup haddock [email protected]**20050416013332] [export matchesDescFile at the request of Lemmih for Hackage [email protected]**20050416013302] [added another missing source file [email protected]**20050415180927] [another missing source file [email protected]**20050415180630] [added missing source file [email protected]**20050415180443] [added missing test case that was in my source tree [email protected]**20050415180110] [first implementation of copy for hi-boot files (ghc 6.) could use more testing [email protected]**20050415175000] [added test case for mutually recursive modules [email protected]**20050415174432] [fail on test returning error code, add test cases [email protected]**20050413000307] [added setup test command, not deeply tested [email protected]**20050412235706] [haddock markup fixes [email protected]**20050414145004] [cvs pull: added LICENSE file [email protected]**20050414144905] [added strip flag. probably from CVS [email protected]**20050414144841] [cvs patch from Wolfgang Thaller [email protected]**20050414144748 Fix handling of end-of-options markers (--). getOpt would correctly return the non-options after the marker, but it would return errors for things after the marker that looked like options. ] [Fixed bug in Distribution.GetOpt [email protected]**20050412015302 The bug caused unknown long opts to get stripped of their argument (--test=arg => --test). ] [little HUnit test wibble to get out of way of instaled package [email protected]**20050320231118] [fixed expected errors [email protected]**20050320230707] [wibble last commit, only if genScript true [email protected]**20050320230634] [fix bug in ghc > 6.3 where it wasn't reading from stdin :( [email protected]**20050320213348] [fixes to parser from krasimir, fixes to sdist from ross [email protected]**20050317180215 Krasimir says: Small fixes in the parser/printer. When there is a package description with executables only then the old implementation of pretty printer was written to print empty "exposed-modules" field while there isn`t any library. After that the parser will generate PackageDescription with (Just emptyLibrary) instead of Nothing. Now exposed-modules field is printed only if library /= Nothing Ross says: In smartCopySources, don't try to strip the prefix if it was ".", because joinFileName "." x == x (fixes bug reported by Iavor Diatchki) Improve sdist a bit: copy files named in main-is, license-file and c-sources. Also supply a default Setup.hs if none is present. This will get it working for only the simplest of packages. It omits header files, configure stuff and files named in the buildinfo file. To do it properly, we'd need a field in the package description listing extra files to copy into a source distribution. ] [Fixed bug in 'smartCopySources' [email protected]**20050317012645 smartCopySources dropped the prefix of source paths with length+drop. This fails when the prefix is eg. ".". ] [added / fixed haddock code [email protected]**20050315070527] [TAG 0.6 [email protected]**20050312213231] Patch bundle hash: 4e802e2515fae60ec20d169072ac2aa1cdd29c81