Skip to content

Build Linux Kernel with ThinLTO #5

Build Linux Kernel with ThinLTO

Build Linux Kernel with ThinLTO #5

Workflow file for this run

name: Build Linux Kernel with ThinLTO
on:
# Automatic triggers
push:
branches:
- main
pull_request:
branches:
- main
# Manual trigger
workflow_dispatch:
jobs:
build:
name: Build Kernel with ThinLTO
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential libncurses-dev bison flex libssl-dev libelf-dev clang lld
- name: Configure Kernel Build
run: |
export ARCH=x86_64
export KERNEL_BUILD_DIR=output
export KERNEL_VERSION="0.$(date +'%Y%m%d').$(date +'%H%M%S')"
echo "KERNEL_VERSION=$KERNEL_VERSION" >> $GITHUB_ENV
# Configure the kernel (adjust to your defconfig as needed)
make O=$KERNEL_BUILD_DIR defconfig
# Ensure configuration is saved to .config
make O=$KERNEL_BUILD_DIR olddefconfig
- name: Build Kernel with ThinLTO
run: |
# Compile with ThinLTO flags
make -j$(nproc) O=$KERNEL_BUILD_DIR \
ARCH=x86_64 \
CC=clang \
LD=ld.lld \
CFLAGS="-flto=thin" \
KCFLAGS="-flto=thin"
- name: Archive the build artifacts
run: |
mkdir -p artifacts
tar -czvf artifacts/kernel-build-$KERNEL_VERSION.tar.gz $KERNEL_BUILD_DIR/arch/x86/boot/bzImage
- name: Upload Kernel Artifact
uses: actions/upload-artifact@v3
with:
name: kernel-build
path: artifacts/kernel-build-$KERNEL_VERSION.tar.gz
release:
name: Release Kernel
needs: build
runs-on: ubuntu-latest
steps:
- name: Download build artifact
uses: actions/download-artifact@v3
with:
name: kernel-build
- name: Create GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: "v${{ env.KERNEL_VERSION }}" # Auto-generate tag using version
release_name: "Kernel Build v${{ env.KERNEL_VERSION }}"
draft: false
prerelease: true
body: |
**Build Information**
- **Version:** ${{ env.KERNEL_VERSION }}
- **Build Configuration:** ThinLTO
- **Build Date:** $(date +'%Y-%m-%d %H:%M:%S')
- name: Upload Kernel to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: artifacts/kernel-build-${{ env.KERNEL_VERSION }}.tar.gz
asset_name: kernel-build-${{ env.KERNEL_VERSION }}.tar.gz
asset_content_type: application/gzip