uiri / SEGIMAP

IMAP (and LMTP) Server written in Rust
MIT License
32 stars 6 forks source link

Update the codebase to Rust edition 2018 #35

Open kruton opened 2 years ago

kruton commented 2 years ago

This change is Reviewable

indiv0 commented 2 years ago

Hey! Thanks for the PR. I'll take a look at it.

Might I ask why the interest in this old repo? :)

kruton commented 2 years ago

Nothing exciting. I just wanted something written in Rust that spoke LMTP and IMAP (and nothing else) for my Home Automation installation. The small binary size makes it easy to run in docker or a Kubernetes cluster.

kruton commented 2 years ago

I've continued to iron out some more stuff in my fork of the repo. It builds with GitHub Actions now since I've migrated all my other projects away from Travis-CI, but I haven't recreated the coverage stats that travis-cargo apparently produces.

indiv0 commented 2 years ago

👍 sounds good. I mostly use GitHub actions on my projects now so that would be a welcome change.

If it helps, here are snippets from my Github Actions config and Makefile from another project that has code coverage:

on:
  push:
    branches:
      - main
    paths:
      - 'api_backend_2/**'
  pull_request:
  schedule: [cron: "40 1 * * *"]
env:
  RUST_BACKTRACE: full
  RUSTFLAGS: -D warnings
  CARGO_TERM_COLOR: always
  CARGO_INCREMENTAL: 0
  CI: true
jobs:
  fmt:
    runs-on: ubuntu-latest
    timeout-minutes: 1
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          # api_backend_2/.rustfmt.toml` uses unstable lints, which are
          # nightly-only until `rustfmt` 2.0 is released.
          toolchain: nightly
          override: true
          components: rustfmt
      - run: make -j2 fmt
        working-directory: api_backend_2
  clippy:
    runs-on: ubuntu-latest
    timeout-minutes: 3
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
          components: clippy
      - run: make -j2 clippy
        working-directory: api_backend_2
  doc:
    runs-on: ubuntu-latest
    timeout-minutes: 3
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          # The `--document-hidden-items` unstable option requires the
          # `nightly` toolchain. If it is not enables, we don't document
          # `#[doc(hidden)]` items.
          toolchain: nightly
          override: true
      - run: make -j2 doc
        working-directory: api_backend_2
  test:
    strategy:
      matrix:
        include:
          - toolchain: nightly
            os: ubuntu-latest
          - toolchain: stable
            os: ubuntu-latest
          - toolchain: 1.45.0
            os: ubuntu-latest
    runs-on: ubuntu-latest
    timeout-minutes: 4
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: ${{ matrix.toolchain }}
          override: true
      # `actions-rs/cargo` doesn't support running cargo within a subdir.
      # https://github.com/actions-rs/cargo/pull/59
      - run: make -j2 test
        working-directory: api_backend_2
  coverage:
    runs-on: ubuntu-latest
    timeout-minutes: 9
    steps:
      - uses: actions/checkout@v2
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      # Fetch the latest release version of `cargo-tarpaulin`.
      - run: |
          mkdir -p .github/caching
          curl -sL https://api.github.com/repos/xd009642/tarpaulin/releases/latest | jq -r '.name' > .github/caching/cargo-tarpaulin.lock
      # Cache `cargo-tarpaulin/bin`.
      - uses: actions/cache@v2
        with:
          path: ~/.cargo/bin
          key: coverage-${{ hashFiles('.github/caching/cargo-tarpaulin.lock')}}
      - run: make -j2 setup-tarpaulin
        working-directory: api_backend_2
      - run: make -j2 coverage
        working-directory: api_backend_2
      - run: make -j2 upload-coverage
        working-directory: api_backend_2
# Copyright (c) 2021 Nikita Pekin

# By default, print out some help.
.PHONY: usage
usage:
    @echo "$$(tput bold)Welcome to api_backend_2!$$(tput sgr0)"
    @echo
    @echo "First things first, if you haven't yet, check out the README from api_backend_2."
    @echo "You'll need to install a few requirements before we get going."
    @echo
    @echo "Run 'make setup' to setup Rust to build api_backend_2"
    @echo "Run 'make build' to build api_backend_2"
    @echo "    Set the DEBUG flag to enable the debug build"
    @echo "Run 'make test' to test any local changes you have made"
    @echo "Run 'make check' to check, but not compile api_backend_2"
    @echo "Run 'make doc' to build documentation for the library"
    @echo "Run 'make fmt' to run the \`rustfmt\` formatter on all sources"
    @echo "Run 'make clippy' to run the \`clippy\` linter on all sources"
    @echo "Run 'make audit' to audit Cargo dependencies for vulnerabilities"
    @echo "Run 'make coverage' to calculate coverage data for tests"
    @echo
    @echo "The make system also drives all continuous integration and testing."
    @echo
    @echo "Run 'make prepush' to run the recommended local development CI."
    @echo "Run 'make ci-all' to run all continuous integration tests."

## Utility functions.

eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))

## Setup targets.

.PHONY: setup
setup: setup-audit setup-tarpaulin

# Installs `cargo-audit` to analyze the dependency tree for security
# vulnerabilities.
.PHONY: setup-audit
setup-audit:
    cargo install cargo-audit

# Installs `cargo-tarpaulin` to calculate code coverage for tests.
.PHONY: setup-tarpaulin
setup-tarpaulin:
    command -v cargo-tarpaulin || cargo install cargo-tarpaulin

## Commands.

# Runs `cargo-audit` against the dependency tree to analyze for security
# vulnerabilities.
.PHONY: audit
audit:
    cargo audit

.PHONY: check
check:
    cargo check

.PHONY: build
build:
    cargo build$(if $(call eq,$(DEBUG),true),, --release)

.PHONY: test
test:
    cargo test --all

.PHONY: coverage
coverage:
    cargo tarpaulin --ignore-tests

.PHONY: upload-coverage
upload-coverage:
    curl -s https://codecov.io/bash > /tmp/coverage.sh
    chmod +x /tmp/coverage.sh
    /tmp/coverage.sh

# Generates documentation using the `rustdoc` tool.
# FIXME: `cargo doc` doesn't currently provide a way to deny warnings.
# `RUSTFLAGS="-D warnings" doesn't solve the problem and neither does
# `#[deny(warnings)]`.
# https://github.com/rust-lang/cargo/issues/8424#issuecomment-774715945
.PHONY: doc
doc:
    RUSTDOCFLAGS='-Z unstable-options --document-hidden-items -D warnings' cargo doc --all --document-private-items$(if $(call eq,$(CI),true), --no-deps)

# Runs the `rustfmt` tool to check for style & lint errors.
.PHONY: fmt
fmt:
    cargo fmt --all$(if $(call eq,$(CI),true), -- --check)

# Runs the `clippy` tool to check for extra lints & style errors.
.PHONY: clippy
clippy:
    cargo clippy --all$(if $(call eq,$(CI),true), -- -D warnings)

# Run the fast jobs.
# This is designed for developers, to be run often and before submitting code
# upstream.
.PHONY: prepush
prepush: fmt check clippy

# Run all possible CI. If this passes locally, all cloud CI *must* pass as
# well.
.PHONY: ci-all
ci-all:
    @CI=true make fmt clippy doc test coverage audit