Files
rustytorch/scripts/migration/update-dependency-paths.sh
T
2026-03-04 00:08:42 +00:00

112 lines
4.8 KiB
Bash
Executable File

#!/bin/bash
set -e
echo "🔧 Updating internal dependency paths"
echo "===================================="
# Function to determine the relative path from one crate to another
get_relative_path() {
local from_category=$1
local to_category=$2
local to_crate=$3
if [ "$from_category" == "$to_category" ]; then
echo "../$to_crate"
else
echo "../../$to_category/$to_crate"
fi
}
# Function to update dependencies in a Cargo.toml file
update_crate_dependencies() {
local cargo_file=$1
local from_category=$2
if [ ! -f "$cargo_file" ]; then
echo "⚠️ No Cargo.toml found at $cargo_file"
return
fi
echo "🔧 Updating $cargo_file"
# Create backup
cp "$cargo_file" "$cargo_file.backup"
# Update each rtx dependency to use correct relative path
# We need to know where each crate lives
# Core crates
for crate in tensor runtime autograd memory kernel bindings graph validation losses; do
sed -i "s|rtx-$crate = { path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category core rtx-$crate)\"|g" "$cargo_file"
sed -i "s|rtx-$crate = { version = \"[^\"]*\", path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category core rtx-$crate)\"|g" "$cargo_file"
done
# Training crates
for crate in transformers distributed rl compress flash-attention preprocessing auto automeasure evolution federated; do
sed -i "s|rtx-$crate = { path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category training rtx-$crate)\"|g" "$cargo_file"
sed -i "s|rtx-$crate = { version = \"[^\"]*\", path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category training rtx-$crate)\"|g" "$cargo_file"
done
# Models crates
for crate in vision vision-advanced multimodal diffuse timeseries neuromorphic nlg; do
sed -i "s|rtx-$crate = { path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category models rtx-$crate)\"|g" "$cargo_file"
sed -i "s|rtx-$crate = { version = \"[^\"]*\", path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category models rtx-$crate)\"|g" "$cargo_file"
done
# Production crates
for crate in serving-api inference streaming mlops-orchestrator edge security robust cloud hub; do
sed -i "s|rtx-$crate = { path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category production rtx-$crate)\"|g" "$cargo_file"
sed -i "s|rtx-$crate = { version = \"[^\"]*\", path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category production rtx-$crate)\"|g" "$cargo_file"
done
# Specialized crates
for crate in quantum synthesis compiler geom polygraph sklearn-py ml-classic platform hardware-extended science; do
sed -i "s|rtx-$crate = { path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category specialized rtx-$crate)\"|g" "$cargo_file"
sed -i "s|rtx-$crate = { version = \"[^\"]*\", path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category specialized rtx-$crate)\"|g" "$cargo_file"
done
# Tooling crates
for crate in bench profiler governance privacy eval docs examples debug codegen finance audio games; do
sed -i "s|rtx-$crate = { path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category tooling rtx-$crate)\"|g" "$cargo_file"
sed -i "s|rtx-$crate = { version = \"[^\"]*\", path = \"[^\"]*\"|rtx-$crate = { path = \"$(get_relative_path $from_category tooling rtx-$crate)\"|g" "$cargo_file"
done
# Also update to use workspace dependencies where applicable
sed -i 's/nalgebra = "0\.[0-9]*"/nalgebra.workspace = true/g' "$cargo_file"
sed -i 's/statrs = "0\.[0-9]*"/statrs.workspace = true/g' "$cargo_file"
echo " ✅ Updated dependencies in $cargo_file"
}
# Update all crate dependencies
echo "📦 Updating dependency paths in all crates..."
for category in core training models production specialized tooling; do
echo "Processing $category crates..."
if [ -d "crates/$category" ]; then
for crate_dir in crates/$category/*/; do
if [ -d "$crate_dir" ]; then
crate_name=$(basename "$crate_dir")
update_crate_dependencies "$crate_dir/Cargo.toml" "$category"
fi
done
fi
done
# Update meta-crates too
echo "📦 Updating meta-crates..."
for meta_crate in crates/meta/*/; do
if [ -d "$meta_crate" ]; then
update_crate_dependencies "$meta_crate/Cargo.toml" "meta"
fi
done
echo "✅ Dependency path updates complete!"
# Count how many files were updated
updated_count=$(find crates -name "*.backup" | wc -l)
echo "📊 Updated $updated_count Cargo.toml files"
echo ""
echo "🧪 Next step: Test compilation with updated paths"