chore: use cross to build binaries (#507)

This commit is contained in:
Lifei Zhou
2025-01-02 16:53:37 +11:00
committed by GitHub
parent 6573147d63
commit a27a753e41
4 changed files with 147 additions and 48 deletions
+16 -46
View File
@@ -17,73 +17,43 @@ jobs:
strategy:
fail-fast: false
matrix:
include:
# Linux x86_64 build on Ubuntu
- os: ubuntu-latest
architecture: x86_64
suffix: unknown-linux-gnu
# TODO: Linux aarch64 (ARM64) build on Ubuntu via cross-compilation - probably use `cross-rs`
# macOS x86_64 build
- os: macos-latest
architecture: x86_64
suffix: apple-darwin
# macOS ARM64 build
- os: macos-latest
architecture: aarch64
suffix: apple-darwin
os: [ ubuntu-latest, macos-latest ]
architecture: [ aarch64, x86_64 ]
include:
- os: ubuntu-latest
target-suffix: unknown-linux-gnu
- os: macos-latest
target-suffix: apple-darwin
steps:
# Step 1: Checkout the code
- name: Checkout code
uses: actions/checkout@v4
# Step 2: Set up Rust toolchain
# This will install the specified target as per matrix
- name: Set up Rust toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
uses: actions-rs/toolchain@v1
with:
target: ${{ matrix.architecture }}-${{ matrix.suffix }}
toolchain: stable
# Step 3: Install dependencies for macOS ARM64 builds
- name: Install dependencies for macOS ARM64
if: matrix.os == 'macos-latest' && matrix.architecture == 'aarch64'
- name: build
run: |
brew install llvm
rustup target add aarch64-apple-darwin
echo "export PATH=$(brew --prefix llvm)/bin:\$PATH" >> $GITHUB_ENV
# Step 4: Install Libs for Ubuntu (x86_64 and aarch64)
- name: Install Libs for Ubuntu
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt update -y
sudo apt install -y libdbus-1-dev gnome-keyring libxcb1-dev
gnome-keyring-daemon --components=secrets --daemonize --unlock <<< 'foobar'
# Step 5: Build the project
- name: Build
run: |
export TARGET=${{ matrix.architecture }}-${{ matrix.suffix }}
cargo build --release --target $TARGET
export TARGET=${{ matrix.architecture }}-${{ matrix.target-suffix }}
rustup target add "${TARGET}"
cargo install cross --git https://github.com/cross-rs/cross
CROSS_NO_WARNINGS=0 cross build --release --target ${TARGET}
cd target/${TARGET}/release
tar -cjf goose-${TARGET}.tar.bz2 goose goosed
echo "ARTIFACT=target/${TARGET}/release/goose-${TARGET}.tar.bz2" >> $GITHUB_ENV
# Step 6: Upload artifacts
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: goose-${{ matrix.architecture }}-${{ matrix.suffix }}
name: goose-${{ matrix.architecture }}-${{ matrix.target-suffix }}
path: ${{ env.ARTIFACT }}
release:
name: Release
runs-on: ubuntu-latest
needs: [build]
needs: [ build ]
permissions:
contents: write
steps:
+19
View File
@@ -0,0 +1,19 @@
[target.aarch64-unknown-linux-gnu]
xargo = false
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH && apt-get update --fix-missing && apt-get install --assume-yes libxcb1-dev:$CROSS_DEB_ARCH libdbus-1-dev:$CROSS_DEB_ARCH",
]
# If you run the build on your local machine,
# This is a workaround for the missing pkg-config path on aarch64
# You also need to add pkg-config:$CROSS_DEB_ARCH to the apt-get install command above
#[target.aarch64-unknown-linux-gnu.env]
#passthrough = ["PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig"]
# If you run the build on your local machine,
# You need to add pkg-config:$CROSS_DEB_ARCH to the apt-get install command below
[target.x86_64-unknown-linux-gnu]
xargo = false
pre-build = [
"dpkg --add-architecture $CROSS_DEB_ARCH && apt-get update --fix-missing && apt-get install --assume-yes libxcb1-dev:$CROSS_DEB_ARCH libdbus-1-dev:$CROSS_DEB_ARCH",
]
+2 -2
View File
@@ -50,7 +50,7 @@ sha2 = "0.10"
base64 = "0.21"
url = "2.5"
urlencoding = "2.1.3"
axum = { version = "0.7" }
axum = "0.7"
tower-http = { version = "0.5", features = ["cors"] }
webbrowser = "0.8"
dotenv = "0.15"
@@ -84,4 +84,4 @@ path = "examples/databricks_oauth.rs"
[[bench]]
name = "tokenization_benchmark"
harness = false
harness = false
+110
View File
@@ -0,0 +1,110 @@
# Instructions for running cross to test release builds locally
## Prerequisites
Before start, check the comments in `Cross.toml` to turn on some commented configs for the target you want to build.
## Targets
### aarch64-unknown-linux-gnu
#### Build release
```sh
CROSS_BUILD_OPTS="--platform linux/amd64 --no-cache" CROSS_CONTAINER_OPTS="--platform linux/amd64" cross build --release --target aarch64-unknown-linux-gnu
```
#### Inspect container created by cross for debugging
```sh
docker run --platform linux/amd64 -it <image-id> /bin/bash
```
#### Testing the binary
1. Download docker image for testing environment
```sh
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker pull arm64v8/ubuntu
```
2. Run the container
pwd is the directory contains the binary built in the previous step on your host machine
```sh
docker run -v $(pwd):/app -it arm64v8/ubuntu /bin/bash
```
3. Install dependencies in the container and set up api testing environment
```sh
apt update
apt install libxcb1 libxcb1-dev libdbus-1-3 nvi
mkdir -p ~/.config/goose
# create goose config file
# set api key env variable
```
### x86_64-unknown-linux-gnu
#### Build release
```sh
CROSS_BUILD_OPTS="--platform linux/amd64 --no-cache" CROSS_CONTAINER_OPTS="--platform linux/amd64" cross build --release --target x86_64-unknown-linux-gnu
```
#### inspect container created by cross for debugging
```sh
docker run --platform linux/amd64 -it <image-id> /bin/bash
```
#### Testing the binary
1. Download docker image for testing environment
```sh
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
docker pull --platform linux/amd64 debian:latest
```
2. Run the container
pwd is the directory contains the binary built in the previous step on your host machine
```sh
docker run --platform linux/amd64 -it -v "$(pwd)":/app debian:latest /bin/bash
```
3. Install dependencies in the container and set up api testing environment
```sh
apt update
apt install libxcb1 libxcb1-dev libdbus-1-3 nvi
mkdir -p ~/.config/goose
# create goose config file
# set api key env variable
```
### aarch64-apple-darwin
#### build release
```sh
cross build --release --target aarch64-apple-darwin
```
There is no docker image available for aarch64-apple-darwin. It will fall back to your host machine for building the binary if your host machine matches.
#### testing the build
If the binary is signed with a certificate, run
```sh
xattr -d com.apple.quarantine goose
````
### x86_64-apple-darwin
#### build release
```sh
cross build --release --target x86_64-apple-darwin
```
There is no docker image available for x86_64-apple-darwin. It will fall back to your host machine for building the binary if your host machine matches.
#### testing the build
1. If the binary is signed with a certificate, run
```sh
xattr -d com.apple.quarantine goose
````
2. If you are on Apple Silicon (ARM), you can use Rosetta to test the binary
```sh
softwareupdate --install-rosetta # make sure Rosetta 2 is installed
```
```sh
arch -x86_64 ./goose help
```