name: setup-llvm-with-apt description: | Set up LLVM toolchain with APT package management and smart caching. Supports cross-compilation architectures and additional package installation. Creates symlinks in /usr/bin: clang, clang++, lld, llvm-ar, llvm-ranlib inputs: dpkg-arch: description: 'Debian architecture for cross-compilation (e.g. arm64)' required: false default: '' extra-packages: description: 'Additional APT packages to install (space-separated)' required: false default: '' llvm-version: description: 'LLVM version to install' required: false default: '20' outputs: llvm-version: description: 'Installed LLVM version' value: ${{ steps.configure.outputs.version }} runs: using: composite steps: - name: Detect runner OS id: runner-os uses: ./.forgejo/actions/detect-runner-os - name: Configure cross-compilation architecture if: inputs.dpkg-arch != '' shell: bash run: | echo "🏗️ Adding ${{ inputs.dpkg-arch }} architecture" sudo dpkg --add-architecture ${{ inputs.dpkg-arch }} # Restrict default sources to amd64 sudo sed -i 's/^deb http/deb [arch=amd64] http/g' /etc/apt/sources.list sudo sed -i 's/^deb https/deb [arch=amd64] https/g' /etc/apt/sources.list # Add ports sources for foreign architecture sudo tee /etc/apt/sources.list.d/${{ inputs.dpkg-arch }}.list > /dev/null <> $GITHUB_OUTPUT else echo "📦 LLVM ${{ inputs.llvm-version }} not found or incomplete - installing..." echo "::group::🔧 Installing LLVM ${{ inputs.llvm-version }}" wget -O - https://apt.llvm.org/llvm.sh | bash -s -- ${{ inputs.llvm-version }} echo "::endgroup::" if [ ! -f "/usr/bin/clang-${{ inputs.llvm-version }}" ]; then echo "❌ Failed to install LLVM ${{ inputs.llvm-version }}" exit 1 fi echo "✅ Installed LLVM ${{ inputs.llvm-version }}" echo "needs-install=true" >> $GITHUB_OUTPUT fi - name: Prepare for additional packages if: inputs.extra-packages != '' shell: bash run: | # Update APT if LLVM was cached (installer script already does apt-get update) if [[ "${{ steps.llvm-setup.outputs.needs-install }}" != "true" ]]; then echo "::group::📦 Running apt-get update (LLVM cached, extra packages needed)" sudo apt-get update echo "::endgroup::" fi echo "::group::📦 Installing additional packages" - name: Install additional packages if: inputs.extra-packages != '' uses: https://github.com/awalsh128/cache-apt-pkgs-action@latest with: packages: ${{ inputs.extra-packages }} version: 1.0 - name: End package installation group if: inputs.extra-packages != '' shell: bash run: echo "::endgroup::" - name: Configure LLVM environment id: configure shell: bash run: | echo "::group::🔧 Configuring LLVM ${{ inputs.llvm-version }} environment" # Create symlinks sudo ln -sf "/usr/bin/clang-${{ inputs.llvm-version }}" /usr/bin/clang sudo ln -sf "/usr/bin/clang++-${{ inputs.llvm-version }}" /usr/bin/clang++ sudo ln -sf "/usr/bin/lld-${{ inputs.llvm-version }}" /usr/bin/lld sudo ln -sf "/usr/bin/llvm-ar-${{ inputs.llvm-version }}" /usr/bin/llvm-ar sudo ln -sf "/usr/bin/llvm-ranlib-${{ inputs.llvm-version }}" /usr/bin/llvm-ranlib echo " ✓ Created symlinks" # Setup library paths LLVM_LIB_PATH="/usr/lib/llvm-${{ inputs.llvm-version }}/lib" if [ -d "$LLVM_LIB_PATH" ]; then echo "LD_LIBRARY_PATH=${LLVM_LIB_PATH}:${LD_LIBRARY_PATH:-}" >> $GITHUB_ENV echo "LIBCLANG_PATH=${LLVM_LIB_PATH}" >> $GITHUB_ENV echo "$LLVM_LIB_PATH" | sudo tee "/etc/ld.so.conf.d/llvm-${{ inputs.llvm-version }}.conf" > /dev/null sudo ldconfig echo " ✓ Configured library paths" else # Fallback to standard library location if [ -d "/usr/lib/x86_64-linux-gnu" ]; then echo "LIBCLANG_PATH=/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV echo " ✓ Using fallback library path" fi fi # Set output echo "version=${{ inputs.llvm-version }}" >> $GITHUB_OUTPUT echo "::endgroup::" echo "✅ LLVM ready: $(clang --version | head -1)"