Skip to content

Add armhf cross-compilation support via candidate-armhf branch#119

Merged
lengau merged 13 commits intocandidate-armhffrom
copilot/fix-29598503-600908950-27c070ae-41cf-49b6-a772-dcc7c48042d6
Dec 6, 2025
Merged

Add armhf cross-compilation support via candidate-armhf branch#119
lengau merged 13 commits intocandidate-armhffrom
copilot/fix-29598503-600908950-27c070ae-41cf-49b6-a772-dcc7c48042d6

Conversation

Copy link
Copy Markdown

Copilot AI commented Nov 3, 2025

Summary: candidate-armhf branch for cross-compilation

This PR implements the changes needed for a candidate-armhf branch that enables cross-compilation for armhf architecture on arm64 build machines. The implementation follows the same approach used in the uv snap at https://github.com/lengau/uv-snap/.

Completed Tasks

  • Create branch configuration for armhf cross-compilation
  • Modify snapcraft.yaml to enable armhf cross-compilation
    • Add package-repositories for ARM ports
    • Update platforms section to build armhf on arm64/amd64
    • Add build-environment variables for static musl binary
    • Add required build-packages (clang-20, musl-dev, gcc-arm-linux-gnueabihf, libc6-dev-armhf-cross, etc.)
    • Add override-build section to install Rust target and handle binary placement
  • Address code review feedback
    • Remove unused arm64/ppc64el conditional settings (not relevant for armhf-only branch)
    • Use explicit package name 'libc6-dev-armhf-cross' instead of variable
    • Make install command specific to ruff binary only
  • Fix build failure issues
    • Removed organize/stage sections to avoid conflict with default rust plugin installation
    • Updated override-build to install directly to bin/ruff path
    • Corrected package-repositories to use target architecture ($CRAFT_ARCH_BUILD_FOR) matching uv-snap
  • Add CI workflows for candidate-armhf branch
    • pull-request.yaml: Build-only workflow on arm64 (testing not possible during cross-compilation)
    • release-to-candidate-armhf.yaml: Release armhf snap and test on armhf runners
    • sync-to-armhf.yaml: Auto-sync changes from candidate to candidate-armhf branch
  • Validate YAML syntax
  • Pass security checks

Key Configuration Changes

  1. Package Repositories: Added Ubuntu ARM ports repository configuration for target architecture (armhf)
  2. Platforms: Configured armhf-only platform with cross-compilation support from arm64/amd64
  3. Build Environment:
    • CARGO_BUILD_TARGET: armv7-unknown-linux-musleabihf (static musl target)
    • CARGO_TARGET_ARMV7_UNKNOWN_LINUX_MUSLEABIHF_LINKER: rust-lld
    • CARGO_CFG_TARGET_FEATURE: crt-static
    • CC: clang-20
    • CARGO_PROFILE_RELEASE_LTO: "off"
  4. Build Packages: Added cross-compilation toolchain (clang-20, musl-dev, musl-tools, gcc-arm-linux-gnueabihf, libc6-dev-armhf-cross, cmake, libclang-20-dev)
  5. Override Build: Custom script to install Rust target and place binary directly to bin/ruff (avoiding conflicts with default rust plugin)
  6. CI Workflows: Streamlined workflows that build on arm64
    • pull-request.yaml: Build-only workflow on arm64 (ubuntu-24.04-arm) - tests removed since cross-compiled armhf binaries cannot run on arm64
    • release-to-candidate-armhf.yaml: Triggers on pushes to candidate-armhf, releases armhf snap to store and runs tests on armhf runners after release
    • sync-to-armhf.yaml: Triggers on pushes to candidate, automatically syncs changes to candidate-armhf branch

How This Solves the Memory Issue

