From f0f477bee46cd62c803518e3289a1c7e4c32f8f5 Mon Sep 17 00:00:00 2001 From: Jack Jennings Date: Mon, 20 Jan 2025 22:01:18 -0800 Subject: [PATCH] Switch to GitHub Actions for compiling binaries --- .github/actions/compile.sh | 29 ++++++ .github/actions/cross-compile/action.yml | 41 ++++++++ .github/actions/install-cross-dependencies.sh | 29 ++++++ .github/workflows/release.yml | 42 +++++++++ .github/workflows/test.yml | 33 +++++++ .gitignore | 3 + .travis.yml | 93 ------------------- ci/before_deploy.sh | 32 ------- ci/install.sh | 27 ------ ci/script.sh | 23 ----- src/main.rs | 4 +- 11 files changed, 179 insertions(+), 177 deletions(-) create mode 100755 .github/actions/compile.sh create mode 100644 .github/actions/cross-compile/action.yml create mode 100755 .github/actions/install-cross-dependencies.sh create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml delete mode 100644 .travis.yml delete mode 100644 ci/before_deploy.sh delete mode 100644 ci/install.sh delete mode 100644 ci/script.sh diff --git a/.github/actions/compile.sh b/.github/actions/compile.sh new file mode 100755 index 0000000..1509903 --- /dev/null +++ b/.github/actions/compile.sh @@ -0,0 +1,29 @@ +NAME=hell + +# Set an output prefix, which is the local directory if not specified +PREFIX=$(pwd) + +# Set the build dir, where built cross-compiled binaries will be output +BUILDDIR=${PREFIX}/cross + +# These are chosen from: https://doc.rust-lang.org/nightly/rustc/platform-support.html +if [[ $(uname) = "Darwin" ]]; then + CROSS_TARGETS=("x86_64-apple-darwin" "aarch64-apple-darwin") +else + CROSS_TARGETS=("x86_64-pc-windows-gnu" "x86_64-unknown-linux-musl" "aarch64-unknown-linux-musl") +fi + +mkdir -p "$BUILDDIR" + +compile() { + rustup target add $1 + cargo build --release --target $1 || cross build --release --target $1 + mv "./target/$1/release/$NAME" "$BUILDDIR/$NAME-$1" || mv "./target/$1/release/$NAME.exe" "$BUILDDIR/$NAME-$1" + md5sum "$BUILDDIR/$NAME-$1" > "$BUILDDIR/$NAME-$1.md5" + sha256sum "$BUILDDIR/$NAME-$1" > "$BUILDDIR/$NAME-$1.sha256" +} + +for target in "${CROSS_TARGETS[@]}" +do + compile $target +done diff --git a/.github/actions/cross-compile/action.yml b/.github/actions/cross-compile/action.yml new file mode 100644 index 0000000..880ef8e --- /dev/null +++ b/.github/actions/cross-compile/action.yml @@ -0,0 +1,41 @@ +name: TK +description: TK + +inputs: + os: + description: OS; either macos or ubuntu + +runs: + using: "composite" + steps: + - name: Install latest nightly + uses: dtolnay/rust-toolchain@stable + - if: ${{ matrix.os == 'ubuntu' }} + name: Install Linux dependencies + shell: bash + run: ./.github/actions/install-cross-dependencies.sh + - if: ${{ matrix.os == 'macos' }} + name: Install macOS dependencies + shell: bash + run: brew install coreutils + - name: Cache cargo registry + uses: actions/cache@v4 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + - name: Cache cargo index + uses: actions/cache@v4 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} + - name: Cache cargo build + uses: actions/cache@v4 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + - name: Run make cross + run: | + export PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" + ./.github/actions/compile.sh + ls -la cross + shell: bash diff --git a/.github/actions/install-cross-dependencies.sh b/.github/actions/install-cross-dependencies.sh new file mode 100755 index 0000000..6e25511 --- /dev/null +++ b/.github/actions/install-cross-dependencies.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -e +set -o pipefail + +# Install our deps. +sudo apt update -y && sudo apt install -y \ + ca-certificates \ + clang \ + cmake \ + curl \ + g++ \ + gcc \ + gcc-mingw-w64-i686 \ + gcc-mingw-w64 \ + jq \ + libmpc-dev \ + libmpfr-dev \ + libgmp-dev \ + libssl-dev \ + libxml2-dev \ + mingw-w64 \ + wget \ + zlib1g-dev + +# We need this for the version. +cargo install toml-cli + +# Install cross. +cargo install cross diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..c5378e5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,42 @@ +on: + push: + tags: + - "v*.*.*" +permissions: + contents: write +name: release +jobs: + compile: + strategy: + matrix: + os: [macos, ubuntu] + name: releases for ${{ matrix.os }} + runs-on: ${{ matrix.os }}-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/cross-compile + with: + os: ${{ matrix.os }} + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: release-${{ matrix.os }}-${{ github.ref_name }} + path: ./cross + release: + runs-on: ubuntu-latest + needs: + - compile + steps: + - uses: actions/checkout@v4 + - uses: actions/download-artifact@v4 + with: + name: release-macos-${{ github.ref_name }} + path: build + - uses: actions/download-artifact@v4 + with: + name: release-ubuntu-${{ github.ref_name }} + path: build + - name: Create a Release + uses: softprops/action-gh-release@v2 + with: + files: ./build/* diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..291ea04 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,33 @@ +on: + push: + branches: + - main + paths: + - "**.rs" + - Cargo.toml + - Cargo.lock + - .github/workflows/cross-compile.yml + - rust-toolchain.toml + pull_request: + paths: + - "**.rs" + - Cargo.toml + - Cargo.lock + - .github/workflows/cross-compile.yml + - rust-toolchain.toml +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true +name: test +jobs: + compile: + strategy: + matrix: + os: [macos, ubuntu] + name: compile + runs-on: ${{ matrix.os }}-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/cross-compile + with: + os: ${{ matrix.os }} diff --git a/.gitignore b/.gitignore index 53b6275..aefa48f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,6 @@ /Hellfile.py /Pipfile* + +/cross +/.vscode \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 07e06a6..0000000 --- a/.travis.yml +++ /dev/null @@ -1,93 +0,0 @@ -# Based on the "trust" template v0.1.2 -# https://github.com/japaric/trust/tree/v0.1.2 - -dist: trusty -language: rust -services: docker -sudo: required - -env: - global: - - CRATE_NAME=hell - -matrix: - include: - # Linux - # - env: TARGET=aarch64-unknown-linux-gnu - # - env: TARGET=arm-unknown-linux-gnueabi - # - env: TARGET=armv7-unknown-linux-gnueabihf - # - env: TARGET=i686-unknown-linux-gnu - # - env: TARGET=i686-unknown-linux-musl - # - env: TARGET=mips-unknown-linux-gnu - # - env: TARGET=mips64-unknown-linux-gnuabi64 - # - env: TARGET=mips64el-unknown-linux-gnuabi64 - # - env: TARGET=mipsel-unknown-linux-gnu - # - env: TARGET=powerpc-unknown-linux-gnu - # - env: TARGET=powerpc64-unknown-linux-gnu - # - env: TARGET=powerpc64le-unknown-linux-gnu - # - env: TARGET=s390x-unknown-linux-gnu DISABLE_TESTS=1 - - env: TARGET=x86_64-unknown-linux-gnu - - env: TARGET=x86_64-unknown-linux-musl - - # OSX - # - env: TARGET=i686-apple-darwin - # os: osx - - env: TARGET=x86_64-apple-darwin - os: osx - - # *BSD - # - env: TARGET=i686-unknown-freebsd DISABLE_TESTS=1 - # - env: TARGET=x86_64-unknown-freebsd DISABLE_TESTS=1 - # - env: TARGET=x86_64-unknown-netbsd DISABLE_TESTS=1 - - # Windows - # - env: TARGET=x86_64-pc-windows-gnu - - # Testing other channels - - env: TARGET=x86_64-unknown-linux-gnu - rust: nightly - - env: TARGET=x86_64-apple-darwin - os: osx - rust: nightly - -before_install: - - set -e - - rustup self update - -install: - - sh ci/install.sh - - source ~/.cargo/env || true - -script: - - bash ci/script.sh - -after_script: set +e - -before_deploy: - - sh ci/before_deploy.sh - -deploy: - api_key: - secure: LOm5Q49UNEwXzITCrRh/f6J9qXPybakMROusUxAiikjpyByY/Clq3jhSRe7Bl8mz+6ilk+PydkQzD4gr+1ddsTxfoSuEDlH9vGt7CAyamfqCkGFM7eIBr61yKOQ6jpQSg8rt83K+OMZqcQzvGE82QJLa3gJWbT/Oxb+G2B1dA1BBSXJ72mfPMKdwmxh7XgdiAxO3GIU99SG42eqZej1e6xffz3cBTIqPb0/gatHjwPCPLOSWRyu/SK9M2vdVKGnqvKCwyaI1f+C4ljmzCQ3PMj0gvUI9wiw2VqtuIw0fF/cRK23fXhWkHCJU1/1TUi4FRvlq54f+Mm+WfrcJEjL1yrFEQ5PqDG7HZUIKRe3l9yqPslcfT/iK3es7I6Cba8/ubN4ib8N2saBQZHqIvgMznvmg99d+Dd1jBbCcCb2rj2MCAVG0fnhfAj0kI5UgHKK0RH0PjCuNeo3Zys2W3l7dmYCxKVdXIWrXgeXzEh6+IC2ciKVTNeUJ4tuIzZkCg65d63gzf5Vl4ab+CLpEXOU/DQN6BrOx8KIvXlgeNGhNf8zqCleDu3u0cHJuxxlW4p15NO/LjTQmmDMNOfgkHHvs7fyFAE/FYgKnLAQAOuhOXxvRmYKuv8FD/D0qojV1dLyMnFkRlNTnwh4XTXCT44gHmyWKC3KZJeo1vQdrONkzvig= - file_glob: true - file: $CRATE_NAME-$TRAVIS_TAG-$TARGET.* - on: - condition: $TRAVIS_RUST_VERSION = stable - tags: true - provider: releases - skip_cleanup: true - -cache: cargo -before_cache: - # Travis can't cache files that are not readable by "others" - - chmod -R a+r $HOME/.cargo - -branches: - only: - # release tags - - /^v\d+\.\d+\.\d+.*$/ - - master - -notifications: - email: - on_success: never diff --git a/ci/before_deploy.sh b/ci/before_deploy.sh deleted file mode 100644 index 1a4e2f9..0000000 --- a/ci/before_deploy.sh +++ /dev/null @@ -1,32 +0,0 @@ -# This script takes care of building your crate and packaging it for release - -set -ex - -main() { - local src=$(pwd) \ - stage= - - case $TRAVIS_OS_NAME in - linux) - stage=$(mktemp -d) - ;; - osx) - stage=$(mktemp -d -t tmp) - ;; - esac - - test -f Cargo.lock || cargo generate-lockfile - - cross rustc --bin hell --target $TARGET --release -- -C lto - - # TODO Update this to package the right artifacts - cp target/$TARGET/release/hell $stage/ - - cd $stage - tar czf $src/$CRATE_NAME-$TRAVIS_TAG-$TARGET.tar.gz * - cd $src - - rm -rf $stage -} - -main diff --git a/ci/install.sh b/ci/install.sh deleted file mode 100644 index bbf0a58..0000000 --- a/ci/install.sh +++ /dev/null @@ -1,27 +0,0 @@ -set -ex - -main() { - local target= - if [ $TRAVIS_OS_NAME = linux ]; then - target=x86_64-unknown-linux-musl - sort=sort - else - target=x86_64-apple-darwin - sort=gsort # for `sort --sort-version`, from brew's coreutils. - fi - - # This fetches latest stable release - local tag=$(git ls-remote --tags --refs --exit-code https://github.com/rust-embedded/cross \ - | cut -d/ -f3 \ - | grep -E '^v[0.1.0-9.]+$' \ - | $sort --version-sort \ - | tail -n1) - curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- \ - --force \ - --git rust-embedded/cross \ - --tag $tag \ - --target $target -} - -main diff --git a/ci/script.sh b/ci/script.sh deleted file mode 100644 index e41ec57..0000000 --- a/ci/script.sh +++ /dev/null @@ -1,23 +0,0 @@ -# This script takes care of testing your crate - -set -ex - -main() { - cross build --target $TARGET - cross build --target $TARGET --release - - if [ ! -z $DISABLE_TESTS ]; then - return - fi - - cross test --target $TARGET - cross test --target $TARGET --release - - cross run --target $TARGET -- --version - cross run --target $TARGET --release -- --version -} - -# we don't run the "test phase" when doing deploys -if [ -z $TRAVIS_TAG ]; then - main -fi diff --git a/src/main.rs b/src/main.rs index e3786e0..9bef44f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -98,8 +98,8 @@ fn handle_init<'a>(environment: Environment) -> Result { eprintln!("init will now happen"); create_pipfile() - .and_then({ |_| install_package(&environment.hellbox_package) }) - .and_then({ |_| create_manifest(&environment.manifest_filename) }) + .and_then(|_| install_package(&environment.hellbox_package)) + .and_then(|_| create_manifest(&environment.manifest_filename)) } fn handle_install<'a>(_environment: Environment) -> Result {