Skip to content

Commit

Permalink
Merge pull request #12 from b5g-ex/pojiro/0.2.0-dev
Browse files Browse the repository at this point in the history
0.2.0 is developed!!
  • Loading branch information
takasehideki authored Feb 21, 2024
2 parents 3d7ded0 + de4d092 commit a2f0300
Show file tree
Hide file tree
Showing 80 changed files with 3,658 additions and 715 deletions.
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: "mix"
directory: "/"
schedule:
interval: daily
open-pull-requests-limit: 10
144 changes: 144 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: CI

env:
OTP_VERSION: 26.1.2
ELIXIR_VERSION: 1.15.7
MIX_ENV: test

# based https://github.com/erlef/setup-beam

on:
pull_request:
push:
branches:
- main

jobs:
build-deps:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
id: setup-beam
with:
otp-version: ${{env.OTP_VERSION}}
elixir-version: ${{env.ELIXIR_VERSION}}

- uses: actions/cache@v4
id: save-deps-cache
with:
path: |
deps
_build
key: deps-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/*.lock') }}

- name: build deps
if: steps.save-deps-cache.outputs.cache-hit != 'true'
run: mix do deps.get, deps.compile

code-analysis:
needs: build-deps
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
id: setup-beam
with:
otp-version: ${{env.OTP_VERSION}}
elixir-version: ${{env.ELIXIR_VERSION}}

- uses: actions/cache/restore@v4
id: restore-deps-cache
with:
path: |
deps
_build
key: deps-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/*.lock') }}
restore-keys: deps-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-

- name: format
run: mix format --check-formatted

- name: cargo fmt
working-directory: native/zenohex_nif
run: cargo fmt --all -- --check

- name: credo
run: mix credo --ignore fixme

- name: restore plts cache
id: restore-plts-cache
uses: actions/cache/restore@v4
with:
key: plts-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/*.lock') }}
restore-keys: plts-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-
path: priv/plts

- name: create plts
if: steps.restore-plts-cache.outputs.cache-hit != 'true'
run: mix dialyzer --plt

- name: save plts cache
id: save-plts-cache
uses: actions/cache/save@v4
if: steps.restore-plts-cache.outputs.cache-hit != 'true'
with:
key: plts-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/*.lock') }}
path: priv/plts

- name: dialyzer
run: mix dialyzer --format github

test-with-one-session:
needs: build-deps
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
id: setup-beam
with:
otp-version: ${{env.OTP_VERSION}}
elixir-version: ${{env.ELIXIR_VERSION}}

- uses: actions/cache/restore@v4
id: restore-deps-cache
with:
path: |
deps
_build
key: deps-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/*.lock') }}
restore-keys: deps-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-

- name: test
run: mix test --warnings-as-errors --cover

test-with-another-session:
needs: build-deps
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: erlef/setup-beam@v1
id: setup-beam
with:
otp-version: ${{env.OTP_VERSION}}
elixir-version: ${{env.ELIXIR_VERSION}}

- uses: actions/cache/restore@v4
id: restore-deps-cache
with:
path: |
deps
_build
key: deps-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-${{ hashFiles('**/*.lock') }}
restore-keys: deps-${{ runner.os }}-${{ steps.setup-beam.outputs.otp-version }}-${{ steps.setup-beam.outputs.elixir-version }}-

- name: test
run: USE_DIFFERENT_SESSION="1" mix test --warnings-as-errors --cover
25 changes: 13 additions & 12 deletions .github/workflows/nif_precompile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ jobs:
strategy:
fail-fast: false
matrix:
nif: ["2.16", "2.15"]
nif: ["2.15"]
job:
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , use-cross: true }
- { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true }
- { target: aarch64-apple-darwin , os: macos-11 }
- { target: x86_64-apple-darwin , os: macos-11 }
- { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 }
- { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true }
- { target: x86_64-pc-windows-gnu , os: windows-2019 }
- { target: x86_64-pc-windows-msvc , os: windows-2019 }
- { target: aarch64-apple-darwin , os: macos-12 }
- { target: aarch64-unknown-linux-gnu , os: ubuntu-22.04 , use-cross: true }
- { target: aarch64-unknown-linux-musl , os: ubuntu-22.04 , use-cross: true }
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-22.04 , use-cross: true }
- { target: x86_64-apple-darwin , os: macos-12 }
- { target: x86_64-pc-windows-gnu , os: windows-2022 }
- { target: x86_64-pc-windows-msvc , os: windows-2022 }
- { target: x86_64-unknown-linux-gnu , os: ubuntu-22.04 }
- { target: x86_64-unknown-linux-musl , os: ubuntu-22.04 , use-cross: true }

steps:
- name: Checkout source code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Extract project version
shell: bash
Expand All @@ -42,12 +43,12 @@ jobs:
id: build-crate
uses: philss/[email protected]
with:
project-name: nifzenoh
project-name: zenohex_nif
project-version: ${{ env.PROJECT_VERSION }}
target: ${{ matrix.job.target }}
nif-version: ${{ matrix.nif }}
use-cross: ${{ matrix.job.use-cross }}
project-dir: "native/nifzenoh"
project-dir: "native/zenohex_nif"

- name: Artifact upload
uses: actions/upload-artifact@v3
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,6 @@ zenohex-*.tar
/tmp/

/priv/native/

/priv/plts/*.plt
/priv/plts/*.plt.hash
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
elixir 1.15.6-otp-26
erlang 26.1.1
elixir 1.15.7-otp-26
erlang 26.1.2
73 changes: 44 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

Zenohex is the [zenoh](https://zenoh.io/) client library for elixir.

Currently zenohex uses version 0.10.1-rc of zenoh.
If you want to communicate with Rust version of Zenoh, please use the same version.
**Currently zenohex uses version 0.10.1-rc of zenoh.
If you want to communicate with other Zenoh clients or routers, please use the same version.**

## Installation

Expand All @@ -17,7 +17,7 @@ by adding `zenohex` to your list of dependencies in `mix.exs`:
```elixir
def deps do
[
{:zenohex, "~> 0.1.5"}
{:zenohex, "~> 0.2.0-rc.2"}
]
end
```
Expand All @@ -27,40 +27,55 @@ and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/zenohex>.

### Install rust (Optional)

Since version 0.1.3, Zenohex uses rustler precompiled and does not require Rust to be installed.

If you need to build rust NIFs code, please set the environment variable and install rust.
```
export RUSTLER_PRECOMPILATION_EXAMPLE_BUILD=1
If you want to build rust NIFs code, please add following to your config file.

```elixir
config :rustler_precompiled, :force_build, zenohex: true
```

https://www.rust-lang.org/tools/install

## Getting Started

### Publisher example
#### terminal 1 (Subscriber)
```
iex -S mix
iex> NifZenoh.tester_sub "demo/example/zenoh-rs-pub"
```
### Low layer Pub/Sub example

#### terminal 2 (Publisher)
```
iex -S mix
iex> session = Zenohex.open
iex> {:ok, publisher} = Session.declare_publisher(session, "demo/example/zenoh-rs-pub")
iex> Publisher.put(publisher, "Hello zenoh?")
```sh
$ iex -S mix
```

### Subscriber example
```
(Subscriber)
iex -S mix
iex> session = Zenohex.open
iex> Session.declare_subscriber(session, "demo/example/zenoh-rs-pub", fn m -> IO.inspect(m) end)
(third argument is callback function)
(Publisher)
iex> {:ok, publisher} = Session.declare_publisher(session, "demo/example/zenoh-rs-pub")
iex> Publisher.put(publisher, "Hello zenoh?")
```elixir
iex(1)> {:ok, session} = Zenohex.open()
{:ok, #Reference<>}
iex(2)> {:ok, publisher} = Zenohex.Session.declare_publisher(session, "pub/sub")
{:ok, #Reference<>}
iex(3)> {:ok, subscriber} = Zenohex.Session.declare_subscriber(session, "pub/sub")
{:ok, #Reference<>}
iex(4)> Zenohex.Publisher.put(publisher, "Hello Zenoh Dragon")
:ok
iex(5)> Zenohex.Subscriber.recv_timeout(subscriber, 1000)
{:ok, "Hello Zenoh Dragon"}
iex(6)> Zenohex.Subscriber.recv_timeout(subscriber, 1000)
{:error, :timeout}
```

### Practical examples

We implemented practical examples under the [lib/zenohex/examples](https://github.com/b5g-ex/zenohex/tree/v0.2.0-rc.2/lib/zenohex/examples).

Please read the [lib/zenohex/examples/README.md](https://github.com/b5g-ex/zenohex/tree/v0.2.0-rc.2/lib/zenohex/examples/README.md) to use them as your implementation's reference.

## For developer

### How to release

1. Change versions, `mix.exs`, `native/zenohex_nif/Cargo.toml`
2. Run test, this step changes `native/zenohex_nif/Cargo.lock` version
3. Commit them and put the version tag, like v0.2.0-rc.2
4. Puth the tag, like `git push origin v0.2.0-rc.2`. this step triggers the `.github/workflows/nif_precompile.yml`
5. After the artifacts are made, run `mix rustler_precompiled.download Zenohex.Nif --all` to update `checksum-Elixir.Zenohex.Nif.exs` and commit it.
6. Then publish to Hex

(These steps just follows [Recommended flow](https://hexdocs.pm/rustler_precompiled/precompilation_guide.html#recommended-flow).)
18 changes: 0 additions & 18 deletions checksum-Elixir.NifZenoh.exs

This file was deleted.

11 changes: 11 additions & 0 deletions checksum-Elixir.Zenohex.Nif.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
%{
"libzenohex_nif-v0.2.0-rc.2-nif-2.15-aarch64-apple-darwin.so.tar.gz" => "sha256:50123c9e497693e616daf10fcc3731329de3b2b25d7201bdfa06d4e1b430383e",
"libzenohex_nif-v0.2.0-rc.2-nif-2.15-aarch64-unknown-linux-gnu.so.tar.gz" => "sha256:d5fa11e706bdf974511c2a2ea4731e16460a272a5752ba9721201b3f6b435ae4",
"libzenohex_nif-v0.2.0-rc.2-nif-2.15-aarch64-unknown-linux-musl.so.tar.gz" => "sha256:4957bd71810dbff7d5685f3a6469cbf1adbe849e0e88c00607910441c701d0db",
"libzenohex_nif-v0.2.0-rc.2-nif-2.15-arm-unknown-linux-gnueabihf.so.tar.gz" => "sha256:db0dcbf78eea7fc7c8f9bfd6b9acd816da560c6ea345494195df8f9b967a2714",
"libzenohex_nif-v0.2.0-rc.2-nif-2.15-x86_64-apple-darwin.so.tar.gz" => "sha256:3413ab2f8f8772a690b59c43b6e5db5e3fcec721bc481ea14da20c890b22f561",
"libzenohex_nif-v0.2.0-rc.2-nif-2.15-x86_64-unknown-linux-gnu.so.tar.gz" => "sha256:c835b87013dc722c647851358deabd17abdc274c79b42fab617662ed06b8866c",
"libzenohex_nif-v0.2.0-rc.2-nif-2.15-x86_64-unknown-linux-musl.so.tar.gz" => "sha256:bc614603b0424618d5e18440cd9637b6deaf835d52f5523f936935b2f863a45f",
"zenohex_nif-v0.2.0-rc.2-nif-2.15-x86_64-pc-windows-gnu.dll.tar.gz" => "sha256:f4acdab20483a65e7e2f85aa139df5856e6ba1db7827e729af8b77fe46562779",
"zenohex_nif-v0.2.0-rc.2-nif-2.15-x86_64-pc-windows-msvc.dll.tar.gz" => "sha256:c9091043d80c1e6183002472cb2bc630767a783980665785836f8644921fae57",
}
3 changes: 3 additions & 0 deletions config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Config

config :rustler_precompiled, :force_build, zenohex: true
Loading

0 comments on commit a2f0300

Please sign in to comment.