[group('build')]
build:
    cargo build --frozen --workspace
alias b := build

# Build statically linked release binaries for all supported architectures
[group('build')]
build-release-static:
    cargo zigbuild \
        --release \
        --frozen \
        --workspace \
        --target 'x86_64-unknown-linux-musl' \
        --target 'aarch64-unknown-linux-musl'

    [ "$(readelf -d target/x86_64-unknown-linux-musl/release/otter | grep NEEDED | wc -l)" = 0 ]
    [ "$(readelf -d target/aarch64-unknown-linux-musl/release/otter | grep NEEDED | wc -l)" = 0 ]

test:
    cargo test --frozen --workspace
alias t := test

check:
    cargo fmt --check --all
    cargo clippy \
        --frozen \
        --all -- \
        --no-deps \
        --deny 'clippy::all'
alias c := check

fmt:
    cargo fmt --all

fetch:
    cargo fetch --locked

clean:
    cargo clean

run:
    cargo run \
        --bin otter \
        -- serve \
        -c ./otter.toml

doc:
    cargo doc --workspace --frozen --open

publish-release-binaries tag: build-release-static
    curl \
        --netrc \
        --fail \
        --upload-file target/x86_64-unknown-linux-musl/release/otter \
        https://git.rustybever.be/api/packages/Chewing_Bever/generic/otter/"{{ tag }}"/otter-linux-amd64
    curl \
        --netrc \
        --fail \
        --upload-file target/aarch64-unknown-linux-musl/release/otter \
        https://git.rustybever.be/api/packages/Chewing_Bever/generic/otter/"{{ tag }}"/otter-linux-arm64
    just docs/publish
