Merge pull request #13 from aeternity/tb-change-load-order
Change load order
This commit is contained in:
commit
68aa9c7481
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").
|
||||||
|
20
default.nix
Normal file
20
default.nix
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
let
|
||||||
|
stable = import (fetchTarball { # 19.09
|
||||||
|
url = https://github.com/NixOS/nixpkgs-channels/archive/a22b0189002.tar.gz;
|
||||||
|
sha256 = "0rgd0cbxg9mrzb830hgjlvy134ivpfcnkyhbnlvvn8vl4y20zqmz";
|
||||||
|
}) {};
|
||||||
|
in {
|
||||||
|
aeternityEnv = stable.stdenv.mkDerivation {
|
||||||
|
name = "ecrecover";
|
||||||
|
buildInputs = [
|
||||||
|
## base
|
||||||
|
stable.stdenv
|
||||||
|
## erlang
|
||||||
|
stable.erlangR21 # OTP 21.3.5.2
|
||||||
|
## rust, required for building the NIF
|
||||||
|
stable.rustc
|
||||||
|
stable.cargo
|
||||||
|
stable.cmake
|
||||||
|
];
|
||||||
|
};
|
||||||
|
}
|
@ -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,15 +41,21 @@ recover(<<_:32/binary>> = Hash, <<_:65/binary>> = Sig) ->
|
|||||||
%%=============================================================================
|
%%=============================================================================
|
||||||
%% Internal Functions
|
%% Internal Functions
|
||||||
|
|
||||||
priv()->
|
load_local_nif() ->
|
||||||
case code:priv_dir(ecrecoverprebuilt) of
|
EbinDir = filename:dirname(code:which(?MODULE)),
|
||||||
{error, _} ->
|
AppDir = filename:dirname(EbinDir),
|
||||||
EbinDir = filename:dirname(code:which(?MODULE)),
|
PrivDir = filename:join(AppDir, "priv"),
|
||||||
AppPath = filename:dirname(EbinDir),
|
SoName = filename:join(PrivDir, atom_to_list(?MODULE)),
|
||||||
filename:join(AppPath, "priv");
|
erlang:load_nif(SoName, 0).
|
||||||
Path ->
|
|
||||||
Path
|
load_prebuilt_nif() ->
|
||||||
end.
|
case code:priv_dir(ecrecoverprebuilt) of
|
||||||
|
{error, _} ->
|
||||||
|
{error, prebuilt_priv_dir_not_found};
|
||||||
|
PrivDir ->
|
||||||
|
SoName = filename:join(PrivDir, atom_to_list(?MODULE)),
|
||||||
|
erlang:load_nif(SoName, 0)
|
||||||
|
end.
|
||||||
|
|
||||||
recover_(_Input) ->
|
recover_(_Input) ->
|
||||||
not_loaded(?LINE).
|
not_loaded(?LINE).
|
||||||
|
Loading…
x
Reference in New Issue
Block a user