From 9c1a6ab4610c29bfac27fc16fdd316ff2689d70f Mon Sep 17 00:00:00 2001 From: Tim Gremore Date: Tue, 7 May 2024 09:45:39 -0500 Subject: [PATCH] feat: Precompilation with rustler_precompiled --- .github/workflows/rustler_precompiled.yml | 72 ++++++++++++++++++++++ lib/edix/parser.ex | 6 +- mix.exs | 9 ++- mix.lock | 2 + priv/native/libedix_parser.so | Bin 562808 -> 562808 bytes 5 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/rustler_precompiled.yml diff --git a/.github/workflows/rustler_precompiled.yml b/.github/workflows/rustler_precompiled.yml new file mode 100644 index 0000000..aa295c4 --- /dev/null +++ b/.github/workflows/rustler_precompiled.yml @@ -0,0 +1,72 @@ +name: Build precompiled NIFs + +on: + push: + branches: + - main + tags: + - '*' + +jobs: + build_release: + name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }}) + runs-on: ${{ matrix.job.os }} + strategy: + fail-fast: false + matrix: + nif: ["2.15"] + job: + - { target: aarch64-apple-darwin , os: macos-11 } + - { 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: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , use-cross: true } + - { target: riscv64gc-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true } + - { target: x86_64-apple-darwin , os: macos-11 } + - { target: x86_64-pc-windows-gnu , os: windows-2019 } + - { target: x86_64-pc-windows-msvc , os: windows-2019 } + - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 } + - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true } + + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Install rust toolchain + uses: dtolnay/rust-toolchain@stable + + - 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: edix_parser + project-version: ${{ env.PROJECT_VERSION }} + target: ${{ matrix.job.target }} + nif-version: ${{ matrix.nif }} + use-cross: ${{ matrix.job.use-cross }} + project-dir: "native/edix_parser" + + - name: Artifact upload + uses: actions/upload-artifact@v3 + with: + name: ${{ steps.build-crate.outputs.file-name }} + path: ${{ steps.build-crate.outputs.file-path }} + + - 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/') + diff --git a/lib/edix/parser.ex b/lib/edix/parser.ex index 2bb964f..0ccb15c 100644 --- a/lib/edix/parser.ex +++ b/lib/edix/parser.ex @@ -1,5 +1,9 @@ defmodule Edix.Parser do - use Rustler, otp_app: :edix, crate: "edix_parser" + use RustlerPrecompiled, + otp_app: :edix, + crate: "edix_parser", + base_url: "https://github.com/headwayio/edix/releases/download/v#{Edix.MixProject.version}", + version: Edix.MixProject.version # When your NIF is loaded, it will override this function. def add(_a, _b), do: :erlang.nif_error(:nif_not_loaded) diff --git a/mix.exs b/mix.exs index c27b613..84c5138 100644 --- a/mix.exs +++ b/mix.exs @@ -1,10 +1,12 @@ defmodule Edix.MixProject do use Mix.Project + @version "0.1.1" + def project do [ app: :edix, - version: "0.1.0", + version: @version, elixir: "~> 1.15", start_permanent: Mix.env() == :prod, deps: deps() @@ -18,12 +20,15 @@ defmodule Edix.MixProject do ] end + def version, do: @version + # Run "mix help deps" to learn about dependencies. defp deps do [ # {:dep_from_hexpm, "~> 0.3.0"}, # {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"} - {:rustler, "~> 0.29.0"} + {:rustler_precompiled, "~> 0.7.1", runtime: false}, + {:rustler, ">= 0.0.0", optional: true} ] end end diff --git a/mix.lock b/mix.lock index 79e9e68..3a57f07 100644 --- a/mix.lock +++ b/mix.lock @@ -1,5 +1,7 @@ %{ + "castore": {:hex, :castore, "1.0.7", "b651241514e5f6956028147fe6637f7ac13802537e895a724f90bf3e36ddd1dd", [:mix], [], "hexpm", "da7785a4b0d2a021cd1292a60875a784b6caef71e76bf4917bdee1f390455cf5"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, "rustler": {:hex, :rustler, "0.29.1", "880f20ae3027bd7945def6cea767f5257bc926f33ff50c0d5d5a5315883c084d", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "109497d701861bfcd26eb8f5801fe327a8eef304f56a5b63ef61151ff44ac9b6"}, + "rustler_precompiled": {:hex, :rustler_precompiled, "0.7.1", "ecadf02cc59a0eccbaed6c1937303a5827fbcf60010c541595e6d3747d3d0f9f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "b9e4657b99a1483ea31502e1d58c464bedebe9028808eda45c3a429af4550c66"}, "toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"}, } diff --git a/priv/native/libedix_parser.so b/priv/native/libedix_parser.so index 59289de08dd204051e49d897a0d72ac883177013..75b87182af438c269bbee55ed006aeca84b96d11 100755 GIT binary patch delta 115 zcmeydM(M{Ir43bVEG4PMC6jB}oF*S&TOd%AS!-nU*JSnFJ+D0EH*M-`E?{pjU}pqk zCLm@8Viq7~1!6WJX5U`G&hfBTL2sU-==0DukK#DZi$8C;6;bGvxqYePH?6s%UuK?~ NDzSTeVJio_AOMW=E``en@p?Ck~Yj6lo; z#LPg<0>rF9%m&2l+Y8t^9@Z+{P6&M)^FheR?7+jR+w^t$x49m1QeLe$rA*f4Oo+0c L@b