From 672f4470832151d1b6eaef15906494f622ff4da3 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Wed, 6 Dec 2023 17:36:15 -0600 Subject: [PATCH] compiling --- .editorconfig | 11 +++- .github/workflows/release.yml | 10 +++ .github/workflows/rtx.yml | 4 ++ scripts/build-deb.sh | 40 ++++++------ scripts/build-rpm.sh | 40 ++++++------ scripts/build-tarball.sh | 108 ++++++++++++++++--------------- scripts/pre-release-hook.sh | 4 +- scripts/publish-s3.sh | 6 +- scripts/release-npm.sh | 72 ++++++++++----------- scripts/render-homebrew.sh | 24 +++---- scripts/render-install.sh | 24 +++---- scripts/setup-zipsign.sh | 4 +- scripts/update-shorthand-repo.sh | 32 ++++----- 13 files changed, 200 insertions(+), 179 deletions(-) diff --git a/.editorconfig b/.editorconfig index 7ff8aed42..ac106646c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,11 @@ -[*.sh] -indent_style = tab +[*.toml] +indent_style = space +indent_size = 2 -[Cargo.toml] +[*.sh] indent_style = space indent_size = 2 + +# shfmt +switch_case_indent = true +simplify = true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dda6b691d..ac7b9b394 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -63,8 +63,18 @@ jobs: name: macos-arm64 target: aarch64-apple-darwin runs-on: macos-12 + - os: macos + name: macos + target: universal2-apple-darwin + runs-on: macos-12 steps: - uses: actions/checkout@v4 + - run: | + brew install zig + rustup target add x86_64-apple-darwin + rustup target add aarch64-apple-darwin + cargo install cargo-zigbuild + if: matrix.target == 'universal2-apple-darwin' - run: sudo apt-get update; sudo apt-get install musl-tools if: matrix.runs-on == 'buildjet-4vcpu-ubuntu-2204-arm' - run: rustup target add ${{matrix.target}} diff --git a/.github/workflows/rtx.yml b/.github/workflows/rtx.yml index 875f5e9d4..d2a33be6c 100644 --- a/.github/workflows/rtx.yml +++ b/.github/workflows/rtx.yml @@ -47,6 +47,10 @@ jobs: if: github.event_name == 'pull_request' steps: - uses: actions/checkout@v4 + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + ref: ${{ github.event.pull_request.head.ref }} + - uses: Swatinem/rust-cache@v2 with: shared-key: test diff --git a/scripts/build-deb.sh b/scripts/build-deb.sh index 9182978fa..dca75d3c7 100755 --- a/scripts/build-deb.sh +++ b/scripts/build-deb.sh @@ -8,29 +8,29 @@ touch rtx/lib/.disable-self-update tar -xvJf "dist/rtx-$RTX_VERSION-linux-x64.tar.xz" fpm -s dir -t deb \ - --name rtx \ - --license MIT \ - --version "${RTX_VERSION#v*}" \ - --architecture amd64 \ - --description "Polyglot runtime manager" \ - --url "https://github.com/jdx/rtx" \ - --maintainer "Jeff Dickey @jdx" \ - rtx/bin/rtx=/usr/bin/rtx \ - rtx/lib/.disable-self-update=/usr/lib/rtx/.disable-self-update \ - rtx/man/man1/rtx.1=/usr/share/man/man1/rtx.1 + --name rtx \ + --license MIT \ + --version "${RTX_VERSION#v*}" \ + --architecture amd64 \ + --description "Polyglot runtime manager" \ + --url "https://github.com/jdx/rtx" \ + --maintainer "Jeff Dickey @jdx" \ + rtx/bin/rtx=/usr/bin/rtx \ + rtx/lib/.disable-self-update=/usr/lib/rtx/.disable-self-update \ + rtx/man/man1/rtx.1=/usr/share/man/man1/rtx.1 tar -xvJf "dist/rtx-$RTX_VERSION-linux-arm64.tar.xz" fpm -s dir -t deb \ - --name rtx \ - --license MIT \ - --version "${RTX_VERSION#v*}" \ - --architecture arm64 \ - --description "Polyglot runtime manager" \ - --url "https://github.com/jdx/rtx" \ - --maintainer "Jeff Dickey @jdx" \ - rtx/bin/rtx=/usr/bin/rtx \ - rtx/lib/.disable-self-update=/usr/lib/rtx/.disable-self-update \ - rtx/man/man1/rtx.1=/usr/share/man/man1/rtx.1 + --name rtx \ + --license MIT \ + --version "${RTX_VERSION#v*}" \ + --architecture arm64 \ + --description "Polyglot runtime manager" \ + --url "https://github.com/jdx/rtx" \ + --maintainer "Jeff Dickey @jdx" \ + rtx/bin/rtx=/usr/bin/rtx \ + rtx/lib/.disable-self-update=/usr/lib/rtx/.disable-self-update \ + rtx/man/man1/rtx.1=/usr/share/man/man1/rtx.1 mkdir -p dist/deb/pool/main cp -v ./*.deb dist/deb/pool/main diff --git a/scripts/build-rpm.sh b/scripts/build-rpm.sh index e2ae06555..5ae865985 100755 --- a/scripts/build-rpm.sh +++ b/scripts/build-rpm.sh @@ -8,29 +8,29 @@ touch rtx/lib/.disable-self-update tar -xvJf "dist/rtx-$RTX_VERSION-linux-x64.tar.xz" fpm -s dir -t rpm \ - --name rtx \ - --license MIT \ - --version "${RTX_VERSION#v*}" \ - --architecture x86_64 \ - --description "Polyglot runtime manager" \ - --url "https://github.com/jdx/rtx" \ - --maintainer "Jeff Dickey @jdx" \ - rtx/bin/rtx=/usr/bin/rtx \ - rtx/lib/.disable-self-update=/usr/lib/rtx/.disable-self-update \ - rtx/man/man1/rtx.1=/usr/share/man/man1/rtx.1 + --name rtx \ + --license MIT \ + --version "${RTX_VERSION#v*}" \ + --architecture x86_64 \ + --description "Polyglot runtime manager" \ + --url "https://github.com/jdx/rtx" \ + --maintainer "Jeff Dickey @jdx" \ + rtx/bin/rtx=/usr/bin/rtx \ + rtx/lib/.disable-self-update=/usr/lib/rtx/.disable-self-update \ + rtx/man/man1/rtx.1=/usr/share/man/man1/rtx.1 tar -xvJf "dist/rtx-$RTX_VERSION-linux-arm64.tar.xz" fpm -s dir -t rpm \ - --name rtx \ - --license MIT \ - --version "${RTX_VERSION#v*}" \ - --architecture aarch64 \ - --description "Polyglot runtime manager" \ - --url "https://github.com/jdx/rtx" \ - --maintainer "Jeff Dickey @jdx" \ - rtx/bin/rtx=/usr/bin/rtx \ - rtx/lib/.disable-self-update=/usr/lib/rtx/.disable-self-update \ - rtx/man/man1/rtx.1=/usr/share/man/man1/rtx.1 + --name rtx \ + --license MIT \ + --version "${RTX_VERSION#v*}" \ + --architecture aarch64 \ + --description "Polyglot runtime manager" \ + --url "https://github.com/jdx/rtx" \ + --maintainer "Jeff Dickey @jdx" \ + rtx/bin/rtx=/usr/bin/rtx \ + rtx/lib/.disable-self-update=/usr/lib/rtx/.disable-self-update \ + rtx/man/man1/rtx.1=/usr/share/man/man1/rtx.1 cat <~/.rpmmacros %_signature gpg diff --git a/scripts/build-tarball.sh b/scripts/build-tarball.sh index c641fdafa..7ad62ebcf 100755 --- a/scripts/build-tarball.sh +++ b/scripts/build-tarball.sh @@ -2,72 +2,72 @@ set -euo pipefail error() { - echo "$@" >&2 - exit 1 + echo "$@" >&2 + exit 1 } NAME="$1" shift for arg in "$@"; do - if [ "${next_target:-}" = 1 ]; then - next_target= - TARGET="$arg" - continue - fi - case "$arg" in - --target) - next_target=1 - ;; - *) ;; + if [ "${next_target:-}" = 1 ]; then + next_target= + TARGET="$arg" + continue + fi + case "$arg" in + --target) + next_target=1 + ;; + *) ;; - esac + esac done RUST_TRIPLE=${TARGET:-$(rustc -vV | grep ^host: | cut -d ' ' -f2)} #region os/arch get_os() { - case "$RUST_TRIPLE" in - *-apple-darwin*) - echo "macos" - ;; - *-linux-*) - echo "linux" - ;; - *) - error "unsupported OS: $RUST_TRIPLE" - ;; - esac + case "$RUST_TRIPLE" in + *-apple-darwin*) + echo "macos" + ;; + *-linux-*) + echo "linux" + ;; + *) + error "unsupported OS: $RUST_TRIPLE" + ;; + esac } get_arch() { - case "$RUST_TRIPLE" in - aarch64-*) - echo "arm64" - ;; - arm-*) - echo "armv6" - ;; - armv7-*) - echo "armv7" - ;; - x86_64-*) - echo "x64" - ;; - *) - error "unsupported arch: $RUST_TRIPLE" - ;; - esac + case "$RUST_TRIPLE" in + aarch64-*) + echo "arm64" + ;; + arm-*) + echo "armv6" + ;; + armv7-*) + echo "armv7" + ;; + x86_64-*) + echo "x64" + ;; + *) + error "unsupported arch: $RUST_TRIPLE" + ;; + esac } get_suffix() { - case "$RUST_TRIPLE" in - *-musl | *-musleabi | *-musleabihf) - echo "-musl" - ;; - *) - echo "" - ;; - esac + case "$RUST_TRIPLE" in + *-musl | *-musleabi | *-musleabihf) + echo "-musl" + ;; + *) + echo "" + ;; + esac } #endregion @@ -76,9 +76,11 @@ VERSION=$(./scripts/get-version.sh) BASENAME=$NAME-$VERSION-$(get_os)-$(get_arch)$(get_suffix) if command -v cross >/dev/null; then - cross build "$@" + cross build "$@" +elif command -v zig >/dev/null; then + cargo zigbuild "$@" else - cargo build "$@" + cargo build "$@" fi mkdir -p dist/rtx/bin mkdir -p dist/rtx/man/man1 @@ -94,8 +96,8 @@ tar -cJf "$BASENAME.tar.xz" rtx tar -czf "$BASENAME.tar.gz" rtx if [ -f ~/.zipsign/rtx.priv ]; then - zipsign sign tar "$BASENAME.tar.gz" ~/.zipsign/rtx.priv - zipsign verify tar "$BASENAME.tar.gz" ../zipsign.pub + zipsign sign tar "$BASENAME.tar.gz" ~/.zipsign/rtx.priv + zipsign verify tar "$BASENAME.tar.gz" ../zipsign.pub fi ls -oh "$BASENAME.tar.xz" diff --git a/scripts/pre-release-hook.sh b/scripts/pre-release-hook.sh index e1fd6adf6..4e051d9ad 100755 --- a/scripts/pre-release-hook.sh +++ b/scripts/pre-release-hook.sh @@ -2,9 +2,9 @@ set -euxo pipefail if [[ "${NO_UPDATE:-}" == "1" ]]; then - echo "NO_UPDATE is set, skipping update" + echo "NO_UPDATE is set, skipping update" else - cargo update && git add Cargo.lock + cargo update && git add Cargo.lock fi just render-mangen render-help diff --git a/scripts/publish-s3.sh b/scripts/publish-s3.sh index f63d25893..4852411ee 100755 --- a/scripts/publish-s3.sh +++ b/scripts/publish-s3.sh @@ -26,6 +26,6 @@ aws s3 cp artifacts/deb/dists/ "s3://$AWS_S3_BUCKET/deb/dists/" --cache-control export CLOUDFLARE_ACCOUNT_ID=6e243906ff257b965bcae8025c2fc344 export CLOUDFLARE_ZONE_ID=80d977fd09f01db52bec165778088891 curl --fail-with-body -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/purge_cache" \ - -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ - -H "Content-Type: application/json" \ - --data '{ "purge_everything": true }' + -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \ + -H "Content-Type: application/json" \ + --data '{ "purge_everything": true }' diff --git a/scripts/release-npm.sh b/scripts/release-npm.sh index dc5890241..773a92d1d 100755 --- a/scripts/release-npm.sh +++ b/scripts/release-npm.sh @@ -2,52 +2,52 @@ set -euxo pipefail error() { - echo "$@" >&2 - exit 1 + echo "$@" >&2 + exit 1 } if [[ -z "${NODE_AUTH_TOKEN:-}" ]]; then - echo "NODE_AUTH_TOKEN must be set" >&2 - exit 0 + echo "NODE_AUTH_TOKEN must be set" >&2 + exit 0 fi mkdir -p "$RELEASE_DIR/npm" dist_tag_from_version() { - IFS="-" read -r -a version_split <<<"$1" - IFS="." read -r -a version_split <<<"${version_split[1]:-latest}" - echo "${version_split[0]}" + IFS="-" read -r -a version_split <<<"$1" + IFS="." read -r -a version_split <<<"${version_split[1]:-latest}" + echo "${version_split[0]}" } dist_tag="$(dist_tag_from_version "$RTX_VERSION")" platforms=( - linux-x64 - linux-x64-musl - linux-arm64 - linux-arm64-musl - linux-armv6 - linux-armv6-musl - linux-armv7 - linux-armv7-musl - macos-x64 - macos-arm64 + linux-x64 + linux-x64-musl + linux-arm64 + linux-arm64-musl + linux-armv6 + linux-armv6-musl + linux-armv7 + linux-armv7-musl + macos-x64 + macos-arm64 ) for platform in "${platforms[@]}"; do - # shellcheck disable=SC2206 - platform_split=(${platform//-/ }) - os="${platform_split[0]}" - arch="${platform_split[1]}" - - if [[ "$os" == "macos" ]]; then - os="darwin" - fi - - cp "$RELEASE_DIR/$RTX_VERSION/rtx-$RTX_VERSION-$platform.tar.gz" "$RELEASE_DIR/rtx-latest-$platform.tar.gz" - cp "$RELEASE_DIR/$RTX_VERSION/rtx-$RTX_VERSION-$platform.tar.xz" "$RELEASE_DIR/rtx-latest-$platform.tar.xz" - tar -xzvf "$RELEASE_DIR/rtx-latest-$platform.tar.gz" -C "$RELEASE_DIR" - rm -rf "$RELEASE_DIR/npm" - mv "$RELEASE_DIR/rtx" "$RELEASE_DIR/npm" - cat <"$RELEASE_DIR/npm/package.json" + # shellcheck disable=SC2206 + platform_split=(${platform//-/ }) + os="${platform_split[0]}" + arch="${platform_split[1]}" + + if [[ "$os" == "macos" ]]; then + os="darwin" + fi + + cp "$RELEASE_DIR/$RTX_VERSION/rtx-$RTX_VERSION-$platform.tar.gz" "$RELEASE_DIR/rtx-latest-$platform.tar.gz" + cp "$RELEASE_DIR/$RTX_VERSION/rtx-$RTX_VERSION-$platform.tar.xz" "$RELEASE_DIR/rtx-latest-$platform.tar.xz" + tar -xzvf "$RELEASE_DIR/rtx-latest-$platform.tar.gz" -C "$RELEASE_DIR" + rm -rf "$RELEASE_DIR/npm" + mv "$RELEASE_DIR/rtx" "$RELEASE_DIR/npm" + cat <"$RELEASE_DIR/npm/package.json" { "name": "$NPM_PREFIX-$os-$arch", "version": "$RTX_VERSION", @@ -68,10 +68,10 @@ for platform in "${platforms[@]}"; do "cpu": "$arch" } EOF - pushd "$RELEASE_DIR/npm" - tree || true - npm publish --access public --tag "$dist_tag" - popd + pushd "$RELEASE_DIR/npm" + tree || true + npm publish --access public --tag "$dist_tag" + popd done cat <"$RELEASE_DIR/npm/installArchSpecificPackage.js" diff --git a/scripts/render-homebrew.sh b/scripts/render-homebrew.sh index 3e297ac65..51c1e85aa 100755 --- a/scripts/render-homebrew.sh +++ b/scripts/render-homebrew.sh @@ -3,15 +3,15 @@ set -euxo pipefail # shellcheck disable=SC2016 RTX_VERSION=${RTX_VERSION#v*} \ - RTX_CHECKSUM_LINUX_X86_64=$(grep "rtx-v$RTX_VERSION-linux-x64.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - RTX_CHECKSUM_LINUX_X86_64_MUSL=$(grep "rtx-v$RTX_VERSION-linux-x64-musl.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - RTX_CHECKSUM_LINUX_ARM64=$(grep "rtx-v$RTX_VERSION-linux-arm64.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - RTX_CHECKSUM_LINUX_ARM64_MUSL=$(grep "rtx-v$RTX_VERSION-linux-arm64-musl.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - RTX_CHECKSUM_LINUX_ARMV6=$(grep "rtx-v$RTX_VERSION-linux-armv6.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - RTX_CHECKSUM_LINUX_ARMV6_MUSL=$(grep "rtx-v$RTX_VERSION-linux-armv6-musl.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - RTX_CHECKSUM_LINUX_ARMV7=$(grep "rtx-v$RTX_VERSION-linux-armv7.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - RTX_CHECKSUM_LINUX_ARMV7_MUSL=$(grep "rtx-v$RTX_VERSION-linux-armv7-musl.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - RTX_CHECKSUM_MACOS_X86_64=$(grep "rtx-v$RTX_VERSION-macos-x64.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - RTX_CHECKSUM_MACOS_ARM64=$(grep "rtx-v$RTX_VERSION-macos-arm64.tar.xz" "$RELEASE_DIR/v$RTX_VERSION/SHASUMS256.txt" | cut -d ' ' -f1) \ - envsubst '$RTX_VERSION,$RTX_CHECKSUM_LINUX_X86_64,$RTX_CHECKSUM_LINUX_ARM64,$RTX_CHECKSUM_MACOS_X86_64,$RTX_CHECKSUM_MACOS_ARM64' \ - >src/default_shorthands.rs + plugin=$(basename "$file") + repository=$(cat "$file") + repository="${repository/#repository = /}" + echo " (\"$plugin\", \"$repository\")," >>src/default_shorthands.rs done echo " // rtx custom shorthands" >>src/default_shorthands.rs for plugin in "${custom_plugins[@]}"; do - echo " $plugin" >>src/default_shorthands.rs + echo " $plugin" >>src/default_shorthands.rs done echo "];" >>src/default_shorthands.rs rm -rf asdf-plugins