Skip to content

Cross-compile binaries for aarch64-unknown-linux-gnu #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 40 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,20 @@ jobs:
strategy:
matrix:
os:
- ubuntu-latest
- windows-latest
- macos-latest

runs-on: ${{ matrix.os }}
- name: ubuntu-latest
cross_compile_os: linux
Copy link
Member

Choose a reason for hiding this comment

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

can we somehow infer this from matrix.os? maybe using uname or something?

cross_compile_target: aarch64-unknown-linux-gnu
- name: ubuntu-latest
cross_compile_os:
Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if we need to specify those... If we don't, surely ${{ }} expressions referencing those fields will fail?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I don't think we need to specify this. Can't say for sure though.

cross_compile_target:
- name: windows-latest
cross_compile_os:
cross_compile_target:
- name: macos-latest
cross_compile_os:
cross_compile_target:

runs-on: ${{ matrix.os.name }}

steps:
- uses: actions/checkout@v4
Expand All @@ -66,17 +75,34 @@ jobs:
- name: Setup PostgreSQL
uses: ikalnytskyi/action-setup-postgres@v6

- uses: actions-rs/cargo@v1
with:
command: build
args: --release
- run: |
if [ -z "${CROSS_COMPILE_TARGET}" ]; then
# normal build targetting the CPU architecture and the OS of the host
cargo build --release
else
# cross build with the specified rustc target
cargo install cross
cross build --release --target ${CROSS_COMPILE_TARGET}
fi
env:
CROSS_COMPILE_TARGET: ${{ matrix.os.cross_compile_target }}

- id: build
run: |
rustc --print cfg | grep = > rustc.vars
source rustc.vars
if [ -z "${CROSS_COMPILE_TARGET}" ]; then
# normal build targetting the CPU architecture and the OS of the host
rustc --print cfg | grep = > rustc.vars
Copy link
Member Author

Choose a reason for hiding this comment

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

Alternatively, we can get rid of calling rustc to set target_os and target_arch, and specify the values for both statically in the config.

source rustc.vars

pushd target/release
else
# cross build with the specified rustc target
export target_os=${CROSS_COMPILE_OS}
export target_arch=${CROSS_COMPILE_TARGET}

pushd target/${CROSS_COMPILE_TARGET}/release
fi

pushd target/release
if [ "$RUNNER_OS" == "Windows" ]; then
export ASSET_NAME="xsnippet-api-${target_arch}-${target_os}.exe.7z"
7z a $ASSET_NAME xsnippet-api.exe
Expand All @@ -89,6 +115,8 @@ jobs:

echo "asset_path=target/release/$ASSET_NAME" >> $GITHUB_OUTPUT
env:
CROSS_COMPILE_OS: ${{ matrix.os.cross_compile_os }}
CROSS_COMPILE_TARGET: ${{ matrix.os.cross_compile_target }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ env.GITHUB_REPOSITORY }}
RELEASE_TAG: ${{ needs.create_release.outputs.release_tag }}
Expand Down
5 changes: 5 additions & 0 deletions Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build]
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH",
"apt-get update && apt-get install --assume-yes libssl-dev:$CROSS_DEB_ARCH libpq-dev:$CROSS_DEB_ARCH"
]
Loading