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

Add RISC-V (64-bit) support #9

Closed
benz0li opened this issue Aug 22, 2024 · 9 comments
Closed

Add RISC-V (64-bit) support #9

benz0li opened this issue Aug 22, 2024 · 9 comments
Labels
enhancement New feature or request

Comments

@benz0li
Copy link
Owner

benz0li commented Aug 22, 2024

Create linux/riscv64 docker images.

@benz0li benz0li added the enhancement New feature or request label Aug 22, 2024
@benz0li
Copy link
Owner Author

benz0li commented Aug 22, 2024

Currently, there is no official support for GHC on Linux/RISC-V:

@benz0li
Copy link
Owner Author

benz0li commented Aug 22, 2024

This requires cross-compiling GHC1 from either linux/amd64 or linux/arm64/v8 to linux/riscv64.

This is quite a lot of work and to compile it in a reasonable time, 'native RISC-V hardware'2 is required.
👉 IMHO Docker/QEMU emulation is just not suitable for such a compilation effort.

@bgamari @mpickering Is cross-compiling GHC to Linux/RISC-V currently even possible?

ℹ️ 2024-08-22: Debian sid has GHC 9.4.7 for riscv64 in its package repository.

Footnotes

  1. On Alpine Linux using the GHC musl images.

  2. On its way

@benz0li benz0li pinned this issue Aug 22, 2024
@mpickering
Copy link

I believe you can cross-compiler to RISC-V using the LLVM backend (your linked ticket seems to suggest that people do this).

@benz0li
Copy link
Owner Author

benz0li commented Sep 13, 2024

@supersven At some point I would like to add a linux/riscv64 image to the Alpine-based GHC musl docker manifest.

There is not much documentation about 'porting GHC'1 to a new architecture using hadrian. Any hints/tips?

Dockerfile to build GHC 9.10.1 for both linux/amd64 and linux/arm64/v8: https://github.com/benz0li/ghc-musl/blob/6f4d9658c96f16a6a9ed5d577512a147adf4ccaf/latest.Dockerfile

Footnotes

  1. Cross-compiling GHC itself

@supersven
Copy link

I believe you can cross-compiler to RISC-V using the LLVM backend (your linked ticket seems to suggest that people do this).

To shed some light on this:
GHC can cross-compile to RISC-V, with both the LLVM and NCG backends. However, GHC itself cannot be cross-compiled. The autoconf scripts do not allow that:

configure: error:
You've selected:

  BUILD:  x86_64-unknown-linux   (the architecture we're building on)
  HOST:   riscv64-unknown-linux    (the architecture the compiler we're building will execute on)
  TARGET: riscv64-unknown-linux  (the architecture the compiler we're building will produce code for)

BUILD must equal HOST; that is, we do not support building GHC itself
with a cross-compiler.  To cross-compile GHC itself, set TARGET: stage
1 will be a cross-compiler, and stage 2 will be the cross-compiled
GHC.

So, the only way to get a GHC bindist (for a recent GHC version) is to create it on real hardware (or an emulated VM, e.g. Qemu.)

If you got RISCV-V hardware, this shouldn't be much of an issue: Distributions like SuSE or Debian ship GHC with the LLVM backend configured. Though, be prepared that building and bundling with take about a day (without running the testsuite.)

As you likely want to ship only from trusted sources, I fear you'll need to wait until either Hadrian allows build != host builds. Or, we got a RISC-V CI runner.

So, I'd be excited to see a GHC/RISC-V Docker image (thanks a lot for bringing this up, BTW 👍 ), but we probably aren't ready, yet.

@benz0li
Copy link
Owner Author

benz0li commented Sep 13, 2024

I believe you can cross-compiler to RISC-V using the LLVM backend (your linked ticket seems to suggest that people do this).

To shed some light on this: GHC can cross-compile to RISC-V, with both the LLVM and NCG backends. However, GHC itself cannot be cross-compiled. The autoconf scripts do not allow that:

configure: error:
You've selected:

  BUILD:  x86_64-unknown-linux   (the architecture we're building on)
  HOST:   riscv64-unknown-linux    (the architecture the compiler we're building will execute on)
  TARGET: riscv64-unknown-linux  (the architecture the compiler we're building will produce code for)

BUILD must equal HOST; that is, we do not support building GHC itself
with a cross-compiler.  To cross-compile GHC itself, set TARGET: stage
1 will be a cross-compiler, and stage 2 will be the cross-compiled
GHC.

According to https://gitlab.haskell.org/ghc/ghc/-/wikis/cross-compilation#meshing-with-ghcs-2-stage-build this is one of two ways.

So, the only way to get a GHC bindist (for a recent GHC version) is to create it on real hardware (or an emulated VM, e.g. Qemu.)

I currently use QEMU...

If you got RISCV-V hardware, this shouldn't be much of an issue: Distributions like SuSE or Debian ship GHC with the LLVM backend configured. Though, be prepared that building and bundling with take about a day (without running the testsuite.)

...but HW is on its way.

As you likely want to ship only from trusted sources, [...]

No. I intend to cross-compile from either linux/amd64 or linux/arm64/v8 to linux/riscv64 using my Alpine-based GHC musl docker images.

So, I'd be excited to see a GHC/RISC-V Docker image (thanks a lot for bringing this up, BTW 👍 ), but we probably aren't ready, yet.

@benz0li
Copy link
Owner Author

benz0li commented Sep 13, 2024

[.................................] To cross-compile GHC itself, set TARGET: stage
1 will be a cross-compiler, and stage 2 will be the cross-compiled
GHC.

@supersven This seems to be the alternative.

But with my limited knowledge regarding GHC and cross-compiling1, I am unable to derive the required steps for hadrian myself.

Footnotes

  1. RISC-V GNU Compiler Toolchain: https://github.com/riscv-collab/riscv-gnu-toolchain

@supersven
Copy link

@benz0li Ah, I see 💡

E.g. Debian Sid (GHC 9.4.7, https://packages.debian.org/sid/ghc) and Experimental (9.6.6, https://packages.debian.org/experimental/ghc) ship with RISC-V GHC. If you get one of these running in Qemu, you should be able to build a GHC bindist:

./boot && ./configure
hadrian/build -j --flavour=release binary-dist

I fear the documentation is a bit outdated. To my knowledge, building cross-compiled GHCs with Hadrian is a work-in-progress: https://gitlab.haskell.org/ghc/ghc/-/merge_requests/11444

@benz0li
Copy link
Owner Author

benz0li commented Sep 20, 2024

FYI @mpilgrem The quay.io/benz0li/ghc-musl:9.10.1-linux-riscv64 image also includes an unofficial and untested Linux/RISC-V build of Stack.

Both GHC and Stack are built (manually) from source on an emulated Linux/RISC-V platform.
👉 Since this takes a lot of time, linux/riscv64 images are released with a delay.

@benz0li benz0li changed the title Add RISC-V support Add RISC-V 64-bit support Sep 20, 2024
@benz0li benz0li changed the title Add RISC-V 64-bit support Add RISC-V (64-bit) support Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants