From 60ba702d6842d6930ce000cedf14a1cbeabfcafe Mon Sep 17 00:00:00 2001 From: Michael Ilyin Date: Wed, 21 Feb 2024 17:06:14 +0300 Subject: [PATCH 1/9] build plugins with default zenoh features --- plugins/zenoh-backend-example/Cargo.toml | 2 +- plugins/zenoh-plugin-example/Cargo.toml | 2 +- plugins/zenoh-plugin-rest/Cargo.toml | 2 +- plugins/zenoh-plugin-storage-manager/Cargo.toml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/zenoh-backend-example/Cargo.toml b/plugins/zenoh-backend-example/Cargo.toml index eac0e0d803..da9ee94424 100644 --- a/plugins/zenoh-backend-example/Cargo.toml +++ b/plugins/zenoh-backend-example/Cargo.toml @@ -19,7 +19,7 @@ authors = { workspace = true } edition = { workspace = true } [features] -default = ["no_mangle"] +default = ["no_mangle", "zenoh/default"] no_mangle = [] [lib] diff --git a/plugins/zenoh-plugin-example/Cargo.toml b/plugins/zenoh-plugin-example/Cargo.toml index 6d49826238..71f6615713 100644 --- a/plugins/zenoh-plugin-example/Cargo.toml +++ b/plugins/zenoh-plugin-example/Cargo.toml @@ -20,7 +20,7 @@ edition = { workspace = true } publish = false [features] -default = ["no_mangle"] +default = ["no_mangle", "zenoh/default"] no_mangle = [] [lib] diff --git a/plugins/zenoh-plugin-rest/Cargo.toml b/plugins/zenoh-plugin-rest/Cargo.toml index 461f33170a..f5ec439511 100644 --- a/plugins/zenoh-plugin-rest/Cargo.toml +++ b/plugins/zenoh-plugin-rest/Cargo.toml @@ -24,7 +24,7 @@ categories = ["network-programming", "web-programming::http-server"] description = "The zenoh REST plugin" [features] -default = ["no_mangle"] +default = ["no_mangle", "zenoh/default"] no_mangle = [] [lib] diff --git a/plugins/zenoh-plugin-storage-manager/Cargo.toml b/plugins/zenoh-plugin-storage-manager/Cargo.toml index 87215d45eb..8a470236e4 100644 --- a/plugins/zenoh-plugin-storage-manager/Cargo.toml +++ b/plugins/zenoh-plugin-storage-manager/Cargo.toml @@ -24,7 +24,7 @@ categories = { workspace = true } description = "The zenoh storages plugin." [features] -default = ["no_mangle"] +default = ["no_mangle", "zenoh/default"] no_mangle = [] [lib] From 6045bfe599408f359f092dc038edba99ee395f3c Mon Sep 17 00:00:00 2001 From: Pierre Avital Date: Wed, 13 Mar 2024 08:51:12 +0100 Subject: [PATCH 2/9] update documentation to the new api for keformat's generated Parsed (#783) --- commons/zenoh-macros/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/commons/zenoh-macros/src/lib.rs b/commons/zenoh-macros/src/lib.rs index 800ad3475d..5c208fe90f 100644 --- a/commons/zenoh-macros/src/lib.rs +++ b/commons/zenoh-macros/src/lib.rs @@ -252,7 +252,7 @@ impl syn::parse::Parse for FormatDeclarations { /// - `formatter()`, a function that constructs a `Formatter` specialized for your format: /// - for every spec in your format, `Formatter` will have a method named after the spec's `id` that lets you set a value for that field of your format. These methods will return `Result<&mut Formatter, FormatError>`. /// - `parse(target: &keyexpr) -> ZResult>` will parse the provided key expression according to your format. Just like `KeFormat::parse`, parsing is lazy: each field will match the smallest subsection of your `target` that is included in its pattern. -/// - like `Formatter`, `Parsed` will have a method named after each spec's `id` that returns `Option<&keyexpr>`. That `Option` will only be `None` if the spec's format was `**` and matched a sequence of 0 chunks. +/// - like `Formatter`, `Parsed` will have a method named after each spec's `id` that returns `&keyexpr`; except for specs whose pattern was `**`, these will return an `Option<&keyexpr>`, where `None` signifies that the pattern was matched by an empty list of chunks. #[proc_macro] pub fn kedefine(tokens: TokenStream) -> TokenStream { let declarations: FormatDeclarations = syn::parse(tokens).unwrap(); @@ -265,7 +265,7 @@ pub fn kedefine(tokens: TokenStream) -> TokenStream { - `formatter()`, a function that constructs a `Formatter` specialized for your format: - for every spec in your format, `Formatter` will have a method named after the spec's `id` that lets you set a value for that field of your format. These methods will return `Result<&mut Formatter, FormatError>`. - `parse(target: &keyexpr) -> ZResult>` will parse the provided key expression according to your format. Just like `KeFormat::parse`, parsing is lazy: each field will match the smallest subsection of your `target` that is included in its pattern. - - like `Formatter`, `Parsed` will have a method named after each spec's `id` that returns `Option<&keyexpr>`. That `Option` will only be `None` if the spec's format was `**` and matched a sequence of 0 chunks." + - like `Formatter`, `Parsed` will have a method named after each spec's `id` that returns `&keyexpr`; except for specs whose pattern was `**`, these will return an `Option<&keyexpr>`, where `None` signifies that the pattern was matched by an empty list of chunks." ); let support = keformat_support(&source); quote! { From c12c005439420db80b7585f400be4377e57a58f8 Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Wed, 13 Mar 2024 08:58:21 +0100 Subject: [PATCH 3/9] fix: Relax dependency requirements (#758) - async-io - unix-named-pipe - filepath - advisory-lock --- Cargo.toml | 2 +- io/zenoh-links/zenoh-link-unixpipe/Cargo.toml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d7210ebc0e..d82d8ae7a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -76,7 +76,7 @@ ahash = "0.8.7" anyhow = { version = "1.0.69", default-features = false } # Default features are disabled due to usage in no_std crates async-executor = "1.5.0" async-global-executor = "2.3.1" -async-io = "=1.13.0" +async-io = "1.13.0" async-rustls = "0.4.0" async-std = { version = "=1.12.0", default-features = false } # Default features are disabled due to some crates' requirements async-trait = "0.1.60" diff --git a/io/zenoh-links/zenoh-link-unixpipe/Cargo.toml b/io/zenoh-links/zenoh-link-unixpipe/Cargo.toml index bf8d2a2c08..2801dc3a22 100644 --- a/io/zenoh-links/zenoh-link-unixpipe/Cargo.toml +++ b/io/zenoh-links/zenoh-link-unixpipe/Cargo.toml @@ -41,9 +41,9 @@ zenoh-protocol = { workspace = true } zenoh-result = { workspace = true } [target.'cfg(unix)'.dependencies] -unix-named-pipe = "=0.2.0" +unix-named-pipe = "0.2.0" nix = { workspace = true } -filepath = "=0.1.2" +filepath = "0.1.2" [target.'cfg(all(not(target_os="macos"), unix))'.dependencies] -advisory-lock = "=0.3.0" +advisory-lock = "0.3.0" From ceb982d1ce97cbce8f2298663b3d893d3d1d4f9d Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Wed, 13 Mar 2024 09:11:22 +0100 Subject: [PATCH 4/9] feat: Improve release workflow (#756) * wip: Improve Release workflow * feat: Add DockerHub & GHCR releases * feat: Refactor checks and tests into pre-release workflow * chore: Remove crates_check.sh and crates_publish.sh * fix: Remove Dockerfile --- .github/workflows/Dockerfile | 41 -- .github/workflows/crates_check.sh | 32 -- .github/workflows/crates_publish.sh | 32 -- .github/workflows/pre-release.yml | 104 +++++ .github/workflows/publish-docker.yml | 88 ++++ .github/workflows/release.yml | 609 +++++++-------------------- 6 files changed, 349 insertions(+), 557 deletions(-) delete mode 100644 .github/workflows/Dockerfile delete mode 100755 .github/workflows/crates_check.sh delete mode 100755 .github/workflows/crates_publish.sh create mode 100644 .github/workflows/pre-release.yml create mode 100644 .github/workflows/publish-docker.yml diff --git a/.github/workflows/Dockerfile b/.github/workflows/Dockerfile deleted file mode 100644 index 53958f9ac4..0000000000 --- a/.github/workflows/Dockerfile +++ /dev/null @@ -1,41 +0,0 @@ -# Copyright (c) 2023 ZettaScale Technology -# -# This program and the accompanying materials are made available under the -# terms of the Eclipse Public License 2.0 which is available at -# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 -# which is available at https://www.apache.org/licenses/LICENSE-2.0. -# -# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 -# -# Contributors: -# ZettaScale Zenoh Team, - -### -### Dockerfile creating the eclipse/zenoh image from cross-compiled binaries. -### It assumes that zenohd and it's plugins libraries are installed in docker/$TARGETPLATFORM/ -### where $TARGETPLATFORM is set by buildx to a Docker supported platform such as linux/amd64 or linux/arm64 -### (see https://docs.docker.com/buildx/working-with-buildx/#build-multi-platform-images) -### - - -FROM alpine:latest - -ARG TARGETPLATFORM - -RUN apk add --no-cache libgcc libstdc++ - -COPY docker/$TARGETPLATFORM/zenohd / -COPY docker/$TARGETPLATFORM/*.so / - -RUN echo '#!/bin/ash' > /entrypoint.sh -RUN echo 'echo " * Starting: /zenohd $*"' >> /entrypoint.sh -RUN echo 'exec /zenohd $*' >> /entrypoint.sh -RUN chmod +x /entrypoint.sh - -EXPOSE 7446/udp -EXPOSE 7447/tcp -EXPOSE 8000/tcp - -ENV RUST_LOG info - -ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/workflows/crates_check.sh b/.github/workflows/crates_check.sh deleted file mode 100755 index 7e9fca4c8c..0000000000 --- a/.github/workflows/crates_check.sh +++ /dev/null @@ -1,32 +0,0 @@ -cargo check -p zenoh-result --manifest-path commons/zenoh-result/Cargo.toml && -cargo check -p zenoh-core --manifest-path commons/zenoh-core/Cargo.toml && -cargo check -p zenoh-keyexpr --manifest-path commons/zenoh-keyexpr/Cargo.toml && -cargo check -p zenoh-collections --manifest-path commons/zenoh-collections/Cargo.toml && -cargo check -p zenoh-crypto --manifest-path commons/zenoh-crypto/Cargo.toml && -cargo check -p zenoh-buffers --manifest-path commons/zenoh-buffers/Cargo.toml && -cargo check -p zenoh-protocol --manifest-path commons/zenoh-protocol/Cargo.toml && -cargo check -p zenoh-util --manifest-path commons/zenoh-util/Cargo.toml && -cargo check -p zenoh-sync --manifest-path commons/zenoh-sync/Cargo.toml && -cargo check -p zenoh-macros --manifest-path commons/zenoh-macros/Cargo.toml && -cargo check -p zenoh-shm --manifest-path commons/zenoh-shm/Cargo.toml && -cargo check -p zenoh-codec --manifest-path commons/zenoh-codec/Cargo.toml && -cargo check -p zenoh-config --manifest-path commons/zenoh-config/Cargo.toml && -cargo check -p zenoh-link-commons --manifest-path io/zenoh-link-commons/Cargo.toml && -cargo check -p zenoh-link-udp --manifest-path io/zenoh-links/zenoh-link-udp/Cargo.toml && -cargo check -p zenoh-link-tcp --manifest-path io/zenoh-links/zenoh-link-tcp/Cargo.toml && -cargo check -p zenoh-link-tls --manifest-path io/zenoh-links/zenoh-link-tls/Cargo.toml && -cargo check -p zenoh-link-quic --manifest-path io/zenoh-links/zenoh-link-quic/Cargo.toml && -cargo check -p zenoh-link-unixpipe --manifest-path io/zenoh-links/zenoh-link-unixpipe/Cargo.toml && -cargo check -p zenoh-link-unixsock_stream --manifest-path io/zenoh-links/zenoh-link-unixsock_stream/Cargo.toml && -cargo check -p zenoh-link-serial --manifest-path io/zenoh-links/zenoh-link-serial/Cargo.toml && -cargo check -p zenoh-link-ws --manifest-path io/zenoh-links/zenoh-link-ws/Cargo.toml && -cargo check -p zenoh-link --manifest-path io/zenoh-link/Cargo.toml && -cargo check -p zenoh-transport --manifest-path io/zenoh-transport/Cargo.toml && -cargo check -p zenoh-plugin-trait --manifest-path plugins/zenoh-plugin-trait/Cargo.toml && -cargo check -p zenoh --manifest-path zenoh/Cargo.toml && -cargo check -p zenoh-ext --manifest-path zenoh-ext/Cargo.toml && -cargo check -p zenohd --manifest-path zenohd/Cargo.toml && -cargo check -p zenoh-plugin-rest --manifest-path plugins/zenoh-plugin-rest/Cargo.toml && -cargo check -p zenoh_backend_traits --manifest-path plugins/zenoh-backend-traits/Cargo.toml && -cargo check -p zenoh-plugin-storage-manager --manifest-path plugins/zenoh-plugin-storage-manager/Cargo.toml && -true \ No newline at end of file diff --git a/.github/workflows/crates_publish.sh b/.github/workflows/crates_publish.sh deleted file mode 100755 index 3cd1243a61..0000000000 --- a/.github/workflows/crates_publish.sh +++ /dev/null @@ -1,32 +0,0 @@ -cargo login $1 -(cd commons/zenoh-result && cargo publish; cargo clean) -(cd commons/zenoh-core && cargo publish; cargo clean) -(cd commons/zenoh-keyexpr && cargo publish; cargo clean) -(cd commons/zenoh-collections && cargo publish; cargo clean) -(cd commons/zenoh-crypto && cargo publish; cargo clean) -(cd commons/zenoh-buffers && cargo publish; cargo clean) -(cd commons/zenoh-protocol && cargo publish; cargo clean) -(cd commons/zenoh-util && cargo publish; cargo clean) -(cd commons/zenoh-sync && cargo publish; cargo clean) -(cd commons/zenoh-macros && cargo publish; cargo clean) -(cd commons/zenoh-shm && cargo publish; cargo clean) -(cd commons/zenoh-codec && cargo publish; cargo clean) -(cd commons/zenoh-config && cargo publish; cargo clean) -(cd io/zenoh-link-commons && cargo publish; cargo clean) -(cd io/zenoh-links/zenoh-link-udp && cargo publish; cargo clean) -(cd io/zenoh-links/zenoh-link-tcp && cargo publish; cargo clean) -(cd io/zenoh-links/zenoh-link-tls && cargo publish; cargo clean) -(cd io/zenoh-links/zenoh-link-quic && cargo publish; cargo clean) -(cd io/zenoh-links/zenoh-link-unixpipe && cargo publish; cargo clean) -(cd io/zenoh-links/zenoh-link-unixsock_stream && cargo publish; cargo clean) -(cd io/zenoh-links/zenoh-link-serial && cargo publish; cargo clean) -(cd io/zenoh-links/zenoh-link-ws && cargo publish; cargo clean) -(cd io/zenoh-link && cargo publish; cargo clean) -(cd io/zenoh-transport && cargo publish; cargo clean) -(cd plugins/zenoh-plugin-trait && cargo publish; cargo clean) -(cd zenoh && cargo publish; cargo clean) -(cd zenoh-ext && cargo publish; cargo clean) -(cd zenohd && cargo publish; cargo clean) -(cd plugins/zenoh-plugin-rest && cargo publish; cargo clean) -(cd plugins/zenoh-backend-traits && cargo publish; cargo clean) -(cd plugins/zenoh-plugin-storage-manager && cargo publish; cargo clean) \ No newline at end of file diff --git a/.github/workflows/pre-release.yml b/.github/workflows/pre-release.yml new file mode 100644 index 0000000000..631302d722 --- /dev/null +++ b/.github/workflows/pre-release.yml @@ -0,0 +1,104 @@ +# +# Copyright (c) 2023 ZettaScale Technology +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +# which is available at https://www.apache.org/licenses/LICENSE-2.0. +# +# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +# +# Contributors: +# ZettaScale Zenoh Team, +# +name: Pre-Release + +on: + schedule: + - cron: "0 0 * * 1-5" + workflow_dispatch: + inputs: + features: + description: Build with specified features (comma separated, no space) + type: string + workflow_call: + inputs: + features: + description: Build with specified features (comma separated, no space) + type: string + +jobs: + checks: + name: Code checks + runs-on: ubuntu-latest + steps: + - name: Clone this repository + uses: actions/checkout@v4 + + - name: Install Rust toolchain + run: | + rustup show + rustup component add rustfmt clippy + + - name: Code format check + run: cargo fmt --check + env: + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse + + - name: Clippy check + run: cargo +stable clippy --all-targets --features=${{ inputs.features }} -- --deny warnings + + - name: Clippy unstable check + run: cargo +stable clippy --all-targets -- --deny warnings + + - name: Clippy all features + run: cargo +stable clippy --all-targets --all-features -- --deny warnings + + tests: + name: Tests + needs: checks + runs-on: ubuntu-latest + steps: + - name: Clone this repository + uses: actions/checkout@v4 + + - name: Install Rust toolchain + run: rustup show + + - name: Install nextest + run: cargo install --locked cargo-nextest + env: + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse + + - name: Run tests + run: cargo nextest run --release --features=${{ inputs.features }} --verbose + env: + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse + ASYNC_STD_THREAD_COUNT: 4 + + - name: Run doctests + run: cargo test --release --features=${{ inputs.features }} --doc + env: + CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse + ASYNC_STD_THREAD_COUNT: 4 + + doc: + name: Doc generation + needs: checks + runs-on: ubuntu-latest + steps: + - name: Clone this repository + uses: actions/checkout@v4 + + # Use a similar command than docs.rs build: rustdoc with nightly toolchain + - name: Install Rust toolchain nightly for docs gen + run: rustup toolchain install nightly + + - name: generate doc + # NOTE: force 'unstable' feature for doc generation, as forced for docs.rs build in zenoh/Cargo.toml + run: > + cargo +nightly rustdoc --manifest-path ./zenoh/Cargo.toml --lib --features unstable -j3 + -Z rustdoc-map -Z unstable-options -Z rustdoc-scrape-examples + --config build.rustdocflags='["-Z", "unstable-options", "--emit=invocation-specific", "--cap-lints", "warn", "--disable-per-crate-search", "--extern-html-root-takes-precedence"]' + env: + RUSTDOCFLAGS: -Dwarnings diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml new file mode 100644 index 0000000000..30b465b04c --- /dev/null +++ b/.github/workflows/publish-docker.yml @@ -0,0 +1,88 @@ +# +# Copyright (c) 2023 ZettaScale Technology +# +# This program and the accompanying materials are made available under the +# terms of the Eclipse Public License 2.0 which is available at +# http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +# which is available at https://www.apache.org/licenses/LICENSE-2.0. +# +# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +# +# Contributors: +# ZettaScale Zenoh Team, +# +name: Publish (Docker) + +on: + workflow_dispatch: + inputs: + live-run: + type: boolean + required: true + version: + type: string + required: false + workflow_call: + inputs: + live-run: + type: boolean + required: true + version: + type: string + required: true + +jobs: + main: + name: Docker build and push + runs-on: ubuntu-latest + steps: + - name: Checkout this repository + uses: actions/checkout@v4 + with: + ref: ${{ inputs.version }} + + - name: Download packages from previous job + uses: actions/download-artifact@v3 + with: + path: build + + - name: Unzip artifacts + run: | + ls build + + mkdir -p docker/linux/amd + unzip build/zenoh-${{ inputs.version }}-x86_64-unknown-linux-musl-artifacts.zip -d docker/linux/amd64/ + rm docker/linux/amd64/libzenoh_plugin_example.so + + mkdir -p docker/linux/arm64 + unzip build/zenoh-${{ inputs.version }}-aarch64-unknown-linux-musl-artifacts.zip -d docker/linux/arm64/ + rm docker/linux/arm64/libzenoh_plugin_example.so + + tree docker + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Docker meta - set tags and labels + id: meta + uses: docker/metadata-action@v5 + with: + images: eclipse/zenoh + labels: | + org.opencontainers.image.licenses=EPL-2.0 OR Apache-2.0 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_COM_USERNAME }} + password: ${{ secrets.DOCKER_COM_PASSWORD }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + push: ${{ inputs.live-run }} + platforms: linux/amd64, linux/arm64 + file: .github/workflows/Dockerfile + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 982a474956..da80b102db 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,463 +14,168 @@ name: Release on: - release: - types: [published] schedule: - cron: "0 0 * * 1-5" workflow_dispatch: inputs: - runtests: - description: "run tests" + live-run: type: boolean - doc: - description: "generate doc" - type: boolean - build: - description: "build" - type: boolean - publish: - description: "publish" - type: boolean - githubrelease: - description: "publish as github release" - type: boolean - eclipse: - description: "publish to download.eclipse.org/zenoh" - type: boolean - cratesio: - description: "publish to crates.io" - type: boolean - dockerhub: - description: "publish to dockerhub" - type: boolean - features: - description: "build with specified features (comma separated, no space)" + description: If false (or undefined) the workflow runs in dry-run mode (i.e. with no side-effects) + required: false + version: type: string - -env: - VERSION_CROSS: 0.2.4 - VERSION_CARGO_DEB: 1.44.1 - VERSION_CARGO_NEXTEST: 0.9.67 + description: Release number. If undefined, the workflow auto-generates a version using git-describe + required: false jobs: - checks: - name: Code checks - runs-on: ubuntu-latest - steps: - - name: Clone this repository - uses: actions/checkout@v4 - - - name: Install Rust toolchain - run: | - rustup show - rustup component add rustfmt clippy - - - name: Code format check - run: cargo fmt --check - env: - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - - - name: Clippy check - run: cargo +stable clippy --all-targets --features=${{ github.event.inputs.features}} -- --deny warnings - - - name: Clippy unstable check - run: cargo +stable clippy --all-targets -- --deny warnings - - - name: Clippy all features - run: cargo +stable clippy --all-targets --all-features -- --deny warnings - - - name: Environment setup - id: env - shell: bash - run: | - # log some info - gcc --version || true - rustup -V - rustup toolchain list - rustup default - cargo -V - rustc -V - - echo "GITHUB_REF=${GITHUB_REF}" - echo "GITHUB_SHA=${GITHUB_SHA:0:8}" - GIT_BRANCH=`[[ $GITHUB_REF =~ ^refs/heads/.* ]] && echo ${GITHUB_REF/refs\/heads\//} || true` - echo "GIT_BRANCH=${GIT_BRANCH}" >> $GITHUB_OUTPUT - GIT_TAG=`[[ $GITHUB_REF =~ ^refs/tags/.* ]] && echo ${GITHUB_REF/refs\/tags\//} || true` - echo "GIT_TAG=${GIT_TAG}" >> $GITHUB_OUTPUT - - sudo apt-get update - sudo apt-get install -y jq - - ZENOH_VERSION=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[] | select(.name == "zenoh") | .version') - echo "ZENOH_VERSION=${ZENOH_VERSION}" >> $GITHUB_OUTPUT - if [ -n "${GIT_TAG}" ]; then - IS_RELEASE="true" - echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT - PKG_VERSION=${ZENOH_VERSION} - elif [ -n "${GIT_BRANCH}" ]; then - PKG_VERSION=${GIT_BRANCH}-${GITHUB_SHA:0:8} - else - PKG_VERSION=${ZENOH_VERSION}-${GITHUB_SHA:0:8} - fi - echo "PKG_VERSION=${PKG_VERSION}" >> $GITHUB_OUTPUT - echo "GITHUB_OUTPUT : ${GITHUB_OUTPUT}" - outputs: - GIT_BRANCH: ${{ steps.env.outputs.GIT_BRANCH }} - GIT_TAG: ${{ steps.env.outputs.GIT_TAG }} - IS_RELEASE: ${{ steps.env.outputs.IS_RELEASE }} - ZENOH_VERSION: ${{ steps.env.outputs.ZENOH_VERSION }} - PKG_VERSION: ${{ steps.env.outputs.PKG_VERSION }} - - tests: - name: Tests - if: ${{ !(github.event.inputs.runtests == 'false') }} - needs: checks - runs-on: ubuntu-latest - steps: - - name: Clone this repository - uses: actions/checkout@v4 - - - name: Install Rust toolchain - run: rustup show - - - name: Install nextest - run: cargo install --version ${{ env.VERSION_CARGO_NEXTEST }} --locked cargo-nextest - env: - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - - - name: Run tests - run: cargo nextest run --release --features=${{ github.event.inputs.features}} --verbose - env: - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - ASYNC_STD_THREAD_COUNT: 4 - - - name: Run doctests - run: cargo test --release --features=${{ github.event.inputs.features}} --doc - env: - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - ASYNC_STD_THREAD_COUNT: 4 - - doc: - name: Doc generation - if: ${{ !(github.event.inputs.doc == 'false') }} - needs: checks - runs-on: ubuntu-latest - steps: - - name: Clone this repository - uses: actions/checkout@v4 - - # Use a similar command than docs.rs build: rustdoc with nightly toolchain - - name: Install Rust toolchain nightly for docs gen - run: rustup toolchain install nightly - - - name: generate doc - # NOTE: force 'unstable' feature for doc generation, as forced for docs.rs build in zenoh/Cargo.toml - run: > - cargo +nightly rustdoc --manifest-path ./zenoh/Cargo.toml --lib --features unstable -j3 - -Z rustdoc-map -Z unstable-options -Z rustdoc-scrape-examples - --config build.rustdocflags='["-Z", "unstable-options", "--emit=invocation-specific", "--cap-lints", "warn", "--disable-per-crate-search", "--extern-html-root-takes-precedence"]' - env: - RUSTDOCFLAGS: -Dwarnings - - builds: - name: Build for ${{ matrix.job.target }} on ${{ matrix.job.os }} - if: ${{ !(github.event.inputs.build == 'false') }} - needs: checks - runs-on: ${{ matrix.job.os }} - strategy: - fail-fast: false - matrix: - job: - - { - target: x86_64-unknown-linux-gnu, - arch: amd64, - os: ubuntu-20.04, - build-cmd: "cargo", - } - - { - target: x86_64-unknown-linux-musl, - arch: amd64, - os: ubuntu-20.04, - build-cmd: "cross", - } - - { - target: arm-unknown-linux-gnueabi, - arch: armel, - os: ubuntu-20.04, - build-cmd: "cross", - } - - { - target: arm-unknown-linux-gnueabihf, - arch: armhf, - os: ubuntu-20.04, - build-cmd: "cross", - } - - { - target: armv7-unknown-linux-gnueabihf, - arch: armhf, - os: ubuntu-20.04, - build-cmd: "cross", - } - - { - target: aarch64-unknown-linux-gnu, - arch: arm64, - os: ubuntu-20.04, - build-cmd: "cross", - } - - { - target: aarch64-unknown-linux-musl, - arch: arm64, - os: ubuntu-20.04, - build-cmd: "cross", - } - - { - target: x86_64-apple-darwin, - arch: darwin, - os: macos-latest, - build-cmd: "cargo", - } - - { - target: aarch64-apple-darwin, - arch: darwin, - os: macos-latest, - build-cmd: "cargo", - } - - { - target: x86_64-pc-windows-msvc, - arch: win64, - os: windows-2019, - build-cmd: "cargo", - } - # - { target: x86_64-pc-windows-gnu , arch: win64 , os: windows-2019 } - steps: - - name: Checkout source code - uses: actions/checkout@v4 - with: - fetch-depth: 500 # NOTE: get long history for git-version crate to correctly compute a version - - - name: Fetch Git tags # NOTE: workaround for https://github.com/actions/checkout/issues/290 - shell: bash - run: git fetch --tags --force - - - name: Install prerequisites - shell: bash - run: | - case ${{ matrix.job.target }} in - *-linux-gnu*) cargo install --version ${{ env.VERSION_CARGO_DEB }} cargo-deb ;; - esac - - case ${{ matrix.job.target }} in - arm-unknown-linux-gnueabi) - sudo apt-get -y update - sudo apt-get -y install gcc-arm-linux-gnueabi - ;; - arm*-unknown-linux-gnueabihf) - sudo apt-get -y update - sudo apt-get -y install gcc-arm-linux-gnueabihf - ;; - aarch64-unknown-linux-gnu) - sudo apt-get -y update - sudo apt-get -y install gcc-aarch64-linux-gnu - ;; - esac - - cargo install --version ${{ env.VERSION_CROSS }} cross - - - name: Install Rust toolchain - run: | - rustup show - rustup target add ${{ matrix.job.target }} - - - name: Build - run: ${{ matrix.job.build-cmd }} build --release --bins --lib --features=${{ github.event.inputs.features}} --target=${{ matrix.job.target }} - - - name: Debian package - zenohd - if: contains(matrix.job.target, '-linux-gnu') - run: cargo deb --no-build --target=${{ matrix.job.target }} -p zenohd - env: - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - - - name: Debian package - zenoh-plugin-storage-manager - if: contains(matrix.job.target, '-linux-gnu') - run: cargo deb --no-build --target=${{ matrix.job.target }} -p zenoh-plugin-storage-manager - env: - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - - - name: Debian package - zenoh-plugin-rest - if: contains(matrix.job.target, '-linux-gnu') - run: cargo deb --no-build --target=${{ matrix.job.target }} -p zenoh-plugin-rest - env: - CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse - - - name: Packaging - id: package - shell: bash - run: | - TARGET=${{ matrix.job.target }} - MAIN_PKG_NAME="${GITHUB_WORKSPACE}/zenoh-${{ needs.checks.outputs.PKG_VERSION }}-${TARGET}.zip" - DEBS_PKG_NAME="${GITHUB_WORKSPACE}/zenoh-${{ needs.checks.outputs.PKG_VERSION }}-${TARGET}-deb-pkgs.zip" - - case ${TARGET} in - *linux*) - cd "target/${TARGET}/release/" - echo "Packaging ${MAIN_PKG_NAME}:" - zip ${MAIN_PKG_NAME} zenohd libzenoh_plugin_*.so - cd - - echo "MAIN_PKG_NAME=${MAIN_PKG_NAME}" >> $GITHUB_OUTPUT - - # check if debian packages has been created and packages them in a single tgz - if [[ -d target/${TARGET}/debian ]]; then - cd target/${TARGET}/debian - echo "Packaging ${DEBS_PKG_NAME}:" - zip ${DEBS_PKG_NAME} *.deb - cd - - echo "DEBS_PKG_NAME=${DEBS_PKG_NAME}" >> $GITHUB_OUTPUT - fi - ;; - *apple*) - cd "target/${TARGET}/release/" - echo "Packaging ${MAIN_PKG_NAME}:" - zip ${MAIN_PKG_NAME} zenohd libzenoh_plugin_*.dylib - cd - - echo "MAIN_PKG_NAME=${MAIN_PKG_NAME}" >> $GITHUB_OUTPUT - ;; - *windows*) - cd "target/${TARGET}/release/" - echo "Packaging ${MAIN_PKG_NAME}:" - 7z -y a "${MAIN_PKG_NAME}" zenohd.exe zenoh_plugin_*.dll - cd - - echo "MAIN_PKG_NAME=${MAIN_PKG_NAME}" >> $GITHUB_OUTPUT - ;; - esac - - - name: "Upload packages" - uses: actions/upload-artifact@v3 - with: - name: ${{ matrix.job.target }} - path: | - ${{ steps.package.outputs.MAIN_PKG_NAME }} - ${{ steps.package.outputs.DEBS_PKG_NAME }} - - publication: - name: Release publication - if: ${{ (needs.checks.outputs.IS_RELEASE == 'true' || github.event.inputs.publish == 'true') && !failure() }} - needs: [checks, builds, tests, doc] - runs-on: ubuntu-latest - steps: - - name: Download result of previous builds - uses: actions/download-artifact@v3 - with: - path: ARTIFACTS - - - name: Publish as github release - if: ${{ !(github.event.inputs.githubrelease == 'false') }} - uses: softprops/action-gh-release@v1 - with: - files: ARTIFACTS/*/*.* - - - name: Publish to download.eclipse.org/zenoh - if: ${{ !(github.event.inputs.eclipse == 'false') }} - env: - SSH_TARGET: genie.zenoh@projects-storage.eclipse.org - ECLIPSE_BASE_DIR: /home/data/httpd/download.eclipse.org/zenoh - shell: bash - run: | - echo "--- setup ssh-agent" - eval "$(ssh-agent -s)" - echo 'echo "${{ secrets.SSH_PASSPHRASE }}"' > ~/.ssh_askpass && chmod +x ~/.ssh_askpass - echo "${{ secrets.SSH_PRIVATE_KEY }}" | tr -d '\r' | DISPLAY=NONE SSH_ASKPASS=~/.ssh_askpass ssh-add - > /dev/null 2>&1 - rm -f ~/.ssh_askpass - echo "--- test ssh:" - ssh -o "StrictHostKeyChecking=no" ${SSH_TARGET} ls -al - echo "---- list artifacts to upload:" - ls -R ARTIFACTS || true - DOWNLOAD_DIR=${ECLIPSE_BASE_DIR}/zenoh/${{ needs.checks.outputs.ZENOH_VERSION }} - echo "---- copy artifacts into ${DOWNLOAD_DIR}" - ssh -o "StrictHostKeyChecking=no" ${SSH_TARGET} mkdir -p ${DOWNLOAD_DIR} - cd ARTIFACTS - sha256sum */* > sha256sums.txt - scp -o "StrictHostKeyChecking=no" -r * ${SSH_TARGET}:${DOWNLOAD_DIR}/ - echo "---- cleanup identity" - ssh-add -D - - - name: Checkout this repository - uses: actions/checkout@v4 - - - name: Install Rust toolchain - if: ${{ !(github.event.inputs.cratesio == 'false') }} - run: rustup show - - - name: Check crates - if: ${{ !(github.event.inputs.cratesio == 'false') }} - shell: bash - run: .github/workflows/crates_check.sh - - - name: Publish to crates.io - if: ${{ !(github.event.inputs.cratesio == 'false') }} - shell: bash - run: | - set +x - .github/workflows/crates_publish.sh ${{ secrets.CRATES_IO_TOKEN }} - - - name: Cancel workflow if fail # thus Docker job be interrupted - if: failure() - uses: andymckay/cancel-action@0.2 - - docker: - name: Docker build and push - if: ${{ !(github.event.inputs.dockerhub == 'false') && !failure() }} - needs: [checks, builds, tests, doc] - runs-on: ubuntu-latest - steps: - - name: Checkout this repository - uses: actions/checkout@v4 - with: - fetch-depth: 500 # NOTE: get long history for git-version crate to correctly compute a version - - - name: Fetch Git tags # NOTE: workaround for https://github.com/actions/checkout/issues/290 - shell: bash - run: git fetch --tags --force - - - name: Download packages from previous job - uses: actions/download-artifact@v3 - with: - path: PACKAGES - - - name: Unzip PACKAGES - run: | - ls PACKAGES - mkdir -p docker/linux/amd - unzip PACKAGES/x86_64-unknown-linux-musl/zenoh-${{ needs.checks.outputs.PKG_VERSION }}-x86_64-unknown-linux-musl.zip -d docker/linux/amd64/ - rm docker/linux/amd64/libzenoh_plugin_example.so - mkdir -p docker/linux/arm64 - unzip PACKAGES/aarch64-unknown-linux-musl/zenoh-${{ needs.checks.outputs.PKG_VERSION }}-aarch64-unknown-linux-musl.zip -d docker/linux/arm64/ - rm docker/linux/arm64/libzenoh_plugin_example.so - tree docker - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Docker meta - set tags and labels - id: meta - uses: docker/metadata-action@v5 - with: - images: eclipse/zenoh - labels: | - org.opencontainers.image.licenses=EPL-2.0 OR Apache-2.0 - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_COM_USERNAME }} - password: ${{ secrets.DOCKER_COM_PASSWORD }} - - - name: Build and push - uses: docker/build-push-action@v5 - with: - context: . - push: true - platforms: linux/amd64, linux/arm64 - file: .github/workflows/Dockerfile - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} + tag: + name: Bump and tag crates + uses: eclipse-zenoh/ci/.github/workflows/tag-crates.yml@main + with: + repo: ${{ github.repository }} + live-run: ${{ inputs.live-run }} + version: ${{ inputs.version }} + inter-deps-pattern: zenoh.* + secrets: inherit + + build-debian: + name: Build Debian packages + needs: tag + uses: eclipse-zenoh/ci/.github/workflows/build-crates-debian.yml@main + with: + repo: ${{ github.repository }} + version: ${{ needs.tag.outputs.version }} + branch: ${{ needs.tag.outputs.branch }} + secrets: inherit + + build-standalone: + name: Build executables and libraries + needs: tag + uses: eclipse-zenoh/ci/.github/workflows/build-crates-standalone.yml@main + with: + repo: ${{ github.repository }} + version: ${{ needs.tag.outputs.version }} + branch: ${{ needs.tag.outputs.branch }} + exclude-builds: '[{ build: { target: "x86_64-pc-windows-gnu", os: "windows-2019" } }]' + artifact-patterns: | + ^zenohd(\.exe)?$ + ^libzenoh_plugin_(rest|storage_manager)\.(dylib|so)$ + ^zenoh_plugin_(rest|storage_manager)\.dll$ + secrets: inherit + + cargo: + name: Publish Cargo crates + needs: tag + uses: eclipse-zenoh/ci/.github/workflows/release-crates-cargo.yml@main + with: + repos: ${{ github.repository }} + live-run: ${{ inputs.live-run }} + branch: ${{ needs.tag.outputs.branch }} + inter-deps-pattern: zenoh.* + secrets: inherit + + debian: + name: Publish Debian packages + needs: [tag, build-debian] + uses: eclipse-zenoh/ci/.github/workflows/release-crates-debian.yml@main + with: + no-build: true + live-run: ${{ inputs.live-run }} + version: ${{ needs.tag.outputs.version }} + repo: ${{ github.repository }} + branch: ${{ needs.tag.outputs.branch }} + secrets: inherit + + homebrew: + name: Publish Homebrew formulae + needs: [tag, build-standalone] + uses: eclipse-zenoh/ci/.github/workflows/release-crates-homebrew.yml@main + with: + no-build: true + repo: ${{ github.repository }} + live-run: ${{ inputs.live-run }} + version: ${{ needs.tag.outputs.version }} + branch: ${{ needs.tag.outputs.branch }} + artifact-patterns: | + ^zenohd$ + ^libzenoh_plugin_rest\.dylib$ + ^libzenoh_plugin_storage_manager\.dylib$ + formulae: | + zenoh + zenohd + zenoh-plugin-rest + zenoh-plugin-storage-manager + secrets: inherit + + eclipse: + name: Publish artifacts to Eclipse downloads + needs: [tag, build-standalone] + uses: eclipse-zenoh/ci/.github/workflows/release-crates-eclipse.yml@main + with: + no-build: true + live-run: ${{ inputs.live-run }} + version: ${{ needs.tag.outputs.version }} + repo: ${{ github.repository }} + branch: ${{ needs.tag.outputs.branch }} + artifact-patterns: | + ^zenohd(\.exe)?$ + ^libzenoh_plugin_(rest|storage_manager)\.(dylib|so)$ + ^zenoh_plugin_(rest|storage_manager)\.dll$ + name: zenoh + secrets: inherit + + github: + name: Publish artifacts to GitHub Releases + needs: [tag, build-standalone] + uses: eclipse-zenoh/ci/.github/workflows/release-crates-github.yml@main + with: + no-build: true + live-run: ${{ inputs.live-run }} + version: ${{ needs.tag.outputs.version }} + repo: ${{ github.repository }} + branch: ${{ needs.tag.outputs.branch }} + artifact-patterns: | + ^zenohd(\.exe)?$ + ^libzenoh_plugin_(rest|storage_manager)\.(dylib|so)$ + ^zenoh_plugin_(rest|storage_manager)\.dll$ + secrets: inherit + + dockerhub: + name: Publish container image to DockerHub + needs: [tag, build-standalone] + uses: eclipse-zenoh/ci/.github/workflows/release-crates-dockerhub.yml@main + with: + no-build: true + live-run: ${{ inputs.live-run }} + version: ${{ needs.tag.outputs.version }} + repo: ${{ github.repository }} + tags: "eclipse/zenoh:${{ inputs.version }}" + binary: zenohd + files: | + zenohd + libzenoh_plugin_rest.so + libzenoh_plugin_storage_manager.so + platforms: | + linux/arm64 + linux/amd64 + secrets: inherit + + ghcr: + name: Publish container image to GitHub Container Registry + needs: [tag, build-standalone] + uses: eclipse-zenoh/ci/.github/workflows/release-crates-ghcr.yml@main + with: + no-build: true + live-run: ${{ inputs.live-run }} + version: ${{ needs.tag.outputs.version }} + repo: ${{ github.repository }} + tags: "${{ github.repository }}:${{ inputs.version }}" + binary: zenohd + files: | + zenohd + libzenoh_plugin_rest.so + libzenoh_plugin_storage_manager.so + platforms: | + linux/arm64 + linux/amd64 + secrets: inherit From 1c8ed89b659a2eb9561684602a03390c4f46e279 Mon Sep 17 00:00:00 2001 From: Dmitrii Bannov <104833606+yellowhatter@users.noreply.github.com> Date: Wed, 13 Mar 2024 13:20:01 +0300 Subject: [PATCH 5/9] restore SN in case of frame drops caused by congestion control (#815) --- io/zenoh-transport/src/common/pipeline.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/io/zenoh-transport/src/common/pipeline.rs b/io/zenoh-transport/src/common/pipeline.rs index 954c656280..d3a80af34b 100644 --- a/io/zenoh-transport/src/common/pipeline.rs +++ b/io/zenoh-transport/src/common/pipeline.rs @@ -130,7 +130,7 @@ impl StageIn { let is_droppable = msg.is_droppable(); macro_rules! zgetbatch_rets { - ($fragment:expr) => { + ($fragment:expr, $restore_sn:expr) => { loop { match c_guard.take() { Some(batch) => break batch, @@ -142,6 +142,8 @@ impl StageIn { None => { drop(c_guard); if !$fragment && is_droppable { + // Restore the sequence number + $restore_sn; // We are in the congestion scenario // The yield is to avoid the writing task to spin // indefinitely and monopolize the CPU usage. @@ -149,6 +151,8 @@ impl StageIn { return false; } else { if !self.s_ref.wait() { + // Restore the sequence number + $restore_sn; return false; } } @@ -171,7 +175,7 @@ impl StageIn { } // Get the current serialization batch. - let mut batch = zgetbatch_rets!(false); + let mut batch = zgetbatch_rets!(false, {}); // Attempt the serialization on the current batch let e = match batch.encode(&*msg) { Ok(_) => zretok!(batch), @@ -201,7 +205,7 @@ impl StageIn { if !batch.is_empty() { // Move out existing batch self.s_out.move_batch(batch); - batch = zgetbatch_rets!(false); + batch = zgetbatch_rets!(false, tch.sn.set(sn).unwrap()); } // Attempt a second serialization on fully empty batch @@ -232,7 +236,7 @@ impl StageIn { while reader.can_read() { // Get the current serialization batch // Treat all messages as non-droppable once we start fragmenting - batch = zgetbatch_rets!(true); + batch = zgetbatch_rets!(true, tch.sn.set(sn).unwrap()); // Serialize the message fragmnet match batch.encode((&mut reader, &mut fragment)) { From ba50eec2a9628a284d09b59abeec2d6b8809f68e Mon Sep 17 00:00:00 2001 From: DenisBiryukov91 <155981813+DenisBiryukov91@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:11:56 +0100 Subject: [PATCH 6/9] move Publisher.write method into trait (#736) * move Publisher.write method into HasWriteWithSampleKind trait * fix broken test * fix format --- zenoh/src/publication.rs | 57 ++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 19 deletions(-) diff --git a/zenoh/src/publication.rs b/zenoh/src/publication.rs index e0cd1d33c6..d54a77b793 100644 --- a/zenoh/src/publication.rs +++ b/zenoh/src/publication.rs @@ -318,25 +318,6 @@ impl<'a> Publisher<'a> { } } - /// Send data with [`kind`](SampleKind) (Put or Delete). - /// - /// # Examples - /// ``` - /// # async_std::task::block_on(async { - /// use zenoh::prelude::r#async::*; - /// - /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); - /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); - /// publisher.write(SampleKind::Put, "value").res().await.unwrap(); - /// # }) - /// ``` - pub fn write(&self, kind: SampleKind, value: IntoValue) -> Publication - where - IntoValue: Into, - { - self._write(kind, value.into()) - } - /// Put data. /// /// # Examples @@ -448,6 +429,43 @@ impl<'a> Publisher<'a> { } } +/// Internal function for sending data with specified [`kind`](SampleKind) +pub trait HasWriteWithSampleKind { + type WriteOutput<'a> + where + Self: 'a; + fn write>( + &self, + kind: SampleKind, + value: IntoValue, + ) -> Self::WriteOutput<'_>; +} + +impl<'a> HasWriteWithSampleKind for Publisher<'a> { + type WriteOutput<'b> = Publication<'b> + where + 'a: 'b; + /// Send data with [`kind`](SampleKind) (Put or Delete). + /// + /// # Examples + /// ``` + /// # async_std::task::block_on(async { + /// use zenoh::prelude::r#async::*; + /// use zenoh::publication::HasWriteWithSampleKind; + /// + /// let session = zenoh::open(config::peer()).res().await.unwrap().into_arc(); + /// let publisher = session.declare_publisher("key/expression").res().await.unwrap(); + /// publisher.write(SampleKind::Put, "value").res().await.unwrap(); + /// # }) + /// ``` + fn write(&self, kind: SampleKind, value: IntoValue) -> Self::WriteOutput<'_> + where + IntoValue: Into, + { + self._write(kind, value.into()) + } +} + /// Functions to create zenoh entities with `'static` lifetime. /// /// This trait contains functions to create zenoh entities like @@ -1351,6 +1369,7 @@ mod tests { #[test] fn sample_kind_integrity_in_publication() { + use crate::publication::HasWriteWithSampleKind; use crate::{open, prelude::sync::*}; use zenoh_protocol::core::SampleKind; From c75401bc4d28e3159e6eebc25ec0497fbd94b69c Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Wed, 13 Mar 2024 15:47:59 +0100 Subject: [PATCH 7/9] fix(workflows/release): Get release number from tag job (#820) --- .github/workflows/release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index da80b102db..8c364ca881 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -149,7 +149,7 @@ jobs: live-run: ${{ inputs.live-run }} version: ${{ needs.tag.outputs.version }} repo: ${{ github.repository }} - tags: "eclipse/zenoh:${{ inputs.version }}" + tags: "eclipse/zenoh:${{ needs.tag.outputs.version }}" binary: zenohd files: | zenohd @@ -169,7 +169,7 @@ jobs: live-run: ${{ inputs.live-run }} version: ${{ needs.tag.outputs.version }} repo: ${{ github.repository }} - tags: "${{ github.repository }}:${{ inputs.version }}" + tags: "${{ github.repository }}:${{ needs.tag.outputs.version }}" binary: zenohd files: | zenohd From 61838d57b88ba2d06f8e16720d6020a80502a905 Mon Sep 17 00:00:00 2001 From: oteffahi <70609372+oteffahi@users.noreply.github.com> Date: Wed, 13 Mar 2024 15:52:20 +0100 Subject: [PATCH 8/9] Align examples and remove reading from stdin (#768) * Remove reading from stdin, align example implementations * Change counter start to 0 * Replace sleep with thread-parking * Remove select, format files * Uncomment liveliness token undeclaration --- examples/examples/z_liveliness.rs | 28 ++++-------- examples/examples/z_pong.rs | 4 +- examples/examples/z_pub.rs | 1 + examples/examples/z_pub_shm.rs | 1 + examples/examples/z_pub_shm_thr.rs | 1 + examples/examples/z_pub_thr.rs | 1 + examples/examples/z_pull.rs | 40 +++++----------- examples/examples/z_queryable.rs | 66 ++++++++------------------- examples/examples/z_storage.rs | 15 +----- examples/examples/z_sub.rs | 29 +++--------- examples/examples/z_sub_liveliness.rs | 41 +++++------------ examples/examples/z_sub_thr.rs | 9 +--- zenoh-ext/examples/z_pub_cache.rs | 1 + zenoh-ext/examples/z_query_sub.rs | 29 +++--------- 14 files changed, 74 insertions(+), 192 deletions(-) diff --git a/examples/examples/z_liveliness.rs b/examples/examples/z_liveliness.rs index 41890f7d77..06c83c1e6f 100644 --- a/examples/examples/z_liveliness.rs +++ b/examples/examples/z_liveliness.rs @@ -11,10 +11,7 @@ // Contributors: // ZettaScale Zenoh Team, // -use async_std::task::sleep; use clap::Parser; -use futures::prelude::*; -use std::time::Duration; use zenoh::config::Config; use zenoh::prelude::r#async::*; use zenoh_examples::CommonArgs; @@ -39,23 +36,14 @@ async fn main() { .unwrap(), ); - println!("Enter 'd' to undeclare LivelinessToken, 'q' to quit..."); - let mut stdin = async_std::io::stdin(); - let mut input = [0_u8]; - loop { - let _ = stdin.read_exact(&mut input).await; - match input[0] { - b'q' => break, - b'd' => { - if let Some(token) = token.take() { - println!("Undeclaring LivelinessToken..."); - token.undeclare().res().await.unwrap(); - } - } - 0 => sleep(Duration::from_secs(1)).await, - _ => (), - } - } + println!("Press CTRL-C to undeclare LivelinessToken and quit..."); + std::thread::park(); + // LivelinessTokens are automatically closed when dropped + // Use the code below to manually undeclare it if needed + if let Some(token) = token.take() { + println!("Undeclaring LivelinessToken..."); + token.undeclare().res().await.unwrap(); + }; } #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] diff --git a/examples/examples/z_pong.rs b/examples/examples/z_pong.rs index f057075434..53ff03b778 100644 --- a/examples/examples/z_pong.rs +++ b/examples/examples/z_pong.rs @@ -1,5 +1,3 @@ -use std::io::{stdin, Read}; - // // Copyright (c) 2023 ZettaScale Technology // @@ -44,7 +42,7 @@ fn main() { .callback(move |sample| publisher.put(sample.value).res().unwrap()) .res() .unwrap(); - for _ in stdin().bytes().take_while(|b| !matches!(b, Ok(b'q'))) {} + std::thread::park(); } #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] diff --git a/examples/examples/z_pub.rs b/examples/examples/z_pub.rs index b892eeafc3..7ba17745b5 100644 --- a/examples/examples/z_pub.rs +++ b/examples/examples/z_pub.rs @@ -31,6 +31,7 @@ async fn main() { println!("Declaring Publisher on '{key_expr}'..."); let publisher = session.declare_publisher(&key_expr).res().await.unwrap(); + println!("Press CTRL-C to quit..."); for idx in 0..u32::MAX { sleep(Duration::from_secs(1)).await; let buf = format!("[{idx:4}] {value}"); diff --git a/examples/examples/z_pub_shm.rs b/examples/examples/z_pub_shm.rs index fc329cadfc..c54fb358d3 100644 --- a/examples/examples/z_pub_shm.rs +++ b/examples/examples/z_pub_shm.rs @@ -44,6 +44,7 @@ async fn main() -> Result<(), zenoh::Error> { println!("Allocating Shared Memory Buffer..."); let publisher = session.declare_publisher(&path).res().await.unwrap(); + println!("Press CTRL-C to quit..."); for idx in 0..(K * N as u32) { sleep(Duration::from_secs(1)).await; let mut sbuf = match shm.alloc(1024) { diff --git a/examples/examples/z_pub_shm_thr.rs b/examples/examples/z_pub_shm_thr.rs index 9921c869e5..7c6f3cbbd3 100644 --- a/examples/examples/z_pub_shm_thr.rs +++ b/examples/examples/z_pub_shm_thr.rs @@ -42,6 +42,7 @@ async fn main() { // Make sure to not drop messages because of congestion control .congestion_control(CongestionControl::Block).res().await.unwrap(); + println!("Press CTRL-C to quit..."); loop { publisher.put(buf.clone()).res().await.unwrap(); } diff --git a/examples/examples/z_pub_thr.rs b/examples/examples/z_pub_thr.rs index 3e130e0608..89b8b9b55c 100644 --- a/examples/examples/z_pub_thr.rs +++ b/examples/examples/z_pub_thr.rs @@ -44,6 +44,7 @@ fn main() { .res() .unwrap(); + println!("Press CTRL-C to quit..."); let mut count: usize = 0; let mut start = std::time::Instant::now(); loop { diff --git a/examples/examples/z_pull.rs b/examples/examples/z_pull.rs index 812c47294e..db1c9d0670 100644 --- a/examples/examples/z_pull.rs +++ b/examples/examples/z_pull.rs @@ -11,10 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use async_std::prelude::FutureExt; use async_std::task::sleep; use clap::Parser; -use futures::prelude::*; use std::time::Duration; use zenoh::config::Config; use zenoh::prelude::r#async::*; @@ -35,40 +33,24 @@ async fn main() { let subscriber = session .declare_subscriber(&key_expr) .pull_mode() - .res() - .await - .unwrap(); - - println!("Press to pull data..."); - - // Define the future to handle incoming samples of the subscription. - let subs = async { - while let Ok(sample) = subscriber.recv_async().await { + .callback(|sample| { println!( ">> [Subscriber] Received {} ('{}': '{}')", sample.kind, sample.key_expr.as_str(), sample.value, ); - } - }; - - // Define the future to handle keyboard's input. - let keyb = async { - let mut stdin = async_std::io::stdin(); - let mut input = [0_u8]; - loop { - stdin.read_exact(&mut input).await.unwrap(); - match input[0] { - b'q' => break, - 0 => sleep(Duration::from_secs(1)).await, - _ => subscriber.pull().res().await.unwrap(), - } - } - }; + }) + .res() + .await + .unwrap(); - // Execute both futures concurrently until one of them returns. - subs.race(keyb).await; + println!("Press CTRL-C to quit..."); + for idx in 0..u32::MAX { + sleep(Duration::from_secs(1)).await; + println!("[{idx:4}] Pulling..."); + subscriber.pull().res().await.unwrap(); + } } #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] diff --git a/examples/examples/z_queryable.rs b/examples/examples/z_queryable.rs index 54b9858cf0..20c946bc0b 100644 --- a/examples/examples/z_queryable.rs +++ b/examples/examples/z_queryable.rs @@ -11,12 +11,7 @@ // Contributors: // ZettaScale Zenoh Team, // -use async_std::task::sleep; use clap::Parser; -use futures::prelude::*; -use futures::select; -use std::sync::atomic::Ordering::Relaxed; -use std::time::Duration; use zenoh::config::Config; use zenoh::prelude::r#async::*; use zenoh_examples::CommonArgs; @@ -27,7 +22,6 @@ async fn main() { env_logger::init(); let (config, key_expr, value, complete) = parse_args(); - let send_errors = std::sync::atomic::AtomicBool::new(false); println!("Opening session..."); let session = zenoh::open(config).res().await.unwrap(); @@ -40,47 +34,27 @@ async fn main() { .await .unwrap(); - println!("Enter 'q' to quit, 'e' to reply an error to next query..."); - let mut stdin = async_std::io::stdin(); - let mut input = [0_u8]; - loop { - select!( - query = queryable.recv_async() => { - let query = query.unwrap(); - match query.value() { - None => println!(">> [Queryable ] Received Query '{}'", query.selector()), - Some(value) => println!(">> [Queryable ] Received Query '{}' with value '{}'", query.selector(), value), - } - let reply = if send_errors.swap(false, Relaxed) { - println!( - ">> [Queryable ] Replying (ERROR: '{}')", - value, - ); - Err(value.clone().into()) - } else { - println!( - ">> [Queryable ] Responding ('{}': '{}')", - key_expr.as_str(), - value, - ); - Ok(Sample::new(key_expr.clone(), value.clone())) - }; - query - .reply(reply) - .res() - .await - .unwrap_or_else(|e| println!(">> [Queryable ] Error sending reply: {e}")); - }, - - _ = stdin.read_exact(&mut input).fuse() => { - match input[0] { - b'q' => break, - 0 => sleep(Duration::from_secs(1)).await, - b'e' => send_errors.store(true, Relaxed), - _ => (), - } - } + println!("Press CTRL-C to quit..."); + while let Ok(query) = queryable.recv_async().await { + match query.value() { + None => println!(">> [Queryable ] Received Query '{}'", query.selector()), + Some(value) => println!( + ">> [Queryable ] Received Query '{}' with value '{}'", + query.selector(), + value + ), + } + println!( + ">> [Queryable ] Responding ('{}': '{}')", + key_expr.as_str(), + value, ); + let reply = Ok(Sample::new(key_expr.clone(), value.clone())); + query + .reply(reply) + .res() + .await + .unwrap_or_else(|e| println!(">> [Queryable ] Error sending reply: {e}")); } } diff --git a/examples/examples/z_storage.rs b/examples/examples/z_storage.rs index 79164c914a..88849f5b0d 100644 --- a/examples/examples/z_storage.rs +++ b/examples/examples/z_storage.rs @@ -13,12 +13,9 @@ // #![recursion_limit = "256"] -use async_std::task::sleep; use clap::Parser; -use futures::prelude::*; use futures::select; use std::collections::HashMap; -use std::time::Duration; use zenoh::config::Config; use zenoh::prelude::r#async::*; use zenoh_examples::CommonArgs; @@ -46,9 +43,7 @@ async fn main() { .await .unwrap(); - println!("Enter 'q' to quit..."); - let mut stdin = async_std::io::stdin(); - let mut input = [0u8]; + println!("Press CTRL-C to quit..."); loop { select!( sample = subscriber.recv_async() => { @@ -70,14 +65,6 @@ async fn main() { query.reply(Ok(sample.clone())).res().await.unwrap(); } } - }, - - _ = stdin.read_exact(&mut input).fuse() => { - match input[0] { - b'q' => break, - 0 => sleep(Duration::from_secs(1)).await, - _ => (), - } } ); } diff --git a/examples/examples/z_sub.rs b/examples/examples/z_sub.rs index 0542f85870..3205f3270b 100644 --- a/examples/examples/z_sub.rs +++ b/examples/examples/z_sub.rs @@ -11,11 +11,7 @@ // Contributors: // ZettaScale Zenoh Team, // -use async_std::task::sleep; use clap::Parser; -use futures::prelude::*; -use futures::select; -use std::time::Duration; use zenoh::config::Config; use zenoh::prelude::r#async::*; use zenoh_examples::CommonArgs; @@ -39,24 +35,13 @@ async fn main() { let subscriber = session.declare_subscriber(&key_expr).res().await.unwrap(); - println!("Enter 'q' to quit..."); - let mut stdin = async_std::io::stdin(); - let mut input = [0_u8]; - loop { - select!( - sample = subscriber.recv_async() => { - let sample = sample.unwrap(); - println!(">> [Subscriber] Received {} ('{}': '{}')", - sample.kind, sample.key_expr.as_str(), sample.value); - }, - - _ = stdin.read_exact(&mut input).fuse() => { - match input[0] { - b'q' => break, - 0 => sleep(Duration::from_secs(1)).await, - _ => (), - } - } + println!("Press CTRL-C to quit..."); + while let Ok(sample) = subscriber.recv_async().await { + println!( + ">> [Subscriber] Received {} ('{}': '{}')", + sample.kind, + sample.key_expr.as_str(), + sample.value ); } } diff --git a/examples/examples/z_sub_liveliness.rs b/examples/examples/z_sub_liveliness.rs index 52ba53875c..596deaef00 100644 --- a/examples/examples/z_sub_liveliness.rs +++ b/examples/examples/z_sub_liveliness.rs @@ -11,11 +11,7 @@ // Contributors: // ZettaScale Zenoh Team, // -use async_std::task::sleep; use clap::Parser; -use futures::prelude::*; -use futures::select; -use std::time::Duration; use zenoh::config::Config; use zenoh::prelude::r#async::*; use zenoh_examples::CommonArgs; @@ -39,31 +35,18 @@ async fn main() { .await .unwrap(); - println!("Enter 'q' to quit..."); - let mut stdin = async_std::io::stdin(); - let mut input = [0_u8]; - loop { - select!( - sample = subscriber.recv_async() => { - let sample = sample.unwrap(); - match sample.kind { - SampleKind::Put => println!( - ">> [LivelinessSubscriber] New alive token ('{}')", - sample.key_expr.as_str()), - SampleKind::Delete => println!( - ">> [LivelinessSubscriber] Dropped token ('{}')", - sample.key_expr.as_str()), - } - }, - - _ = stdin.read_exact(&mut input).fuse() => { - match input[0] { - b'q' => break, - 0 => sleep(Duration::from_secs(1)).await, - _ => (), - } - } - ); + println!("Press CTRL-C to quit..."); + while let Ok(sample) = subscriber.recv_async().await { + match sample.kind { + SampleKind::Put => println!( + ">> [LivelinessSubscriber] New alive token ('{}')", + sample.key_expr.as_str() + ), + SampleKind::Delete => println!( + ">> [LivelinessSubscriber] Dropped token ('{}')", + sample.key_expr.as_str() + ), + } } } diff --git a/examples/examples/z_sub_thr.rs b/examples/examples/z_sub_thr.rs index afdd07ed23..0a8426edf0 100644 --- a/examples/examples/z_sub_thr.rs +++ b/examples/examples/z_sub_thr.rs @@ -12,7 +12,6 @@ // ZettaScale Zenoh Team, // use clap::Parser; -use std::io::{stdin, Read}; use std::time::Instant; use zenoh::config::Config; use zenoh::prelude::sync::*; @@ -95,12 +94,8 @@ fn main() { .res() .unwrap(); - for byte in stdin().bytes() { - match byte { - Ok(b'q') => break, - _ => std::thread::yield_now(), - } - } + println!("Press CTRL-C to quit..."); + std::thread::park(); } #[derive(clap::Parser, Clone, PartialEq, Eq, Hash, Debug)] diff --git a/zenoh-ext/examples/z_pub_cache.rs b/zenoh-ext/examples/z_pub_cache.rs index 882764b8f9..ecf3824ef4 100644 --- a/zenoh-ext/examples/z_pub_cache.rs +++ b/zenoh-ext/examples/z_pub_cache.rs @@ -38,6 +38,7 @@ async fn main() { } let _publication_cache = publication_cache_builder.res().await.unwrap(); + println!("Press CTRL-C to quit..."); for idx in 0..u32::MAX { sleep(Duration::from_secs(1)).await; let buf = format!("[{idx:4}] {value}"); diff --git a/zenoh-ext/examples/z_query_sub.rs b/zenoh-ext/examples/z_query_sub.rs index 73433ebf14..7ecf866355 100644 --- a/zenoh-ext/examples/z_query_sub.rs +++ b/zenoh-ext/examples/z_query_sub.rs @@ -11,12 +11,8 @@ // Contributors: // ZettaScale Zenoh Team, // -use async_std::task::sleep; use clap::arg; use clap::Command; -use futures::prelude::*; -use futures::select; -use std::time::Duration; use zenoh::config::Config; use zenoh::prelude::r#async::*; use zenoh::query::ReplyKeyExpr; @@ -55,24 +51,13 @@ async fn main() { .unwrap() }; - println!("Enter 'q' to quit..."); - let mut stdin = async_std::io::stdin(); - let mut input = [0_u8]; - loop { - select!( - sample = subscriber.recv_async() => { - let sample = sample.unwrap(); - println!(">> [Subscriber] Received {} ('{}': '{}')", - sample.kind, sample.key_expr.as_str(), sample.value); - }, - - _ = stdin.read_exact(&mut input).fuse() => { - match input[0] { - b'q' => break, - 0 => sleep(Duration::from_secs(1)).await, - _ => (), - } - } + println!("Press CTRL-C to quit..."); + while let Ok(sample) = subscriber.recv_async().await { + println!( + ">> [Subscriber] Received {} ('{}': '{}')", + sample.kind, + sample.key_expr.as_str(), + sample.value ); } } From 65e0fb7519617813781faeb281d85eee977117cc Mon Sep 17 00:00:00 2001 From: Mahmoud Mazouz Date: Thu, 14 Mar 2024 09:50:05 +0100 Subject: [PATCH 9/9] fix: Reverse default paths list (#825) --- commons/zenoh-util/src/std_only/lib_loader.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/commons/zenoh-util/src/std_only/lib_loader.rs b/commons/zenoh-util/src/std_only/lib_loader.rs index b1aa77b06b..12a6da8489 100644 --- a/commons/zenoh-util/src/std_only/lib_loader.rs +++ b/commons/zenoh-util/src/std_only/lib_loader.rs @@ -26,7 +26,7 @@ zconfigurable! { /// The libraries suffix for the current platform (`".dll"` or `".so"` or `".dylib"`...) pub static ref LIB_SUFFIX: String = DLL_SUFFIX.to_string(); /// The default list of paths where to search for libraries to load - pub static ref LIB_DEFAULT_SEARCH_PATHS: String = "/usr/local/lib:/usr/lib:/opt/homebrew/lib:~/.zenoh/lib:.".to_string(); + pub static ref LIB_DEFAULT_SEARCH_PATHS: String = ".:~/.zenoh/lib:/opt/homebrew/lib:/usr/local/lib:/usr/lib".to_string(); } /// LibLoader allows search for librairies and to load them.