diff --git a/Dockerfile b/Dockerfile index 600be3d..3dc80d5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 \ @@ -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 diff --git a/README.md b/README.md index 0f0f535..071ab14 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/requirements.sh b/requirements.sh deleted file mode 100755 index 8c1b445..0000000 --- a/requirements.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/bash - -if echo "$LD_LIBRARY_PATH" | grep -q libgmp && echo "$LD_LIBRARY_PATH" | grep -q libisl && echo "$LD_LIBRARY_PATH" | grep -q libmpc && echo "$LD_LIBRARY_PATH" | grep -q libmpfr; then - echo "LD_LIBRARY_PATH contains MPFR library, ISL library, GMP library, and MPC library" -elif ! echo "$LD_LIBRARY_PATH" | grep -q libgmp; then - echo "LD_LIBRARY_PATH missing GMP library" -elif ! echo "$LD_LIBRARY_PATH" | grep -q libisl; then - echo "LD_LIBRARY_PATH missing ISL library" -elif ! echo "$LD_LIBRARY_PATH" | grep -q libmpc; then - echo "LD_LIBRARY_PATH missing MPC library" -elif ! echo "$LD_LIBRARY_PATH" | grep -q libmpfr; then - echo "LD_LIBRARY_PATH missing MPFR library" -fi - -check_version() { - package=$1 - version_command=$2 - - echo -n "Checking $package... " - if $version_command &> /dev/null; then - version=$($version_command | head -n 1) - echo "Installed ($version)" - else - echo "Not installed" - fi -} - -# Check versions of packages -check_version "CMake" "cmake --version" -check_version "NASM" "nasm -v" -check_version "Flex" "flex --version" -check_version "Bison" "bison --version" \ No newline at end of file diff --git a/toolchain.sh b/toolchain.sh deleted file mode 100755 index 1b14121..0000000 --- a/toolchain.sh +++ /dev/null @@ -1,94 +0,0 @@ -#!/bin/bash -# -# script to build HermitCore's toolchain -# -# $1 = specifies the target architecture -# $2 = specifies the installation directory - -# exit when any command fails -set -e - -PREFIX="$2" -TARGET=$1 -NJOBS=-j"$(nproc)" -PATH=$PATH:$PREFIX/bin -export CFLAGS="-w" -export CXXFLAGS="-w" -export CFLAGS_FOR_TARGET="-fPIE -pie" -export GOFLAGS_FOR_TARGET="-fPIE -pie" -export FCFLAGS_FOR_TARGET="-fPIE -pie" -export FFLAGS_FOR_TARGET="-fPIE -pie" -export CXXFLAGS_FOR_TARGET="-fPIE -pie" - -echo "Build bootstrap toolchain for $TARGET with $NJOBS jobs for $PREFIX" - -if [ ! -d "tmp/bootstrap" ]; then -mkdir -p tmp/bootstrap -cd tmp/bootstrap -../../gcc/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 $NJOBS all-gcc -make install-gcc -cd - -fi - -if [ ! -d "tmp/newlib" ]; then -mkdir -p tmp/newlib -cd tmp/newlib -../../newlib/configure \ - --target=$TARGET \ - --prefix=$PREFIX \ - --disable-shared \ - --disable-multilib \ - --enable-lto \ - --enable-newlib-io-c99-formats \ - --enable-newlib-multithread -make -O $NJOBS -make install -cd - -fi - -cd pte -./configure \ - --target=$TARGET \ - --prefix=$PREFIX -make -O $NJOBS -make install -cd .. - -if [ ! -d "tmp/gcc" ]; then -mkdir -p tmp/gcc -cd tmp/gcc -../../gcc/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 $NJOBS -make install -cd - -fi