Skip to content
This repository has been archived by the owner on Feb 3, 2022. It is now read-only.

Windows installer should add MSYS to extra-prog-path/extra-lib-dirs/... #279

Closed
23Skidoo opened this issue Jun 11, 2017 · 19 comments
Closed
Assignees
Labels

Comments

@23Skidoo
Copy link
Member

The problem: build-type: Configure packages like old-time and network don't build out of the box on Windows, unless you perform the following steps:

Add to the cabal config file the following lines:

extra-prog-path: C:\Program Files\Haskell Platform\7.10.3\msys\usr\bin
extra-lib-dirs: C:\Program Files\Haskell Platform\7.10.3\mingw\lib
extra-include-dirs: C:\Program Files\Haskell Platform\7.10.3\mingw\include

In the program-location subsection of the cabal config file add

gcc-location: C:\PROGRA1\HASKEL1\7.10.3\mingw\bin\gcc.exe

(gcc-location is probably not needed nowadays)

IMO, the HP installer should do this automatically. I can't think of any objections, and #207 doesn't mention any either.

/cc @randen @ndmitchell

@gbaz
Copy link
Contributor

gbaz commented Jun 11, 2017 via email

@hvr
Copy link
Member

hvr commented Jun 11, 2017

I think it's generally a good idea to run cabal user-config init always after the HP installer runs.

Because an old config file may be lurking around, and that's generally a source of confusion (i.e. when your config file was created by some ancient cabal 1.18, and you use it with cabal 2.0, I wouldn't be surprised there to be undesired effects). It may even point to some old msys install location from a previous HP installation... (in this context cabal user-config diff --with-msys-locatio=... may be interesting as well)

So by running cabal user-config init (with --with-msys-location=... for windows) always by the installer, you could make the user aware about a pre-existing config file (as the command would fail w/o --force flag given), and ask the user to inspect & resolve the situation manually. Also this provides a simple test whether cabal is able to write a file to the installing user's ~/.cabal/config location, which may catch setup/configuration problems early on.


Here's the --help output just for reference:

$ cabal user-config init --help
Display and update the user's global cabal configuration.

Usage: cabal user-config init
   or: cabal user-config diff
   or: cabal user-config update

When upgrading cabal, the set of configuration keys and their default values
may change. This command provides means to merge the existing config in
~/.cabal/config (i.e. all bindings that are actually defined and not commented
out) and the default config of the new version.

init: Creates a new config file at either ~/.cabal/config or as specified by
--config-file, if given. An existing file won't be overwritten unless -f or
--force is given.
diff: Shows a pseudo-diff of the user's ~/.cabal/config file and the default
configuration that would be created by cabal if the config file did not exist.
update: Applies the pseudo-diff to the configuration that would be created by
default, and write the result back to ~/.cabal/config.

Flags for user-config:
 -h --help        Show this help text
 -v --verbose[=n] Control verbosity (n is 0--3, default verbosity level is 1)
 -f --force       Overwrite the config file if it already exists.

@Mistuke
Copy link

Mistuke commented Jun 11, 2017

Hmmm I may have an alternate solution.

What if we change the way HP is packaged. So HP can use the GHC provided by MSYS2 or build a GHC packaged using this patch https://phabricator.haskell.org/D3637 which I'll land for 8.4.

The idea of it is to allow GHC to use the CC on the path. So the idea is HP would package the same GCC and utils that we do (you can just use pacman to install the tarballs) and then GHC would pick those up.

Configure would then find the libraries in their standard locations, no extra configuration needed. But as a bonus as well, user libraries installed with pacman will also automatically be picked up, without the need for any path munging.

This also means that users have a standard place aside from System32 to drop libraries in that we'll automatically pick up. and Includes etc.

I've been looking for alternative ways to package Windows binaries and this is one of the solutions I'm considering.

@gbaz
Copy link
Contributor

gbaz commented Jun 11, 2017 via email

@Mistuke
Copy link

Mistuke commented Jun 11, 2017

So at the moment, from your post above I think the current situation with HP is:

  1. you provide a stock GHC with the bundled bindist
  2. you provide the GCC shipped In the bindists
  3. You don't change the settings file to point to the outside GCC.

This is why the paths need fudging at the moment. Concretely this proposal is to

  1. provide a GHC which uses the system compiler
  2. provide the GCC and tools installed MSYS2 wide as you do now

GHC uses GCC to determine locations of libraries. As far as I am aware cabal does not detect any paths.
configure currently fails because it gets the path to the GCC provided with GHC, which does not know about /usr/lib etc. By changing to using the system compiler GHC will be able to see any package it can see, and so configure would work out of the box without any other paths required.