The original issue (#117) was that building armhf natively ran out of memory. This solution:

  1. Cross-compiles from arm64 machines which have more memory
  2. Builds a static binary using musl (avoids enable-patchelf build-attribute uses ld for the build-on host, not the build-for host canonical/snapcraft#5836)
  3. Uses the same proven approach as the uv snap

Branch Management

⚠️ Note: This PR is currently targeting the candidate branch. The base branch should be changed to candidate-armhf through the GitHub UI. Once merged to candidate-armhf, the sync-to-armhf workflow will keep it synchronized with updates from the main candidate branch.

Latest Changes

Removed the test step from the PR workflow since we're cross-compiling armhf binaries on arm64 runners. The armhf binaries cannot be tested on arm64. Testing will occur in the release workflow after the snap is published to the store, where it can be installed and tested on actual armhf hardware.

Original prompt

This section details on the original issue you should resolve

<issue_title>[Bug]: armhf build running out of memory</issue_title>
<issue_description>### What happened?

ruff is running out of memory when trying to build the armhf snap

What should have happened?

...

Output of snap info $snap_name

...

Output of snap connections $snap_name

...

Output of snap version

...

Relevant log output

...

Teminal output of app

```</issue_description>

<agent_instructions>Create a candidate-armhf branch for the ruff snap that cross-compiles on an arm64 machine using a similar method as was used in the uv snap at https://github.com/lengau/uv-snap/</agent_instructions>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits November 3, 2025 09:37
Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
@lengau lengau requested a review from Copilot November 3, 2025 09:45
Copilot AI changed the title [WIP] [Bug]: armhf build running out of memory Add armhf cross-compilation support via candidate-armhf branch Nov 3, 2025
Copilot AI requested a review from lengau November 3, 2025 09:45
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR configures the ruff snap for armhf cross-compilation to resolve out-of-memory build failures on armhf architecture. The solution builds armhf binaries on arm64/amd64 machines with more available memory, using a static musl binary approach proven in the uv snap.

Key changes:

  • Configured armhf-only platform with cross-compilation from arm64/amd64 build hosts
  • Added Ubuntu ARM ports repository and cross-compilation toolchain packages
  • Implemented static musl binary build using armv7-unknown-linux-musleabihf target with custom override-build script

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@lengau
Copy link
Copy Markdown
Contributor

lengau commented Nov 3, 2025

…ion path

Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 3, 2025

@copilot fix the build issue from https://github.com/snapcrafters/ruff/actions/runs/19030236464/job/54342989050?pr=119

Fixed in cf7f88d. The build was failing because:

  1. Package repository used $CRAFT_ARCH_BUILD_FOR (armhf) instead of $CRAFT_ARCH_BUILD_ON (arm64/amd64) - we need packages for the build host
  2. Binary installation conflicted with the default rust plugin - removed organize/stage sections and install directly to bin/ruff

The changes now match the working uv-snap approach more closely.

@lengau
Copy link
Copy Markdown
Contributor

lengau commented Nov 3, 2025

@copilot snap/snapcraft.yaml:35 should be using the target architecture, not the build host architecture

Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 3, 2025

@copilot snap/snapcraft.yaml:35 should be using the target architecture, not the build host architecture

Corrected in 51601f1. Changed back to $CRAFT_ARCH_BUILD_FOR to match the uv-snap implementation - the ports repository provides packages for the target ARM architecture (armhf), not the build host.

@lengau
Copy link
Copy Markdown
Contributor

lengau commented Nov 3, 2025

@copilot this should:

  1. target the candidate-armhf branch, not the candidate branch
  2. Change the CI for this branch so we're building on arm64 and testing on armhf

Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 3, 2025

@copilot this should:

  1. target the candidate-armhf branch, not the candidate branch
    ...

Added CI workflows for candidate-armhf in 3fa051d:

  • pull-request-armhf.yaml: Builds on arm64 for PRs to candidate-armhf
  • release-to-candidate-armhf.yaml: Releases armhf snap and tests on armhf
  • sync-to-armhf.yaml: Auto-syncs candidate → candidate-armhf

However, I cannot change the PR base branch from candidate to candidate-armhf - that needs to be done through the GitHub UI by clicking "Edit" next to the PR title and changing the base branch dropdown.

@lengau lengau changed the base branch from candidate to candidate-armhf November 3, 2025 10:21
@lengau lengau marked this pull request as ready for review November 3, 2025 10:28
@lengau lengau marked this pull request as draft November 3, 2025 10:28
@lengau lengau changed the base branch from candidate-armhf to candidate November 3, 2025 10:28
@lengau
Copy link
Copy Markdown
Contributor

lengau commented Nov 3, 2025

@copilot Add a step to the PR workflow that runs the tests

Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 3, 2025

@copilot Revert the last commit

Reverted in 25055f2. The PR trigger for candidate-armhf branch has been removed from the release-to-candidate workflow, restoring it to its previous state.

Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 3, 2025

@copilot Add a step to the PR workflow that runs the tests

Added in 5d840f5. Both PR workflows now include a test step that runs ./test.sh after building the snap using the snapcrafters/ci/run-tests@main action.

@lengau
Copy link
Copy Markdown
Contributor

lengau commented Nov 3, 2025

@copilot on this branch we should only build on arm, not on amd64

Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 3, 2025

@copilot on this branch we should only build on arm, not on amd64

Updated in d9b10fb. The pull-request.yaml workflow now builds only on arm64 (ubuntu-24.04-arm), removing the amd64 matrix build that was previously included.

@lengau
Copy link
Copy Markdown
Contributor

lengau commented Nov 3, 2025

@copilot merge the pull-request and pull-request-armhf workflows

Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 3, 2025

@copilot merge the pull-request and pull-request-armhf workflows

Merged in 7b422ba. The pull-request-armhf.yaml workflow has been removed, and pull-request.yaml now serves as the unified workflow for all PR branches, building on arm64 and running tests.

@lengau
Copy link
Copy Markdown
Contributor

lengau commented Nov 4, 2025

@copilot why isn't it getting the PR number?

Run actions/github-script@v7
  with:
    script: const fs = require('node:fs');
  const summary = fs.readFileSync('test-output.txt', 'utf8');
  github.rest.issues.createComment({
    issue_number: ,
    owner: context.repo.owner,
    repo: context.repo.repo,
    body: `Automated testing skipped.
  
    Full logs are available at https://github.com/snapcrafters/ruff/actions/runs/19032494926. The first 100, and last 100 lines of the log are displayed in the Summary below.
  
    <details><summary>Logs</summary>
  
    \`\`\`
    ${summary}
    \`\`\`
  
    </details>
    `
  })
  
    github-token: ***
    debug: false
    user-agent: actions/github-script
    result-encoding: json
    retries: 0
    retry-exempt-status-codes: 400,401,403,404,422
