Skip to content

Commit

Permalink
Merge #88: Improve "infrastructure" crate wide
Browse files Browse the repository at this point in the history
c691a83 Add githooks directory (Tobin C. Harding)
d4191cc Improve CI pipeline (Tobin C. Harding)
ef35d89 Enable build of docs with doc_auto_cfg (Tobin C. Harding)
a37819b Remove default lint config options (Tobin C. Harding)
81b8201 Remove allow(bare_trait_objects) (Tobin C. Harding)
7fb1755 Remove allow(unknown_lints) (Tobin C. Harding)
f5cd60e Bump MSRV to Rust 1.48.0 (Tobin C. Harding)
5962169 Do trivial cleanup to readme (Tobin C. Harding)
ded35fe Use SPDX license ID (Tobin C. Harding)

Pull request description:

  Improve various things around the crate (infrastructure for want of a better word)

  **Please note:** Includes bump of MSRV to 1.48.0 because arrayvec was failing with 1.41 after improving CI.

  EDIT: Oooooh, now I get it, arrayvec feature breaks the MSRV, regardless of if its 1.41 or 1.48 - I forgot that. I"m totally sick of rebasing this so I'm leaving the MSRV bump in there.

  - CI
  - github actions
  - linting
  - docs
  - githooks

  Patch 7 `ef35d89 Enable build of docs with doc_auto_cfg` fixes #75

ACKs for top commit:
  apoelstra:
    ACK c691a83

Tree-SHA512: 6b9f684c72e72972c8ba319bd8f2337acac3563418a0f25f9f99abbc58107c0fbd8662d8afd41ee6adec9cb81996ba439f693e12c9d61e139315261d4ce48056
  • Loading branch information
apoelstra committed Apr 3, 2023
2 parents d566ec4 + c691a83 commit 8f6d5d9
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 130 deletions.
40 changes: 38 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ jobs:
- name: Running test script
env:
DO_LINT: true
DO_DOCS: true
DO_FEATURE_MATRIX: true
run: ./contrib/test.sh

Beta:
Expand Down Expand Up @@ -44,19 +46,20 @@ jobs:
uses: dtolnay/rust-toolchain@nightly
- name: Running test script
env:
DO_DOCSRS: true
DO_FMT: true
run: ./contrib/test.sh

MSRV:
name: Test - 1.41.1 toolchain
name: Test - 1.48.0 toolchain
runs-on: ubuntu-latest
strategy:
fail-fast: false
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@1.41.1
uses: dtolnay/rust-toolchain@1.48.0
- name: Running test script
run: ./contrib/test.sh

Expand Down Expand Up @@ -99,3 +102,36 @@ jobs:
RUSTFLAGS: "-C link-arg=-Tlink.x"
CARGO_TARGET_THUMBV7M_NONE_EABI_RUNNER: "qemu-system-arm -cpu cortex-m3 -machine mps2-an385 -nographic -semihosting-config enable=on,target=native -kernel"
run: cd embedded/no-allocator && cargo run --target thumbv7m-none-eabi

Arch32bit:
name: Test 32-bit version
runs-on: ubuntu-latest
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@stable
- name: Add architecture i386
run: sudo dpkg --add-architecture i386
- name: Install i686 gcc
run: sudo apt-get update -y && sudo apt-get install -y gcc-multilib
- name: Install target
run: rustup target add i686-unknown-linux-gnu
- name: Run tests on i686
run: cargo test --target i686-unknown-linux-gnu

Cross:
name: Cross test
if: ${{ !github.event.act }}
runs-on: ubuntu-latest
steps:
- name: Checkout Crate
uses: actions/checkout@v3
- name: Checkout Toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install target
run: rustup target add s390x-unknown-linux-gnu
- name: install cross
run: cargo install cross --locked
- name: run cross test
run: cross test --target s390x-unknown-linux-gnu
3 changes: 0 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ default = ["std"]
std = ["alloc"]
alloc = []

# Only for CI to make all warnings errors, do not activate otherwise (may break forward compatibility)
strict = []

[dependencies.arrayvec]
version = "0.7.1"
default-features = false
Expand Down
25 changes: 25 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Copyright (c) 2017 Clark Moody

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
21 changes: 18 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Bech32 Rust
Rust Bech32
===========

