Skip to content

Commit

Permalink
Use espup (#16)
Browse files Browse the repository at this point in the history
* refactor: ♻️ Use espup instead of rust-build script

* chore: 🎨 Add name to step

* refactor: ♻️ Avoid using install.sh

* chore: 🔥 Remove install.sh

* docs: 📝 Update readme

* refactor: ♻️ Use curl with header argument

* ci: 🐛 Fix permission issues

* ci: 🐛 Add shell property
  • Loading branch information
SergioGasquez authored Dec 20, 2022
1 parent b7ce3a9 commit 0b7f70e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 63 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: ./
name: Install Xtensa Rust
with:
default: true
ldproxy: false
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ jobs:
| `buildtargets` | Comma separated list of targets | string | _all_ |
| `version` | Which version of the toolchain to install | string | _latest_ |
| `ldproxy` | Whether to install `ldproxy` (required for `std`) | bool | `true` |
| `override` | Overrides the installed toolchain | bool | `true` |
| `override` | Overrides the installed toolchain | bool | `true` |


All inputs are optional; if no inputs are provided:

- the Rust compiler fork with Xtensa support will **NOT** be set as the default (but is usable via the `+esp` toolchain specifier)
- all available build targets will be installed
- the latest available version of the compiler will be installed
- [ldproxy](https://github.com/ivmarkov/embuild) **WILL** be installed; this is required for `std`, however installing it significantly increases the total run time of this action
- [ldproxy](https://github.com/ivmarkov/embuild) **WILL** be installed; this is required for `std`

## License

Expand Down
21 changes: 13 additions & 8 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@ inputs:
runs:
using: composite
steps:
- name: Install latest stable
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: ${{ inputs.override }}
- name: Install ldproxy
if: inputs.ldproxy
shell: bash
run: |
curl -L https://github.com/esp-rs/embuild/releases/latest/download/ldproxy-x86_64-unknown-linux-gnu.zip -o $HOME/.cargo/bin/ldproxy.zip
unzip "$HOME/.cargo/bin/ldproxy.zip" -d "$HOME/.cargo/bin/"
chmod a+x $HOME/.cargo/bin/ldproxy
- name: Install espup
shell: bash
run: |
curl -L https://github.com/esp-rs/espup/releases/latest/download/espup-x86_64-unknown-linux-gnu -o $HOME/.cargo/bin/espup
chmod a+x $HOME/.cargo/bin/espup
- name: Install Xtensa toolchain
shell: bash
run: |
[[ "${{ inputs.ldproxy }}" = true ]] && crates="ldproxy" || crates=""
${{ github.action_path }}/install.sh "$crates" ${{ inputs.version }} ${{ inputs.buildtargets }}
bash ${{ github.action_path }}/install.sh ${{ inputs.buildtargets }} ${{ inputs.version }}
[[ "${{ inputs.default }}" = true ]] && rustup default esp || true
[[ "${{ inputs.override }}" = true ]] && rustup override unset || true
75 changes: 22 additions & 53 deletions install.sh
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@

set -eu


RE_VERSION="^[0-9]+\.[0-9]+(\.[0-9]+)?(\.[0-9]+)?$"

function check_version_formatting() {
if [[ ! "${1}" =~ $RE_VERSION ]];
then
if [[ ! "${1}" =~ $RE_VERSION ]]; then
echo "ERROR: version number is not correctly formatted: ${1}"
exit 1
fi
Expand All @@ -19,76 +17,47 @@ function format_version() {
# The number of iterations to perform is 3 (the maximum occurences of '.' in
# a version string) minus the number of occurences of '.' already present in
# the version string.
res=${ver//[^.]}
res=${ver//[^.]/}
iters=$((3 - ${#res}))

# Append '.0' to the version string $iters number of times to create a
# version string which matches the release tags.
for ((i = 0; i < iters; i++));
do
for ((i = 0; i < iters; i++)); do
ver="${ver}.0"
done

echo "$ver"
}

function latest_version() {
curl -s https://api.github.com/repos/esp-rs/rust-build/releases \
| jq -r "map(select(.prerelease | not)) | map(.tag_name) | first" \
| sed -e "s/^v//"
curl -s https://api.github.com/repos/esp-rs/rust-build/releases -H 'Authorization: $GITHUB_TOKEN' |
jq -r "map(select(.prerelease | not)) | map(.tag_name) | first" |
sed -e "s/^v//"
}


# Download and execute the installation script from the esp-rs/rust-build
# repository: https://github.com/esp-rs/rust-build
#
# This installs not only the Rust compiler fork with support for the Xtensa
# architecture but also the required Xtensa toolchain binaries. We save the
# required exports to a file for later processing, to handle around some
# weirdness with GitHub runners (see below for details). If a version number
# formatted following (our extended version of) semver is provided, attempt to
# install that version of the compiler.

crates="${1:-}"
buildtargets="${1:-all}"
version="${2:-latest}"
buildtargets="${3:-all}"

case $version in
latest)
version=$(latest_version)
;;
latest)
version=$(latest_version)
;;

*)
version=$(format_version "$version")
;;
*)
version=$(format_version "$version")
;;
esac

check_version_formatting "$version"

curl \
-L "https://github.com/esp-rs/rust-build/releases/download/v$version/install-rust-toolchain.sh" \
-o "$HOME/install-rust-toolchain.sh"

chmod +x "$HOME/install-rust-toolchain.sh"

function install_rust_toolchain() {
"$HOME/install-rust-toolchain.sh" \
--export-file "$HOME/exports" \
--extra-crates "$crates" \
--build-target "${buildtargets}" \
"@"
}

case $version in
latest)
install_rust_toolchain
;;

*)
install_rust_toolchain --toolchain-version "$version"
;;
esac
# This installs not only the Rust compiler fork with support for the Xtensa
# architecture but also the required Xtensa toolchain binaries. We save the
# required exports to a file for later processing, to handle around some
# weirdness with GitHub runners (see below for details). If a version number
# formatted following (our extended version of) semver is provided, attempt to
# install that version of the compiler.

$HOME/.cargo/bin/espup install -l debug --export-file $HOME/exports --targets ${buildtargets} --toolchain-version $version

# With the required exports specified by the rust-build installation script
# saved to a file, we can simply `source` it to export said variables. GitHub
Expand All @@ -98,5 +67,5 @@ esac

#shellcheck source=/dev/null
source "$HOME/exports"
echo "$PATH" >> "$GITHUB_PATH"
echo "LIBCLANG_PATH=${LIBCLANG_PATH}" >> "$GITHUB_ENV"
echo "$PATH" >>"$GITHUB_PATH"
echo "LIBCLANG_PATH=${LIBCLANG_PATH}" >>"$GITHUB_ENV"

0 comments on commit 0b7f70e

Please sign in to comment.