Skip to content

Commit e5535d9

Browse files
authored
Replace built in precompiled module with dependency (#47)
This removes the built in feature that makes the precompilation work and add the `RustlerPrecompiled` package as dependency.
1 parent b1e16b4 commit e5535d9

File tree

6 files changed

+12
-889
lines changed

6 files changed

+12
-889
lines changed

lib/html5ever/native.ex

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,18 @@ defmodule Html5ever.Native do
99
rustler_opts = [otp_app: :html5ever, crate: "html5ever_nif", mode: :release]
1010
env_config = Application.get_env(rustler_opts[:otp_app], Html5ever, [])
1111

12-
opts =
13-
if System.get_env("HTML5EVER_BUILD") in ["1", "true"] or env_config[:build_from_source] do
14-
rustler_opts
15-
else
16-
case Html5ever.Precompiled.download_or_reuse_nif_file(
17-
rustler_opts,
18-
nif_module: __MODULE__,
19-
base_url: "#{github_url}/releases/download/v#{version}",
20-
version: version
21-
) do
22-
{:ok, new_opts} ->
23-
new_opts
24-
25-
{:error, error} ->
26-
error =
27-
"Error while downloading precompiled NIF: #{error}\n\nSet HTML5EVER_BUILD=1 env var to compile the NIF from scratch. You can also configure this application to force compilation:\n\n config :html5ever, Html5ever, build_from_source: true\n"
28-
29-
if Mix.env() == :prod do
30-
raise error
31-
else
32-
Logger.debug(error)
33-
rustler_opts
34-
end
35-
end
36-
end
37-
3812
# This module will be replaced by the NIF module after
3913
# loaded. It throws an error in case the NIF can't be loaded.
40-
use Rustler, opts
14+
if System.get_env("HTML5EVER_BUILD") in ["1", "true"] or env_config[:build_from_source] do
15+
use Rustler, rustler_opts
16+
else
17+
use RustlerPrecompiled,
18+
rustler_opts ++
19+
[
20+
base_url: "#{github_url}/releases/download/v#{version}",
21+
version: version
22+
]
23+
end
4124

4225
def parse_sync(_binary), do: err()
4326
def parse_dirty(_binary), do: err()

0 commit comments

Comments
 (0)