haskell / cabal

Official upstream development repository for Cabal and cabal-install
https://haskell.org/cabal
Other
1.63k stars 696 forks source link

Version 3.12.1.0 Fails to Bootstrap with Error "Installation directories are not prefix_relative" #10155

Open essandess opened 5 months ago

essandess commented 5 months ago

Describe the bug

I'm the maintainer for MacPorts cabal, and am trying to update to version 3.12.1.0, which is bootstrapped from source using the prebuilt binary at https://downloads.haskell.org/~cabal/cabal-install-latest/.

Source builds using either --project-file=cabal.bootstrap.project or --project-file=cabal.release.project fail to build with the multiple errors of the form:

:info:build Build log (
:info:build /opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/.home/.cabal/logs/ghc-9.6.4/rgx-bs-0.94.0.2-56aa30a0.log
:info:build ):
:info:build Configuring library for regex-base-0.94.0.2...
:info:build Error: [Cabal-6000]
:info:build Installation directories are not prefix_relative:
:info:build internal error InstallDirs.libsubdir
:info:build CallStack (from HasCallStack):
:info:build   error, called at src/Distribution/Simple/InstallDirs.hs:147:19 in Cabal-3.12.1.0-inplace:Distribution.Simple.InstallDirs
:info:build Failed to build os-string-2.0.3. The failure occurred during the configure
:info:build step.

This error is new in version 3.12.1.0. Version 3.10.3.0 bootstraps as expected.

See:

https://github.com/haskell/cabal/blob/7cbc45ede7545a39003d6fb56b5a9d2d7d505176/Cabal/src/Distribution/Simple/Errors.hs#L633

To Reproduce Steps to reproduce the behavior:

$ env CABAL_CONFIG=/opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/.home/.cabal/config GHC=/opt/local/bin/ghc /opt/local/bin/cabal-prebuilt --config-file=/opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/.home/.cabal/config update
$ /opt/local/bin/cabal-prebuilt --config-file=/opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/.home/.cabal/config configure
$ /opt/local/bin/cabal-prebuilt --config-file=/opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/.home/.cabal/config build cabal-install --project-file=cabal.bootstrap.project -j12 --builddir=/opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/dist --prefix=/opt/local --datadir=/opt/local/share/cabal --docdir=/opt/local/share/doc/cabal --htmldir=/opt/local/share/doc/cabal --haddockdir=/opt/local/share/doc/cabal --sysconfdir=/opt/local/etc/cabal --enable-relocatable --bindir=/opt/local/bin --datadir=/opt/local/share/cabal

Expected behavior

A successful bootstrap.

System information

Additional context

Automated builds of cabal 3.10.3.0 across multiple macOS versions: https://ports.macports.org/port/cabal/details/

mpickering commented 5 months ago

~You probably also need to pass --libsubdir on the command line?~

geekosaur commented 5 months ago

This looks to me a lot like a cabal v1 workflow (cabal [v2-]configure edits cabal.project.local, it does not configure a build). It probably wants to become a runghc Setup.hs workflow these days.

geekosaur commented 5 months ago

If there's a bug, it's that cabal 3.10.3 might have allowed (and possibly done unexpected things with) v1-build parameters given to v2-build.

essandess commented 5 months ago

I thought these were the correct v2 calls.

What’s the correct call to bootstrap cabal from source?

geekosaur commented 5 months ago

If you have an existing cabal binary, you don't need to do anything special; just cabal-boot build cabal and cp $(cabal-boot list-bin cabal) targetDir, since there are no data files associated with it. Our bootstrap procedure is for when you don't have an existing cabal binary, and you need to work from a checkout of the source tree so you have the bootstrap directory, which isn't distributed.

cabal configure in cabal-install v2 is used to edit cabal.project.local. It has nothing to do directly with building a package, it just edits local project settings. The things it used to do in cabal v1 are now done by cabal build or cabal run as appropriate.

While cabal run in v2 commands (which have been the default since cabal-install 3.0.0.0) accepts the options you gave it, most of them either do nothing or affect paths in cabal's store (see https://cabal.readthedocs.io/en/3.10/nix-local-build-overview.html) and may therefore cause breakage if they're set wrong; that they point into the store is why they're supposed to be relative (to the package's directory in the store), and that older cabal-install accepted them was a bug. (We know the help lists them; there's a ticket about it incorrectly showing both v1 and v2 options.) Additionally, cabal install by default installs to the store and then makes a symlink to the final install location, and any data files etc. are within the store, not installed to the system.

The intended workflow for system packagers is to use the runghc Setup.hs interface, which still requires a separate configure, and most of your prefix options should be passed to that instead of build.

essandess commented 4 months ago

Thanks for comment @geekosaur .

But please note this is a build for a package manager that itself downloads a specific source code version, and builds and distributes that specific version of cabal. None of these instructions in your comment appear to provide version control.

How does one build cabal from downloaded source at https://downloads.haskell.org/~cabal/cabal-install-3.12.1.0/ (latest version 3.12.1.0, but in general), using the prebuilt binary https://downloads.haskell.org/~cabal/cabal-install-3.12.1.0/cabal-install-3.12.1.0-aarch64-darwin.tar.xz ?

What are the commands to build a cabal package version 2 from a specific source code downloads? MacPorts has been using this general build approach for all cabal-based builds, and everything has worked prior to cabal version 3.12.1.0:

https://github.com/macports/macports-ports/blob/master/_resources/port1.0/group/haskell_cabal-1.0.tcl

essandess commented 4 months ago

@geekosaur This diagnosis doesn't appear to be correct. cabal-boot build cabal still throws the error:

Installation directories are not prefix_relative:

This issue is pretty simple: The source code for cabal 3.12.1.0 is here. The binary for cabal 3.12.1.0 is here.

What are the commands to build a cabal binary (or any cabal-based binary in general) from source? The command cabal-boot build cabal throws an error. It did not throw an error in previous versions of cabal.

If you have an existing cabal binary, you don't need to do anything special; just cabal-boot build cabal and cp $(cabal-boot list-bin cabal) targetDir, …

essandess commented 4 months ago

The intended workflow for system packagers is to use the runghc Setup.hs interface, which still requires a separate configure, and most of your prefix options should be passed to that instead of build.

I've been trying to follow the instructions at https://github.com/haskell/cabal/blob/master/doc/setup-commands.rst#creating-a-binary-package. But there are 74 files named Setup.hs in the cabal source file tree. Which specific runhaskell command should be used?

If I try the one in ./cabal-install or ./cabal-install-solver with the command

runhaskell Setup.hs configure --prefix=/opt/local

(note: after running cabal update) I get the error:

Encountered missing or private dependencies:

Details:

:debug:configure system -W /opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/cabal-3.12.1.0/cabal-install-solver: env CABAL_CONFIG=/opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/.home/.cabal/config GHC=/opt/local/bin/ghc /opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/.home/.cabal/bin/runhaskell Setup.hs configure --prefix=/opt/local
:info:configure Configuring cabal-install-solver-3.12.1.0...
:info:configure Error: Setup.hs: Encountered missing or private dependencies:
:info:configure Cabal >=3.12.1.0 && <3.13, 
:info:configure Cabal-syntax >=3.12.1.0 && <3.13,
:info:configure edit-distance >=0.2.2 && <0.3,
:info:configure network-uri >=2.6.0.2 && <2.7
:info:configure Command failed: env CABAL_CONFIG=/opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/.home/.cabal/config GHC=/opt/local/bin/ghc /opt/local/var/macports/build/_opt_local_ports_lang_cabal/cabal/work/.home/.cabal/bin/runhaskell Setup.hs configure --prefix=/opt/local