Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"containerEnv": {
"HOME": "/home/vscode"
},
"containerUser": "vscode",
"customizations": {
"jetbrains": {
"plugins": [
"com.jetbrains.rust",
"systems.fehn.intellijdirenv"
]
},
"vscode": {
"extensions": [
"rust-lang.rust-analyzer",
"ms-vscode.cpptools",
"mkhl.direnv",
"vadimcn.vscode-lldb",
"tamasfe.even-better-toml"
],
"settings": {
"rust-analyzer.cargo.features": [
"vendored"
]
}
}
},
"image": "ghcr.io/cachix/devenv/devcontainer:latest",
"overrideCommand": false,
"runArgs": [
"--userns=keep-id:uid=1000,gid=1000"
],
"updateContentCommand": "devenv test",
"updateRemoteUserUID": true
}
10 changes: 10 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export DIRENV_WARN_TIMEOUT=20s

eval "$(devenv direnvrc)"

# `use devenv` supports the same options as the `devenv shell` command.
#
# To silence the output, use `--quiet`.
#
# Example usage: use devenv --quiet --impure --option services.postgres.enable:bool true
use devenv
26 changes: 26 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

## Description

Please describe the changes made in the Pull Request here.

## How to Test

If there are any specific test procedures that pertain to this change in
particular, you may describe them here.

## Related Issues

If this pull request resolves an issue that can be found in the repository's
issue tracker, you [may reference the issue here using a keyword](https://docs.github.com/en/issues/tracking-your-work-with-issues/using-issues/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword).
Example: This pull request closes [TODO].

## Checklist

- [ ] I have read, understood, and acknowledged the [NOTICE](https://github.com/namib-project/libcoap-rs/blob/main/NOTICE.md) file and the [Contribution Guide](https://github.com/namib-project/libcoap-rs/blob/main/CONTRIBUTING.md)
- [ ] I affirm that I have the right to submit the changes made by this pull
request under the BSD-2-Clause license as indicated in the NOTICE file.
- [ ] This PR is either a) free of any LLM-generated code, or b) I have
disclosed all uses of LLM-generated code in this pull request and
indicated the models that were used.
Any submitted LLM-generated code may verifiably be licensed under the
BSD-2-Clause license.
122 changes: 76 additions & 46 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,50 +28,44 @@ jobs:
LLVM_PROFILE_FILE: "${{ github.workspace }}/coverage-data/coverage/libcoap-rs-%p-%m.profraw"
RUSTFLAGS: "${{ matrix.rust_version == 'nightly' && '-Cinstrument-coverage -Cpanic=abort -Zpanic_abort_tests' || ' ' }}"
RUSTDOCFLAGS: "${{ matrix.rust_version == 'nightly' && '-C instrument-coverage -Cpanic=abort -Zpanic_abort_tests -Z unstable-options --persist-doctests target/debug/doctests' || ' ' }}"
LIBRARY_FEATURES: |
${{ (matrix.crate == 'libcoap-rs' && 'tcp,vendored,rand')
|| (matrix.crate == 'libcoap-sys' && 'default,vendored')
|| 'vendored'
}}
LIBCOAP_RS_DTLS_BACKEND: ${{ matrix.dtls_backend }}
LIBCOAP_RS_BUILD_SYSTEM: "vendored"
DTLS_LIBRARY_FEATURES: |
${{ (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'tinydtls' && 'tcp,dtls-psk,dtls-rpk,dtls-tinydtls-sys-vendored')
|| (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'mbedtls' && 'tcp,dtls-psk,dtls-pki')
|| (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'openssl' && 'tcp,dtls-psk,dtls-pki,dtls-openssl-sys-vendored')
|| (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'gnutls' && 'tcp,dtls-psk,dtls-pki,dtls-rpk')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'tinydtls' && 'dtls,dtls-tinydtls-sys-vendored')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'mbedtls' && 'dtls')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'openssl' && 'dtls,dtls-openssl-sys-vendored')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'gnutls' && 'dtls')
|| 'vendored'
}}
steps:
- uses: actions/checkout@v4
with:
submodules: true
- uses: dtolnay/rust-toolchain@stable
- uses: nixbuild/nix-quick-install-action@v33
- name: Restore and save Nix store in GitHub cache
uses: nix-community/cache-nix-action@v6
with:
components: rust-src, rustc, rust-std, cargo, llvm-tools, llvm-tools-preview
toolchain: ${{ matrix.rust_version == 'msrv' && '1.82' || matrix.rust_version }}
- if: matrix.dtls_backend == 'gnutls'
uses: awalsh128/[email protected]
with:
packages: libgnutls28-dev libgnutls30
version: 1.0
- if: matrix.dtls_backend == 'mbedtls'
uses: awalsh128/[email protected]
with:
packages: libmbedtls-dev
version: 1.0
- run: cargo test -p ${{ matrix.crate }} --no-default-features --features "$LIBRARY_FEATURES" --features "$DTLS_LIBRARY_FEATURES" --no-fail-fast
# restore and save a cache using this key
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/devenv.lock') }}
# if there's no cache hit, restore a cache by this prefix
restore-prefixes-first-match: nix-${{ runner.os }}-
# collect garbage until the Nix store size (in bytes) is at most this number
# before trying to save a new cache
# 1G = 1073741824
gc-max-store-size: 3G
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: nix-${{ runner.os }}-
# last accessed more than this number of seconds ago
# relative to the start of the `Post Restore and save Nix store` phase
purge-last-accessed: 86400
# except any version with the key that is the same as the `primary-key`
purge-primary-key: never
- name: Install devenv.sh using Nix
run: nix profile install 'nixpkgs#devenv'
- name: Run tests
run: devenv shell --option rust-version:string ${{ matrix.rust_version }} ${{ matrix.crate }}:test_${{ matrix.dtls_backend }}
- if: matrix.rust_version == 'nightly'
name: Generate coverage data
run: |
mkdir -p coverage-data/test-binaries
mkdir -p target/debug/doctests
cp $(cargo test -p ${{ matrix.crate }} --no-run --message-format=json --no-default-features --features "$LIBRARY_FEATURES" --features "$DTLS_LIBRARY_FEATURES" --no-fail-fast \
devenv shell --option rust-version:string ${{ matrix.rust_version }} 'cp $(${{ matrix.crate }}:test_${{ matrix.dtls_backend }} --no-run --message-format=json --no-fail-fast \
| jq -r "select(.profile.test == true) | .filenames[]" \
| grep -v dSYM -) coverage-data/test-binaries/
| grep -v dSYM -) coverage-data/test-binaries/'
cp -r target/debug/doctests coverage-data/test-binaries/
- if: matrix.rust_version == 'nightly'
uses: actions/upload-artifact@v4
Expand All @@ -80,6 +74,8 @@ jobs:
name: test-coverage-data-${{ matrix.crate }}-${{ matrix.dtls_backend }}
path: |
coverage-data/
- name: devenv.sh garbage collection
run: devenv gc

