|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Strip git-only features, deps and patches from Cargo.toml for publishing. |
| 5 | +# crates.io rejects packages with git-only deps — even optional ones. |
| 6 | +# Backs up Cargo.toml and restores it after publish (or dry-run). |
| 7 | + |
| 8 | +cp Cargo.toml Cargo.toml.bak |
| 9 | +trap 'mv Cargo.toml.bak Cargo.toml' EXIT |
| 10 | + |
| 11 | +# --- Features --- |
| 12 | + |
| 13 | +# Remove blitz feature block (multi-line: "blitz = [" through "]") |
| 14 | +sed -i '/^blitz = \[$/,/^\]$/d' Cargo.toml |
| 15 | + |
| 16 | +# Remove servo feature line |
| 17 | +sed -i '/^servo = \[/d' Cargo.toml |
| 18 | + |
| 19 | +# --- Dependencies --- |
| 20 | + |
| 21 | +# Blitz git deps |
| 22 | +sed -i '/^# Blitz engine deps/d' Cargo.toml |
| 23 | +sed -i '/^blitz-dom = {/d' Cargo.toml |
| 24 | +sed -i '/^blitz-html = {/d' Cargo.toml |
| 25 | +sed -i '/^blitz-paint = {/d' Cargo.toml |
| 26 | +sed -i '/^blitz-traits = {/d' Cargo.toml |
| 27 | +sed -i '/^blitz-net = {/d' Cargo.toml |
| 28 | + |
| 29 | +# Blitz crates.io deps (only used by blitz feature) |
| 30 | +sed -i '/^anyrender = {/d' Cargo.toml |
| 31 | +sed -i '/^anyrender_vello_cpu = {/d' Cargo.toml |
| 32 | +sed -i '/^peniko = {/d' Cargo.toml |
| 33 | +sed -i '/^cursor-icon = {/d' Cargo.toml |
| 34 | +sed -i '/^keyboard-types = {/d' Cargo.toml |
| 35 | +sed -i '/^tokio = {/d' Cargo.toml |
| 36 | + |
| 37 | +# Servo git dep |
| 38 | +sed -i '/^# Servo engine deps/d' Cargo.toml |
| 39 | +sed -i '/^servo = {/d' Cargo.toml |
| 40 | + |
| 41 | +# Servo crates.io deps (only used by servo feature) |
| 42 | +sed -i '/^rustls = {/d' Cargo.toml |
| 43 | +sed -i '/^euclid = {/d' Cargo.toml |
| 44 | +sed -i '/^keyboard-types-servo = {/d' Cargo.toml |
| 45 | +sed -i '/^dpi = {/d' Cargo.toml |
| 46 | + |
| 47 | +# --- Patch section --- |
| 48 | + |
| 49 | +# Remove patch comment block |
| 50 | +sed -i '/^# When both blitz/d' Cargo.toml |
| 51 | +sed -i '/^# stylo (crates.io/d' Cargo.toml |
| 52 | +sed -i '/^# git rev so they/d' Cargo.toml |
| 53 | + |
| 54 | +# Remove [patch.crates-io] section header and all entries |
| 55 | +sed -i '/^\[patch\.crates-io\]$/d' Cargo.toml |
| 56 | +sed -i '/^stylo = {/d' Cargo.toml |
| 57 | +sed -i '/^stylo_traits = {/d' Cargo.toml |
| 58 | +sed -i '/^stylo_atoms = {/d' Cargo.toml |
| 59 | +sed -i '/^stylo_dom = {/d' Cargo.toml |
| 60 | +sed -i '/^selectors = {/d' Cargo.toml |
| 61 | + |
| 62 | +# --- Cleanup --- |
| 63 | + |
| 64 | +# Collapse runs of blank lines into one |
| 65 | +sed -i '/^$/N;/^\n$/d' Cargo.toml |
| 66 | + |
| 67 | +echo "=== Stripped Cargo.toml ===" |
| 68 | +cat Cargo.toml |
| 69 | +echo "===========================" |
| 70 | + |
| 71 | +if [[ "${1:-}" == "--publish" ]]; then |
| 72 | + cargo publish --allow-dirty |
| 73 | +else |
| 74 | + cargo publish --dry-run --allow-dirty |
| 75 | +fi |
0 commit comments