Skip to content

Commit

Permalink
Merge pull request #42 from hermit-os/rm-toolchain.sh
Browse files Browse the repository at this point in the history
feat: remove `toolchain.sh` in favor of `Dockerfile`
  • Loading branch information
mkroening authored Aug 20, 2024
2 parents e975fa9 + 62e5fac commit 68e664c
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 211 deletions.
141 changes: 133 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,56 @@
FROM rust:bookworm AS builder
ARG TARGET=x86_64-hermit
ARG PREFIX=/opt/hermit

FROM --platform=$BUILDPLATFORM rust:bookworm AS kernel
ADD --link https://github.com/hermit-os/kernel.git /kernel
WORKDIR /kernel
RUN cargo xtask build \
--artifact-dir . \
--arch x86_64 \
--release \
--no-default-features \
--features pci,smp,acpi,newlib,tcp,dhcpv4

FROM buildpack-deps:bookworm AS binutils
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
bison \
flex \
texinfo \
; \
rm -rf /var/lib/apt/lists/*;
ADD --link https://github.com/hermit-os/binutils.git /binutils
WORKDIR /binutils
ENV CFLAGS="-w" \
CXXFLAGS="-w"
ARG TARGET
ARG PREFIX
RUN set -eux; \
./configure \
--target=$TARGET \
--prefix=$PREFIX \
--with-sysroot \
--disable-werror \
--disable-multilib \
--disable-shared \
--disable-nls \
--disable-gdb \
--disable-libdecnumber \
--disable-readline \
--disable-sim \
--enable-tls \
--enable-lto \
--enable-plugin; \
make -O -j$(nproc); \
make install; \
make clean

FROM buildpack-deps:bookworm AS gcc
RUN set -eux; \
apt-get update; \
apt-get install -y --no-install-recommends \
bison \
git \
flex \
libgmp-dev \
libisl-dev \
Expand All @@ -13,13 +59,92 @@ 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 ./toolchain.sh /root/toolchain.sh
RUN ./toolchain.sh x86_64-hermit /opt/hermit
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; \
make clean
ENV PATH=$PREFIX/bin:$PATH

COPY --link --from=kernel /kernel/libhermit.a /kernel/libhermit.a
ENV LDFLAGS_FOR_TARGET="-L/kernel -lhermit"

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; \
make clean

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; \
make clean

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; \
make clean

FROM rust:bookworm AS toolchain
COPY --from=builder /opt/hermit /opt/hermit
ENV PATH=/opt/hermit/bin:$PATH \
LD_LIBRARY_PATH=/opt/hermit/lib:$LD_LIBRARY_PATH
ARG PREFIX
COPY --from=gcc $PREFIX $PREFIX
ENV PATH=$PREFIX/bin:$PATH \
LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
# 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 provides an OCI image ([`ghcr.io/hermit-os/hermit-gcc`], [`Dockerfile`]) containing the GCC cross-compiler for the [Hermit Operating System].

## Requirements
[`ghcr.io/hermit-os/hermit-gcc`]: https://github.com/hermit-os/hermit-gcc/pkgs/container/hermit-gcc
[`Dockerfile`]: Dockerfile
[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:
## Available Components

* 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
- [hermit-os/binutils](https://github.com/hermit-os/binutils)
- [hermit-os/newlib](https://github.com/hermit-os/newlib)
- [hermit-os/pthread-embedded](https://github.com/hermit-os/pthread-embedded)
- [hermit-os/gcc](https://github.com/hermit-os/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).
## Usage

## Building the HermitCore's toolchain
To compile Hermit applications using this image, you need a built [Hermit kernel] (`libhermit.a`).
You can then compile applications like this:

To build the toolchain just call the script as follow:
[Hermit kernel]: https://github.com/hermit-os/kernel

```bash
$ ./toolchain.sh x86_64-hermit /home/usr/hermit
docker run --rm -v .:/mnt -w /mnt ghcr.io/hermit-os/hermit-gcc:latest x86_64-hermit-gcc -o app app.c libhermit.a
```

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.
You can also use the image interactively:

```bash
docker run --rm -it -v .:/mnt -w /mnt ghcr.io/hermit-os/hermit-gcc:latest
```
32 changes: 0 additions & 32 deletions requirements.sh

This file was deleted.

153 changes: 0 additions & 153 deletions toolchain.sh

This file was deleted.

0 comments on commit 68e664c

Please sign in to comment.