diff --git a/.github/workflows/build-kernel.yml b/.github/workflows/build-kernel.yml new file mode 100644 index 00000000..64686dc9 --- /dev/null +++ b/.github/workflows/build-kernel.yml @@ -0,0 +1,55 @@ +name: Build Kernel + +on: + pull_request: + push: + branches: + - master + +jobs: + toolchain: + uses: ./.github/workflows/build-toolchain.yml + + build: + name: Build kernel + runs-on: ubuntu-latest + needs: toolchain + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Install toolchain + uses: actions/cache@v4 + with: + key: ${{ needs.toolchain.outputs.cache-key-gcc }} + path: /opt/toolchains/i686-dailyrun + + - name: Install libc + uses: actions/cache@v4 + with: + key: ${{ needs.toolchain.outputs.cache-key-libc }} + path: build/root + + - name: Install Nix + uses: cachix/install-nix-action@v17 + with: + extra_nix_config: | + access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} + + - name: Configure (i686) + run: | + cp defconfigs/config.i686 .config + + - name: Build Kernel + run: | + nix develop --command make kernel + + - name: Build initramfs + run: | + mkdir -p dev + tar cvf initramfs.tar dev + + - name: Build ISO + run: | + nix develop --command make iso diff --git a/.github/workflows/build-toolchain.yml b/.github/workflows/build-toolchain.yml new file mode 100644 index 00000000..5f7164d1 --- /dev/null +++ b/.github/workflows/build-toolchain.yml @@ -0,0 +1,192 @@ +name: Build Toolchain + +on: + pull_request: + push: + branches: + - master + workflow_call: + outputs: + cache-key-gcc: + description: "GCC cache key" + value: ${{ jobs.cache-gcc.outputs.cache-key }} + cache-key-libc: + description: "Libc cache key" + value: ${{ jobs.cache-libc.outputs.cache-key }} + +jobs: + + # + # Do not re-build toolchain if already cached + # + + cache-gcc: + name: Find cached GCC version + runs-on: ubuntu-latest + outputs: + cache-key: ${{ steps.cache-key.outputs.key }} + cache-hit: ${{ steps.cache-fetch.outputs.cache-hit }} + steps: + - uses: actions/checkout@v4 + + - name: Generate cache key + id: cache-key + run: | + echo "key=toolchain-${{ runner.os }}-${{ hashFiles('toolchain/gcc/**', 'toolchain/binutils/**') }}" >> $GITHUB_OUTPUT + + - name: Find cached version + id: cache-fetch + uses: actions/cache@v4 + with: + lookup-only: true + key: ${{ steps.cache-key.outputs.key }} + path: /opt/toolchains/i686-dailyrun + + cache-libc: + name: Find cached Libc version + runs-on: ubuntu-latest + outputs: + cache-key: ${{ steps.cache-key.outputs.key }} + cache-hit: ${{ steps.cache-fetch.outputs.cache-hit }} + steps: + - uses: actions/checkout@v4 + + - name: Generate cache key + id: cache-key + run: | + echo "key=libc-${{ runner.os }}-${{ hashFiles('toolchain/newlib/**', 'root/usr/lib/dailyrun/**') }}" >> $GITHUB_OUTPUT + + - name: Find cached version + id: cache-fetch + uses: actions/cache@v4 + with: + lookup-only: true + key: ${{ steps.cache-key.outputs.key }} + path: build/root + + build-gcc: + name: "Build GCC" + needs: cache-gcc + if: needs.cache-gcc.outputs.cache-hit != 'true' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + # + # Downloading the archives takes time, so use a cache here also + # + - name: Restore GCC sources from cache + id: cache-gcc + uses: actions/cache@v4 + env: + cache-name: gcc-sources + release: 12.3.0 + with: + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.release }} + path: toolchain/gcc/gcc-${{ env.release }}.tar.gz + + - name: Restore binutils/GDB sources from cache + id: cache-binutils + uses: actions/cache@v4 + env: + cache-name: binutils-sources + release: 2.44 + with: + key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.release }} + path: toolchain/binutils/binutils-${{ env.release }}.tar.gz + + - name: Install dependencies + run: | + sudo apt install build-essential pkg-config automake autoconf autoconf-archive autogen + sudo apt install libisl-dev libgmp-dev libmpfr-dev libmpc-dev + sudo apt install flex bison + + - name: Configure (i686) + run: | + cp defconfigs/config.i686 .config + + - name: Build Toolchain (i686) + run: | + make gcc TARGET=i686-dailyrun ARCH= CROSS_COMPILE= GCC_CONFIGURE_FLAGS="--with-newlib" + + - name: Save toolchain to cache + uses: actions/cache/save@v4 + with: + key: ${{ needs.cache-gcc.outputs.cache-key }} + path: /opt/toolchains/i686-dailyrun + + build-libc: + name: "Build Libc" + needs: [ cache-gcc, cache-libc, build-gcc ] + if: | + always() && + needs.cache-libc.outputs.cache-hit != 'true' && + (needs.cache-gcc.outputs.cache-hit == 'true' || needs.build-gcc.result == 'success') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install toolchain + uses: actions/cache@v4 + with: + key: ${{ needs.cache-gcc.outputs.cache-key }} + path: /opt/toolchains/i686-dailyrun + + - name: Install dependencies + run: | + sudo apt install build-essential pkg-config + sudo apt install libisl-dev libgmp-dev libmpfr-dev libmpc-dev + + # Install automake 1.15.1 (specific version required by newlib) + cd /tmp + wget https://ftp.gnu.org/gnu/automake/automake-1.15.1.tar.gz + tar -xzf automake-1.15.1.tar.gz + cd automake-1.15.1 + ./configure --prefix=/usr/local + make + sudo make install + + # Install autoconf 2.69 (specific version required by newlib) + cd /tmp + wget https://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz + tar -xzf autoconf-2.69.tar.gz + cd autoconf-2.69 + ./configure --prefix=/usr/local + make + sudo make install + + - name: Configure (i686) + run: | + cp defconfigs/config.i686 .config + + - name: Install headers + run: make root + + - name: Build libc + id: build-libc + continue-on-error: true + run: | + make newlib + + - name: Upload build logs on failure + if: steps.build-libc.outcome == 'failure' + uses: actions/upload-artifact@v4 + with: + name: libc-build-logs + path: | + build/newlib/i686-dailyrun-4.5.0/**/config.log + build/newlib/i686-dailyrun-4.5.0/configure.err + build/newlib/i686-dailyrun-4.5.0/configure.log + build/newlib/i686-dailyrun-4.5.0/make.err + build/newlib/i686-dailyrun-4.5.0/make.log + + - name: Save libc to cache + if: steps.build-libc.outcome == 'success' + uses: actions/cache/save@v4 + with: + key: ${{ needs.cache-libc.outputs.cache-key }} + path: build/root + + - name: Exit if build failed + if: steps.build-libc.outcome == 'failure' + run: exit 1 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index a4d16323..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: Build - -on: - pull_request: - push: - branches: - - master - -jobs: - - build-kernel: - name: Kernel - runs-on: ubuntu-latest - - steps: - - - name: Checkout repository - uses: actions/checkout@v2 - with: - submodules: recursive - - # We use nix flakes to setup environment - - name: Install Nix - uses: cachix/install-nix-action@v17 - with: - extra_nix_config: | - access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} - - # Performing the wget on the GCC and sources takes almost 45min ! - # So we try caching it. - # - # NOTE: If ever changing the GCC version, do not forget to also - # update the cached version's release parameter (same for binutils). - - - name: Cache GCC sources - id: cache-gcc - uses: actions/cache@v4 - env: - cache-name: gcc-sources - release: 12.3.0 - with: - key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.release }} - path: toolchain/gcc/gcc-${{ env.release }}.tar.gz - - - name: Cache binutils/gdb sources - id: cache-binutils - uses: actions/cache@v4 - env: - cache-name: binutils-sources - release: 2.44 - with: - key: ${{ runner.os }}-${{ env.cache-name }}-${{ env.release }} - path: toolchain/binutils/binutils-${{ env.release }}.tar.gz - - - name: Configure (i686) - run: | - cp defconfigs/config.i686 .config - - - name: Install headers - run: | - make root - - - name: Build Toolchain (i686) - run: | - nix develop .#gcc --command make gcc TARGET=i686-dailyrun ARCH= CROSS_COMPILE= GCC_CONFIGURE_FLAGS="--with-newlib" - - - name: Build libc - run: | - nix develop .#newlib --command make newlib - - - name: Build Kernel - run: | - nix develop --command make kernel - - - name: Build initramfs - run: | - mkdir -p dev - tar cvf initramfs.tar dev - - - name: Build ISO - run: | - nix develop --command make iso