.github/workflows/linux.yml #9
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| on: | |
| workflow_dispatch: | |
| inputs: | |
| binary: | |
| description: 'Name of the generated binary' | |
| required: true | |
| type: string | |
| path: | |
| description: 'Path to the project root (where Cargo.toml is)' | |
| required: false | |
| default: '.' | |
| type: string | |
| deps_x86_64: | |
| description: 'Dependencias APT para x86_64 (ej: libssl-dev)' | |
| required: false | |
| default: '' | |
| type: string | |
| deps_aarch64: | |
| description: 'Dependencias APT para aarch64 (ej: libssl-dev:arm64)' | |
| required: false | |
| default: '' | |
| type: string | |
| deps_armv7: | |
| description: 'Dependencias APT para armv7 (ej: libssl-dev:armhf)' | |
| required: false | |
| default: '' | |
| type: string | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| build-linux: | |
| runs-on: ubuntu-22.04 # Fixed to 22.04 to ensure sed commands on sources.list work correctly | |
| permissions: | |
| contents: write | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - target: x86_64-unknown-linux-gnu | |
| name: x86_64 | |
| linker: "" | |
| dpkg_arch: "" | |
| pkg_config_path: "/usr/lib/x86_64-linux-gnu/pkgconfig" | |
| - target: aarch64-unknown-linux-gnu | |
| name: aarch64 | |
| linker: gcc-aarch64-linux-gnu | |
| dpkg_arch: "arm64" | |
| pkg_config_path: "/usr/lib/aarch64-linux-gnu/pkgconfig" | |
| - target: armv7-unknown-linux-gnueabihf | |
| name: armv7 | |
| linker: gcc-arm-linux-gnueabihf | |
| dpkg_arch: "armhf" | |
| pkg_config_path: "/usr/lib/arm-linux-gnueabihf/pkgconfig" | |
| defaults: | |
| run: | |
| working-directory: ${{ inputs.path }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust target | |
| run: rustup target add ${{ matrix.target }} | |
| - name: Setup Rust Cache | |
| uses: Swatinem/rust-cache@v2 | |
| with: | |
| workspaces: ${{ inputs.path }} | |
| - name: Map dynamic dependencies | |
| run: | | |
| # Map input dependencies based on the current matrix architecture | |
| if [ "${{ matrix.name }}" == "x86_64" ]; then | |
| echo "TARGET_DEPS=${{ inputs.deps_x86_64 }}" >> $GITHUB_ENV | |
| elif [ "${{ matrix.name }}" == "aarch64" ]; then | |
| echo "TARGET_DEPS=${{ inputs.deps_aarch64 }}" >> $GITHUB_ENV | |
| elif [ "${{ matrix.name }}" == "armv7" ]; then | |
| echo "TARGET_DEPS=${{ inputs.deps_armv7 }}" >> $GITHUB_ENV | |
| fi | |
| - name: Configure Multi-Arch repositories | |
| if: matrix.dpkg_arch != '' | |
| run: | | |
| # 1. Restrict current sources to amd64 only | |
| 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 | |
| # 2. Add ports server for arm64 and armhf | |
| OS_CODENAME=$(lsb_release -sc) | |
| echo "deb [arch=${{ matrix.dpkg_arch }}] http://ports.ubuntu.com/ubuntu-ports $OS_CODENAME main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/arm-ports.list | |
| echo "deb [arch=${{ matrix.dpkg_arch }}] http://ports.ubuntu.com/ubuntu-ports ${OS_CODENAME}-updates main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/arm-ports.list | |
| echo "deb [arch=${{ matrix.dpkg_arch }}] http://ports.ubuntu.com/ubuntu-ports ${OS_CODENAME}-security main restricted universe multiverse" | sudo tee -a /etc/apt/sources.list.d/arm-ports.list | |
| - name: Install cross-compilation tools | |
| if: matrix.linker != '' | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y ${{ matrix.linker }} | |
| - name: Install system dependencies per architecture | |
| if: env.TARGET_DEPS != '' | |
| run: | | |
| # Enable architecture in package manager | |
| if [ -n "${{ matrix.dpkg_arch }}" ]; then | |
| sudo dpkg --add-architecture ${{ matrix.dpkg_arch }} | |
| fi | |
| # Install deps and pkg-config to manage C bindings | |
| sudo apt-get update | |
| sudo apt-get install -y ${{ env.TARGET_DEPS }} pkg-config | |
| - name: Install packaging tools | |
| uses: taiki-e/install-action@v2 | |
| with: | |
| tool: cargo-deb,cargo-generate-rpm | |
| - name: Build for ${{ matrix.name }} | |
| run: cargo build --release --target ${{ matrix.target }} | |
| env: | |
| CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc | |
| CARGO_TARGET_ARMV7_UNKNOWN_LINUX_GNUEABIHF_LINKER: arm-linux-gnueabihf-gcc | |
| PKG_CONFIG_ALLOW_CROSS: 1 | |
| PKG_CONFIG_SYSROOT_DIR: / | |
| PKG_CONFIG_PATH: ${{ matrix.pkg_config_path }} | |
| - name: Generate DEB Package | |
| run: cargo deb --target ${{ matrix.target }} --no-build | |
| - name: Generate RPM Package | |
| run: cargo generate-rpm --target ${{ matrix.target }} | |
| - name: Get version | |
| id: get_version | |
| run: | | |
| VERSION=$(grep -m1 '^version = ' Cargo.toml | cut -d'"' -f2) | |
| echo "version=$VERSION" >> $GITHUB_ENV | |
| - name: Prepare Binary for upload | |
| run: | | |
| TARGET="target/${{ matrix.target }}/release" | |
| mv "$TARGET/${{ inputs.binary }}" "$TARGET/${{ inputs.binary }}-${{ matrix.name }}-v${{ env.version }}" | |
| # - name: Upload release assets | |
| # uses: softprops/action-gh-release@v2 | |
| # with: | |
| # tag_name: "v${{ env.version }}" | |
| # files: | | |
| # ${{ inputs.path }}/target/${{ matrix.target }}/debian/*.deb | |
| # ${{ inputs.path }}/target/${{ matrix.target }}/generate-rpm/*.rpm | |
| # ${{ inputs.path }}/target/${{ matrix.target }}/release/${{ inputs.binary }}-* |