Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring of the libcoap-sys build script #42

Merged
merged 26 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
ad838a8
refactor(sys): convert build script to directory
pulsastrix Dec 19, 2024
5a136d2
refactor(sys): implement pkg-config based build system for sys crate
pulsastrix Jan 16, 2025
d640bdf
fix(sys): Fix include paths for pkg-config build system, update bindgen
pulsastrix Jan 16, 2025
93b1c69
refactor(sys): re-implement vendored library build
pulsastrix Jan 17, 2025
6767a7e
fix(sys): only link the DTLS library crate that is _actually_ used.
pulsastrix Jan 17, 2025
2a69255
refactor(sys): simplify build system selection, add stubs for ESP-IDF…
pulsastrix Jan 17, 2025
d08a16d
refactor(sys): reimplement ESP-IDF build to re-export esp-idf-sys
pulsastrix Jan 17, 2025
478bfd0
refactor(sys): improve reliability of new build script, add ESP-IDF c…
pulsastrix Jan 18, 2025
88758b1
feat(sys): Allow manual specification of include and library paths
pulsastrix Jan 18, 2025
8bd6e93
fix(test): properly propagate panics produced (in test server setup)
pulsastrix Jan 20, 2025
1252c3b
chore(lib): remove remaining compatibility code for libcoap < 4.3.5
pulsastrix Jan 20, 2025
157ee9b
fix(sys|test): provide version+DTLS lib to downstream crates, update …
pulsastrix Jan 20, 2025
6d2a339
refactor(sys): improve error output and coap_startup_with_feature_checks
pulsastrix Jan 21, 2025
7a702bf
fix(sys): respect LIBCOAP_RS_BYPASS_COMPILE_FEATURE_CHECKS on ESP-IDF…
pulsastrix Jan 21, 2025
63a5796
fix(lib): specify the ESP-IDF libcoap component in libcoap-rs
pulsastrix Jan 21, 2025
8e10554
refactor(sys|lib): change bindgen enums+unions, re-export libc
pulsastrix Jan 21, 2025
9441e02
feat(test): Add example for libcoap-rs+ESP-IDF, update libcoap-sys+ES…
pulsastrix Jan 21, 2025
cb3ef19
docs(sys): Start rewriting the libcoap-sys documentation
pulsastrix Jan 21, 2025
cdd49d1
docs(sys|lib): Finish rewrite of build instructions
pulsastrix Jan 22, 2025
3f17b4e
fix(ci): Adjust CI pipeline for new build script, fix docs deploy
pulsastrix Jan 22, 2025
e251b56
chore(lib|sys): bump MSRV to 1.82 to support bindgen-generated unsafe…
pulsastrix Jan 22, 2025
5978778
chore(lib|sys): Run cargo fmt to make linter happy
pulsastrix Jan 22, 2025
3e1493c
chore(sys): remove old build script
pulsastrix Jan 22, 2025
448822f
refactor(lib|sys): address comments from PR #42
pulsastrix Jan 23, 2025
7f98718
fix(ci): update cache-apt-pkgs-action to fix upload-artifacts depreca…
pulsastrix Jan 23, 2025
8eb6f1e
docs(lib|sys): Add READMEs explaining esp-idf examples
pulsastrix Jan 23, 2025
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
4 changes: 2 additions & 2 deletions .github/workflows/report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ jobs:
pattern: docs
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: coverage-data
path: ./doc
- name: 'Get artifact ID'
id: get-artifact-id
uses: actions/github-script@v7
Expand All @@ -79,7 +79,7 @@ jobs:
- if: ${{ (github.event.workflow_run.head_repository.owner.login == github.event.workflow_run.repository.owner.login) && (vars.DOCS_AND_COV_REPO != '') }}
uses: peaceiris/actions-gh-pages@v4
with:
publish_dir: ./target/doc
publish_dir: ./doc
publish_branch: main
external_repository: ${{ vars.DOCS_AND_COV_REPO }}
personal_token: ${{ secrets.DOCS_AND_COV_REPO_TOKEN }}
Expand Down
26 changes: 14 additions & 12 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ jobs:
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')
|| (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_vendored')
|| (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'mbedtls' && 'tcp,dtls-psk,dtls-pki,dtls_mbedtls_vendored')
|| (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'openssl' && 'tcp,dtls-psk,dtls-pki,dtls_openssl_vendored')
|| (matrix.crate == 'libcoap-rs' && matrix.dtls_backend == 'gnutls' && 'tcp,dtls-psk,dtls-pki,dtls-rpk,dtls_gnutls')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'tinydtls' && 'dtls,dtls_backend_tinydtls,dtls_backend_tinydtls_vendored')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'mbedtls' && 'dtls,dtls_backend_mbedtls,dtls_backend_mbedtls_vendored')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'openssl' && 'dtls,dtls_backend_openssl,dtls_backend_openssl_vendored')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'gnutls' && 'dtls,dtls_backend_gnutls')
${{ (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,dtls-mbedtls-sys')
|| (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,dtls-mbedtls-sys')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'openssl' && 'dtls,dtls-openssl-sys-vendored')
|| (matrix.crate == 'libcoap-sys' && matrix.dtls_backend == 'gnutls' && 'dtls')
|| 'vendored'
}}
steps:
Expand All @@ -51,9 +53,9 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
with:
components: rust-src, rustc, rust-std, cargo, llvm-tools, llvm-tools-preview
toolchain: ${{ matrix.rust_version == 'msrv' && '1.81' || matrix.rust_version }}
toolchain: ${{ matrix.rust_version == 'msrv' && '1.82' || matrix.rust_version }}
- if: matrix.dtls_backend == 'gnutls'
uses: awalsh128/cache-apt-pkgs-action@latest
uses: awalsh128/cache-apt-pkgs-action@v1.4.3
with:
packages: libgnutls28-dev libgnutls30
version: 1.0
Expand Down Expand Up @@ -105,7 +107,7 @@ jobs:
submodules: true
ref: ${{ env.HEAD_REF }}
# --all-features uses GNUTLS as backend, must provide it.
- uses: awalsh128/cache-apt-pkgs-action@latest
- uses: awalsh128/cache-apt-pkgs-action@v1.4.3
with:
packages: libgnutls28-dev libgnutls30
version: 1.0
Expand Down
8 changes: 8 additions & 0 deletions .idea/libcoap-rs.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

94 changes: 50 additions & 44 deletions libcoap-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,54 +18,56 @@ categories = ["external-ffi-bindings", "network-programming", "embedded"]
keywords = ["coap", "libcoap"]
exclude = ["src/libcoap/ext/"]
resolver = "2"
# Current reason for MSRV (please update when increasing MSRV): Transient dependency "home" requires Rust 1.81.
rust-version = "1.81.0"
build = "build/main.rs"
# Current reason for MSRV (please update when increasing MSRV): bindgen generates unsafe extern "C" blocks, which are
# not supported on Rust < 1.82.
# See also: https://doc.rust-lang.org/nightly/edition-guide/rust-2024/unsafe-extern.html
rust-version = "1.82.0"

[features]
# The default features match those of libcoaps configure script, except for dtls, which is disabled here because it
# requires a backend to be set manually.
default = ["oscore", "ipv4", "ipv6", "af-unix", "tcp", "websockets", "async", "observe-persist", "q-block", "thread-safe", "thread-recursive-lock-detection", "server", "client", "epoll", "vendored", "static"]
# While not specified here due to limitations in Cargo's syntax, the DTLS feature depends on one of the DTLS backends
# being enabled.
# If you are developing a library based on libcoap-sys and do not care about the DTLS backend, enable the dtls feature
# and let the user decide on the backend to use, either by re-exporting these features (see
# https://doc.rust-lang.org/cargo/reference/features.html#dependency-features) or by assuming that the user will use
# libcoap-sys as a dependency and enable the corresponding backend feature themselves, relying on Cargo's feature
# unification to enable it for your crate as well.
# Also note that the backends are **mutually exclusive** due to the C library having these backends as mutually
# exclusive features. If multiple backends are enabled (e.g. because multiple dependencies use libcoap-sys and use
# different backends), we select one based on the auto-detection order specified in
# https://github.com/obgm/libcoap/blob/develop/configure.ac#L494 (gnutls > openssl > mbedtls > tinydtls).
# The default features match those of libcoap's configure script for
# the minimum supported version.
default = [
"dtls",
"oscore",
"ipv4",
"ipv6",
"af-unix",
"tcp",
"websockets",
"async",
"observe-persist",
"q-block",
"thread-safe",
"thread-recursive-lock-detection",
"server",
"client",
"epoll",
# TODO add proxy
]

# Allows using the version of OpenSSL provided by openssl-sys instead of a system-provided one.
# Note that this does not enforce the use of OpenSSL in libcoap, see the crate-level documentation for more info.
dtls-openssl-sys = ["dep:openssl-sys"]
# Tell the openssl-sys version that is possibly used by libcoap-sys to use the vendored version of its library.
dtls-openssl-sys-vendored = ["dtls-openssl-sys", "openssl-sys/vendored"]
# Allows using the version of MbedTLS provided by mbedtls-sys-auto instead of a system-provided one.
# Note that this does not enforce the use of MbedTLS in libcoap, see the crate-level documentation for more info.
dtls-mbedtls-sys = ["dep:mbedtls-sys-auto"]
# Allows using the version of TinyDTLS provided by tinydtls-sys instead of a system-provided one.
# Note that this does not enforce the use of TinyDTLS in libcoap, see the crate-level documentation for more info.
dtls-tinydtls-sys = ["dep:tinydtls-sys", "tinydtls-sys/ecc", "tinydtls-sys/psk"]
# Tell the tinydtls-sys version that is possibly used by libcoap-sys to use the vendored version of its library.
dtls-tinydtls-sys-vendored = ["dtls-tinydtls-sys", "tinydtls-sys/vendored"]

# Corresponding libcoap configure flag: --with-openssl
dtls_backend_openssl = ["dtls", "dep:openssl-sys"]
dtls_backend_openssl_vendored = ["dtls_backend_openssl", "openssl-sys/vendored"]
# Corresponding libcoap configure flag: --with-gnutls
dtls_backend_gnutls = ["dtls"]
# Corresponding libcoap configure flag: --with-mbedtls
dtls_backend_mbedtls = ["dtls"] # can't use mbedtls-sys-auto to generate linker flags here, as the crate doesn't support mbedtls >= 3.0.0
dtls_backend_mbedtls_vendored = ["dep:mbedtls-sys-auto", "dtls_backend_mbedtls"]
# Corresponding libcoap configure flags: --with-tinydtls --without-submodule-tinydtls
dtls_backend_tinydtls = ["dtls", "dep:tinydtls-sys", "tinydtls-sys/ecc", "tinydtls-sys/psk"]
dtls_backend_tinydtls_vendored = ["dtls_backend_tinydtls", "tinydtls-sys/vendored"]
# Enabling this feature will force libcoap-sys to be built with and statically linked to a vendored version of libcoap,
# which will be built by the build-script before building libcoap-sys.
# Enabling this feature will allow libcoap-sys to be built with and statically linked to a vendored version of libcoap,
# This way, it is no longer required to have libcoap installed to use this crate.
vendored = ["static"]
# Enable this feature to use static linking to libcoap instead of dynamic linking.
static = []
vendored = []
# --- FEATURE FLAGS ---
# Note that setting the feature flags currently has no effect on the generated Rust code, because the libcoap headers do
# not use these feature flags. They only affect the features built into the vendored C library (if enabled).

# Enable this feature to enable/require CoAP over DTLS support in the C library.
# Important: also read the section on DTLS backends before enabling this feature.
# Corresponding libcoap configure flag: --enable-dtls
dtls = []
# Enable this feature to enable/require TLS support in addition to DTLS support.
# Note: Will also enable the TCP and DTLS features, so consider the above section regarding DTLS backends before +
# enabling this.
tls = ["dtls", "tcp"]
# Enable this feature to enable/require OSCORE functionality in the C library.
# Corresponding libcoap configure flag: --enable-oscore
Expand Down Expand Up @@ -137,24 +139,28 @@ dtls-rpk = ["dtls"]
[dependencies]
openssl-sys = { version = "^0.9.74", optional = true }
mbedtls-sys-auto = { version = "^2.26", optional = true }
libc = "^0.2.126"
tinydtls-sys = { version = "^0.2.0", default-features = false, optional = true }

[target.'cfg(target_os="espidf")'.dependencies]
esp-idf-sys = { version = "0.35.0" }
esp-idf-sys = { version = "0.36.1" }

[target.'cfg(not(target_os="espidf"))'.dependencies]
libc = "0.2.126"

[build-dependencies]
bindgen = "0.69.4"
bindgen = { version = "0.71.1" }
autotools = "^0.2.3"
fs_extra = "^1.2"
pkg-config = "^0.3.24"
regex = "1.10.5"
embuild = { version = "0.32.0", features = ["bindgen", "espidf", "cmake"] }
version-compare = "0.2.0"
anyhow = { version = "1.0.94", features = ["backtrace"] }
enumset = "1.1.5"
syn = { version = "2.0.96" }
embuild = { version = "0.33.0", features = ["espidf"] }

[package.metadata.docs.rs]
features = ["dtls", "dtls_backend_openssl", "vendored"]

[[package.metadata.esp-idf-sys.extra_components]]
remote_component = { name = "espressif/coap", version = "4.3.4~3" }
remote_component = { name = "espressif/coap", version = "4.3.5~3" }
bindings_header = "src/wrapper.h"
Loading
Loading