Skip to content

Commit

Permalink
Add the standard Linebender CI script and satisfy Clippy. (#33)
Browse files Browse the repository at this point in the history
* Add the standard Linebender CI script.

* Update dependencies and commit `Cargo.lock`.

* Add `.clippy.toml` and `.rustfmt.toml`.

* Add MSRV info to `README.md`.

* Satisfy Clippy 1.77.

* Rewrite bidi order sequencing with an enumerator.
  • Loading branch information
xStrom authored Apr 19, 2024
1 parent 1ffcb3e commit 4f05e18
Show file tree
Hide file tree
Showing 21 changed files with 1,209 additions and 57 deletions.
5 changes: 5 additions & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# The default Clippy value for this is 8 bytes, which is chosen to improve performance on 32-bit.
# Given that we're building for the future and even mobile phones have 64-bit CPUs,
# it makes sense to optimize for 64-bit and accept the performance hits on 32-bit.
# 16 bytes is the number of bytes that fits into two 64-bit CPU registers.
trivial-copy-size-limit = 16
23 changes: 23 additions & 0 deletions .github/copyright.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# If there are new files with headers that can't match the conditions here,
# then the files can be ignored by an additional glob argument via the -g flag.
# For example:
# -g "!src/special_file.rs"
# -g "!src/special_directory"

# Check all the standard Rust source files
output=$(rg "^// Copyright (19|20)[\d]{2} (.+ and )?the Parley Authors( and .+)?$\n^// SPDX-License-Identifier: Apache-2\.0 OR MIT$\n\n" --files-without-match --multiline -g "*.rs" .)

if [ -n "$output" ]; then
echo -e "The following files lack the correct copyright header:\n"
echo $output
echo -e "\n\nPlease add the following header:\n"
echo "// Copyright $(date +%Y) the Parley Authors"
echo "// SPDX-License-Identifier: Apache-2.0 OR MIT"
echo -e "\n... rest of the file ...\n"
exit 1
fi

echo "All files have correct copyright headers."
exit 0
222 changes: 222 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
env:
# We aim to always test with the latest stable Rust toolchain, however we pin to a specific
# version like 1.70. Note that we only specify MAJOR.MINOR and not PATCH so that bugfixes still
# come automatically. If the version specified here is no longer the latest stable version,
# then please feel free to submit a PR that adjusts it along with the potential clippy fixes.
RUST_STABLE_VER: "1.77" # In quotes because otherwise (e.g.) 1.70 would be interpreted as 1.7
# The purpose of checking with the minimum supported Rust toolchain is to detect its staleness.
# If the compilation fails, then the version specified here needs to be bumped up to reality.
# Be sure to also update the rust-version property in the workspace Cargo.toml file,
# plus all the README.md files of the affected packages.
RUST_MIN_VER: "1.70"
# List of packages that will be checked with the minimum supported Rust version.
# This should be limited to packages that are intended for publishing.
RUST_MIN_VER_PKGS: "-p parley"


# Rationale
#
# We don't run clippy with --all-targets because then even --lib and --bins are compiled with
# dev dependencies enabled, which does not match how they would be compiled by users.
# A dev dependency might enable a feature that we need for a regular dependency,
# and checking with --all-targets would not find our feature requirements lacking.
# This problem still applies to cargo resolver version 2.
# Thus we split all the targets into two steps, one with --lib --bins
# and another with --tests --benches --examples.
# Also, we can't give --lib --bins explicitly because then cargo will error on binary-only packages.
# Luckily the default behavior of cargo with no explicit targets is the same but without the error.
#
# We use cargo-hack for a similar reason. Cargo's --workspace will do feature unification across
# the whole workspace. While cargo-hack will instead check each workspace package separately.
#
# Using cargo-hack also allows us to more easily test the feature matrix of our packages.
# We use --each-feature & --optional-deps which will run a separate check for every feature.
#
# We use macos-14 explictly instead of macos-latest because:
# * macos-latest currently points to macos-12
# * macos-14 comes with the M1 CPU which compiles our code much faster than the older runners
# This explicit dependency can be switched back to macos-latest once it points to macos-14,
# which is expected to happen sometime in Q2 FY24 (April – June 2024).
# https://github.blog/changelog/2024-01-30-github-actions-macos-14-sonoma-is-now-available/
#
# The MSRV jobs run only cargo check because different clippy versions can disagree on goals and
# running tests introduces dev dependencies which may require a higher MSRV than the bare package.

name: CI

on:
pull_request:
merge_group:

jobs:
fmt:
name: cargo fmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
components: rustfmt

- name: cargo fmt
run: cargo fmt --all --check

- name: install ripgrep
run: |
sudo apt update
sudo apt install ripgrep
- name: check copyright headers
run: bash .github/copyright.sh

clippy-stable:
name: cargo clippy
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-14, ubuntu-latest]
steps:
- uses: actions/checkout@v4

