{"id":51570452,"url":"https://github.com/boopi7/cf-rust-buildpack","last_synced_at":"2026-07-10T19:02:05.518Z","repository":{"id":320174984,"uuid":"1081076537","full_name":"Boopi7/cf-rust-buildpack","owner":"Boopi7","description":"A Cloud Foundry buildpack for deploying rust code","archived":false,"fork":false,"pushed_at":"2025-10-28T02:44:16.000Z","size":14,"stargazers_count":15,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-02-17T20:51:44.316Z","etag":null,"topics":["rust","shell"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Boopi7.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-22T09:23:25.000Z","updated_at":"2025-11-03T09:25:23.000Z","dependencies_parsed_at":"2025-10-22T11:41:50.810Z","dependency_job_id":null,"html_url":"https://github.com/Boopi7/cf-rust-buildpack","commit_stats":null,"previous_names":["devnova777/cf-rust-buildpack","dravynn/cf-rust-buildpack","boopi7/cf-rust-buildpack"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Boopi7/cf-rust-buildpack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Boopi7%2Fcf-rust-buildpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Boopi7%2Fcf-rust-buildpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Boopi7%2Fcf-rust-buildpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Boopi7%2Fcf-rust-buildpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Boopi7","download_url":"https://codeload.github.com/Boopi7/cf-rust-buildpack/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Boopi7%2Fcf-rust-buildpack/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35339931,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-10T02:00:06.465Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rust","shell"],"created_at":"2026-07-10T19:02:01.041Z","updated_at":"2026-07-10T19:02:05.509Z","avatar_url":"https://github.com/Boopi7.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Cloud Foundry Rust Buildpack Implementation Guide\n\n## Overview\nA Cloud Foundry buildpack consists of three main executable scripts that handle the application lifecycle: `detect`, `compile`, and `release`.\n\n## Directory Structure\n```\nrust-buildpack/\n├── bin/\n│   ├── detect\n│   ├── compile\n│   └── release\n├── lib/\n│   └── common.sh\n└── README.md\n```\n\n## 1. Detection Script (`bin/detect`)\n\nThis script determines if the buildpack should be used for an application.\n\n```bash\n#!/usr/bin/env bash\n# bin/detect\n\nBUILD_DIR=$1\n\n# Check for Cargo.toml (primary indicator of a Rust project)\nif [ -f \"$BUILD_DIR/Cargo.toml\" ]; then\n    echo \"Rust\"\n    exit 0\nfi\n\n# Check for main.rs or lib.rs as secondary indicators\nif [ -f \"$BUILD_DIR/src/main.rs\" ] || [ -f \"$BUILD_DIR/src/lib.rs\" ]; then\n    echo \"Rust\"\n    exit 0\nfi\n\n# Not a Rust application\nexit 1\n```\n\n## 2. Compilation Script (`bin/compile`)\n\nThis is the main script that installs Rust and compiles the application.\n\n```bash\n#!/usr/bin/env bash\n# bin/compile\n\nset -eo pipefail\n\nBUILD_DIR=$1\nCACHE_DIR=$2\nENV_DIR=$3\nBUILDPACK_DIR=$(cd $(dirname $0); cd ..; pwd)\n\n# Load common functions\nsource $BUILDPACK_DIR/lib/common.sh\n\n# Determine Rust version to use\nif [ -n \"$RUST_VERSION\" ]; then\n    echo \"       Using RUST_VERSION environment variable: $RUST_VERSION\"\nelse\n    RUST_VERSION=$(get_rust_version \"$BUILD_DIR\")\n    echo \"       Detected Rust version: $RUST_VERSION\"\nfi\n\n# Configuration - Default to stable channel\nRUST_VERSION=${RUST_VERSION:-\"stable\"}\n\necho \"-----\u003e Installing Rust $RUST_VERSION\"\n\n# Create cache directory for Rust installation\nRUST_CACHE_DIR=\"$CACHE_DIR/rust\"\nmkdir -p \"$RUST_CACHE_DIR\"\n\n# Install Rust if not cached or cache is old\nCACHE_AGE_DAYS=7  # Refresh cache weekly\nif [ ! -d \"$RUST_CACHE_DIR/bin\" ] || [ $(find \"$RUST_CACHE_DIR\" -mtime +$CACHE_AGE_DAYS | wc -l) -gt 0 ]; then\n    echo \"       Downloading and installing Rust...\"\n    \n    # Remove old cache if it exists\n    rm -rf \"$RUST_CACHE_DIR\"\n    mkdir -p \"$RUST_CACHE_DIR\"\n    \n    # Download rustup installer\n    curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \u003e /tmp/rustup-init.sh\n    chmod +x /tmp/rustup-init.sh\n    \n    # Install Rust to cache directory\n    RUSTUP_HOME=\"$RUST_CACHE_DIR\" CARGO_HOME=\"$RUST_CACHE_DIR\" \\\n        /tmp/rustup-init.sh -y --default-toolchain $RUST_VERSION --no-modify-path\n    \n    rm /tmp/rustup-init.sh\nelse\n    echo \"       Using cached Rust installation\"\n    # Update to latest stable if using stable channel\n    if [ \"$RUST_VERSION\" = \"stable\" ]; then\n        echo \"       Updating stable toolchain...\"\n        RUSTUP_HOME=\"$RUST_CACHE_DIR\" CARGO_HOME=\"$RUST_CACHE_DIR\" \\\n            \"$RUST_CACHE_DIR/bin/rustup\" update stable\n    fi\nfi\n\n# Set up Rust environment\nexport RUSTUP_HOME=\"$RUST_CACHE_DIR\"\nexport CARGO_HOME=\"$RUST_CACHE_DIR\"\nexport PATH=\"$RUST_CACHE_DIR/bin:$PATH\"\n\n# Copy Rust installation to build directory\necho \"-----\u003e Setting up Rust environment\"\ncp -r \"$RUST_CACHE_DIR\" \"$BUILD_DIR/.rust\"\n\n# Set up Cargo cache\nCARGO_CACHE_DIR=\"$CACHE_DIR/cargo\"\nmkdir -p \"$CARGO_CACHE_DIR\"\n\n# Link cargo cache to build directory\nmkdir -p \"$BUILD_DIR/.cargo\"\nif [ -d \"$CARGO_CACHE_DIR/registry\" ]; then\n    ln -sf \"$CARGO_CACHE_DIR/registry\" \"$BUILD_DIR/.cargo/registry\"\nfi\nif [ -d \"$CARGO_CACHE_DIR/git\" ]; then\n    ln -sf \"$CARGO_CACHE_DIR/git\" \"$BUILD_DIR/.cargo/git\"\nfi\n\n# Set environment for compilation\nexport CARGO_HOME=\"$BUILD_DIR/.cargo\"\nexport RUSTUP_HOME=\"$BUILD_DIR/.rust\"\nexport PATH=\"$BUILD_DIR/.rust/bin:$PATH\"\n\necho \"-----\u003e Building Rust application\"\ncd \"$BUILD_DIR\"\n\n# Check if this is a web application (has dependencies like actix-web, warp, etc.)\nif grep -q -E \"(actix-web|warp|rocket|axum|tide)\" Cargo.toml; then\n    echo \"       Detected web framework\"\n    WEB_APP=true\nelse\n    WEB_APP=false\nfi\n\n# Build the application in release mode\ncargo build --release\n\n# Copy cargo cache back for next build\ncp -r \"$BUILD_DIR/.cargo/registry\" \"$CARGO_CACHE_DIR/\" 2\u003e/dev/null || true\ncp -r \"$BUILD_DIR/.cargo/git\" \"$CARGO_CACHE_DIR/\" 2\u003e/dev/null || true\n\n# Create start script\necho \"-----\u003e Creating startup script\"\ncat \u003e \"$BUILD_DIR/start.sh\" \u003c\u003c 'EOF'\n#!/usr/bin/env bash\n\nexport RUSTUP_HOME=\"/app/.rust\"\nexport CARGO_HOME=\"/app/.cargo\"\nexport PATH=\"/app/.rust/bin:$PATH\"\n\n# Find the binary to run\nBINARY_NAME=$(find target/release -maxdepth 1 -type f -executable ! -name \"*.so\" ! -name \"*.d\" | head -1)\n\nif [ -z \"$BINARY_NAME\" ]; then\n    echo \"Error: No executable binary found in target/release\"\n    exit 1\nfi\n\necho \"Starting $(basename $BINARY_NAME)...\"\nexec \"$BINARY_NAME\" \"$@\"\nEOF\n\nchmod +x \"$BUILD_DIR/start.sh\"\n\necho \"-----\u003e Rust buildpack compilation complete\"\n```\n\n## 3. Release Script (`bin/release`)\n\nThis script provides metadata about how to run the application.\n\n```bash\n#!/usr/bin/env bash\n# bin/release\n\nBUILD_DIR=$1\n\n# Check if this appears to be a web application\nif [ -f \"$BUILD_DIR/Cargo.toml\" ] \u0026\u0026 grep -q -E \"(actix-web|warp|rocket|axum|tide)\" \"$BUILD_DIR/Cargo.toml\"; then\n    # Web application - default to PORT environment variable\n    cat \u003c\u003c EOF\n---\ndefault_process_types:\n  web: ./start.sh\nconfig_vars:\n  RUST_LOG: info\nEOF\nelse\n    # CLI application\n    cat \u003c\u003c EOF\n---\ndefault_process_types:\n  console: ./start.sh\nconfig_vars:\n  RUST_LOG: info\nEOF\nfi\n```\n\n## 4. Common Functions (`lib/common.sh`)\n\nShared utilities for the buildpack scripts.\n\n```bash\n#!/usr/bin/env bash\n# lib/common.sh\n\n# Output formatting functions\nfunction puts-step() {\n    echo \"-----\u003e $@\"\n}\n\nfunction puts-warn() {\n    echo \" !     $@\"\n}\n\nfunction puts-verbose() {\n    if [ -n \"$VERBOSE\" ]; then\n        echo \"       $@\"\n    fi\n}\n\n# Utility to get Rust version from Cargo.toml or rust-toolchain\nfunction get_rust_version() {\n    local build_dir=$1\n    local version=\"stable\"\n    \n    # Check for rust-toolchain.toml (newer format)\n    if [ -f \"$build_dir/rust-toolchain.toml\" ]; then\n        if command -v toml \u003e/dev/null 2\u003e\u00261; then\n            version=$(toml get \"$build_dir/rust-toolchain.toml\" toolchain.channel 2\u003e/dev/null || echo \"stable\")\n        else\n            # Fallback parsing without toml tool\n            version=$(grep -E '^\\s*channel\\s*=' \"$build_dir/rust-toolchain.toml\" | sed -E 's/.*=\\s*\"([^\"]+)\".*/\\1/' || echo \"stable\")\n        fi\n    # Check for rust-toolchain file (legacy format)\n    elif [ -f \"$build_dir/rust-toolchain\" ]; then\n        version=$(cat \"$build_dir/rust-toolchain\" | tr -d '\\n\\r' | head -1)\n    # Check Cargo.toml for rust-version (MSRV)\n    elif [ -f \"$build_dir/Cargo.toml\" ] \u0026\u0026 grep -q \"rust-version\" \"$build_dir/Cargo.toml\"; then\n        version=$(grep \"rust-version\" \"$build_dir/Cargo.toml\" | sed -E 's/.*=\\s*\"([^\"]+)\".*/\\1/' | head -1)\n        echo \"       Found minimum Rust version $version in Cargo.toml, using stable instead\"\n        version=\"stable\"  # Use stable even if MSRV is specified\n    fi\n    \n    echo \"$version\"\n}\n\n# Check if binary exists in PATH\nfunction check_command() {\n    command -v \"$1\" \u003e/dev/null 2\u003e\u00261\n}\n```\n\n## 5. Configuration Options\n\nYou can configure the buildpack through environment variables:\n\n- `RUST_VERSION`: Specify Rust version (default: stable)\n- `CARGO_BUILD_FLAGS`: Additional flags for cargo build\n- `RUST_LOG`: Set logging level for the application\n\n## 6. Usage\n\n1. **Package the buildpack:**\n   ```bash\n   tar czf rust-buildpack.tgz rust-buildpack/\n   ```\n\n2. **Deploy with cf CLI:**\n   ```bash\n   cf push myapp -b https://github.com/yourusername/rust-buildpack.git\n   ```\n\n3. **Or specify in manifest.yml:**\n   ```yaml\n   applications:\n   - name: rust-app\n     buildpack: https://github.com/yourusername/rust-buildpack.git\n     command: ./start.sh\n   ```\n\n## 7. Advanced Features\n\n### Custom Build Commands\nAdd support for custom build commands in `bin/compile`:\n\n```bash\n# Check for custom build command\nif [ -f \"$BUILD_DIR/.buildpack-build-cmd\" ]; then\n    BUILD_CMD=$(cat \"$BUILD_DIR/.buildpack-build-cmd\")\n    echo \"-----\u003e Running custom build command: $BUILD_CMD\"\n    eval \"$BUILD_CMD\"\nelse\n    cargo build --release\nfi\n```\n\n### Multi-Binary Support\nHandle projects with multiple binaries:\n\n```bash\n# In start.sh, allow specifying which binary to run\nBINARY_NAME=${1:-$(find target/release -maxdepth 1 -type f -executable ! -name \"*.so\" ! -name \"*.d\" | head -1)}\n```\n\n## 8. Testing\n\nCreate a simple test application:\n\n```toml\n# Cargo.toml\n[package]\nname = \"hello-rust\"\nversion = \"0.1.0\"\nedition = \"2021\"\n\n[dependencies]\nactix-web = \"4.0\"\ntokio = { version = \"1.0\", features = [\"full\"] }\n```\n\n```rust\n// src/main.rs\nuse actix_web::{web, App, HttpResponse, HttpServer, Result};\nuse std::env;\n\nasync fn hello() -\u003e Result\u003cHttpResponse\u003e {\n    Ok(HttpResponse::Ok().body(\"Hello from Rust on Cloud Foundry!\"))\n}\n\n#[actix_web::main]\nasync fn main() -\u003e std::io::Result\u003c()\u003e {\n    let port = env::var(\"PORT\").unwrap_or_else(|_| \"8080\".to_string());\n    let port: u16 = port.parse().expect(\"PORT must be a number\");\n\n    println!(\"Starting server on port {}\", port);\n\n    HttpServer::new(|| {\n        App::new()\n            .route(\"/\", web::get().to(hello))\n    })\n    .bind((\"0.0.0.0\", port))?\n    .run()\n    .await\n}\n```\n\nThis buildpack will detect Rust applications, install the Rust toolchain, compile the application, and provide appropriate runtime configuration for Cloud Foundry deployment.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboopi7%2Fcf-rust-buildpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fboopi7%2Fcf-rust-buildpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fboopi7%2Fcf-rust-buildpack/lists"}