// OxygenHub's pipeline (OxygenFlow, docs in the oxygenflow repository).
// Every push to a bookmark on OxygenHub runs it in Firecracker microVMs on
// Earth; the jobs appear as checks on the change. oxygen and oxygenflow come
// from the pinned subrepos in deps/, which the runner puts in the workspace.
schema-version 1

// The OxygenFlow build image: Rust with rustfmt and clippy, Node, every
// crate of Cargo.lock vendored, and this workspace's dependencies prebuilt
// in /opt/warm/oxygenhub, which .flow/warm-target.sh copies onto a job's
// target disk (oxygenflow/images/rust). Rebuild and re-pin it when
// Cargo.lock changes; until then only the changed crates are compiled.
sandbox "rust" {
    runtime "microvm"
    rootfs "cas://blob/d2d24c2211f00d6ccf89fbee63095ad2a81d0cc9af92d7a0ede9129e18d46e91"
    memory-limit "8GiB"
    cpu-limit 4
    // Tests serve and connect on 127.0.0.1; nothing leaves the guest.
    network "loopback"
}

sandbox "rust-small" {
    runtime "microvm"
    rootfs "cas://blob/d2d24c2211f00d6ccf89fbee63095ad2a81d0cc9af92d7a0ede9129e18d46e91"
    memory-limit "1GiB"
    cpu-limit 1
    network "isolated"
}

// The riscv64 build image on narvi-1 (oxygenflow#69): Ubuntu 24.04 riscv64
// with Rust 1.97.1 and the same vendored crates, in the syscall tier (the
// board has no hardware virtualisation, so no microVM). `runs-on` keeps it
// on a RISC-V runner.
sandbox "rust-riscv64" {
    runtime "syscall"
    rootfs "cas://blob/b4edba9173ddf63aa1df46222e6a59b265071b19f2815c89d0153b593835c616"
    runs-on "riscv64"
    memory-limit "4GiB"
    cpu-limit 6
    network "loopback"
    env {
        CARGO_INCREMENTAL "0"
        CARGO_PROFILE_RELEASE_DEBUG "0"
        CARGO_BUILD_JOBS "4"
    }
}

job "fmt" {
    sandbox "rust-small"
    // Only this workspace's packages: --all would also check the path
    // dependencies in deps/, which follow their own formatting.
    exec "cargo" "fmt" "--check" "-p" "oxygenhub" "-p" "hub-api"
}

job "clippy" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
<<<<<<< oxy conflict 1 of 2, side 1 of 2: change 6532b323 "oxygen and oxygenflow as pinned subrepos in deps/ (make pins moves them), and an OxygenFlow pipeline: fmt of this workspace, then clippy, tests and a release build against the pins"
    env {
        CARGO_INCREMENTAL "0"
    }
======= oxy conflict 1 of 2, side 2 of 2: change bce3997c "CI starts from the build image's prebuilt dependencies"
    exec "sh" ".flow/warm-target.sh" "cargo" "clippy" "--workspace" "--all-targets" "--locked" "--" "-D" "warnings"
>>>>>>> oxy conflict 1 of 2 end
}

job "test" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
<<<<<<< oxy conflict 2 of 2, side 1 of 2: change 6532b323 "oxygen and oxygenflow as pinned subrepos in deps/ (make pins moves them), and an OxygenFlow pipeline: fmt of this workspace, then clippy, tests and a release build against the pins"
    env {
        CARGO_INCREMENTAL "0"
    }
======= oxy conflict 2 of 2, side 2 of 2: change bce3997c "CI starts from the build image's prebuilt dependencies"
    exec "sh" ".flow/warm-target.sh" "cargo" "test" "--workspace" "--locked"
>>>>>>> oxy conflict 2 of 2 end
}

job "build" {
    sandbox "rust"
    depends-on "fmt"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
    env {
        CARGO_INCREMENTAL "0"
    }
    exec "sh" ".flow/warm-target.sh" "cargo" "build" "--release" "--locked"
}

// Release files for every platform (oxygen#59): scripts/dist.sh in the
// build image's cross toolchains. A push runs it only when it touches
// these paths (a release moves Cargo.toml's version); "Run pipeline" and
// reruns always do. The files are kept as this run's artifacts, named by
// its signed receipt, and attached to the release from there, so the
// release's trust page shows each as built here.
job "dist" {
    sandbox "rust"
    depends-on "fmt"
    scope "Cargo.toml" "scripts/dist.sh" "packaging/**"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "24GiB"
    }
    env {
        DIST_FLAT "/src/target/dist-flat"
        ZIG_GLOBAL_CACHE_DIR "/src/target/zig-cache"
    }
    exec "bash" "scripts/dist.sh"
    output {
        artifact "oh-linux-x86_64.tar.gz" {
            path "/src/target/dist-flat/oh-linux-x86_64.tar.gz"
        }
        artifact "oh-linux-arm64.tar.gz" {
            path "/src/target/dist-flat/oh-linux-arm64.tar.gz"
        }
        artifact "oh-linux-riscv64.tar.gz" {
            path "/src/target/dist-flat/oh-linux-riscv64.tar.gz"
        }
        artifact "oh-macos-x86_64.tar.gz" {
            path "/src/target/dist-flat/oh-macos-x86_64.tar.gz"
        }
        artifact "oh-macos-arm64.tar.gz" {
            path "/src/target/dist-flat/oh-macos-arm64.tar.gz"
        }
        artifact "oh-windows-x86_64.zip" {
            path "/src/target/dist-flat/oh-windows-x86_64.zip"
        }
        artifact "oh_amd64.deb" {
            path "/src/target/dist-flat/oh_amd64.deb"
        }
        artifact "oh_arm64.deb" {
            path "/src/target/dist-flat/oh_arm64.deb"
        }
        artifact "oh_riscv64.deb" {
            path "/src/target/dist-flat/oh_riscv64.deb"
        }
        artifact "SHA256SUMS" {
            path "/src/target/dist-flat/SHA256SUMS"
        }
    }
}

// The native RISC-V check (oxygenflow#69): oh built and run on narvi-1, a
// real riscv64 board, so each release is known to run there and not only
// to cross-compile (dist). Like dist, a push runs it only when it touches
// these paths; "Run pipeline" and reruns always do. Its target directory
// is cached between passing runs (oxygenflow#70).
job "riscv64" {
    sandbox "rust-riscv64"
    depends-on "fmt"
    scope "Cargo.toml" "scripts/dist.sh" "packaging/**" ".flow/riscv64-check.sh"
    timeout "3h"
    mount {
        source "ephemeral://disk"
        target "/src/target"
        size "16GiB"
        cache "target"
        key "Cargo.lock"
    }
    exec "sh" ".flow/riscv64-check.sh"
    output {
        artifact "oh-linux-riscv64-native" {
            path "/src/target/release/oh"
        }
    }
}