- name: restore cache
uses: Swatinem/rust-cache@v2

- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
components: clippy

- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack

- name: cargo clippy
run: cargo hack clippy --workspace --locked --each-feature --optional-deps -- -D warnings

- name: cargo clippy (auxiliary)
run: cargo hack clippy --workspace --locked --each-feature --optional-deps --tests --benches --examples -- -D warnings

clippy-stable-android:
name: cargo clippy (android)
runs-on: ubuntu-latest
strategy:
matrix:
target: [armv7-linux-androideabi, aarch64-linux-android, x86_64-linux-android]
steps:
- uses: actions/checkout@v4

- name: restore cache
uses: Swatinem/rust-cache@v2

- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}
targets: ${{ matrix.target }}
components: clippy

- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack

- name: cargo clippy
run: cargo hack clippy --workspace --locked --target ${{ matrix.target }} --each-feature --optional-deps -- -D warnings

- name: cargo clippy (auxiliary)
run: cargo hack clippy --workspace --locked --target ${{ matrix.target }} --each-feature --optional-deps --tests --benches --examples -- -D warnings

test-stable:
name: cargo test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-14, ubuntu-latest]
steps:
- uses: actions/checkout@v4

- name: restore cache
uses: Swatinem/rust-cache@v2

- name: install stable toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_STABLE_VER }}

- name: cargo test
run: cargo test --workspace --locked --all-features

check-msrv:
name: cargo check (msrv)
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-14, ubuntu-latest]
steps:
- uses: actions/checkout@v4

- name: restore cache
uses: Swatinem/rust-cache@v2

- name: install msrv toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_MIN_VER }}

- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack

- name: cargo check
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --each-feature --optional-deps

check-msrv-android:
name: cargo check (msrv) (android)
runs-on: ubuntu-latest
strategy:
matrix:
target: [armv7-linux-androideabi, aarch64-linux-android, x86_64-linux-android]
steps:
- uses: actions/checkout@v4

- name: restore cache
uses: Swatinem/rust-cache@v2

- name: install msrv toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{ env.RUST_MIN_VER }}
targets: ${{ matrix.target }}

- name: install cargo-hack
uses: taiki-e/install-action@v2
with:
tool: cargo-hack

- name: cargo check
run: cargo hack check ${{ env.RUST_MIN_VER_PKGS }} --locked --target ${{ matrix.target }} --each-feature --optional-deps

doc:
name: cargo doc
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, macos-14, ubuntu-latest]
steps:
- uses: actions/checkout@v4

- name: restore cache
uses: Swatinem/rust-cache@v2

- name: install nightly toolchain
uses: dtolnay/rust-toolchain@nightly

# We test documentation using nightly to match docs.rs. This prevents potential breakages
- name: cargo doc
run: cargo doc --workspace --locked --all-features --no-deps --document-private-items -Zunstable-options -Zrustdoc-scrape-examples
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
/target
Cargo.lock
2 changes: 2 additions & 0 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use_field_init_shorthand = true
newline_style = "Unix"
Loading

0 comments on commit 4f05e18

Please sign in to comment.