diff --git a/.github/workflows/nightly.yaml b/.github/workflows/nightly.yaml index f6f49a0..ca89ac3 100644 --- a/.github/workflows/nightly.yaml +++ b/.github/workflows/nightly.yaml @@ -26,6 +26,9 @@ jobs: check-msrv: uses: ./.github/workflows/verify-msrv.yaml + test-all-features: + uses: ./.github/workflows/test-featurematrix.yaml + x-build: # The jury is still out on whether this actually adds any value, besides simply being possible... uses: ./.github/workflows/x-build.yaml diff --git a/.github/workflows/test-featurematrix.yaml b/.github/workflows/test-featurematrix.yaml new file mode 100644 index 0000000..2c0db4b --- /dev/null +++ b/.github/workflows/test-featurematrix.yaml @@ -0,0 +1,79 @@ +# ******************************************************************************** +# Copyright (c) 2024 Contributors to the Eclipse Foundation +# +# See the NOTICE file(s) distributed with this work for additional +# information regarding copyright ownership. +# +# This program and the accompanying materials are made available under the +# terms of the Apache License Version 2.0 which is available at +# https://www.apache.org/licenses/LICENSE-2.0 +# +# SPDX-License-Identifier: Apache-2.0 +# *******************************************************************************/ + +# Test all feature combinations on a range of OS platforms + +name: Matrix-test + +on: + workflow_call: + workflow_dispatch: + +env: + RUST_TOOLCHAIN: ${{ vars.RUST_TOOLCHAIN || 'stable' }} + RUSTFLAGS: -Dwarnings + CARGO_TERM_COLOR: always + +jobs: + # [impl->req~up-language-ci-test~1] + test-all-features: + name: all feature combinations + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, windows-latest, macOS-latest] + steps: + - uses: actions/checkout@v4 + with: + submodules: "recursive" + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ env.RUST_TOOLCHAIN }} + - uses: Swatinem/rust-cache@v2 + - name: Install cargo-all-features + run: | + cargo install cargo-all-features + + - name: Show toolchain information + working-directory: ${{ github.workspace }} + run: | + rustup toolchain list + cargo --version + + - name: cargo-check all possible feature combinations + run: | + cargo check-all-features + - name: cargo-test all possible feature combinations + run: | + cargo test-all-features + + + # Alternative to the full feature matrix tested in the step above - somewhat faster... + # multi-os-nextest: + # runs-on: ${{ matrix.os }} + # env: + # NEXTEST_EXPERIMENTAL_LIBTEST_JSON: 1 + # strategy: + # matrix: + # os: [ubuntu-latest, windows-latest, macOS-latest] + # feature-flags: ["", "--no-default-features", "--all-features"] + # steps: + # - uses: actions/checkout@v4 + # - uses: dtolnay/rust-toolchain@master + # with: + # toolchain: ${{ env.RUST_TOOLCHAIN }} + # - uses: Swatinem/rust-cache@v2 + # - uses: taiki-e/install-action@nextest + # - name: Run cargo nextest + # run: | + # cargo nextest run --message-format libtest-json-plus ${{ matrix.feature-flags }} diff --git a/Cargo.toml b/Cargo.toml index bf1bb93..547f418 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,13 +40,17 @@ tokio = { version = "1.35.1", default-features = false } tracing = "0.1.40" tracing-subscriber = "0.3.18" up-rust = "0.2.0" -zenoh = { version = "1.0.0", features = ["unstable", "internal"] } +zenoh = { version = "1.0.0" } [dev-dependencies] chrono = "0.4.31" clap = { version = "4.4.11", features = ["derive"] } test-case = { version = "3.3" } +[features] +default = [] +zenoh-unstable = ["zenoh/unstable", "zenoh/internal"] + [profile.release] opt-level = 3 lto = "fat" diff --git a/README.md b/README.md index 9a5c22e..7ecedb5 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,8 @@ uProtocol transport implementation for Zenoh in Rust cargo clippy --all-targets # Build cargo build +# Optional: Build with feature `zenoh-unstable` in uStreamer use case +cargo build --features zenoh-unstable # Run test cargo test # Test coverage @@ -45,4 +47,4 @@ The configuration file example is under the folder `config`. The implementation follows the spec defined in [up-l1/zenoh](https://github.com/eclipse-uprotocol/up-spec/blob/main/up-l1/zenoh.adoc). [^1]: Some PC configurations cannot connect locally. Add multicast to lo interface using - ` $ sudo ip link set dev lo multicast on ` \ No newline at end of file + ` $ sudo ip link set dev lo multicast on ` diff --git a/examples/common/mod.rs b/examples/common/mod.rs index d0b5022..92846f3 100644 --- a/examples/common/mod.rs +++ b/examples/common/mod.rs @@ -20,6 +20,15 @@ pub enum WhatAmIType { Router, } +#[cfg(not(feature = "zenoh-unstable"))] +#[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] +pub struct Args { + #[arg(short, long)] + /// A configuration file. + config: Option, +} + +#[cfg(feature = "zenoh-unstable")] #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] pub struct Args { #[arg(short, long)] @@ -44,45 +53,49 @@ pub fn get_zenoh_config() -> zenoh_config::Config { let args = Args::parse(); // Load the config from file path + #[allow(unused_mut)] let mut zenoh_cfg = match &args.config { Some(path) => zenoh_config::Config::from_file(path).unwrap(), None => zenoh_config::Config::default(), }; - // You can choose from Router, Peer, Client - match args.mode { - Some(WhatAmIType::Peer) => zenoh_cfg.set_mode(Some(zenoh::config::WhatAmI::Peer)), - Some(WhatAmIType::Client) => zenoh_cfg.set_mode(Some(zenoh::config::WhatAmI::Client)), - Some(WhatAmIType::Router) => zenoh_cfg.set_mode(Some(zenoh::config::WhatAmI::Router)), - None => Ok(None), - } - .unwrap(); + #[cfg(feature = "zenoh-unstable")] + { + // You can choose from Router, Peer, Client + match args.mode { + Some(WhatAmIType::Peer) => zenoh_cfg.set_mode(Some(zenoh::config::WhatAmI::Peer)), + Some(WhatAmIType::Client) => zenoh_cfg.set_mode(Some(zenoh::config::WhatAmI::Client)), + Some(WhatAmIType::Router) => zenoh_cfg.set_mode(Some(zenoh::config::WhatAmI::Router)), + None => Ok(None), + } + .unwrap(); - // Set connection address - if !args.connect.is_empty() { - zenoh_cfg - .connect - .endpoints - .set(args.connect.iter().map(|v| v.parse().unwrap()).collect()) - .unwrap(); - } + // Set connection address + if !args.connect.is_empty() { + zenoh_cfg + .connect + .endpoints + .set(args.connect.iter().map(|v| v.parse().unwrap()).collect()) + .unwrap(); + } - // Set listener address - if !args.listen.is_empty() { - zenoh_cfg - .listen - .endpoints - .set(args.listen.iter().map(|v| v.parse().unwrap()).collect()) - .unwrap(); - } + // Set listener address + if !args.listen.is_empty() { + zenoh_cfg + .listen + .endpoints + .set(args.listen.iter().map(|v| v.parse().unwrap()).collect()) + .unwrap(); + } - // Set multicast configuration - if args.no_multicast_scouting { - zenoh_cfg - .scouting - .multicast - .set_enabled(Some(false)) - .unwrap(); + // Set multicast configuration + if args.no_multicast_scouting { + zenoh_cfg + .scouting + .multicast + .set_enabled(Some(false)) + .unwrap(); + } } zenoh_cfg diff --git a/src/lib.rs b/src/lib.rs index 38e2d45..761a94e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,10 +24,9 @@ use tracing::error; use up_rust::{ComparableListener, LocalUriProvider, UAttributes, UCode, UPriority, UStatus, UUri}; // Re-export Zenoh config pub use zenoh::config as zenoh_config; -use zenoh::{ - bytes::ZBytes, internal::runtime::Runtime as ZRuntime, pubsub::Subscriber, qos::Priority, - Session, -}; +#[cfg(feature = "zenoh-unstable")] +use zenoh::internal::runtime::Runtime as ZRuntime; +use zenoh::{bytes::ZBytes, pubsub::Subscriber, qos::Priority, Session}; const UATTRIBUTE_VERSION: u8 = 1; const THREAD_NUM: usize = 10; @@ -88,6 +87,7 @@ impl UPTransportZenoh { } /// Create `UPTransportZenoh` by applying the Zenoh Runtime and local `UUri`. This can be used by uStreamer. + /// You need to enable feature `zenoh-unstable` to support this function. /// /// # Arguments /// @@ -96,6 +96,7 @@ impl UPTransportZenoh { /// /// # Errors /// Will return `Err` if unable to create `UPTransportZenoh` + #[cfg(feature = "zenoh-unstable")] pub async fn new_with_runtime(runtime: ZRuntime, uri: U) -> Result where U: TryInto,