lint:
name: lint
Expand All @@ -88,21 +84,40 @@ jobs:
- uses: actions/checkout@v4
with:
submodules: true
- uses: nixbuild/nix-quick-install-action@v33
- name: Restore and save Nix store in GitHub cache
uses: nix-community/cache-nix-action@v6
with:
# restore and save a cache using this key
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/devenv.lock') }}
# if there's no cache hit, restore a cache by this prefix
restore-prefixes-first-match: nix-${{ runner.os }}-
# collect garbage until the Nix store size (in bytes) is at most this number
# before trying to save a new cache
# 1G = 1073741824
gc-max-store-size: 3G
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: nix-${{ runner.os }}-
# last accessed more than this number of seconds ago
# relative to the start of the `Post Restore and save Nix store` phase
purge-last-accessed: 86400
# except any version with the key that is the same as the `primary-key`
purge-primary-key: never
- name: Install devenv.sh using Nix
run: nix profile install 'nixpkgs#devenv'
- uses: reviewdog/action-setup@v1
with:
reviewdog_version: latest
# Nightly required for rustfmt's --emit=checkstyle argument
- uses: dtolnay/rust-toolchain@nightly
with:
components: clippy, rustfmt
- uses: baptiste0928/cargo-install@v3
with:
crate: clippy-reviewdog-filter
- name: Run Linter
env:
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
reviewdog -reporter=github-pr-check -fail-level=any
devenv shell --option rust-version:string nightly reviewdog -reporter=github-pr-check -fail-level=any

docs:
runs-on: ubuntu-latest
Expand All @@ -113,16 +128,31 @@ jobs:
with:
submodules: true
ref: ${{ env.HEAD_REF }}
# --all-features uses GNUTLS as backend, must provide it.
- uses: awalsh128/[email protected]
with:
packages: libgnutls28-dev libgnutls30
version: 1.0
- uses: dtolnay/rust-toolchain@nightly
- uses: nixbuild/nix-quick-install-action@v33
- name: Restore and save Nix store in GitHub cache
uses: nix-community/cache-nix-action@v6
with:
components: rustc
# restore and save a cache using this key
primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/devenv.lock') }}
# if there's no cache hit, restore a cache by this prefix
restore-prefixes-first-match: nix-${{ runner.os }}-
# collect garbage until the Nix store size (in bytes) is at most this number
# before trying to save a new cache
# 1G = 1073741824
gc-max-store-size: 3G
# do purge caches
purge: true
# purge all versions of the cache
purge-prefixes: nix-${{ runner.os }}-
# last accessed more than this number of seconds ago
# relative to the start of the `Post Restore and save Nix store` phase
purge-last-accessed: 86400
# except any version with the key that is the same as the `primary-key`
purge-primary-key: never
- name: Install devenv.sh using Nix
run: nix profile install 'nixpkgs#devenv'
- name: Build documentation
run: cargo doc --all-features --no-deps --workspace
run: devenv shell docs
- uses: actions/upload-artifact@v4
id: upload-docs
with:
Expand Down
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,28 @@ fabric.properties

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

# Devenv
.devenv*
devenv.local.nix

# direnv
.direnv

# pre-commit
.pre-commit-config.yaml

# VSCode, see https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
# VS Code files for those working on multiple tools
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets

# Local History for Visual Studio Code
.history/

# Built Visual Studio Code Extensions
*.vsix
Loading
Loading