|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Publish script for axplat crates |
| 4 | +# This script publishes crates in the correct dependency order |
| 5 | + |
| 6 | +set -e # Exit on error |
| 7 | + |
| 8 | +echo "==========================================" |
| 9 | +echo "Publishing axplat crates..." |
| 10 | +echo "==========================================" |
| 11 | + |
| 12 | +# Define targets for different architectures |
| 13 | +AARCH64_TARGET="aarch64-unknown-none-softfloat" |
| 14 | +X86_64_TARGET="x86_64-unknown-none" |
| 15 | +RISCV64_TARGET="riscv64gc-unknown-none-elf" |
| 16 | +LOONGARCH64_TARGET="loongarch64-unknown-none" |
| 17 | + |
| 18 | +# Colors for output |
| 19 | +GREEN='\033[0;32m' |
| 20 | +BLUE='\033[0;34m' |
| 21 | +YELLOW='\033[1;33m' |
| 22 | +RED='\033[0;31m' |
| 23 | +NC='\033[0m' # No Color |
| 24 | + |
| 25 | +# Function to get local crate version from Cargo.toml |
| 26 | +# Handles both direct version and workspace = true |
| 27 | +get_local_version() { |
| 28 | + local crate_path=$1 |
| 29 | + local version_line |
| 30 | + # Only match direct version assignment (version = "..."), not version.workspace = true |
| 31 | + version_line=$(grep -E '^version\s*=\s*"' "${crate_path}/Cargo.toml" | head -1) |
| 32 | + |
| 33 | + if [ -n "$version_line" ]; then |
| 34 | + # Direct version: version = "0.1.0" |
| 35 | + echo "$version_line" | sed -E 's/.*=\s*"([^"]+)".*/\1/' |
| 36 | + else |
| 37 | + # Workspace version: version.workspace = true |
| 38 | + # Get from workspace Cargo.toml (always in project root) |
| 39 | + grep -E '^version\s*=' "Cargo.toml" | head -1 | sed -E 's/.*=\s*"([^"]+)".*/\1/' |
| 40 | + fi |
| 41 | +} |
| 42 | + |
| 43 | +# Function to check if a crate version already exists on crates.io |
| 44 | +crate_version_exists() { |
| 45 | + local crate_name=$1 |
| 46 | + local version=$2 |
| 47 | + |
| 48 | + # Search for the crate on crates.io and check if the version exists |
| 49 | + local search_result |
| 50 | + search_result=$(cargo search "${crate_name}" --limit 1 2>/dev/null | grep "^${crate_name} = \"${version}\"") || true |
| 51 | + |
| 52 | + if [ -n "${search_result}" ]; then |
| 53 | + return 0 # Version exists |
| 54 | + else |
| 55 | + return 1 # Version does not exist |
| 56 | + fi |
| 57 | +} |
| 58 | + |
| 59 | +# Function to publish a crate |
| 60 | +publish_crate() { |
| 61 | + local crate_name=$1 |
| 62 | + local crate_path=$2 |
| 63 | + local target=$3 |
| 64 | + local version |
| 65 | + |
| 66 | + # Get the local version from Cargo.toml |
| 67 | + version=$(get_local_version "${crate_path}") |
| 68 | + |
| 69 | + echo "" |
| 70 | + echo -e "${BLUE}Checking ${crate_name} (version ${version})...${NC}" |
| 71 | + |
| 72 | + # Check if this version already exists on crates.io |
| 73 | + if crate_version_exists "${crate_name}" "${version}"; then |
| 74 | + echo -e "${YELLOW}Skipping ${crate_name} ${version} - already published on crates.io${NC}" |
| 75 | + return 0 |
| 76 | + fi |
| 77 | + |
| 78 | + echo -e "${BLUE}Publishing ${crate_name} ${version}...${NC}" |
| 79 | + |
| 80 | + if [ -n "$target" ]; then |
| 81 | + cargo publish -p "${crate_name}" --target "${target}" |
| 82 | + else |
| 83 | + cargo publish -p "${crate_name}" |
| 84 | + fi |
| 85 | + |
| 86 | + if [ $? -eq 0 ]; then |
| 87 | + echo -e "${GREEN}Successfully published ${crate_name} ${version}${NC}" |
| 88 | + else |
| 89 | + echo -e "${RED}Failed to publish ${crate_name}${NC}" |
| 90 | + exit 1 |
| 91 | + fi |
| 92 | + |
| 93 | + # Wait a bit for the crate to be available on crates.io |
| 94 | + echo "Waiting for ${crate_name} to be available on crates.io..." |
| 95 | + sleep 10 |
| 96 | +} |
| 97 | + |
| 98 | +echo "" |
| 99 | +echo "Step 1: Publishing base crates (no special target required)..." |
| 100 | +echo "------------------------------------------------------------" |
| 101 | + |
| 102 | +# 1. Publish axplat-macros first (no dependencies) |
| 103 | +publish_crate "axplat-macros" "axplat-macros" "" |
| 104 | + |
| 105 | +# 2. Publish axplat (depends on axplat-macros) |
| 106 | +publish_crate "axplat" "axplat" "" |
| 107 | + |
| 108 | +echo "" |
| 109 | +echo "Step 2: Publishing platform-specific crates with appropriate targets..." |
| 110 | +echo "-----------------------------------------------------------------------" |
| 111 | + |
| 112 | +# 3. Publish axplat-aarch64-peripherals (depends on axplat, needs aarch64 target) |
| 113 | +publish_crate "axplat-aarch64-peripherals" "platforms/axplat-aarch64-peripherals" "${AARCH64_TARGET}" |
| 114 | + |
| 115 | +# 4. Publish aarch64 platform crates (all depend on axplat-aarch64-peripherals) |
| 116 | +publish_crate "axplat-aarch64-qemu-virt" "platforms/axplat-aarch64-qemu-virt" "${AARCH64_TARGET}" |
| 117 | +publish_crate "axplat-aarch64-raspi" "platforms/axplat-aarch64-raspi" "${AARCH64_TARGET}" |
| 118 | +publish_crate "axplat-aarch64-bsta1000b" "platforms/axplat-aarch64-bsta1000b" "${AARCH64_TARGET}" |
| 119 | +publish_crate "axplat-aarch64-phytium-pi" "platforms/axplat-aarch64-phytium-pi" "${AARCH64_TARGET}" |
| 120 | + |
| 121 | +# 5. Publish x86_64 platform crate |
| 122 | +publish_crate "axplat-x86-pc" "platforms/axplat-x86-pc" "${X86_64_TARGET}" |
| 123 | + |
| 124 | +# 6. Publish riscv64 platform crate |
| 125 | +publish_crate "axplat-riscv64-qemu-virt" "platforms/axplat-riscv64-qemu-virt" "${RISCV64_TARGET}" |
| 126 | + |
| 127 | +# 7. Publish loongarch64 platform crate |
| 128 | +publish_crate "axplat-loongarch64-qemu-virt" "platforms/axplat-loongarch64-qemu-virt" "${LOONGARCH64_TARGET}" |
| 129 | + |
| 130 | +echo "" |
| 131 | +echo "==========================================" |
| 132 | +echo -e "${GREEN}All crates published successfully!${NC}" |
| 133 | +echo "==========================================" |
0 commit comments