Change NIF build order to prefer local builds
This commit is contained in:
parent
c67464c35c
commit
b3fa59a061
2
Makefile
2
Makefile
@ -20,8 +20,10 @@ compile:
|
|||||||
./rebar3 compile
|
./rebar3 compile
|
||||||
|
|
||||||
priv/$(nif_lib): src/lib.rs
|
priv/$(nif_lib): src/lib.rs
|
||||||
|
ifneq ($(ECRECOVER_DISABLE_NIF_BUILD), true)
|
||||||
cargo build --release
|
cargo build --release
|
||||||
cp target/release/$(nif_lib_src) $@
|
cp target/release/$(nif_lib_src) $@
|
||||||
|
endif
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f priv/$(nif_lib) target/release/$(nif_lib_src)
|
rm -f priv/$(nif_lib) target/release/$(nif_lib_src)
|
||||||
|
24
README.md
24
README.md
@ -1,15 +1,29 @@
|
|||||||
# ecrecover
|
# ecrecover
|
||||||
FFI (NIF) export of Ethereum's ecrecover for use from Erlang.
|
FFI (NIF) export of Ethereum's ecrecover for use from Erlang.
|
||||||
|
|
||||||
### prerequisite:
|
### Prerequisites
|
||||||
- a checked out copy of my fork of parity-ethereum (https://github.com/johnsnewby/parity-ethereum) checked out into this directory this is (i.e. it will be referenced as `./parity-ethereum`)
|
The NIF is written in Rust, therefore the following additional build
|
||||||
|
dependencies are needed:
|
||||||
|
|
||||||
### to compile:
|
- Rust
|
||||||
`cargo build`
|
- Cargo
|
||||||
|
- Cmake
|
||||||
|
|
||||||
|
### Build
|
||||||
|
Execute:
|
||||||
|
```
|
||||||
|
make
|
||||||
|
```
|
||||||
|
|
||||||
|
To disable the local build of the NIF library, e.g. to use a prebuilt binary,
|
||||||
|
use the following command:
|
||||||
|
```
|
||||||
|
ECRECOVER_DISABLE_NIF_BUILD=true make
|
||||||
|
```
|
||||||
|
|
||||||
## Erlang integration
|
## Erlang integration
|
||||||
|
|
||||||
The shared library uses NIF. Use the erlang file `src/ecrecover.erl` to use this:
|
The shared library uses NIF. Use the Erlang file `src/ecrecover.erl` to use this:
|
||||||
|
|
||||||
```
|
```
|
||||||
c("src/ecrecover").
|
c("src/ecrecover").
|
||||||
|
@ -11,8 +11,14 @@
|
|||||||
%% NIF API
|
%% NIF API
|
||||||
|
|
||||||
load() ->
|
load() ->
|
||||||
SoName = filename:join(priv(), atom_to_list(?MODULE)),
|
% Prefer locally built NIF (good for testing and exotic platforms) over
|
||||||
ok = erlang:load_nif(SoName, 0).
|
% prebuilt binaries.
|
||||||
|
case load_local_nif() of
|
||||||
|
ok ->
|
||||||
|
ok;
|
||||||
|
{error, _} ->
|
||||||
|
load_prebuilt_nif()
|
||||||
|
end.
|
||||||
|
|
||||||
not_loaded(Line) ->
|
not_loaded(Line) ->
|
||||||
erlang:nif_error({error, {not_loaded, [{module, ?MODULE}, {line, Line}]}}).
|
erlang:nif_error({error, {not_loaded, [{module, ?MODULE}, {line, Line}]}}).
|
||||||
@ -35,14 +41,20 @@ recover(<<_:32/binary>> = Hash, <<_:65/binary>> = Sig) ->
|
|||||||
%%=============================================================================
|
%%=============================================================================
|
||||||
%% Internal Functions
|
%% Internal Functions
|
||||||
|
|
||||||
priv()->
|
load_local_nif() ->
|
||||||
|
EbinDir = filename:dirname(code:which(?MODULE)),
|
||||||
|
AppDir = filename:dirname(EbinDir),
|
||||||
|
PrivDir = filename:join(AppDir, "priv"),
|
||||||
|
SoName = filename:join(PrivDir, atom_to_list(?MODULE)),
|
||||||
|
erlang:load_nif(SoName, 0).
|
||||||
|
|
||||||
|
load_prebuilt_nif() ->
|
||||||
case code:priv_dir(ecrecoverprebuilt) of
|
case code:priv_dir(ecrecoverprebuilt) of
|
||||||
{error, _} ->
|
{error, _} ->
|
||||||
EbinDir = filename:dirname(code:which(?MODULE)),
|
{error, prebuilt_priv_dir_not_found};
|
||||||
AppPath = filename:dirname(EbinDir),
|
PrivDir ->
|
||||||
filename:join(AppPath, "priv");
|
SoName = filename:join(PrivDir, atom_to_list(?MODULE)),
|
||||||
Path ->
|
erlang:load_nif(SoName, 0)
|
||||||
Path
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
recover_(_Input) ->
|
recover_(_Input) ->
|
||||||
|
Loading…
x
Reference in New Issue
Block a user