Skip to content

Commit

Permalink
feat: remove toolchain.sh in favor of Dockerfile
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <[email protected]>
  • Loading branch information
mkroening committed Aug 20, 2024
1 parent 331b296 commit a1cbb64
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 160 deletions.
91 changes: 76 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ RUN set -eux; \
make -O -j$(nproc); \
make install

FROM buildpack-deps:bookworm AS builder

FROM buildpack-deps:bookworm AS gcc
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
Expand All @@ -59,26 +58,88 @@ RUN set -eux; \
texinfo \
; \
rm -rf /var/lib/apt/lists/*;
ARG TARGET
ARG PREFIX
COPY --link --from=binutils $PREFIX $PREFIX
ENV CFLAGS="-w" \
CXXFLAGS="-w" \
CFLAGS_FOR_TARGET="-fPIE -pie" \
GOFLAGS_FOR_TARGET="-fPIE -pie" \
FCFLAGS_FOR_TARGET="-fPIE -pie" \
FFLAGS_FOR_TARGET="-fPIE -pie" \
CXXFLAGS_FOR_TARGET="-fPIE -pie"

WORKDIR /root
ADD --link https://github.com/hermit-os/gcc.git /gcc
WORKDIR /gcc/builddir-bootstrap
RUN set -eux; \
../configure \
--target=$TARGET \
--prefix=$PREFIX \
--without-headers \
--disable-multilib \
--with-isl \
--enable-languages=c,c++,lto \
--disable-nls \
--disable-shared \
--disable-libssp \
--disable-libgomp \
--enable-threads=posix \
--enable-tls \
--enable-lto \
--disable-symvers; \
make -O -j$(nproc) all-gcc; \
make install-gcc
ENV PATH=$PREFIX/bin:$PATH

COPY --link --from=kernel /kernel/libhermit.a /root/kernel/libhermit.a
ENV LDFLAGS_FOR_TARGET="-L/root/target/x86_64/release -lhermit"
COPY --link --from=kernel /kernel/libhermit.a /gcc/builddir-bootstrap/libhermit.a
ENV LDFLAGS_FOR_TARGET="-L/gcc/builddir-bootstrap -lhermit"

ARG PREFIX
COPY --link --from=binutils $PREFIX $PREFIX
ADD --link https://github.com/hermit-os/gcc.git gcc
ADD --link https://github.com/hermit-os/hermit-playground.git hermit
ADD --link https://github.com/hermit-os/newlib.git newlib
ADD --link https://github.com/hermit-os/pthread-embedded.git pte
ADD --link ./toolchain.sh ./toolchain.sh
ADD --link https://github.com/hermit-os/newlib.git /newlib
WORKDIR /newlib
RUN set -eux; \
./configure \
--target=$TARGET \
--prefix=$PREFIX \
--disable-shared \
--disable-multilib \
--enable-lto \
--enable-newlib-io-c99-formats \
--enable-newlib-multithread; \
make -O -j$(nproc); \
make install

ARG TARGET
RUN ./toolchain.sh $TARGET $PREFIX
ADD --link https://github.com/hermit-os/pthread-embedded.git /pthread-embedded
WORKDIR /pthread-embedded
RUN set -eux; \
./configure \
--target=$TARGET \
--prefix=$PREFIX; \
make -O -j$(nproc); \
make install

WORKDIR /gcc/builddir
RUN set -eux; \
../configure \
--target=$TARGET \
--prefix=$PREFIX \
--with-newlib \
--with-isl \
--disable-multilib \
--without-libatomic \
--enable-languages=c,c++,fortran,lto \
--disable-nls \
--disable-shared \
--enable-libssp \
--enable-threads=posix \
--enable-libgomp \
--enable-tls \
--enable-lto \
--disable-symver; \
make -O -j$(nproc); \
make install

FROM rust:bookworm AS toolchain
ARG PREFIX
COPY --from=builder $PREFIX $PREFIX
COPY --from=gcc $PREFIX $PREFIX
ENV PATH=$PREFIX/bin:$PATH \
LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH
30 changes: 11 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@
# hermit-gcc

This repository contains scripts to build the cross-compiler for the Rust-based library OS [HermitCore](https://github.com/hermit-os/libhermit-rs).
This repository contains a [`Dockerfile`] to build the GCC cross-compiler for [the Hermit Operating System].

## Requirements
[`Dockerfile`]: Dockerfile
[the Hermit Operating System]: http://hermit-os.org

The build process works currently only on **x86-based Linux** systems. The following software packets are required to build HermitCore's toolchain on a Linux system:
## Usage

* Netwide Assembler (NASM)
* GNU Make, GNU Binutils, cmake
* Tools and libraries to build *linux*, *binutils* and *gcc* (e.g. flex, bison, MPFR library, ISL library, GMP library, MPC library)
* Rust
You can use the prebuilt [hermit-toolchain] OCI image to run `x86_64-hermit-gcc`:

On Debian-based systems the packets can be installed by executing:
```
sudo apt-get install cmake nasm libmpfr-dev libisl-dev libmpc-dev libgmp-dev flex bison
```

Note: If issues arise during the build, try using requirements.sh to check the versions of the necessary packets and the configuration of the LD_LIBRARY_PATH (it should contain the MPFR library, GMP library and MPC library).
[`hermit-toolchain`]: https://github.com/hermit-os/hermit-gcc/pkgs/container/hermit-toolchain

## Building the HermitCore's toolchain
```bash
docker run ghcr.io/hermit-os/hermit-toolchain:latest x86_64-hermit-gcc -v
```

To build the toolchain just call the script as follow:
You can also use the image interactively and mount your current directory:

```bash
$ ./toolchain.sh x86_64-hermit /home/usr/hermit
docker run --rm -it -v .:/mnt -w /mnt ghcr.io/hermit-os/hermit-toolchain:latest
```

The first argument of the script specifies the target architecture, where the second argument defines the path to the installation directory.
To create the toolchain, write access to the installation directory is required.
32 changes: 0 additions & 32 deletions requirements.sh

This file was deleted.

94 changes: 0 additions & 94 deletions toolchain.sh

This file was deleted.

0 comments on commit a1cbb64

Please sign in to comment.