Skip to content

Commit c73ab26

Browse files
committed
Don't try to load NIF if not built
If building the NIF was disabled, don't even try to load it. The NIF functions will return errors, but that will hopefully be unsurprising.
1 parent 743ad6f commit c73ab26

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/i2c/i2c_nif.ex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
defmodule Circuits.I2C.Nif do
77
@moduledoc false
88

9-
@on_load {:load_nif, 0}
10-
@compile {:autoload, false}
9+
if System.get_env("CIRCUITS_I2C_I2CDEV") != "disabled" do
10+
@on_load {:load_nif, 0}
11+
@compile {:autoload, false}
1112

12-
def load_nif() do
13-
:erlang.load_nif(:code.priv_dir(:circuits_i2c) ++ ~c"/i2c_nif", 0)
13+
def load_nif() do
14+
:erlang.load_nif(:code.priv_dir(:circuits_i2c) ++ ~c"/i2c_nif", 0)
15+
end
1416
end
1517

1618
def open(_device, _timeout), do: :erlang.nif_error(:nif_not_loaded)

0 commit comments

Comments
 (0)