The GCC driver (which will be removed soon in https://phabricator.haskell.org/D3592) pointed all base directories inward.

as would any package installed with pacman without any other change, I think more packages would work out of the box this way.

@gbaz
Copy link
Contributor

gbaz commented Jun 13, 2017

I don't think this is enough for us to change our behavior. Its not just finding libraries thats affected. its finding other build tools, and even sh, etc. themselves which depends on having the extra-bin-dirs in path. Its typically the configure step of build-type-configure scripts that fails.

@Mistuke
Copy link

Mistuke commented Jun 13, 2017

Sure it won't work if we expect the user to be able to use any term to build stuff. Then you would need this.
But how do most users use platform, from a mintty shell for instance it should all work, since that starts a bash session.

Afterall I can install network without needing any extra options in my msys2 install. The proposal is to make the Windows install virtually identical to the unix ones. We don't specify all these paths on Linux either.

Given the fact that you'll need a unix like shell to execute configure anyway, this isn't an issue is it?

@gbaz
Copy link
Contributor

gbaz commented Jun 13, 2017

the unix like shell comes with the msys we distribute. so on a raw system with no dev packages installed, a fresh hp install (plus cabal config files) lets you install build-type configure packages out of the box.

@23Skidoo
Copy link
Member Author

@Mistuke

Sure it won't work if we expect the user to be able to use any term to build stuff.

I should point out that this ticket is specifically about making it possible to build stuff with cabal from powershell/cmd.exe/whatever out of the box. The HP MSYS terminal case works already.

@Mistuke
Copy link

Mistuke commented Dec 13, 2017

I should point out that this ticket is specifically about making it possible to build stuff with cabal from powershell/cmd.exe/whatever out of the box. The HP MSYS terminal case works already.

Right, so this ticket is about getting cabal to find libraries installed in the environment? e.g. using pacman?

As I don't think getting Configure based packages to work in any shell would work with this approach since powershell/cmd etc won't be able to understand configure anyway and cabal doesn't know how to start a shell to run the configure script in. (this would also be a nice addition btw).

But yeah this would be a useful addition as a lot of people don't read the step 2 on the install page.
I think something more general would be more helpful though:

cabal user-config add {key} {value}
cabal user-config remove {key} {value}
cabal user-config list {list}

so HP installer would just issue a series of

cabal user-config add extra-prog-path {path}

It can then use list to figure out if an existing HP installation is there and then properly ask the user what to do.

This would also be useful to everyone on all platforms I think, and to people like me who automate GHC/cabal setups or just simply scripting tests.

If we want to get something like this in the next Cabal release we have to move quick, I believe the deadline is fairly close? What do you think @hvr , @gbaz and @23Skidoo ?

@Mistuke
Copy link

Mistuke commented Dec 13, 2017

If it's too much for the next release, I think an undocumented --with-msys-location= would also be fine.

@23Skidoo
Copy link
Member Author

cabal doesn't know how to start a shell to run the configure script in. (this would also be a nice addition btw).

Actually no, it looks for sh in the environment. See https://github.com/haskell/cabal/blob/master/Cabal/Distribution/Simple.hs#L707

So if it can find an appropriate sh, it can build e.g. network when run from cmd.exe.

@23Skidoo
Copy link
Member Author

cabal user-config add/... would be nice to have, but implementing it can get a bit involved. Patches welcome ofc!

@hvr
Copy link
Member

hvr commented Dec 13, 2017

@23Skidoo @Mistuke

Do I sense correctly we're heading towards an agreement on having as a temporary solution an undocumented/hidden handshake as suggested in #279 (comment), i.e.

cabal user-config init --with-msys-location=...

?

@23Skidoo
Copy link
Member Author

I'm fine with adding a temporary undocumented thingie for this.

@Mistuke
Copy link

Mistuke commented Dec 13, 2017 via email

@randen
Copy link
Contributor

randen commented Jan 17, 2018

HP will need to sync with cabal pull request: haskell/cabal#5008

@gbaz
Copy link
Contributor

gbaz commented Mar 18, 2018

This is in the new cabal 2.2 branch. It would be really nice to implement this with the new platform release.

randen added a commit to randen/haskell-platform that referenced this issue Jun 15, 2018
Resolve Windows installer should add MSYS to
extra-prog-path/extra-lib-dirs/... (haskell#279).  When the
installer runs, Windows elevates the process, when possible,
to the role of admin.  If the installer writes the
cabal.config under these privileges, the cabal.config file
will have the wrong permissions for the end user.  So, we
must separate the privilege escalation, and perform the
cabal.config change as the end user.  A new sub-installer
(not visible to the end-user) is introduced which performs
this task, and also launches the full installer, which will
get (when possible) raised privileges.  As before, the full
installer then launches the sub-installers.

Add command line switches to hptool for additional archives
needed for Windows  (haskell#289)

The GHC sub-installer has grown over the NSI 2GB uncompressed
raw payload limit, so another split was done, breaking the
GHC docs out into a separate sub-installer.  As before, the
sub-installers are not end-user visible (unless they looked
really hard).

* hptool/hptool.cabal
  * Add constraint to Cabal package for vers 2.2, as the
    cabal files generated during the build (by invocations of
    cabal.exe) have some changes which are not parsable
    with earlier versions of Cabal.
* hptool/os-extras/win/templates/Bootstrapper.nsi.mu
  * New. This bootstrapper exists for one feature (currently)
    which must be done as the user, which is to write
    update/create the user's cabal config file.
* hptool/os-extras/win/templates/CommonHP.nsh.mu
  * New. A few macros common to our (sub-)installer(s).
* hptool/os-extras/win/templates/Extralibs.nsi.mu
* hptool/os-extras/win/templates/GHC.nsi.mu
* hptool/os-extras/win/templates/MSys.nsi.mu
  * Deleted. Replaced by using a common SubInstall.nsi.mu to
    generate the .nsi files for the sub-installers.
* hptool/os-extras/win/templates/Nsisfile.nsi.mu
  * This is the "main" installer, which runs as an admin if
    possible.  However, it is launched by the "Bootstrapper"
    installer (which continues to run as an unprivileged
    user).  We want this main install to have its windows be
    on top of other windows.  This installer handles all the
    user interaction, so if the user chooses not to have the
    cabal.config file updated, this installer needs to
    communicate back to the Bootstrapper that.  So, when this
    main installer is successful (not cancelled by user or an
    error) *and* the user has chosen to update the
    cabal.config file, it returns to the shell a magic value
    3 (rather than 0 or 1 for failure/success, respectively).
  * Moved some macros to CommonHP.nsh
  * Add some macros to do the sub-installer steps, and
    remove/edit the repeated steps which now use the macros
  * Add some "BringToFront" commands to try to make sure the
    installer window ends up on top of the windows stack.
  * Use nsExec::Exec rather than ExecWait, to get rid of the
    DOS window that shows up when we are running the ghc-pkg
    recache.
  * During the install, use the TEMP dir to hold the
    uncompressed installer payload (we already were doing
    this for the uninstaller).
* hptool/os-extras/win/templates/SubInstall.nsi.mu
  * New. Templatized version of the sub-installer .nsi files
    (Extralibs.nsi.mu, GHC.nsi.mu, and MSys.nsi.mu, which are
    deleted), used to generate the .nsi for the Extralibs,
    GHC, Msys, and the new GHCDoc sub-installers.
* hptool/src/GhcDist.hs
  * Pass in a param to allow the multiple untarrings of GHC
    to be named independently (which allows parallel
    untarring).
* hptool/src/OS/Win.hs
  * Move most of the steps from osRules into genNsisFiles
    time, so that parallel building can be done shake.
* hptool/src/OS/Win/WinNsis.hs
  * Use the SubInstall.nsi.mu to generate the sub-installer
    nsi files, rather than using separate files for each.
  * In adding the sub-installer, we added a couple more
    template variables which need expanding, and this
    requires a bit more info to be threaded through.
  * Add a new sub-installer, GHCDoc, needed since the main
    GHC sub-installer has again went over the NSI limit of
    2GB (uncompressed, raw payload).
  * Re-order some steps, taking some from the function
    osRules in Win.hs, to reflect better dependencies and
    thus allow more parallelism in the shake build.
  * The function copyWinTargetExtras is moved from WinRules
    to this module.
* hptool/src/OS/Win/WinPaths.hs
  * Filename re-working due to the new sub-installer
    template, CommonHP.nsh, plus adding the new GHCDoc
    sub-installer and the "Bootstrapper.nsi".
* hptool/src/OS/Win/WinRules.hs
  * Add the FilePath for the top-level output (the "main"
    installer) to the winRules, so this can be passed to
    genNsisFiles.
  * Change the command which takes the untarred ghc directory
    and allows it to moved to a specified location, which is
    part of the change to allow the installer build to do the
    two ghc untars in parallel.
  * Move copyWinTargetExtras from here to WinNsis.hs
  * copyFileAction, copyFilesAction, copyDirAction moved to
    WinUtils in order to to move the body of
    copyWinTargetExtras into WinNsis.  Note that WinRules
    imports WinNsis, so these common functions needed to be
    in a module separate from either.
* HPTOOL/src/OS/Win/WinUtils.hs
  * copyFileAction, copyFilesAction, copyDirAction moved here
    from WinRules, which imports/exports fixed up accordingly.
* hptool/src/Paths.hs
  * Add an extra parameter for ghcBinDistDir in order to name
    the ghc bin dist directory differently for the two times
    we have to untar the ghc tar file, which allows those two
    un-tars to be done potentially in parallel.
* hptool/src/Target.hs
  * Separated two targets, "ghcVirtualTarget" and
    "haddockDocDir" so they won't be done in parallel (we
    really need to go through the dependencies of this entire
    project, as there have been a few occasional things,
    e.g., sometimes timing-dependent behavior of dependencies
    not being available when needed, etc.)
  * Added missing newline at end-of-file.
* hptool/src/Utils.hs
  * Added a log message during makeDirectory.
* windows-platform.sh
randen added a commit to randen/haskell-platform that referenced this issue Jun 24, 2018
The changes for haskell#279 (Windows installer should add MSYS to
extra-prog-path/extra-lib-dirs/...) broke silent installs.

* hptool/os-extras/win/templates/Bootstrapper.nsi.mu
  * Force /D= to the launched sub-installer to fix haskell#311
  * Add many comments about the weirdness of handling
    $INSTDIR
@gbaz
Copy link
Contributor

gbaz commented Jul 4, 2018

fixed!

@gbaz gbaz closed this as completed Jul 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants