Skip to content

Commit ff06bfa

Browse files
committed
feat: support rustler_precompiled
1 parent 4683f50 commit ff06bfa

File tree

8 files changed

+96
-4
lines changed

8 files changed

+96
-4
lines changed

.github/workflows/release.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Build precompiled NIFs
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
tags:
8+
- '*'
9+
10+
jobs:
11+
build_release:
12+
name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }})
13+
runs-on: ${{ matrix.job.os }}
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
nif: ["2.16", "2.15"]
18+
job:
19+
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , use-cross: true }
20+
- { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true }
21+
- { target: aarch64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true }
22+
- { target: aarch64-apple-darwin , os: macos-12 }
23+
- { target: riscv64gc-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true }
24+
- { target: x86_64-apple-darwin , os: macos-12 }
25+
- { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 }
26+
- { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true }
27+
- { target: x86_64-pc-windows-gnu , os: windows-2019 }
28+
- { target: x86_64-pc-windows-msvc , os: windows-2019 }
29+
30+
steps:
31+
- name: Checkout source code
32+
uses: actions/checkout@v3
33+
34+
- name: Extract project version
35+
shell: bash
36+
run: |
37+
# Get the project version from mix.exs
38+
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV
39+
40+
- name: Install Rust toolchain
41+
uses: dtolnay/rust-toolchain@stable
42+
with:
43+
toolchain: stable
44+
target: ${{ matrix.job.target }}
45+
46+
- name: Build the project
47+
id: build-crate
48+
uses: philss/[email protected]
49+
with:
50+
project-name: captcha_nif
51+
project-version: ${{ env.PROJECT_VERSION }}
52+
target: ${{ matrix.job.target }}
53+
nif-version: ${{ matrix.nif }}
54+
use-cross: ${{ matrix.job.use-cross }}
55+
project-dir: "native/captcha_nif"
56+
57+
- name: Artifact upload
58+
uses: actions/upload-artifact@v3
59+
with:
60+
name: ${{ steps.build-crate.outputs.file-name }}
61+
path: ${{ steps.build-crate.outputs.file-path }}
62+
63+
- name: Publish archives and packages
64+
uses: softprops/action-gh-release@v1
65+
with:
66+
files: |
67+
${{ steps.build-crate.outputs.file-path }}
68+
if: startsWith(github.ref, 'refs/tags/')

config/config.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Config
2+
3+
import_config "#{config_env()}.exs"

config/dev.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Config
2+
3+
config :rustler_precompiled, :force_build, captcha: true

config/test.exs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import Config
2+
3+
config :rustler_precompiled, :force_build, captcha: true

lib/native/native.ex

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ defmodule Captcha.Native do
22
@moduledoc """
33
NIF bindings for the [captcha](https://github.com/daniel-e/captcha) Rust implementation
44
"""
5-
use Rustler, otp_app: :captcha, crate: "captcha_nif"
5+
version = Mix.Project.config()[:version]
6+
7+
use RustlerPrecompiled,
8+
otp_app: :captcha,
9+
crate: "captcha_nif",
10+
base_url: "https://github.com/feng19/captcha/releases/download/v#{version}",
11+
targets:
12+
Enum.uniq(["aarch64-unknown-linux-musl" | RustlerPrecompiled.Config.default_targets()]),
13+
version: version
614

715
def create(_options), do: error()
816
def easy(_options \\ nil), do: error()

mix.exs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defmodule Captcha.MixProject do
22
use Mix.Project
33

4-
@version "0.1.4"
4+
@version "0.2.0"
55
@source_url "https://github.com/feng19/captcha"
66

77
def project do
@@ -24,7 +24,8 @@ defmodule Captcha.MixProject do
2424

2525
defp deps do
2626
[
27-
{:rustler, "~> 0.30"},
27+
{:rustler_precompiled, "~> 0.4"},
28+
{:rustler, ">= 0.0.0", optional: true},
2829
{:ex_doc, ">= 0.0.0", only: [:docs, :dev], runtime: false}
2930
]
3031
end
@@ -47,7 +48,7 @@ defmodule Captcha.MixProject do
4748
[
4849
name: "captcha_nif",
4950
description: "NIF bindings for the captcha Rust implementation",
50-
files: ["lib", "native", "mix.exs", "README.md", "LICENSE.md"],
51+
files: ["lib", "native", "checksum-*.exs", "mix.exs", "README.md", "LICENSE.md"],
5152
maintainers: ["feng19"],
5253
licenses: ["Apache-2.0"],
5354
links: %{"GitHub" => @source_url}

mix.lock

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
%{
2+
"castore": {:hex, :castore, "1.0.9", "5cc77474afadf02c7c017823f460a17daa7908e991b0cc917febc90e466a375c", [:mix], [], "hexpm", "5ea956504f1ba6f2b4eb707061d8e17870de2bee95fb59d512872c2ef06925e7"},
23
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
34
"ex_doc": {:hex, :ex_doc, "0.31.1", "8a2355ac42b1cc7b2379da9e40243f2670143721dd50748bf6c3b1184dae2089", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3178c3a407c557d8343479e1ff117a96fd31bafe52a039079593fb0524ef61b0"},
45
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
@@ -7,5 +8,6 @@
78
"makeup_erlang": {:hex, :makeup_erlang, "0.1.5", "e0ff5a7c708dda34311f7522a8758e23bfcd7d8d8068dc312b5eb41c6fd76eba", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "94d2e986428585a21516d7d7149781480013c56e30c6a233534bedf38867a59a"},
89
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
910
"rustler": {:hex, :rustler, "0.31.0", "7e5eefe61e6e6f8901e5aa3de60073d360c6320d9ec363027b0197297b80c46a", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "99e378459bfb9c3bda6d3548b2b3bc6f9ad97f728f76bdbae7bf5c770a4f8abd"},
11+
"rustler_precompiled": {:hex, :rustler_precompiled, "0.8.2", "5f25cbe220a8fac3e7ad62e6f950fcdca5a5a5f8501835d2823e8c74bf4268d5", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "63d1bd5f8e23096d1ff851839923162096364bac8656a4a3c00d1fff8e83ee0a"},
1012
"toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"},
1113
}

native/captcha_nif/Cross.toml

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[build.env]
2+
passthrough = [
3+
"RUSTLER_NIF_VERSION"
4+
]

0 commit comments

Comments
 (0)