From 80820a3fbbe1492cb3ebe5bf7231403da53ec7f2 Mon Sep 17 00:00:00 2001 From: Joshu <11015195+josh-tracey@users.noreply.github.com> Date: Sun, 25 May 2025 08:58:32 +0100 Subject: [PATCH 1/2] Delete .github/workflows/rust.yml --- .github/workflows/rust.yml | 104 ------------------------------------- 1 file changed, 104 deletions(-) delete mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml deleted file mode 100644 index 2c7f634..0000000 --- a/.github/workflows/rust.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: Rust - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -env: - CARGO_TERM_COLOR: always - -jobs: - release: - name: Release - ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }} - strategy: - matrix: - platform: - - os_name: Linux-x86_64 - os: ubuntu-20.04 - release_for: linux_x86_64 - target: x86_64-unknown-linux-musl - bin: ubi - name: ubi-Linux-x86_64-musl.tar.gz - cross: true - cargo_command: cargo - - toolchain: - - stable - - beta - - nightly - - runs-on: ${{ matrix.platform.os }} - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Install Buildroot Dependencies - run: | - sudo apt-get update - sudo apt-get install -y build-essential make ncurses-dev help2man - - - name: Configure and Build Sysroot with Buildroot - run: | - # Download Buildroot - git clone git://git.buildroot.net/buildroot - cd buildroot - make x86_64_musl_defconfig # Example configuration - customize this! - make - - - name: Configure Git and Set Sysroot - run: | - git config --global user.email "joshua.tracey08@gmail.com" - git config --global user.name "Joshua Tracey" - export PKG_CONFIG_SYSROOT_DIR=$PWD/output/host/usr/x86_64-linux-musl/sysroot - export PKG_CONFIG_ALLOW_CROSS=1 - - - name: Install tools - shell: bash - run: | - sudo apt install musl-tools libssl-dev - if: ${{ !contains(matrix.platform.os, 'macOS-latest') }} - - - name: Build binary - uses: houseabsolute/actions-rust-cross@v0 - with: - command: "build" - target: ${{ matrix.platform.target }} - toolchain: ${{ matrix.toolchain }} - args: "--locked --release" - strip: true - - - name: Package as archive - shell: bash - run: | - cd target/${{ matrix.platform.target }}/release - if [[ "${{ matrix.platform.os }}" == "windows-latest" ]]; then - 7z a ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }} - else - tar czvf ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }} - fi - cd - - - - name: Publish release artifacts - uses: actions/upload-artifact@v3 - with: - name: ubi-${{ matrix.platform.os_name }} - path: "ubi*" - if: github.ref == 'refs/tags/test-release' - - - name: Generate SHA-256 - run: shasum -a 256 ${{ matrix.platform.name }} - if: | - matrix.toolchain == 'stable' && - matrix.platform.os == 'macOS-latest' && - ( startsWith( github.ref, 'refs/tags/v' ) || - github.ref == 'refs/tags/test-release' ) - - - name: Publish GitHub release - uses: softprops/action-gh-release@v1 - with: - draft: true - files: "ubi*" - body_path: Changes.md - if: matrix.toolchain == 'stable' && startsWith( github.ref, 'refs/tags/v' ) From 099416c1a0db37a867a88a1af88f6a720eede355 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 25 May 2025 10:40:40 +0000 Subject: [PATCH 2/2] fix: Refine OpenSSL handling for macOS cross-architecture builds This commit significantly overhauls the OpenSSL dependency handling for macOS builds in the GitHub Actions release workflow, specifically addressing issues you encountered during cross-architecture compilation (e.g., building for x86_64 on an ARM64 runner). Key changes to the macOS steps: - Dynamically determines the target architecture (x86_64 or ARM64) for OpenSSL. - Uses `arch -x86_64` with Homebrew commands when targeting x86_64 to ensure the correct version of OpenSSL is installed and queried, utilizing Rosetta 2 on ARM64 runners. - Sets `OPENSSL_DIR` to the precise Homebrew prefix of the architecture-specific OpenSSL installation. - Sets target-specific environment variables (e.g., `X86_64_APPLE_DARWIN_OPENSSL_DIR`, `AARCH64_APPLE_DARWIN_OPENSSL_DIR`) that the `openssl-sys` crate explicitly checks. - Prepends the correct OpenSSL `lib/pkgconfig` directory to `PKG_CONFIG_PATH` to guide `pkg-config` if it's used. - Includes more robust error checking for Homebrew prefix resolution. These changes are intended to resolve persistent OpenSSL build failures on macOS by ensuring that the build process can reliably locate the appropriate OpenSSL libraries and headers for the specified target architecture. --- .github/workflows/release.yml | 96 +++++++++++++++++++++++++++---- .github/workflows/rust.yml | 104 ++++++++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/rust.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 7f5f6e9..14cfa1e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -65,24 +65,100 @@ jobs: sudo apt-get update sudo apt-get install -y gcc-aarch64-linux-gnu libssl-dev pkg-config - - name: Install OpenSSL (macOS) + - name: Install OpenSSL and Set Vars (macOS) if: runner.os == 'macOS' run: | - brew install openssl@3 - echo "OPENSSL_ROOT_DIR=$(brew --prefix openssl@3)" >> $GITHUB_ENV - echo "OPENSSL_LIB_DIR=$(brew --prefix openssl@3)/lib" >> $GITHUB_ENV - echo "LDFLAGS=-L$(brew --prefix openssl@3)/lib" >> $GITHUB_ENV - echo "CPPFLAGS=-I$(brew --prefix openssl@3)/include" >> $GITHUB_ENV - echo "PKG_CONFIG_PATH=$(brew --prefix openssl@3)/lib/pkgconfig" >> $GITHUB_ENV + OPENSSL_VERSION="openssl@3" # Or openssl@1.1 if needed + TARGET_ARCH_TUPLE="${{ matrix.platform.target }}" # e.g., x86_64-apple-darwin or aarch64-apple-darwin + + echo "Target architecture for OpenSSL: $TARGET_ARCH_TUPLE" + + # Determine Homebrew path and arch command based on GITHUB_RUNNER_ARCH and TARGET_ARCH_TUPLE + # GITHUB_RUNNER_ARCH will be X64 or ARM64 + # TARGET_ARCH_TUPLE is x86_64-apple-darwin or aarch64-apple-darwin + + BREW_CMD="" + ARCH_CMD="" + + if [[ "$TARGET_ARCH_TUPLE" == "x86_64-apple-darwin" ]]; then + echo "Configuring for x86_64 OpenSSL build." + # If runner is ARM, we need to use arch -x86_64 for an x86_64 brew. + # If runner is Intel, arch -x86_64 is benign. + ARCH_CMD="arch -x86_64" + # Standard Homebrew path for Intel installations, even on ARM runners under Rosetta + BREW_CMD="$ARCH_CMD /usr/local/bin/brew" + # Fallback for older setups or if /usr/local/bin/brew isn't the x86_64 one on an ARM machine. + # However, /usr/local/bin/brew *should* be the Rosetta one on Apple Silicon. + if ! $BREW_CMD --prefix $OPENSSL_VERSION > /dev/null 2>&1; then + # On an ARM runner, an x86_64 brew might also be found via a direct path if it was installed by a user script + # but the standard is /usr/local for Rosetta. + # Let's assume /usr/local/bin/brew invoked with arch -x86_64 is correct. + echo "Attempting to install OpenSSL for x86_64 via $BREW_CMD" + fi + else # aarch64-apple-darwin + echo "Configuring for aarch64 OpenSSL build." + # If runner is ARM, use native brew. + # If runner is Intel, this target cannot be built (cross-compilation aarch64-apple-darwin from Intel macOS is not standard). + # However, matrix.platform.target is aarch64-apple-darwin, so runner should be ARM macos-latest. + ARCH_CMD="" # Native architecture + BREW_CMD="/opt/homebrew/bin/brew" # Standard for ARM64 Homebrew + if ! command -v $BREW_CMD > /dev/null 2>&1; then + # Fallback if /opt/homebrew/bin/brew is not found (e.g. Intel runner, though matrix should prevent this) + BREW_CMD="brew" + fi + echo "Attempting to install OpenSSL for aarch64 via $BREW_CMD" + fi + + $ARCH_CMD $BREW_CMD install $OPENSSL_VERSION + OPENSSL_PREFIX=$($ARCH_CMD $BREW_CMD --prefix $OPENSSL_VERSION) + + echo "OpenSSL prefix: $OPENSSL_PREFIX" + if [ -z "$OPENSSL_PREFIX" ] || [ ! -d "$OPENSSL_PREFIX/lib" ]; then + echo "::error::Failed to get Homebrew prefix or lib directory for $OPENSSL_VERSION with target $TARGET_ARCH_TUPLE using $BREW_CMD" + echo "Attempting to find openssl installation path manually..." + # Common paths + if [[ "$TARGET_ARCH_TUPLE" == "x86_64-apple-darwin" ]]; then + if [ -d "/usr/local/opt/$OPENSSL_VERSION" ]; then OPENSSL_PREFIX="/usr/local/opt/$OPENSSL_VERSION"; fi + else # aarch64 + if [ -d "/opt/homebrew/opt/$OPENSSL_VERSION" ]; then OPENSSL_PREFIX="/opt/homebrew/opt/$OPENSSL_VERSION"; fi + fi + echo "Manual OpenSSL prefix: $OPENSSL_PREFIX" + if [ -z "$OPENSSL_PREFIX" ] || [ ! -d "$OPENSSL_PREFIX/lib" ]; then + echo "::error::Still could not find OpenSSL prefix. Please check Homebrew setup and OpenSSL installation for $TARGET_ARCH_TUPLE." + exit 1 + fi + fi + + echo "OPENSSL_DIR=$OPENSSL_PREFIX" >> $GITHUB_ENV + echo "PKG_CONFIG_PATH=$OPENSSL_PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV # Prepend to existing + + # Set target-specific variables that openssl-sys crate checks + # (e.g., X86_64_APPLE_DARWIN_OPENSSL_DIR) + TARGET_ARCH_ENV_PREFIX=$(echo "$TARGET_ARCH_TUPLE" | tr '[:lower:]-' '[:upper:]_') + echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_DIR=$OPENSSL_PREFIX" >> $GITHUB_ENV + echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_LIB_DIR=$OPENSSL_PREFIX/lib" >> $GITHUB_ENV + echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_INCLUDE_DIR=$OPENSSL_PREFIX/include" >> $GITHUB_ENV + # Also set the generic ones as a fallback + echo "OPENSSL_LIB_DIR=$OPENSSL_PREFIX/lib" >> $GITHUB_ENV + echo "OPENSSL_INCLUDE_DIR=$OPENSSL_PREFIX/include" >> $GITHUB_ENV + - name: Verify OpenSSL Env Vars (macOS) if: runner.os == 'macOS' run: | - echo "OPENSSL_ROOT_DIR is: $OPENSSL_ROOT_DIR" + echo "OPENSSL_DIR is: $OPENSSL_DIR" echo "OPENSSL_LIB_DIR is: $OPENSSL_LIB_DIR" - echo "LDFLAGS is: $LDFLAGS" - echo "CPPFLAGS is: $CPPFLAGS" + echo "OPENSSL_INCLUDE_DIR is: $OPENSSL_INCLUDE_DIR" echo "PKG_CONFIG_PATH is: $PKG_CONFIG_PATH" + TARGET_ARCH_TUPLE="${{ matrix.platform.target }}" + TARGET_ARCH_ENV_PREFIX=$(echo "$TARGET_ARCH_TUPLE" | tr '[:lower:]-' '[:upper:]_') + echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_DIR is: $(printenv ${TARGET_ARCH_ENV_PREFIX}_OPENSSL_DIR)" + echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_LIB_DIR is: $(printenv ${TARGET_ARCH_ENV_PREFIX}_OPENSSL_LIB_DIR)" + echo "${TARGET_ARCH_ENV_PREFIX}_OPENSSL_INCLUDE_DIR is: $(printenv ${TARGET_ARCH_ENV_PREFIX}_OPENSSL_INCLUDE_DIR)" + echo "Listing $OPENSSL_DIR/lib/pkgconfig:" + ls -l "$OPENSSL_DIR/lib/pkgconfig" || echo "pkgconfig directory not found or OpenSSL_DIR not set." + echo "Contents of openssl.pc (if found):" + cat "$OPENSSL_DIR/lib/pkgconfig/openssl.pc" || echo "openssl.pc not found." - name: Build binary run: cargo build --release --locked --target ${{ matrix.platform.target }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml new file mode 100644 index 0000000..2c7f634 --- /dev/null +++ b/.github/workflows/rust.yml @@ -0,0 +1,104 @@ +name: Rust + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +env: + CARGO_TERM_COLOR: always + +jobs: + release: + name: Release - ${{ matrix.platform.os_name }} with rust ${{ matrix.toolchain }} + strategy: + matrix: + platform: + - os_name: Linux-x86_64 + os: ubuntu-20.04 + release_for: linux_x86_64 + target: x86_64-unknown-linux-musl + bin: ubi + name: ubi-Linux-x86_64-musl.tar.gz + cross: true + cargo_command: cargo + + toolchain: + - stable + - beta + - nightly + + runs-on: ${{ matrix.platform.os }} + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install Buildroot Dependencies + run: | + sudo apt-get update + sudo apt-get install -y build-essential make ncurses-dev help2man + + - name: Configure and Build Sysroot with Buildroot + run: | + # Download Buildroot + git clone git://git.buildroot.net/buildroot + cd buildroot + make x86_64_musl_defconfig # Example configuration - customize this! + make + + - name: Configure Git and Set Sysroot + run: | + git config --global user.email "joshua.tracey08@gmail.com" + git config --global user.name "Joshua Tracey" + export PKG_CONFIG_SYSROOT_DIR=$PWD/output/host/usr/x86_64-linux-musl/sysroot + export PKG_CONFIG_ALLOW_CROSS=1 + + - name: Install tools + shell: bash + run: | + sudo apt install musl-tools libssl-dev + if: ${{ !contains(matrix.platform.os, 'macOS-latest') }} + + - name: Build binary + uses: houseabsolute/actions-rust-cross@v0 + with: + command: "build" + target: ${{ matrix.platform.target }} + toolchain: ${{ matrix.toolchain }} + args: "--locked --release" + strip: true + + - name: Package as archive + shell: bash + run: | + cd target/${{ matrix.platform.target }}/release + if [[ "${{ matrix.platform.os }}" == "windows-latest" ]]; then + 7z a ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }} + else + tar czvf ../../../${{ matrix.platform.name }} ${{ matrix.platform.bin }} + fi + cd - + + - name: Publish release artifacts + uses: actions/upload-artifact@v3 + with: + name: ubi-${{ matrix.platform.os_name }} + path: "ubi*" + if: github.ref == 'refs/tags/test-release' + + - name: Generate SHA-256 + run: shasum -a 256 ${{ matrix.platform.name }} + if: | + matrix.toolchain == 'stable' && + matrix.platform.os == 'macOS-latest' && + ( startsWith( github.ref, 'refs/tags/v' ) || + github.ref == 'refs/tags/test-release' ) + + - name: Publish GitHub release + uses: softprops/action-gh-release@v1 + with: + draft: true + files: "ubi*" + body_path: Changes.md + if: matrix.toolchain == 'stable' && startsWith( github.ref, 'refs/tags/v' )