-
Notifications
You must be signed in to change notification settings - Fork 11
Use Rustler Precompiled #9
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,71 +1,62 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: ["*"] | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "lib/**/*" | ||
| - "test/**/*" | ||
| - "native/**/*" | ||
|
|
||
| env: | ||
| MIX_ENV: test | ||
| BLAKE3_BUILD: true | ||
|
|
||
| jobs: | ||
| test: | ||
| name: OTP ${{ matrix.otp }} / Elixir ${{ matrix.elixir }} / Rust ${{ matrix.rust }} | ||
| name: Elixir ${{ matrix.pair.elixir }} / OTP ${{ matrix.pair.otp }} | ||
| runs-on: ubuntu-20.04 | ||
|
|
||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| elixir: ["1.13", "1.14", "1.15"] | ||
| otp: ["23", "24", "25", "26"] | ||
| rust: ["stable"] | ||
| exclude: | ||
| - elixir: "1.14" | ||
| otp: "24" | ||
| - elixir: "1.13" | ||
| otp: "25" | ||
| - elixir: "1.13" | ||
| otp: "26" | ||
| - elixir: "1.15" | ||
| otp: "23" | ||
|
|
||
| include: | ||
| - pair: | ||
| elixir: 1.14.3 | ||
| otp: 25.2.1 | ||
| - pair: | ||
| elixir: 1.15.6 | ||
| otp: 26.1 | ||
| lint: lint | ||
| steps: | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
| - uses: erlef/setup-beam@v1 | ||
| with: | ||
| otp-version: ${{ matrix.otp }} | ||
| elixir-version: ${{ matrix.elixir }} | ||
| - name: Install Rust | ||
| uses: actions-rs/toolchain@v1 | ||
| with: | ||
| toolchain: ${{ matrix.rust }} | ||
| override: true | ||
| - name: Cache Elixir deps | ||
| uses: actions/cache@v3 | ||
| with: | ||
| path: | | ||
| deps | ||
| _build | ||
| key: deps-cache-${{ matrix.elixir }}-${{ matrix.otp }}-${{ hashFiles('**/mix.lock') }} | ||
| restore-keys: | | ||
| deps-cache-${{ matrix.elixir }}-${{ matrix.otp }}- | ||
| - name: Cache Rust deps | ||
| uses: actions/cache@v3 | ||
| - uses: actions/checkout@v3 | ||
|
|
||
| - uses: erlef/setup-beam@v1.15 | ||
| with: | ||
| path: | | ||
| ~/.cargo/bin/ | ||
| ~/.cargo/registry/index/ | ||
| ~/.cargo/registry/cache/ | ||
| ~/.cargo/git/db/ | ||
| key: ${{ matrix.rust }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
| restore-keys: ${{ matrix.rust }}-cargo- | ||
| - name: Install elixir dependencies | ||
| run: mix do local.hex --force, local.rebar --force, deps.get | ||
| - name: Check code formatting | ||
| otp-version: ${{ matrix.pair.otp }} | ||
| elixir-version: ${{ matrix.pair.elixir }} | ||
|
|
||
| - name: Install minimal stable Rust toolchain | ||
| uses: dtolnay/rust-toolchain@stable | ||
|
|
||
| - name: Install Dependencies | ||
| run: mix deps.get | ||
|
|
||
| - name: Check formatting | ||
| run: mix format --check-formatted | ||
| - name: Compile dependencies | ||
| if: ${{ matrix.lint }} | ||
|
|
||
| - name: Check unused deps | ||
| run: mix deps.unlock --check-unused | ||
| if: ${{ matrix.lint }} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious about the conditional lint, is the goal only to check the most recent pair?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This just allows you to turn off linting for a specific pair if desired. |
||
|
|
||
| - name: Compile deps | ||
| run: mix deps.compile | ||
| - name: Compile code (warnings as errors) | ||
|
|
||
| - name: Compile | ||
| run: mix compile --warnings-as-errors | ||
| - name: Run tests | ||
|
|
||
| - name: Test | ||
| run: mix test | ||
| - name: Create docs | ||
| run: mix docs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,31 +1,68 @@ | ||
| name: Release | ||
| name: Build precompiled NIFs | ||
|
|
||
| on: | ||
| release: | ||
| types: [released] | ||
| push: | ||
| tags: | ||
| - 'v*.*.*' | ||
|
|
||
| jobs: | ||
| release: | ||
| name: Publish release | ||
| runs-on: ubuntu-latest | ||
| build_release: | ||
| name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }}) | ||
| permissions: | ||
| contents: write | ||
| runs-on: ${{ matrix.job.os }} | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| 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-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true } | ||
| - { target: aarch64-apple-darwin , os: macos-12 } | ||
| - { target: x86_64-apple-darwin , os: macos-12 } | ||
| - { 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: x86_64-unknown-freebsd, os: ubuntu-22.04, use-cross: true, cross-version: v0.2.5 } | ||
|
|
||
| steps: | ||
| - name: Display build environment | ||
| run: printenv | ||
| - name: Checkout code | ||
| uses: actions/checkout@v3 | ||
| - name: Checkout source code | ||
| uses: actions/checkout@v3 | ||
|
|
||
| - name: Extract project version | ||
| shell: bash | ||
| run: | | ||
| # Get the project version from mix.exs | ||
| echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV | ||
| - name: Install Rust toolchain | ||
| uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| toolchain: stable | ||
| target: ${{ matrix.job.target }} | ||
|
|
||
| - name: Build the project | ||
| id: build-crate | ||
| uses: philss/rustler-precompiled-action@v1.1.0 | ||
| with: | ||
| project-name: blake3 | ||
| project-version: ${{ env.PROJECT_VERSION }} | ||
| target: ${{ matrix.job.target }} | ||
| nif-version: ${{ matrix.nif }} | ||
| use-cross: ${{ matrix.job.use-cross }} | ||
| cross-version: ${{ matrix.job.cross-version || 'v0.2.4' }} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why the mix between v0.2.4 and v0.2.5?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't recall. I pretty much always end up copy/pasting my CI configs and probably need to revisit. |
||
| project-dir: "native/blake3" | ||
|
|
||
| - uses: erlef/setup-beam@v1 | ||
| with: | ||
| otp-version: "25" | ||
| elixir-version: "1.14" | ||
| - name: Install dependencies | ||
| run: mix do local.hex --force, local.rebar --force, deps.get | ||
| - name: Artifact upload | ||
| uses: actions/upload-artifact@v3 | ||
| with: | ||
| name: ${{ steps.build-crate.outputs.file-name }} | ||
| path: ${{ steps.build-crate.outputs.file-path }} | ||
|
|
||
| - name: Compile code | ||
| run: mix compile | ||
| - name: Create docs | ||
| run: mix docs | ||
| - name: Publish release | ||
| run: mix hex.publish --yes | ||
| env: | ||
| HEX_API_KEY: ${{ secrets.HEX_API_KEY }} | ||
| - name: Publish archives and packages | ||
| uses: softprops/action-gh-release@v1 | ||
| with: | ||
| files: | | ||
| ${{ steps.build-crate.outputs.file-path }} | ||
| if: startsWith(github.ref, 'refs/tags/') | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've mistakenly removed doc creation and hex publishing, unless I'm missing how this works. Probably need to bring that back unless the idea is that hex publishing becomes some sort of manual process. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| %{ | ||
| "blake3-v1.0.3-nif-2.15-x86_64-pc-windows-gnu.dll.tar.gz" => "sha256:fa25a68693a0824c299ab0717bc46849272c0681b863fb3494c31e2871b29169", | ||
| "blake3-v1.0.3-nif-2.15-x86_64-pc-windows-msvc.dll.tar.gz" => "sha256:e8c595c68d021e66ef07bc5468a205764bf84c45a14c02762fa503bd87055fc4", | ||
| "libblake3-v1.0.3-nif-2.15-aarch64-apple-darwin.so.tar.gz" => "sha256:cc48c5d41911a6e947b36b12f5345e4c07ee273ca1389eaa0d67970095684276", | ||
| "libblake3-v1.0.3-nif-2.15-aarch64-unknown-linux-gnu.so.tar.gz" => "sha256:0907ed122301b1acfe0c6a2de68445a7df60adf27d3444638b87026795935a1a", | ||
| "libblake3-v1.0.3-nif-2.15-aarch64-unknown-linux-musl.so.tar.gz" => "sha256:459998cb86bf18207f2ac5fce17db528cec1d842cd8f73aaeac7a62e9ca86dc3", | ||
| "libblake3-v1.0.3-nif-2.15-arm-unknown-linux-gnueabihf.so.tar.gz" => "sha256:69e2aca5a84f779938065420a9196bbebf2fb5c7567cc31c999ec9c9694fe587", | ||
| "libblake3-v1.0.3-nif-2.15-x86_64-apple-darwin.so.tar.gz" => "sha256:1e4278e95d1b418ac0deb892fae4c4bbc938fd6b41e658c67e4c53fae0dc422c", | ||
| "libblake3-v1.0.3-nif-2.15-x86_64-unknown-linux-gnu.so.tar.gz" => "sha256:ded52eadc26c3f46d456419c1f1186da051483f26f3bb9ae734b7ec75a7dbb8f", | ||
| "libblake3-v1.0.3-nif-2.15-x86_64-unknown-linux-musl.so.tar.gz" => "sha256:3506cd9aefee8b28b1f33e8c3464343974c63aa8542ccc1853924f315f1726df", | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,23 @@ | ||
| defmodule MixBlake3.Project do | ||
| use Mix.Project | ||
|
|
||
| @source_url "https://github.com/Thomas-Jean/blake3" | ||
| @version "1.0.3" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there's enough changing in this that "1.1.0" is warranted |
||
|
|
||
| @rayon Application.compile_env(:blake3, :rayon, System.get_env("BLAKE3_RAYON")) | ||
| @simd_mode Application.compile_env(:blake3, :simd_mode, System.get_env("BLAKE3_SIMD_MODE")) | ||
|
|
||
| def project do | ||
| [ | ||
| app: :blake3, | ||
| version: "1.0.2", | ||
| version: @version, | ||
| elixir: "~> 1.13", | ||
| build_embedded: Mix.env() == :prod, | ||
| start_permanent: Mix.env() == :prod, | ||
| deps: deps(), | ||
| docs: docs(), | ||
| package: package() | ||
| package: package(), | ||
| source_url: @source_url | ||
| ] | ||
| end | ||
|
|
||
|
|
@@ -21,15 +28,24 @@ defmodule MixBlake3.Project do | |
| defp package() do | ||
| [ | ||
| description: "Elixir binding for the Rust Blake3 implementation", | ||
| files: ["lib", "native", ".formatter.exs", "README*", "LICENSE*", "mix.exs"], | ||
| files: [ | ||
| "lib", | ||
| "native", | ||
| ".formatter.exs", | ||
| "README*", | ||
| "LICENSE*", | ||
| "mix.exs", | ||
| "checksum-*.exs" | ||
| ], | ||
| licenses: ["Apache-2.0"], | ||
| links: %{"GitHub" => "https://github.com/Thomas-Jean/blake3"} | ||
| links: %{"GitHub" => @source_url} | ||
| ] | ||
| end | ||
|
|
||
| defp deps do | ||
| [ | ||
| {:rustler, "~> 0.30"}, | ||
| {:rustler, "~> 0.30", optional: true}, | ||
| {:rustler_precompiled, "~> 0.7"}, | ||
| {:ex_doc, "~> 0.21", only: [:dev, :test], runtime: false} | ||
| ] | ||
| end | ||
|
|
@@ -38,26 +54,21 @@ defmodule MixBlake3.Project do | |
| [ | ||
| extras: ["README.md"], | ||
| main: "readme", | ||
| source_url: "https://github.com/Thomas-Jean/blake3" | ||
| source_url: @source_url | ||
| ] | ||
| end | ||
|
|
||
| def config_features() do | ||
| simd = | ||
| case Application.get_env(:blake3, :simd_mode) || System.get_env("BLAKE3_SIMD_MODE") do | ||
| case @simd_mode do | ||
| "c_neon" -> "neon" | ||
| :c_neon -> "neon" | ||
| "neon" -> "neon" | ||
| :neon -> "neon" | ||
| _ -> nil | ||
| end | ||
|
|
||
| rayon = | ||
| if !is_nil(Application.get_env(:blake3, :rayon) || System.get_env("BLAKE3_RAYON")) do | ||
| "rayon" | ||
| else | ||
| nil | ||
| end | ||
| rayon = if @rayon, do: "rayon", else: nil | ||
|
|
||
| Enum.reject([simd, rayon], &is_nil/1) | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,20 @@ | ||
| [target.x86_64-apple-darwin] | ||
| [target.'cfg(target_os = "macos")'] | ||
| rustflags = [ | ||
| "-C", "link-arg=-undefined", | ||
| "-C", "link-arg=dynamic_lookup", | ||
| "-C", "link-arg=-undefined", | ||
| "-C", "link-arg=dynamic_lookup", | ||
| ] | ||
| [target.aarch64-apple-darwin] | ||
|
|
||
| # See https://github.com/rust-lang/rust/issues/59302 | ||
| [target.x86_64-unknown-linux-musl] | ||
| rustflags = [ | ||
| "-C", "link-arg=-undefined", | ||
| "-C", "link-arg=dynamic_lookup", | ||
| "-C", "target-feature=-crt-static" | ||
| ] | ||
|
|
||
| [target.aarch64-unknown-linux-musl] | ||
| rustflags = [ | ||
| "-C", "target-feature=-crt-static" | ||
| ] | ||
|
|
||
| # Provides a small build size, but takes more time to build. | ||
| [profile.release] | ||
| lto = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| [build.env] | ||
| passthrough = [ | ||
| "RUSTLER_NIF_VERSION" | ||
| ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we're missing elixir 1.13 in this build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and might want to add a few more recent ones