SyntaxError: Unexpected token ','
    at new AsyncFunction (<anonymous>)
    at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:36187:16)
    at main (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:36285:26)
    at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:36260:1
    at /home/runner/work/_actions/actions/github-script/v7/dist/index.js:36317:3
    at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v7/dist/index.js:36320:12)
    at Module._compile (node:internal/modules/cjs/loader:1521:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1623:10)
    at Module.load (node:internal/modules/cjs/loader:1266:32)
    at Module._load (node:internal/modules/cjs/loader:1091:12)

Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Nov 4, 2025

@copilot why isn't it getting the PR number?

...

Fixed in becb75d. The test workflow was missing issue-number and github-token inputs. Added issue-number: ${{ github.event.pull_request.number }} and github-token: ${{ secrets.GITHUB_TOKEN }} to provide the PR context needed by the run-tests action.

os: [ubuntu-latest, ubuntu-24.04-arm]
runs-on: ${{ matrix.os }}
build-and-test:
name: 🧪 Build and test snap
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this won't work because it's cross-compiling.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0079328. Removed the test step from the PR workflow since cross-compiled armhf binaries cannot run on the arm64 build runner. The workflow now only builds the snap to validate compilation. Testing will occur in the release workflow where the snap can be tested on actual armhf hardware.

Co-authored-by: lengau <4305943+lengau@users.noreply.github.com>
Copilot AI requested a review from lengau December 5, 2025 23:06
@lengau lengau merged commit 53b0fd5 into candidate-armhf Dec 6, 2025
1 check passed
@lengau lengau deleted the copilot/fix-29598503-600908950-27c070ae-41cf-49b6-a772-dcc7c48042d6 branch December 6, 2025 02:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: armhf build running out of memory

3 participants