Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build GHC with cabal-install and a Makefile #3

Draft
wants to merge 39 commits into
base: master
Choose a base branch
from
Draft

Conversation

hsyl20
Copy link

@hsyl20 hsyl20 commented Nov 27, 2024

Note that we need a patched cabal: https://github.com/hsyl20/cabal/tree/hsyl20/per-file-extra-source-options

  • Build ghc-stage1
  • Generate valid non-cross stage1 settings (reusing stage0's settings for the most part)
  • Build boot libraries with stage1: ghc-prim, ghc-internal, base
  • Build ghc-stage2
  • For every host/arch we want to build a compiler for:
    • generate valid stage2 settings for the target (using ghc-toolchain?)
    • use ghc-stage2 with these settings to build root libraries
    • use ghc-stage2 with these settings to build iserv
    • (optional) use ghc-stage2 with these settings to cross-build a GHC
  • ...

@hsyl20
Copy link
Author

hsyl20 commented Nov 27, 2024

Current status: it builds some ghc program in _build/stage0/bin/ghc. It seems to be linked with the wrong ghc-boot because it reports a GHC version of 9.8.2 (my bootstrap GHC).

@hsyl20
Copy link
Author

hsyl20 commented Nov 27, 2024

Ah, I need to pass some environment variable to ghc-boot's Setup.hs

Copy link

@angerman angerman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @hsyl20 this looks like a great start!

Makefile Outdated
@@ -0,0 +1,67 @@
HADRIAN_SETTINGS_STAGE0 := $(shell ghc --info | runghc GenSettings.hs ghc-boot)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this called HADRIAN_SETTINGS

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's how the environment variable is called in ghc-boot's Setup.hs ¯_(ツ)_/¯

Makefile Outdated
Comment on lines 15 to 56
## Substituting variables
cp _build/stage0/src/ghc-bin/ghc-bin.cabal{.in,}
cp _build/stage0/src/libraries/ghc/ghc.cabal{.in,}
cp _build/stage0/src/libraries/ghc/GHC/CmmToLlvm/Version/Bounds.hs{.in,}
cp _build/stage0/src/libraries/ghc-boot/ghc-boot.cabal{.in,}
cp _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal{.in,}
cp _build/stage0/src/libraries/ghc-heap/ghc-heap.cabal{.in,}
cp _build/stage0/src/libraries/ghci/ghci.cabal{.in,}
cp _build/stage0/src/utils/ghc-pkg/ghc-pkg.cabal{.in,}

sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/ghc-bin/ghc-bin.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/ghc-bin/ghc-bin.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghc/ghc.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghc/ghc.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghc-boot/ghc-boot.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghc-boot/ghc-boot.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal
sed -i 's/@Suffix@//' _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal
sed -i 's/@SourceRoot@/./' _build/stage0/src/libraries/ghc-boot-th/ghc-boot-th.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghc-heap/ghc-heap.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghc-heap/ghc-heap.cabal
sed -i 's/@ProjectVersionForLib@/9.13/' _build/stage0/src/libraries/ghc-heap/ghc-heap.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/libraries/ghci/ghci.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/libraries/ghci/ghci.cabal
sed -i 's/@ProjectVersionForLib@/9.13/' _build/stage0/src/libraries/ghci/ghci.cabal
sed -i 's/@ProjectVersion@/9.13/' _build/stage0/src/utils/ghc-pkg/ghc-pkg.cabal
sed -i 's/@ProjectVersionMunged@/9.13/' _build/stage0/src/utils/ghc-pkg/ghc-pkg.cabal
sed -i 's/@ProjectVersionForLib@/9.13/' _build/stage0/src/utils/ghc-pkg/ghc-pkg.cabal

sed -i 's/@LlvmMinVersion@/13/' _build/stage0/src/libraries/ghc/GHC/CmmToLlvm/Version/Bounds.hs
sed -i 's/@LlvmMaxVersion@/20/' _build/stage0/src/libraries/ghc/GHC/CmmToLlvm/Version/Bounds.hs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could just use a configure script for this right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could. But we moved away from it upstream.

Comment on lines 2 to 24
./_build/stage0/src/ghc-bin/
./_build/stage0/src/libraries/ghc
./_build/stage0/src/libraries/directory/
./_build/stage0/src/libraries/file-io/
./_build/stage0/src/libraries/filepath/
./_build/stage0/src/libraries/ghc-platform/
./_build/stage0/src/libraries/ghc-boot/
./_build/stage0/src/libraries/ghc-boot-th/
./_build/stage0/src/libraries/ghc-heap
./_build/stage0/src/libraries/ghci
./_build/stage0/src/libraries/os-string/
./_build/stage0/src/libraries/process/
./_build/stage0/src/libraries/semaphore-compat
./_build/stage0/src/libraries/time
./_build/stage0/src/libraries/unix/
./_build/stage0/src/libraries/Win32/
./_build/stage0/src/utils/ghc-pkg
./_build/stage0/src/utils/hsc2hs
./_build/stage0/src/utils/unlit
./_build/stage0/src/utils/genprimopcode/
./_build/stage0/src/utils/deriveConstants/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we put them in build/stage0?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't want to modify the source tree directly, this way it's easier to nuke the _build directory and restart from a clean state.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to copy all source files across. It is also annoying to do it propely with Make.

cabal will use a separate build directory anyway, only some generated cabal files will end up in the source tree.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to perform some substitution/file generations more than once (for the different stages). I still think it's cleaner to avoid dirtying the source directory. I don't want to have to fix bugs because we've done something for stage0 and forgot to do it again differently for stage1.

@hsyl20
Copy link
Author

hsyl20 commented Nov 28, 2024

Now it seems like cabal doesn't like empty package databases:

Error: [Cabal-9076]
failed to parse output of 'ghc-pkg dump'

Edit: that was my mistake (a debug statement in ghc-pkg...). Now it works.

Makefile Outdated Show resolved Hide resolved
@andreabedini
Copy link
Member

Effectively we want to completely disable the solver. We can add
active-respositories: :none to cabal.project and remove the source constraints.

@hsyl20
Copy link
Author

hsyl20 commented Nov 29, 2024

Effectively we want to completely disable the solver. We can add active-respositories: :none to cabal.project and remove the source constraints.

I've disabled it for stage1 where we start fresh to build boot libraries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants