Skip to content

Commit 5b0ad65

Browse files
authored
Merge pull request #4 from juulSme/master
Update stuff, release with Github Actions
2 parents d061fcc + db52e7a commit 5b0ad65

File tree

16 files changed

+468
-423
lines changed

16 files changed

+468
-423
lines changed

.github/workflows/ci.yml

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: ["*"]
6+
7+
env:
8+
MIX_ENV: test
9+
10+
jobs:
11+
test:
12+
name: OTP ${{ matrix.otp }} / Elixir ${{ matrix.elixir }} / Rust ${{ matrix.rust }}
13+
runs-on: ubuntu-20.04
14+
strategy:
15+
matrix:
16+
elixir: ["1.12", "1.13", "1.14"]
17+
otp: ["23", "24", "25"]
18+
rust: ["stable"]
19+
exclude:
20+
- elixir: "1.14"
21+
otp: "24"
22+
- elixir: "1.13"
23+
otp: "25"
24+
- elixir: "1.12"
25+
otp: "25"
26+
27+
steps:
28+
- name: Checkout code
29+
uses: actions/checkout@v3
30+
- uses: erlef/setup-beam@v1
31+
with:
32+
otp-version: ${{ matrix.otp }}
33+
elixir-version: ${{ matrix.elixir }}
34+
- name: Install Rust
35+
uses: actions-rs/toolchain@v1
36+
with:
37+
toolchain: ${{ matrix.rust }}
38+
override: true
39+
- name: Cache Elixir deps
40+
uses: actions/cache@v3
41+
with:
42+
path: |
43+
deps
44+
_build
45+
key: deps-cache-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }}
46+
restore-keys: |
47+
deps-cache-${{ matrix.elixir }}-${{ matrix.otp }}-
48+
- name: Cache Rust deps
49+
uses: actions/cache@v3
50+
with:
51+
path: |
52+
~/.cargo/bin/
53+
~/.cargo/registry/index/
54+
~/.cargo/registry/cache/
55+
~/.cargo/git/db/
56+
key: ${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.lock') }}
57+
restore-keys: ${{ matrix.rust }}-cargo-
58+
- name: Install elixir dependencies
59+
run: mix do local.hex --force, local.rebar --force, deps.get
60+
- name: Check code formatting
61+
run: mix format --check-formatted
62+
- name: Compile dependencies
63+
run: mix deps.compile
64+
- name: Compile code (warnings as errors)
65+
run: mix compile --warnings-as-errors
66+
- name: Run tests
67+
run: mix test
68+
- name: Create docs
69+
run: mix docs

.github/workflows/main.yml

-44
This file was deleted.

.github/workflows/release.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Release
2+
on:
3+
release:
4+
types: [released]
5+
6+
jobs:
7+
release:
8+
name: Publish release
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Display build environment
13+
run: printenv
14+
- name: Checkout code
15+
uses: actions/checkout@v3
16+
17+
- name: Set version in readme
18+
uses: weareyipyip/set-version-action@v2
19+
with:
20+
source: tag
21+
file_path: README.md
22+
- name: Set version in mix.exs
23+
uses: weareyipyip/set-version-action@v2
24+
with:
25+
source: tag
26+
file_path: mix.exs
27+
- name: Set version in Cargo.toml
28+
uses: weareyipyip/set-version-action@v2
29+
with:
30+
source: tag
31+
file_path: native/blake3/Cargo.toml
32+
- name: Set version in Cargo.lock
33+
uses: weareyipyip/set-version-action@v2
34+
with:
35+
source: tag
36+
file_path: native/blake3/Cargo.lock
37+
38+
- uses: erlef/setup-beam@v1
39+
with:
40+
otp-version: "25"
41+
elixir-version: "1.14"
42+
- name: Install dependencies
43+
run: mix do local.hex --force, local.rebar --force, deps.get
44+
45+
- name: Compile code
46+
run: mix compile
47+
- name: Create docs
48+
run: mix docs
49+
- name: Publish release
50+
run: mix hex.publish --yes
51+
env:
52+
HEX_API_KEY: ${{ secrets.HEX_API_KEY }}

CHANGELOG.md

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
# Changelog
22

3+
## v0.6.0
4+
5+
- Enhancements
6+
7+
- updated blake3 version to 1.3.3
8+
- updated rustler to 0.22.2
9+
10+
- Other
11+
- add github actions release workflow
12+
- fix CI
13+
- Release version injection
14+
15+
## v0.5.0 (unreleased)
16+
17+
- Enhancements
18+
19+
- updated blake3 version to 1.0.0
20+
- updated rustler to 0.22.1
21+
- refactored Rust crate to use the rustler::nif macro
22+
23+
- Breaking changes
24+
25+
- `update_with_join` has been replacted with `update_rayon` to reflect the
26+
same change in the upstream `blake3` crate. This function is only available
27+
when the `rayon` feature flag is enabled, and will panic otherwise.
28+
329
## v0.4.0
430

531
- Enhancements

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The package can be installed by adding `blake3` to your list of dependencies in
1212
```elixir
1313
def deps do
1414
[
15-
{:blake3, "~> 0.4.1"}
15+
{:blake3, "~> 0.0.0+development"}
1616
]
1717
end
1818
```
@@ -21,7 +21,7 @@ run `mix deps.get` and `mix deps.compile` to pull and build the bindings
2121

2222
## Configuration
2323

24-
There are feature options in the rust implementation that allow for additional SIMD instructions and multithreading. They can be set though environment variable or `Mix.Config`.
24+
There are feature options in the rust implementation that allow for additional SIMD instructions and multithreading. They can be set though environment variable or `Mix.Config`.
2525

2626
```shell
2727
export BLAKE3_SIMD_MODE=neon
@@ -36,8 +36,8 @@ config :blake3,
3636
rayon: :true
3737
```
3838

39-
* `neon` enables ARM NEON support
40-
* `rayon` enables Rayon-based multithreading
39+
- `neon` enables ARM NEON support
40+
- `rayon` enables Rayon-based multithreading
4141

4242
When changing configuration you will need to call `mix deps.compile` to enable the features.
4343

@@ -54,4 +54,9 @@ When changing configuration you will need to call `mix deps.compile` to enable t
5454
#"a74bb4d1d4e44d0a2981d131762f45db9a211313d8e9f2cd151b4e673a35a6c1"
5555
```
5656

57+
## Supported Elixir / Erlang / Rust
58+
59+
We follow Rustler itself, supporting latest three minor Elixir versions and major OTP versions.
60+
As for Rust itself, we only support stable.
61+
5762
Documentation can found at [https://hexdocs.pm/blake3](https://hexdocs.pm/blake3).

config/config.exs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
use Mix.Config
2-
# config :blake3, simd_mode: "std"
3-
# config :blake3, rayon: :false
1+
import Config
2+
3+
config :blake3, Blake3.Native,
4+
mode: :release,
5+
features: MixBlake3.Project.config_features()
6+
7+
import_config("#{Mix.env()}.exs")

config/dev.exs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import Config

config/test.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Config
2+
3+
config :blake3, Blake3.Native, features: ~w(rayon)

lib/blake3.ex

+16-4
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ defmodule Blake3 do
66

77
alias Blake3.Native
88

9+
@type hasher :: reference()
10+
911
@doc """
1012
computes a message digest for the given data
1113
"""
14+
@spec hash(data :: binary()) :: binary()
1215
def hash(data) do
1316
Native.hash(data)
1417
end
@@ -19,6 +22,7 @@ defmodule Blake3 do
1922
diffrent size you can use `derive_key` to get a key of
2023
a proper size.
2124
"""
25+
@spec keyed_hash(key :: binary(), data :: binary()) :: binary() | {:error, String.t()}
2226
def keyed_hash(key, data) when byte_size(key) == 32 do
2327
Native.keyed_hash(key, data)
2428
end
@@ -31,6 +35,7 @@ defmodule Blake3 do
3135
returns a new reference for a Blake3 hasher to be used
3236
for streaming calls with update/2
3337
"""
38+
@spec new() :: hasher()
3439
def new() do
3540
Native.new()
3641
end
@@ -39,6 +44,7 @@ defmodule Blake3 do
3944
returns a new reference for a Blake3 hasher using the passed key
4045
to be used for streaming calls with update/2
4146
"""
47+
@spec new_keyed(key :: binary()) :: hasher() | {:error, String.t()}
4248
def new_keyed(key) when byte_size(key) == 32 do
4349
Native.new_keyed(key)
4450
end
@@ -52,6 +58,7 @@ defmodule Blake3 do
5258
the refernce can be continouly passed to update/2 or
5359
when finished to finalize/1
5460
"""
61+
@spec update(state :: hasher(), data :: binary()) :: hasher()
5562
def update(state, data) do
5663
Native.update(state, data)
5764
end
@@ -60,28 +67,32 @@ defmodule Blake3 do
6067
returns the binary of the current hash state for a
6168
given hasher
6269
"""
70+
@spec finalize(state :: hasher()) :: binary()
6371
def finalize(state) do
6472
Native.finalize(state)
6573
end
6674

6775
@doc """
6876
returns a 32 byte key for use for `hash_keyed` or `new_keyed` from
69-
the given context and key. for more information: [crate](https://github.com/BLAKE3-team/BLAKE3#the-blake3-crate)
77+
the given context and key. for more information: [crate](https://github.com/BLAKE3-team/BLAKE3#the-blake3-crate-)
7078
"""
79+
@spec derive_key(context :: binary(), key :: binary()) :: binary()
7180
def derive_key(context, key) do
7281
Native.derive_key(context, key)
7382
end
7483

7584
@doc """
7685
same as `derive_key/2` but uses an empty string for context
7786
"""
87+
@spec derive_key(key :: binary()) :: binary()
7888
def derive_key(key) do
7989
Native.derive_key("", key)
8090
end
8191

8292
@doc """
8393
reset a hasher to the default stat like when calling Blake3.new
8494
"""
95+
@spec derive_key(state :: hasher()) :: hasher()
8596
def reset(state) do
8697
Native.reset(state)
8798
end
@@ -90,9 +101,10 @@ defmodule Blake3 do
90101
updates state with the potential to multithreading. The rayon
91102
feature needs to be enabled and the input need to be large enough.
92103
for more information see:
93-
[comment](https://github.com/BLAKE3-team/BLAKE3/blob/fdd329ba57896faac4ae797775c175ad880cbe42/src/lib.rs#L948-L981)
104+
[documentation](https://docs.rs/blake3/1.0.0/blake3/struct.Hasher.html#method.update_rayon)
94105
"""
95-
def update_with_join(state, data) do
96-
Native.update_with_join(state, data)
106+
@spec update_rayon(state :: hasher(), data :: binary()) :: hasher()
107+
def update_rayon(state, data) do
108+
Native.update_rayon(state, data)
97109
end
98110
end

lib/blake3/native.ex

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ defmodule Blake3.Native do
44
This module doesn't need to be called direcly.
55
"""
66

7-
use Rustler, otp_app: :blake3, crate: :blake3
7+
use Rustler,
8+
otp_app: :blake3
89

910
def hash(_str), do: error()
1011
def new(), do: error()
1112
def update(_state, _str), do: error()
12-
def update_with_join(_state, _str), do: error()
13+
def update_rayon(_state, _str), do: error()
1314
def finalize(_state), do: error()
1415
def derive_key(_context, _key), do: error()
1516
def keyed_hash(_key, _str), do: error()

0 commit comments

Comments
 (0)