diff --git a/.devcontainer.json b/.devcontainer.json new file mode 100644 index 00000000..11fcc81f --- /dev/null +++ b/.devcontainer.json @@ -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 +} diff --git a/.envrc b/.envrc new file mode 100644 index 00000000..7e9a2d60 --- /dev/null +++ b/.envrc @@ -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 diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 00000000..a5b50cb5 --- /dev/null +++ b/.github/pull_request_template.md @@ -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. diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f29720f2..111a9209 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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/cache-apt-pkgs-action@v1.4.3 - with: - packages: libgnutls28-dev libgnutls30 - version: 1.0 - - if: matrix.dtls_backend == 'mbedtls' - uses: awalsh128/cache-apt-pkgs-action@v1.4.3 - 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 @@ -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 @@ -88,13 +84,32 @@ 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 @@ -102,7 +117,7 @@ jobs: 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 @@ -113,16 +128,31 @@ jobs: with: submodules: true ref: ${{ env.HEAD_REF }} - # --all-features uses GNUTLS as backend, must provide it. - - uses: awalsh128/cache-apt-pkgs-action@v1.4.3 - 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: diff --git a/.gitignore b/.gitignore index bc1dc4b5..11b71119 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/.idea/editor.xml b/.idea/editor.xml new file mode 100644 index 00000000..ead1d8a3 --- /dev/null +++ b/.idea/editor.xml @@ -0,0 +1,248 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..369389b4 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test_libcoap_rs__GnuTLS_.xml b/.idea/runConfigurations/Test_libcoap_rs__GnuTLS_.xml new file mode 100644 index 00000000..0493d347 --- /dev/null +++ b/.idea/runConfigurations/Test_libcoap_rs__GnuTLS_.xml @@ -0,0 +1,22 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test_libcoap_rs__MbedTLS_.xml b/.idea/runConfigurations/Test_libcoap_rs__MbedTLS_.xml new file mode 100644 index 00000000..0696b480 --- /dev/null +++ b/.idea/runConfigurations/Test_libcoap_rs__MbedTLS_.xml @@ -0,0 +1,22 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test_libcoap_rs__OpenSSL_.xml b/.idea/runConfigurations/Test_libcoap_rs__OpenSSL_.xml new file mode 100644 index 00000000..309f693e --- /dev/null +++ b/.idea/runConfigurations/Test_libcoap_rs__OpenSSL_.xml @@ -0,0 +1,22 @@ + + + + \ No newline at end of file diff --git a/.idea/runConfigurations/Test.xml b/.idea/runConfigurations/Test_libcoap_rs__no_DTLS_.xml similarity index 76% rename from .idea/runConfigurations/Test.xml rename to .idea/runConfigurations/Test_libcoap_rs__no_DTLS_.xml index 4f6e6f9d..9dd7e398 100644 --- a/.idea/runConfigurations/Test.xml +++ b/.idea/runConfigurations/Test_libcoap_rs__no_DTLS_.xml @@ -1,6 +1,7 @@ - -