[![Docs.rs badge](https://docs.rs/bech32/badge.svg)](https://docs.rs/bech32/)
[![Continuous Integration](https://github.com/rust-bitcoin/rust-bech32/workflows/Continuous%20Integration/badge.svg)](https://github.com/rust-bitcoin/rust-bech32/actions?query=workflow%3A%22Continuous+Integration%22)

Expand All @@ -9,6 +11,19 @@ You can find some usage examples in the [documentation](https://docs.rs/bech32/)

Bitcoin-specific address encoding is handled by the `bitcoin-bech32` crate.

# MSRV
The minimum supported Rust version with the standard library is **1.41.1**.

## MSRV

This library should always compile with any combination of features excluding "arrayvec" on **Rust 1.48.0**.


## Githooks

To assist devs in catching errors _before_ running CI we provide some githooks. If you do not
already have locally configured githooks you can use the ones in this repository by running, in the
root directory of the repository:
```
git config --local core.hooksPath githooks/
```

Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide.
2 changes: 1 addition & 1 deletion clippy.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
msrv = "1.41.1"
msrv = "1.48.0"
60 changes: 32 additions & 28 deletions contrib/test.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
#!/bin/sh
#
# CI test script for rust-bech32.
#
# The "strict" feature is used to configure cargo to deny all warnings, always use it in test runs.

set -eu
set -x

# "arrayvec" feature breaks the MSRV, its added manually in DO_FEATURE_MATRIX loop below.
FEATURES="std alloc"

# Some tests require certain toolchain types.
NIGHTLY=false
MIN_VERSION=false
MSRV=false
if cargo --version | grep nightly; then
NIGHTLY=true
fi
if cargo --version | grep 1.41; then
MIN_VERSION=true
if cargo --version | grep "1\.48"; then
MSRV=true
fi

build_and_test () {
cargo build --no-default-features --features="$1"
cargo test --no-default-features --features="$1"
}

# Sanity, check tools exist.
cargo --version
rustc --version
Expand All @@ -37,34 +43,32 @@ if [ "${DO_FMT-false}" = true ]; then
cargo fmt --check
fi

check () {
cargo build --no-default-features --features="strict $1"
cargo test --no-default-features --features="strict $1"
}
if [ "${DO_FEATURE_MATRIX-false}" = true ]; then
# No features
build_and_test ""

# Check without features ("strict" is a CI feature only, see above).
check ""

# Check "arrayvec" feature alone.
if [ "$MIN_VERSION" != true ]; then
check "arrayvec"
# Feature combos
build_and_test "std"
build_and_test "alloc"
build_and_test "std alloc"
# arrayvec breaks the MSRV
if [ $MSRV = false
]; then
build_and_test "arrayvec"
build_and_test "std arrayvec"
build_and_test "alloc arrayvec"
fi
fi

# Check "alloc" feature alone.
check "alloc"

# Check "alloc" & "arrayvec" features together.
if [ "$MIN_VERSION" != true ]; then
check "alloc arrayvec"
# Build the docs if told to (this only works with the nightly toolchain)
if [ "${DO_DOCSRS-false}" = true ]; then
RUSTDOCFLAGS="--cfg docsrs -D warnings -D rustdoc::broken-intra-doc-links" cargo +nightly doc --all-features
fi

# Check "std" feature (implies "alloc", so this is equivalent to --all-features).
cargo build --no-default-features --features="std"
cargo test --no-default-features --features="std"

# Check "std" & "arrayvec" features together.
if [ "$MIN_VERSION" != true ]; then
check "std arrayvec"
# Build the docs with a stable toolchain, in unison with the DO_DOCSRS command
# above this checks that we feature guarded docs imports correctly.
if [ "${DO_DOCS-false}" = true ]; then
RUSTDOCFLAGS="-D warnings" cargo +stable doc --all-features
fi

exit 0
49 changes: 49 additions & 0 deletions githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh
#
# Verify what is about to be committed. Called by "git commit" with no
# arguments. The hook should exit with non-zero status after issuing an
# appropriate message if it wants to stop the commit.

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi

# If you want to allow non-ASCII filenames set this variable to true.
allownonascii=$(git config --bool hooks.allownonascii)

# Redirect output to stderr.
exec 1>&2

# Cross platform projects tend to avoid non-ASCII filenames; prevent
# them from being added to the repository. We exploit the fact that the
# printable range starts at the space character and ends with tilde.
if [ "$allownonascii" != "true" ] &&
# Note that the use of brackets around a tr range is ok here, (it's
# even required, for portability to Solaris 10's /usr/bin/tr), since
# the square bracket bytes happen to fall in the designated range.
test $(git diff --cached --name-only --diff-filter=A -z $against |
LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0
then
cat <<\EOF
Error: Attempt to add a non-ASCII file name.
This can cause problems if you want to work with people on other platforms.
To be portable it is advisable to rename the file.
If you know what you are doing you can disable this check using:
git config hooks.allownonascii true
EOF
exit 1
fi

# If there are whitespace errors, print the offending file names and fail.
git diff-index --check --cached $against -- || exit 1

# Check that code lints cleanly.
cargo clippy --all-features -- -D warnings || exit 1

0 comments on commit 8f6d5d9

Please sign in to comment.