Repository navigation
Description
Summary by @ezyang. We considered the following options for restructuring dist/build such that component build directories are not a subdirectory of the library build directory:
- Move library directory to
dist/build/pkgname. Problem: This will conflict with an executable that is named the same as the package. - Move non-library components to
dist/subbuild/compname. Problem: This moves where executables are, and many people (including this author) are used to accessing the executable atdist/build/exename/exename. One way to patch over this is to copy the executables back to the old locations. - Move the library directory to
dist/build/lib-pkgname. Problem: This will still conflict with a component namedlib-pkgname. - Qualify all components with their type, e.g.,
dist/build/exe-exename. Problem: This moves where the executables are. - Move the library directory to
dist/libbuild. No major problems, although @23Skidoo would prefer all build products be indist/build.
We are going to go with proposal (5).
Hey guys. I want to propose a BC-breaking change to the dist directory layout. I'll first explain what the change is, and then why I need it. I'd like to know if people are OK with it. It WILL break code which needs to know where Cabal puts build products. CC @mgsloan, @23Skidoo , @dcoutts
Cabal-1.24 behavior. Suppose we are building a Haskell module M.hs. If this module is in the public library, the interface file is placed in dist/build/M.hi. If the module is in any other component (e.g., a test suite) named comp, the interface file is placed in dist/build/comp/M.hi)
Proposed new behavior. I propose that libraries also get their own subdirectory: dist/build/pkgname; thus if we build M.hs in a library named foobar it will be placed in dist/build/foobar/M.hi. Obviously, this will break any scripts which rely on the interface files/object files having been placed in the old location.
Motivation. Cabal supports pre-processors which may generate extra object files that need to be linked into the final libraries/executables we build. This is tested by the PreProcessExtraSources cabal:package-test. For example, if we build Foo.hsc, this results in a Foo_hsc.o in our build directory.
If a preprocessor generates this extra object file, how does Cabal know to link it in? The "obvious" design is that when you run the preprocessor, it tells you what extra files need to be compiled and you go ahead and compile them. But this is not what Cabal does. Instead, what it does is simply look in the build directory for any files which look like ones that the preprocessor generated, and make sure to link them in. (ian-ross@e38cb0c)
Now here is the problem with Cabal-1.24's behavior: the build directories for the test suites/benchmarks/etc are all INSIDE the library's build directory. So clearly the search code will pick up the extra build products: disaster! And so the most obvious fix (without completely changing the preprocessor interface) is to move the directory out of the way.
The bug got uncovered by #3542 although I am not really sure why it didn't manifest earlier.
Alternatives. I think there are two plausible alternatives which avoid moving the location of library files:
- Move all non-library components to another directory, e.g., "subbuild" in dist. Still a BC break, because the binary for executables is no longer where you expect it to be.
- Keep the current layout, and filter out subdirectories which correspond to other components in the Cabal file. I am morally opposed to this option, since it enshrines a simply incorrect design decision. Look at this Cabal file:
name: xyz
version: 0.1.0.0
license: BSD3
author: Edward Z. Yang
maintainer: [email protected]
extra-source-files: ChangeLog.md
cabal-version: >=1.10
library
exposed-modules: Doom.Foo
build-depends: base
default-language: Haskell2010
test-suite Doom
main-is: Foo.hs
type: exitcode-stdio-1.0
build-depends: base
These two Foos clobber each other! Ouch!
Activity
phadej commentedon Jul 13, 2016
Could this be done for
new-buildonly, and how it relates to it?23Skidoo commentedon Jul 13, 2016
Will this still work when there's an executable with the same name as library (example)? Otherwise +1.
ezyang commentedon Jul 13, 2016
@phadej : No, it affects both new-build and build; it's a modification to how Setup scripts work.
@23Skidoo: Oh right. You'll need to disambiguate the public library somehow. The
subbuildalternative plan would do this (at the cost of moving where all the executables are.) Maybe we should do that then.ezyang commentedon Jul 13, 2016
OK, I came up with another "more BC" scheme:
dist/builddist/subbuild/$component_namedist/build/$component_name/$exe_nameSo, no library files move, and the executables are where you expect them.
ezyang commentedon Jul 15, 2016
The bug that motivated this is present in
master; however it doesn't show up on a fresh build because the benchmarks/test suites get built after the library, avoiding the library linking step from picking up the duplicate objects.A terrible hack which solves haskell#3545.
phadej commentedon Jul 15, 2016
btw, just today I run into situations where two executables in the same package use the same
cabal_macros.h, soMIN_VERSION_packageflags from other one leaks into other one.EDIT in particularly I cannot have a source file with "clever"
#ifdef MIN_VERSION_foodefinitionsSo the fix for this is very welcome!
ezyang commentedon Jul 16, 2016
The cabal_macros.h but is different and already fixed in master, see #1893 and the fixing commit is 90e908b
23Skidoo commentedon Jul 16, 2016
I'd prefer not to add a
subbuilddirectory, IMO thebuild/subbuilddistinction is confusing. Can we put library files into e.g.build/lib-fooand leave everything else as before? We'll have to prohibit components that have a name starting withlib-, but I don't think it's a big problem in practice.ezyang commentedon Jul 16, 2016
@23Skidoo But your proposal exhibits a displeasing asymmetry where the library is called
lib-foobut the test is calledfoo, and so is the executable. Actually, there is already related nastiness inCabalwhere sometimes aString(without a component type tag) is used as a component name (e.g.,PDTagged), and thus there needs to be a convention for what the library is called (currently the empty string is used. Ick.)So if we are rearranging the directory, we might as well do it right, and put the executable in
exe-foo, etc.23Skidoo commentedon Jul 16, 2016
I agree that this is cleaner, but people are used to having exes in
dist/build/foo/foo. So maybe continue usingdist/build/foofor exes and usedist/build/{lib,test,bench}/foofor other components?6 remaining items
ezyang commentedon Jul 19, 2016
I just realized there is another consideration if we go for
dist/libbuild: should the value ofbuildDirinLocalBuildInfobedist/libbuildordist/build?This is quite difficult because either choice will break many setup scripts. Here is some quick grepping on Hackage:
Here
buildDiris assumed to be the directory containing components.buildDiris assumed to be recording where the library goes.And this repeats over and over again repeatedly all over many packages with custom
Setupscripts. This seems to suggest changing this layout is a no-go without a major BC break.23Skidoo commentedon Jul 20, 2016
That's a bummer. My vote is for making this change anyway and setting the default Cabal upper bound for
build-type: Custompackages to < 1.26 when there's no custom-setup section. We can also bump the version to 2.0 in the next release, IIRC cabal-install 1.24 already sets the default upper bound to <2.ezyang commentedon Jul 20, 2016
OK, well, if we are going to release Cabal 2.0 next release, this affects a number of other BC decisions. E.g., #3574 and @ttuegel's #3572. If we are changing the default upper bound (I like this idea more and more, since the preprocessor interface changed backwards incompatibly and I don't think it's possible to keep BC here), what is our policy for BC-breaking changes? I guess the answer is something like, "Please still try to keep BC, so that it's easier for applications to migrate" but minor incompatibility's like #3572 are still fine.
23Skidoo commentedon Jul 20, 2016
Yes, something like this. Plus there should be a mention in the changelog when a part of the API gets changed.
mgsloan commentedon Jul 21, 2016
As a data point, in stack we would also prefer to preserve BC here.
I'm don't have the details here. But it seems like part of the topic post suggests a third, potentially viable approach
How about making this what Cabal does, instead of hacking around the current design? Deprecate the old interface and transition all the pre-processors to the new system.
ezyang commentedon Jul 21, 2016
OK, well, I will have to look at the preprocessor interface and propose a design.
A terrible hack which solves haskell#3545.
ezyang commentedon Jul 21, 2016
OK, so let's say how preprocessors work today. Presently, preprocessors are represented using the following data structure:
A preprocessor takes in an input source file, and an output destination, and arranges for something to be written to that file name. In general, the output file name is always
Modname.hsof some sort, because preprocessors are assumed to be generating Haskell code.However, some preprocessors can generate extra files. There are two situations which are handled by Cabal today:
hsc2hs: produces extraModname_hsc.candModname_hsc.hfiles.c2hsproduces extraModname.chs.c,Modname.handModname.chiThe way they are handled is via
type PreProcessorExtras = FilePath -> IO [FilePath]which takes a path to the build directory and recursively searches the directory for files which match the preprocessor template style.Intuitively, we should be able to determine precisely what the possible generated files are simple from the list of module names that were preprocessed under some preprocessor.
But where should we return this information?
preprocessComponentshould return precisely the C files to be built; otherwise we have no idea wouldModuleNames and under what preprocessors they ranpreprocessFile, because at this point we don't know what preprocessor will run.preprocessFile, once we find the Preprocessor, we need a way to find out what files we should snoop at to find the extra files.Since the extra files are preprocessor specific, we need a hook in
PreProcessorto do it. There are two possibilities:runPreProcessorto return a list of extra files which the preprocessor generated. This is more BC assumingmkSimplePreprocessorwas used, then the signatures can be adjusted in tandem.Other BC considerations:
Preprocessorhttp://hs01.scs.stanford.edu:8910/search/?q=PreProcessor%5B+%5Cn%5Ct%5D%2B%7B+file%3A%2FSetup.hs but among them there's a mix of use ofmkSimplePreprocessorand directly coding up the preprocessor. Gtk2HsSetup is the big outlier http://hs01.scs.stanford.edu:8910/search/?q=PreProcessor%5B+%5Cn%5Ct%5D%2B%7B+file%3A%2FGtk2HsSetup.hs with copies of this code spattered throughout several packages.OK, so concrete proposal in next comment.
gbaz commentedon Sep 5, 2021
I'm pretty sure we moved to a much more granular layout similar to this with new-build?
mpilgrem commentedon Feb 19, 2024
This topic (the structure under directory
build) has been resolved for users of recent versions of Cabal (the tool), but remains an issue for users of Cabal (the library) (theSetup.hscommands) - including users of Stack, which makes use of Cabal (the library) to build. The current structure does not distinguish between, for example, the build artefacts for moduleFoo.Foo.Somethingin directorybuild/Foo/Fooand a package executable named justFoowith pathbuild/Foo/Foo. This affects macOS users in particular because (a) the file system is case-insensitive and (b) executable files are not distinguished with an extension (unlike the use of.exeon Windows).