Skip to content

build Setup.hs with local compiler when cross-compiling #1493

Open

Description

@rwbarton

I have a script that invokes cabal with --with-ghc=..., --with-ghc-pkg=..., --with-gcc=..., etc. for cross-compiling to Android. It works great for most packages, but fails for a package with Build-type: Custom, because it builds Setup.hs with the cross-compiler specified on the command-line, and then obviously it can't run dist/setup/setup because it's an ARM executable.

I can work around the issue by doing an ordinary cabal configure with no --with-ghc=... options first, then doing a cabal install with my cross-compiler script, because the second invocation uses the cached dist/setup/setup from the first one. But that's a hack, obviously, and annoying to do when the package I'm installing is a dependency of the one I actually want.

What I would like is a separate set of options for specifying the program configuration to use to build Setup.hs; or at least an option to tell cabal to just use the ones on my path. I found that using defaultSetupScriptOptions for setupScriptOptions in configure and performInstallations seemed to do the trick for me, to give an idea of what I want to happen, though I haven't tested the resulting libraries. I couldn't determine whether there is already a way to achieve the same effect through command-line options.

Activity

  1. 23Skidoo commented on Sep 9, 2013

    @23Skidoo
    Member

    What would be an appropriate name for such an option? --host-compiler?

  2. rwbarton commented on Sep 9, 2013

    @rwbarton
    ContributorAuthor

    I was imagining a series of options like --with-host-compiler, --with-host-PROGRAM to specify the compiler and program configuration to use for building Setup.hs. (And possibly in the future for building modules to be loaded by Template Haskell?)

  3. rwbarton commented on Sep 23, 2013

    @rwbarton
    ContributorAuthor
  4. singpolyma commented on Oct 1, 2014

    @singpolyma

    Yeah, this is also a pain point for me. I work around it by just running ghc Setup.hs and copying the result over the one produced by cabal and re-running, but it's a pain.

  5. acw commented on Oct 25, 2014

    @acw

    Another possibility, which seems to be sufficient for most cases, would be to allow "build-type" to exist within "if" branches, so that, for example:

    if os(HaLVM) || os(iOS)
    Build-Type: Simple
    else
    Build-Type: Custom

    I was considering looking into a patch to do this, which seemed like it might be simpler, as long as the if cases were restricted to non-computed things (like os()).

  6. 23Skidoo commented on Oct 25, 2014

    @23Skidoo
    Member
    if os(HaLVM) || os(iOS)
    Build-Type: Simple
    else
    Build-Type: Custom
    

    This is a bad idea IMO, since it requires all package authors to modify their .cabal files.

  7. sheyll commented on Oct 29, 2014

    @sheyll

    I think that rwbarton is right with his idea.

    What about adding flags along the line of '--with-build-ghc' --with-target-ghc?
    We could let '--with-ghc' be a shorthand for passing both '--with-build-ghc' and '--with-target-ghc'
    with the same value.
    We could even make it illegal to pass a combination of old and new flags without breaking compatibility.

    Additionally we could allow for additional config file entries.

    Is anyone working on this? Otherwise I will go ahead and try to implement a proposal...

  8. 23Skidoo commented on Oct 29, 2014

    @23Skidoo
    Member

    @sheyll
    To my knowledge, no-one is working on this.

    I think we only need a --with-build-PROGRAM flag for all built-in programs (maybe only GHC initially). By default, Cabal will use the GHC specified with -w for everything, but if --with-build-ghc is provided, it will compile Setup.hs with it. Ditto for other programs.

    I imagine that we would have a new section in the config file for this stuff, akin to program-locations:

    cross-compilation
        build-ghc-location: /path/to/build-ghc
        build-gcc-location: /path/to/build-gcc
        [...]
    
  9. sheyll commented on Oct 29, 2014

    @sheyll

    @23Skidoo Ok it seems to be consensus that additional flags are useful. I will simply start with "--with-build-PROGRAM" for ghc and ghc-pkg and we'll see how it flows from there.

  10. sheyll commented on Nov 2, 2014

    @sheyll

    Ok .. I now have a draft for code review, located here:
    sheyll@06c2501

  11. jms19 commented on Nov 14, 2014

    @jms19

    Thanks sheyll. This is great stuff and just what I need right now to take the pain out of cross building packages (PowerPC as well as ARM). Though I don't feel qualified to comment on your changes in detail will take them for a spin soon.

  12. sheyll commented on Nov 14, 2014

    @sheyll

    hey wait

    this was only a prototype, the real thing is in the making.. I do not
    guarantee it works. I am currently rewriting it using a different approach
    and also with tests etc..

    would you mind making me some kind docker recipe for your cross compiling
    setup so I can test that locally?

    wbr Sven
    Am 14.11.2014 12:28 schrieb "jms19" [email protected]:

    Thanks sheyll. This is great stuff and just what I need right now to take
    the pain out of cross building packages (PowerPC as well as ARM). Though I
    don't feel qualified to comment on your changes in detail will take them
    for a spin soon.

    —
    Reply to this email directly or view it on GitHub
    #1493 (comment).

  13. jms19 commented on Nov 14, 2014

    @jms19

    I should have said I am very new to Haskell, even more so to cabal (a week or two) and the term docker has me reaching for Google. I am off the ground with cross compilers though and have gained some knowledge that might be used to improve https://ghc.haskell.org/trac/ghc/wiki/CrossCompilation and friends.

  14. sheyll commented on Dec 13, 2014

    @sheyll

    I just wanted to let you know I continue to work on this now,

    Do you think this issue could be assigned to me, to indicate that work is going on there?

    I have done a fork of this repo a while ago, but I rebase it regularily, so it should not be too painful to merge when it is done.

    I must admit I am surprised by the sophistication of the cabal internals, and coming from industry rather than academia I appreciate the pragmatic approaches chosen, although I have struggled with the fact that I had to touch so many different places for the intended changes; but this might as well have todo with me having the urge to make the changes as test-covered as possible and follow the boy-scout-rule.

    I'd rather take some more time than leave a mess that just makes other maybe more important changes more expensive

  15. 23Skidoo commented on Dec 13, 2014

    @23Skidoo
    Member

    Do you think this issue could be assigned to me, to indicate that work is going on there?

    It looks like you need to be a member of the Haskell organization on GitHub for me to be able to do that.

  16. 22 remaining items

  17. sebright commented on Jan 27, 2017

    @sebright
    Collaborator

    I just took a quick look, and I think it looks similar to the qualifiers that cabal had before #3220. So I would want to make sure that a new implementation handles the issues that led to #3220 before increasing the depth. Other than that, I think that the structure of the qualifiers looks good.

    How would the solver know which compiler to use for each executable? Would it always be specified by the user?

  18. Ericson2314 commented on Jan 27, 2017

    @Ericson2314
    Collaborator

    @GrayJay the difference is the prune function---it limits the number of QualExes and there can already be only one QualBase, thus the length of the path must be finite. [I forgot to use prune too on user-specified constraints, but those are also finite and worst-case just wouldn't apply, so less harm there.]

    How would the solver know which compiler to use for each executable? Would it always be specified by the user?

    Specifying a single compiler/platform, or single cross and native compiler/platform, generalizes into specifying a list of compilers/platforms----whatever the user-facing interface would be, this is how things would be stored internally. Then, simply take the number of QualExes in the qualifier, and that is the index for compilers/platforms.

    FWIW I am doing some very similar changes with nixpkgs atm, and documenting the new world in https://github.com/NixOS/nixpkgs/blob/master/doc/cross-compilation.xml . That may of interest, but probably not yet.

  19. sebright commented on Jan 28, 2017

    @sebright
    Collaborator

    @GrayJay the difference is the prune function---it limits the number of QualExes and there can already be only one QualBase, thus the length of the path must be finite. [I forgot to use prune too on user-specified constraints, but those are also finite and worst-case just wouldn't apply, so less harm there.]

    I meant that we should make sure that the solver continues to handle cycles well before increasing the pruning depth beyond 0. I don't know if this will be an issue, but increasing the depth might cause the solver to search a large tree of possibilities every time it encounters a cycle through setup dependencies, when it could backtrack quickly with a depth of 0.

    Specifying a single compiler/platform, or single cross and native compiler/platform, generalizes into specifying a list of compilers/platforms----whatever the user-facing interface would be, this is how things would be stored internally. Then, simply take the number of QualExes in the qualifier, and that is the index for compilers/platforms.

    So the solver never has to choose the compiler. Does this feature mean that the solver also needs to keep track of multiple compilers' package databases?

    FWIW I am doing some very similar changes with nixpkgs atm, and documenting the new world in https://github.com/NixOS/nixpkgs/blob/master/doc/cross-compilation.xml . That may of interest, but probably not yet.

    👍

  20. Ericson2314 commented on Jan 29, 2017

    @Ericson2314
    Collaborator

    @GrayJay Granted, I haven't looked to much at the solver code, but as I understand it, cycles would be handled the same, and qualifiers essentially would unroll the cycle up to the length of the qualifier, with the longest qualifier in the series handling the remaining cycle. I hope that makes sense :).

    So the solver never has to choose the compiler. Does this feature mean that the solver also needs to keep track of multiple compilers' package databases?

    In the new-build world, "improvement" i.e. dropping already-built packages/components from the plan takes place after solving. I think this makes stuff not so bad. But yes the compiler/platform, rather than being an input, is now a function of the number of QualExes in the qualifier.

  21. Ericson2314 commented on Apr 4, 2017

    @Ericson2314
    Collaborator

    @GrayJay Would it be useful for me to bother rebasing that prior to your upcoming solver overhaul?

  22. sebright commented on Apr 5, 2017

    @sebright
    Collaborator

    @Ericson2314 Do you mean that you would rebase your cross-solve branch so that it could be merged as part of #4087? I think that the current design for #4087 doesn't affect package qualifiers, so you could change the qualifier types independently. #4087 would just add more information about components that we could use to make the qualifier edges more specific.

  23. Ericson2314 commented on Apr 5, 2017

    @Ericson2314
    Collaborator

    @GrayJay makes sense. Thanks for the feedback.

  24. acw commented on Jun 14, 2017

    @acw

    Hi Folks -

    Any news on this one? In progress? Blocked on something? (And if so what?) I find myself working on a HaLVM issue, and am wondering if I should choose the Right Way, which relies on this issue being solved in the near future, or if I should do something fairly evil, under the assumption that this issue isn't going to be solved for awhile.

    I'm happy to help, if it's just a matter of someone piping data through to the right places, but it's been a long time since I've looked at Cabal internals. Alternatively, I do have a test cross compiler all ready to go, if you want me to run some experiments. 😃

  25. Ericson2314 commented on Jun 14, 2017

    @Ericson2314
    Collaborator

    I was sidetracked with other Cabal work (sub library refactors), and then Nixpkgs cross compilation work. I'd probably be best unwinding that stack before I got back to this. Not sure what the status of @GrayJay's per-component solving is---it will be easiest to work when that's finished but there's things to do in the meantime.

    My plan is more expensive, but solves this the Really Right Way. If you want to write nice cabal files but get by with a hacky Cabal implementation, the patch earlier in the thread is probably still similar to what would be needed for a stop-gap.

  26. x1ddos commented on Jul 23, 2017

    @x1ddos

    Instead of adding or extending existing options, why not make cabal just ignore --with-xxx options during configure phase, when compiling custom setup? It has to always run on host either way, right.

    At least as a quick short term solution. It isn't usable as is at the moment anyway.

  27. x1ddos commented on Jul 23, 2017

    @x1ddos

    Actually, that won't work either. Please, ignore.

  28. howtonotwin commented on Jun 22, 2018

    @howtonotwin

    Has there been any further progress on this?

  29. Ericson2314 commented on Aug 13, 2018

    @Ericson2314
    Collaborator

    It's still on my radar, but no direct work yet.

  30. added
    can-workaround
    on Aug 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Cabal: customcabal-install: othercan-workaroundtype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions