From a47febce2cbaabc8e0572729319745f0c5955566 Mon Sep 17 00:00:00 2001 From: Diemo Gebhardt Date: Tue, 26 Nov 2024 05:08:57 +0100 Subject: [PATCH] Refactor all --- bin/ci-verify-binary-architecture.sh | 72 ----------------------- bin/release-verify-binary-architecture.sh | 72 ----------------------- 2 files changed, 144 deletions(-) delete mode 100755 bin/ci-verify-binary-architecture.sh delete mode 100755 bin/release-verify-binary-architecture.sh diff --git a/bin/ci-verify-binary-architecture.sh b/bin/ci-verify-binary-architecture.sh deleted file mode 100755 index f6e3b520edc..00000000000 --- a/bin/ci-verify-binary-architecture.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash -set -xeuo pipefail - -if [ $# -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi -TARGET_TRIPLE="$1" - -BINARY_PATH="${CARGO_HOME}/bin/gleam" -if [[ "${TARGET_TRIPLE}" == *"windows"* ]]; then - BINARY_PATH="${BINARY_PATH}.exe" -fi - -# Parse target architecture -case "${TARGET_TRIPLE}" in - "x86_64"*) TARGET_ARCHITECTURE="x86_64" ;; - "aarch64"*) TARGET_ARCHITECTURE="aarch64" ;; - *) echo "Unknown target architecture '${TARGET_TRIPLE}'"; exit 1 ;; -esac - -# Parse binary architecture and expected binary architecture for OS -case "${TARGET_TRIPLE}" in - *"darwin"*) - file_output=$(file -b "${BINARY_PATH}") - BINARY_ARCHITECTURE=$(echo "${file_output}" | grep -o "x86_64\|arm64" || echo "") - case "${TARGET_ARCHITECTURE}" in - "x86_64") EXPECTED_BINARY_ARCHITECTURE="x86_64" ;; - "aarch64") EXPECTED_BINARY_ARCHITECTURE="arm64" ;; - *) echo "Unknown Darwin architecture: '${TARGET_ARCHITECTURE}'"; exit 1 ;; - esac - ;; - *"linux"*) - file_output=$(file -b "${BINARY_PATH}") - BINARY_ARCHITECTURE=$(echo "${file_output}" | grep -o "x86-64\|aarch64" | head -n1 || echo "") - case "${TARGET_ARCHITECTURE}" in - "x86_64") EXPECTED_BINARY_ARCHITECTURE="x86-64" ;; - "aarch64") EXPECTED_BINARY_ARCHITECTURE="aarch64" ;; - *) echo "Unknown Linux architecture: '${TARGET_ARCHITECTURE}'"; exit 1 ;; - esac - ;; - *"windows"*) - pe_header_output=$(powershell -Command " - \$bytes = [System.IO.File]::ReadAllBytes('${BINARY_PATH}'); - \$header_offset = [System.BitConverter]::ToInt32(\$bytes, 0x3c); - \$machine_type = [System.BitConverter]::ToUInt16(\$bytes, \$header_offset + 4); - \$machine_type - " 2>&1) || echo "PE header extraction failed" - case "${pe_header_output}" in - *"34404"*) BINARY_ARCHITECTURE="X64" ;; # 0x8664 - *"43620"*) BINARY_ARCHITECTURE="Arm64" ;; # 0xAA64 - *) echo "Unknown PE machine type: '${pe_header_output}'"; exit 1 ;; - esac - case "${TARGET_ARCHITECTURE}" in - "x86_64") EXPECTED_BINARY_ARCHITECTURE="X64" ;; - "aarch64") EXPECTED_BINARY_ARCHITECTURE="Arm64" ;; - *) echo "Unknown Windows architecture: '${TARGET_ARCHITECTURE}'"; exit 1 ;; - esac - ;; - *) - echo "Unknown target OS: '${TARGET_TRIPLE}'" - exit 1 - ;; -esac - -# Verify binary architecture -if [[ "${BINARY_ARCHITECTURE}" != "${EXPECTED_BINARY_ARCHITECTURE}" ]]; then - echo "Architecture mismatch for '${TARGET_TRIPLE}'" - echo "Expected: '${EXPECTED_BINARY_ARCHITECTURE}'" - echo "Got: '${BINARY_ARCHITECTURE}'" - exit 1 -fi diff --git a/bin/release-verify-binary-architecture.sh b/bin/release-verify-binary-architecture.sh deleted file mode 100755 index 2326701d5b7..00000000000 --- a/bin/release-verify-binary-architecture.sh +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env bash -set -xeuo pipefail - -if [ $# -ne 1 ]; then - echo "Usage: $0 " - exit 1 -fi -TARGET_TRIPLE="$1" - -BINARY_PATH="target/${TARGET_TRIPLE}/release/gleam" -if [[ "${TARGET_TRIPLE}" == *"windows"* ]]; then - BINARY_PATH="${BINARY_PATH}.exe" -fi - -# Parse target architecture -case "${TARGET_TRIPLE}" in - "x86_64"*) TARGET_ARCHITECTURE="x86_64" ;; - "aarch64"*) TARGET_ARCHITECTURE="aarch64" ;; - *) echo "Unknown target architecture '${TARGET_TRIPLE}'"; exit 1 ;; -esac - -# Parse binary architecture and expected binary architecture for OS -case "${TARGET_TRIPLE}" in - *"darwin"*) - file_output=$(file -b "${BINARY_PATH}") - BINARY_ARCHITECTURE=$(echo "${file_output}" | grep -o "x86_64\|arm64" || echo "") - case "${TARGET_ARCHITECTURE}" in - "x86_64") EXPECTED_BINARY_ARCHITECTURE="x86_64" ;; - "aarch64") EXPECTED_BINARY_ARCHITECTURE="arm64" ;; - *) echo "Unknown Darwin architecture: '${TARGET_ARCHITECTURE}'"; exit 1 ;; - esac - ;; - *"linux"*) - file_output=$(file -b "${BINARY_PATH}") - BINARY_ARCHITECTURE=$(echo "${file_output}" | grep -o "x86-64\|aarch64" | head -n1 || echo "") - case "${TARGET_ARCHITECTURE}" in - "x86_64") EXPECTED_BINARY_ARCHITECTURE="x86-64" ;; - "aarch64") EXPECTED_BINARY_ARCHITECTURE="aarch64" ;; - *) echo "Unknown Linux architecture: '${TARGET_ARCHITECTURE}'"; exit 1 ;; - esac - ;; - *"windows"*) - pe_header_output=$(powershell -Command " - \$bytes = [System.IO.File]::ReadAllBytes('${BINARY_PATH}'); - \$header_offset = [System.BitConverter]::ToInt32(\$bytes, 0x3c); - \$machine_type = [System.BitConverter]::ToUInt16(\$bytes, \$header_offset + 4); - \$machine_type - " 2>&1) || echo "PE header extraction failed" - case "${pe_header_output}" in - *"34404"*) BINARY_ARCHITECTURE="X64" ;; # 0x8664 - *"43620"*) BINARY_ARCHITECTURE="Arm64" ;; # 0xAA64 - *) echo "Unknown PE machine type: '${pe_header_output}'"; exit 1 ;; - esac - case "${TARGET_ARCHITECTURE}" in - "x86_64") EXPECTED_BINARY_ARCHITECTURE="X64" ;; - "aarch64") EXPECTED_BINARY_ARCHITECTURE="Arm64" ;; - *) echo "Unknown Windows architecture: '${TARGET_ARCHITECTURE}'"; exit 1 ;; - esac - ;; - *) - echo "Unknown target OS: '${TARGET_TRIPLE}'" - exit 1 - ;; -esac - -# Verify binary architecture -if [[ "${BINARY_ARCHITECTURE}" != "${EXPECTED_BINARY_ARCHITECTURE}" ]]; then - echo "Architecture mismatch for '${TARGET_TRIPLE}'" - echo "Expected: '${EXPECTED_BINARY_ARCHITECTURE}'" - echo "Got: '${BINARY_ARCHITECTURE}'" - exit 1 -fi