Skip to content
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

feat: add package input to install packages #23

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Add `packages` input to install additional packages that can be build against. ([#23](https://github.com/taiki-e/setup-cross-toolchain-action/pull/23))

## [1.23.1] - 2024-08-11

- Fix build issue with 32-bit android targets on recent nightly due to [upstream change](https://github.com/rust-lang/rust/pull/120593). ([2068a2d](https://github.com/taiki-e/setup-cross-toolchain-action/commit/2068a2dd8a68fdcf653e4fa1312cbe24475ff07b))
Expand Down
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ GitHub Action for setup toolchains for cross compilation and cross testing for R

### Inputs

| Name | Required | Description | Type | Default |
|----------|:--------:|---------------|--------|----------------|
| target | **true** | Target triple | String | |
| runner | false | Test runner | String | |
| Name | Required | Description | Type | Default |
|----------|:--------:|---------------------|--------|---------|
| target | **true** | Target triple | String | |
| packages | false | Packages to install | String | |
| runner | false | Test runner | String | |

### Example workflow: Basic usage

Expand All @@ -60,6 +61,27 @@ jobs:
- run: ./target/aarch64-unknown-linux-gnu/debug/my-app
```

### Example workflow: Installing additional packages

```yaml
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust
run: rustup update stable
- name: Install cross-compilation tools
uses: taiki-e/setup-cross-toolchain-action@v1
with:
target: aarch64-unknown-linux-gnu
packages: libgbm-dev libxkbcommon-dev libinput-dev libudev-dev libseat-dev
- run: cargo build
```

> [!NOTE]
> The list of packages can be space seperated, comma seperated or newline seperated.

### Example workflow: Multiple targets

```yaml
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ inputs:
target:
description: Target name
required: true
packages:
description: Packages to install
required: false
runner:
description: Test runner
required: false
Expand All @@ -25,6 +28,7 @@ runs:
shell: bash
env:
INPUT_TARGET: ${{ inputs.target }}
INPUT_PACKAGES: ${{ inputs.packages }}
INPUT_RUNNER: ${{ inputs.runner }}
INPUT_QEMU: ${{ inputs.qemu }}
INPUT_WINE: ${{ inputs.wine }}
31 changes: 31 additions & 0 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ if [[ $# -gt 0 ]]; then
fi

target="${INPUT_TARGET:?}"
packages="${INPUT_PACKAGES:-}"
runner="${INPUT_RUNNER:-}"

host=$(rustc -vV | grep '^host:' | cut -d' ' -f2)
Expand Down Expand Up @@ -548,6 +549,7 @@ EOF
wine_root=/opt/wine-arm64
wine_exe="${wine_root}"/bin/wine
qemu_arch=aarch64
_sudo dpkg --add-architecture arm64
if [[ -n "${INPUT_WINE:-}" ]]; then
warn "specifying Wine version for aarch64 windows is not yet supported"
fi
Expand Down Expand Up @@ -764,6 +766,35 @@ EOF
register_binfmt qemu-user
fi

case "${target}" in
aarch64* | arm64*) dpkg_arch=arm64 ;;
arm* | thumb*) dpkg_arch=arm ;;
i?86-*) dpkg_arch=i386 ;;
hexagon-*) dpkg_arch=hexagon ;;
loongarch64-*) dpkg_arch=loongarch64 ;;
m68k-*) dpkg_arch=m68k ;;
mips-* | mipsel-*) dpkg_arch="${target%%-*}" ;;
mips64-* | mips64el-*) dpkg_arch="${target%%-*}" ;;
mipsisa32r6-* | mipsisa32r6el-*) dpkg_arch="${target%%-*}" ;;
mipsisa64r6-* | mipsisa64r6el-*) dpkg_arch="${target%%-*}" ;;
powerpc-*spe) dpkg_arch=ppc ;;
powerpc-*) dpkg_arch=ppc ;;
powerpc64-* | powerpc64le-*) dpkg_arch="${target%%-*}" ;;
riscv32*) dpkg_arch=riscv32 ;;
riscv64*) dpkg_arch=riscv64 ;;
s390x-*) dpkg_arch=s390x ;;
sparc-*) dpkg_arch=sparc ;;
sparc64-* | sparcv9-*) dpkg_arch=sparc64 ;;
x86_64*) dpkg_arch=amd64 ;;
*) bail "unrecognized target '${target}'" ;;
esac
Comment on lines +769 to +790
Copy link
Author

Choose a reason for hiding this comment

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

I don't actually know what the dpkg_arch should be for most of these... Not sure if this is the right strategy even.


while read -rd,; do
if [[ -n "${REPLY}" ]]; then
apt_packages+=("${REPLY}:${dpkg_arch}")
fi
done <<<"${packages//[$' \t\n']/,},"

install_apt_packages

case "${target}" in
Expand Down
Loading