Skip to content

Commit ae7e093

Browse files
committed
rust doc generation script
1 parent 816e90c commit ae7e093

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

scripts/build-rust-docs.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# Build Rust documentation and create redirect index.html
3+
# Note that you should make sure "import binaryninja" will return the
4+
# correct version for the docs you want to upload.
5+
6+
set -e
7+
8+
CARGO_TOML="rust/Cargo.toml"
9+
CARGO_LOCK="Cargo.lock"
10+
11+
# Check for uncommitted changes to Cargo.toml or Cargo.lock
12+
if ! git diff --quiet "$CARGO_TOML" "$CARGO_LOCK" 2>/dev/null; then
13+
echo "Error: Uncommitted changes detected in $CARGO_TOML or $CARGO_LOCK"
14+
echo "Please commit or stash your changes before running this script."
15+
exit 1
16+
fi
17+
18+
# Get Binary Ninja version from Python one-liner
19+
echo "Getting Binary Ninja version..."
20+
BN_VERSION=$(python3 -c "import binaryninja; v = binaryninja.core_version_info(); print(f'{v.major}.{v.minor}.{v.build}')")
21+
echo "Binary Ninja version: $BN_VERSION"
22+
23+
# Function to restore Cargo.toml and Cargo.lock on exit
24+
cleanup() {
25+
echo "Restoring $CARGO_TOML and $CARGO_LOCK..."
26+
git checkout "$CARGO_TOML" "$CARGO_LOCK" 2>/dev/null || true
27+
}
28+
trap cleanup EXIT
29+
30+
# Update version in Cargo.toml
31+
echo "Updating version to $BN_VERSION in $CARGO_TOML..."
32+
sed -i '' "s/^version = \".*\"/version = \"$BN_VERSION\"/" "$CARGO_TOML"
33+
34+
# Clean out old docs
35+
echo "Cleaning target/doc directory..."
36+
rm -rf target/doc
37+
38+
# Build the documentation (without dependencies by default)
39+
echo "Building documentation..."
40+
cargo doc --no-deps "$@"
41+
42+
# Create redirect index.html
43+
echo "Creating redirect index.html..."
44+
cat > target/doc/index.html <<'EOF'
45+
<!DOCTYPE html>
46+
<html lang="en">
47+
<head>
48+
<meta charset="utf-8">
49+
<meta http-equiv="refresh" content="0; url=/binaryninja/index.html">
50+
<title>Binary Ninja Rust Documentation</title>
51+
<script>
52+
window.location.href = "/binaryninja/index.html";
53+
</script>
54+
</head>
55+
<body>
56+
<p>Redirecting to <a href="/binaryninja/index.html">Binary Ninja Rust documentation</a>...</p>
57+
</body>
58+
</html>
59+
EOF
60+
61+
echo "Documentation built successfully with redirect at target/doc/index.html"

0 commit comments

Comments
 (0)