Skip to content

Commit abc9c77

Browse files
committed
feat: rustler precompiled
1 parent c12beb3 commit abc9c77

File tree

9 files changed

+168
-9
lines changed

9 files changed

+168
-9
lines changed

.github/workflows/release.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: Build precompiled NIFs
2+
3+
env:
4+
NIF_DIRECTORY: "native/htmd"
5+
6+
on:
7+
push:
8+
tags: ["v*"]
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.17", "2.16"]
18+
job:
19+
- {
20+
target: aarch64-unknown-linux-gnu,
21+
os: ubuntu-22.04,
22+
use-cross: true,
23+
}
24+
- {
25+
target: aarch64-unknown-linux-musl,
26+
os: ubuntu-22.04,
27+
use-cross: true,
28+
}
29+
- { target: aarch64-apple-darwin, os: macos-13 }
30+
- {
31+
target: riscv64gc-unknown-linux-gnu,
32+
os: ubuntu-22.04,
33+
use-cross: true,
34+
}
35+
- { target: x86_64-apple-darwin, os: macos-13 }
36+
- { target: x86_64-unknown-linux-gnu, os: ubuntu-22.04 }
37+
- {
38+
target: x86_64-unknown-linux-musl,
39+
os: ubuntu-22.04,
40+
use-cross: true,
41+
}
42+
- { target: x86_64-pc-windows-gnu, os: windows-2025 }
43+
- { target: x86_64-pc-windows-msvc, os: windows-2025 }
44+
45+
steps:
46+
- name: Checkout source code
47+
uses: actions/checkout@v4
48+
49+
- name: Extract project version
50+
shell: bash
51+
run: |
52+
# Get the project version from mix.exs
53+
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV
54+
55+
- name: Install Rust toolchain
56+
uses: dtolnay/rust-toolchain@stable
57+
with:
58+
toolchain: stable
59+
target: ${{ matrix.job.target }}
60+
61+
- name: Build the project
62+
id: build-crate
63+
uses: philss/[email protected]
64+
with:
65+
project-name: html2text_nif
66+
project-version: ${{ env.PROJECT_VERSION }}
67+
target: ${{ matrix.job.target }}
68+
nif-version: ${{ matrix.nif }}
69+
use-cross: ${{ matrix.job.use-cross }}
70+
variant: ${{ matrix.job.variant }}
71+
cargo-args: ${{ matrix.job.cargo-args }}
72+
cross-version: "v0.2.5"
73+
project-dir: "native/html2text_nif"
74+
75+
- name: Artifact upload
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: ${{ steps.build-crate.outputs.file-name }}
79+
path: ${{ steps.build-crate.outputs.file-path }}
80+
81+
- name: Publish archives and packages
82+
uses: softprops/action-gh-release@v2
83+
with:
84+
files: |
85+
${{ steps.build-crate.outputs.file-path }}
86+
if: startsWith(github.ref, 'refs/tags/')

Cargo.toml

Lines changed: 0 additions & 4 deletions
This file was deleted.

lib/htmd/native.ex

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
defmodule Htmd.Native do
2-
use Rustler, otp_app: :htmd, crate: "htmd"
2+
mix_config = Mix.Project.config()
3+
version = mix_config[:version]
4+
github_url = mix_config[:package][:links]["GitHub"]
5+
6+
targets = ~w(
7+
aarch64-apple-darwin
8+
aarch64-unknown-linux-gnu
9+
aarch64-unknown-linux-musl
10+
riscv64gc-unknown-linux-gnu
11+
x86_64-apple-darwin
12+
x86_64-pc-windows-gnu
13+
x86_64-pc-windows-msvc
14+
x86_64-unknown-linux-gnu
15+
x86_64-unknown-linux-musl
16+
)
17+
18+
nif_versions = ~w(2.17 2.16)
19+
20+
use RustlerPrecompiled,
21+
otp_app: :htmd,
22+
crate: "htmd",
23+
base_url: "#{github_url}/releases/download/v#{version}",
24+
nif_versions: nif_versions,
25+
targets: targets,
26+
version: version,
27+
force_build: System.get_env("HTMD_BUILD") in ["1", "true"]
328

429
alias Htmd.ConvertOptions
530

mix.exs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,20 @@
11
defmodule Htmd.MixProject do
22
use Mix.Project
3+
@version "0.1.0"
4+
@source_url "https://github.com/kasvith/htmd"
35

46
def project do
57
[
68
app: :htmd,
7-
version: "0.1.0",
9+
name: "Htmd",
10+
version: @version,
811
elixir: "~> 1.18",
912
start_permanent: Mix.env() == :prod,
1013
deps: deps(),
1114
description: description(),
1215
package: package(),
13-
source_url: "https://github.com/kasvith/htmd"
16+
docs: docs(),
17+
source_url: @source_url
1418
]
1519
end
1620

@@ -24,7 +28,9 @@ defmodule Htmd.MixProject do
2428
# Run "mix help deps" to learn about dependencies.
2529
defp deps do
2630
[
27-
{:rustler, "~> 0.36.2", runtime: false}
31+
{:rustler, "~> 0.36.2", optional: true},
32+
{:rustler_precompiled, "~> 0.8"},
33+
{:ex_doc, "~> 0.34", only: :dev, runtime: false, warn_if_outdated: true}
2834
]
2935
end
3036

@@ -36,8 +42,19 @@ defmodule Htmd.MixProject do
3642
[
3743
name: "htmd",
3844
maintainers: ["Kasun Vithanage"],
45+
description: "A fast HTML to Markdown converter for Elixir, powered by Rust.",
3946
licenses: ["MIT"],
40-
links: %{"GitHub" => "https://github.com/kasvith/htmd"}
47+
links: %{"GitHub" => "https://github.com/kasvith/htmd"},
48+
files: ~w(lib native .formatter.exs README* LICENSE* mix.exs checksum-*.exs)
49+
]
50+
end
51+
52+
defp docs do
53+
[
54+
main: "readme",
55+
source_url: @source_url,
56+
source_ref: "v#{@version}",
57+
extras: [{:"README.md", [title: "README"]}]
4158
]
4259
end
4360
end

mix.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
%{
2+
"castore": {:hex, :castore, "1.0.15", "8aa930c890fe18b6fe0a0cff27b27d0d4d231867897bd23ea772dee561f032a3", [:mix], [], "hexpm", "96ce4c69d7d5d7a0761420ef743e2f4096253931a3ba69e5ff8ef1844fe446d3"},
3+
"earmark_parser": {:hex, :earmark_parser, "1.4.44", "f20830dd6b5c77afe2b063777ddbbff09f9759396500cdbe7523efd58d7a339c", [:mix], [], "hexpm", "4778ac752b4701a5599215f7030989c989ffdc4f6df457c5f36938cc2d2a2750"},
4+
"ex_doc": {:hex, :ex_doc, "0.38.3", "ddafe36b8e9fe101c093620879f6604f6254861a95133022101c08e75e6c759a", [:mix], [{:earmark_parser, "~> 1.4.44", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "ecaa785456a67f63b4e7d7f200e8832fa108279e7eb73fd9928e7e66215a01f9"},
25
"jason": {:hex, :jason, "1.4.4", "b9226785a9aa77b6857ca22832cffa5d5011a667207eb2a0ad56adb5db443b8a", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "c5eb0cab91f094599f94d55bc63409236a8ec69a21a67814529e8d5f6cc90b3b"},
6+
"makeup": {:hex, :makeup, "1.2.1", "e90ac1c65589ef354378def3ba19d401e739ee7ee06fb47f94c687016e3713d1", [:mix], [{:nimble_parsec, "~> 1.4", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "d36484867b0bae0fea568d10131197a4c2e47056a6fbe84922bf6ba71c8d17ce"},
7+
"makeup_elixir": {:hex, :makeup_elixir, "1.0.1", "e928a4f984e795e41e3abd27bfc09f51db16ab8ba1aebdba2b3a575437efafc2", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "7284900d412a3e5cfd97fdaed4f5ed389b8f2b4cb49efc0eb3bd10e2febf9507"},
8+
"makeup_erlang": {:hex, :makeup_erlang, "1.0.2", "03e1804074b3aa64d5fad7aa64601ed0fb395337b982d9bcf04029d68d51b6a7", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "af33ff7ef368d5893e4a267933e7744e46ce3cf1f61e2dccf53a111ed3aa3727"},
9+
"nimble_parsec": {:hex, :nimble_parsec, "1.4.2", "8efba0122db06df95bfaa78f791344a89352ba04baedd3849593bfce4d0dc1c6", [:mix], [], "hexpm", "4b21398942dda052b403bbe1da991ccd03a053668d147d53fb8c4e0efe09c973"},
310
"rustler": {:hex, :rustler, "0.36.2", "6c2142f912166dfd364017ab2bf61242d4a5a3c88e7b872744642ae004b82501", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.7", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "93832a6dbc1166739a19cd0c25e110e4cf891f16795deb9361dfcae95f6c88fe"},
11+
"rustler_precompiled": {:hex, :rustler_precompiled, "0.8.3", "4e741024b0b097fe783add06e53ae9a6f23ddc78df1010f215df0c02915ef5a8", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: false]}, {:rustler, "~> 0.23", [hex: :rustler, repo: "hexpm", optional: true]}], "hexpm", "c23f5f33cb6608542de4d04faf0f0291458c352a4648e4d28d17ee1098cddcc4"},
412
"toml": {:hex, :toml, "0.7.0", "fbcd773caa937d0c7a02c301a1feea25612720ac3fa1ccb8bfd9d30d822911de", [:mix], [], "hexpm", "0690246a2478c1defd100b0c9b89b4ea280a22be9a7b313a8a058a2408a2fa70"},
513
}

native/htmd/.cargo/config.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[profile.release]
2+
lto = true
3+
4+
[target.x86_64-apple-darwin]
5+
rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]
6+
7+
[target.aarch64-apple-darwin]
8+
rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]
9+
10+
# Libatomic is needed for 32 bits ARM.
11+
# See: https://github.com/philss/rustler_precompiled/issues/53
12+
[target.arm-unknown-linux-gnueabihf]
13+
linker = "arm-linux-gnueabihf-gcc"
14+
rustflags = ["-l", "dylib=atomic"]
15+
16+
# See https://github.com/rust-lang/rust/issues/59302
17+
[target.x86_64-unknown-linux-musl]
18+
rustflags = ["-C", "target-feature=-crt-static"]
19+
20+
[target.aarch64-unknown-linux-musl]
21+
rustflags = ["-C", "target-feature=-crt-static"]

native/htmd/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target
File renamed without changes.

native/htmd/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,8 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
rustler = "0.36.2"
1313
htmd = "0.3.0"
14+
15+
[features]
16+
default = ["nif_version_2_16"]
17+
nif_version_2_16 = ["rustler/nif_version_2_16"]
18+
nif_version_2_17 = ["rustler/nif_version_2_17"]

0 commit comments

Comments
 (0)