Skip to content

Commit

Permalink
Merge pull request #1 from zackehh/nif-compilation
Browse files Browse the repository at this point in the history
Attempt to fix an issue with NIF compilation
  • Loading branch information
whitfin committed May 19, 2016
2 parents b3cc0ec + e573a18 commit 40c0813
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@
/cover
/deps
/doc
/priv
erl_crash.dump
*.ez
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
language: elixir
elixir:
- 1.2.1
- 1.1.1
- 1.2.5
otp_release:
- 18.3
- 18.2
- 18.1
- 18.0
script:
- SIPHASH_IMPL=native mix test --trace
- SIPHASH_IMPL=embedded mix test --trace
after_success:
- SIPHASH_IMPL=embedded MIX_ENV=test mix coveralls.travis
- SIPHASH_IMPL=embedded mix coveralls.travis
branches:
only:
- master
15 changes: 11 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ERLANG_PATH = $(shell erl -eval 'io:format("~s", [lists:concat([code:root_dir(), "/erts-", erlang:system_info(version), "/include"])])' -s init stop -noshell)
CFLAGS = -g -O3 -ansi -pedantic -Wall -Wextra -I$(ERLANG_PATH)
MIX = mix

ifneq ($(OS),Windows_NT)
CFLAGS += -fPIC
Expand All @@ -9,9 +10,15 @@ ifneq ($(OS),Windows_NT)
endif
endif

_native: clean
mkdir -p _native
$(CC) -w $(CFLAGS) -shared $(LDFLAGS) -o $@/siphash.so c_src/siphash.c
all: siphash

siphash:
$(MIX) compile

priv/siphash.so: c_src/siphash.c
mkdir priv
$(CC) -w $(CFLAGS) -shared $(LDFLAGS) -o $@ c_src/siphash.c

clean:
$(RM) -r _native/*
$(MIX) clean
$(RM) priv/siphash.so
2 changes: 1 addition & 1 deletion coveralls.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"^\\s+use\\s+"
],
"custom_stop_words": [
"_native"
":erlang.load_nif"
],
"coverage_options": {
"treat_no_relevant_lines_as_covered": false
Expand Down
12 changes: 7 additions & 5 deletions lib/siphash/internals.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ defmodule SipHash.Internals do
alias SipHash.State, as: State
alias SipHash.Util, as: Util

# define native implementation
@native_impl [".", "_native", "siphash"] |> Path.join |> Path.expand

# setup init load
@on_load :init

Expand All @@ -21,8 +18,13 @@ defmodule SipHash.Internals do
# implementation, we don't have to exit on failure.
def init do
case System.get_env("SIPHASH_IMPL") do
"embedded" -> :ok;
_native -> :erlang.load_nif(@native_impl, 0)
"embedded" ->
:ok
_native ->
:siphash
|> :code.priv_dir
|> :filename.join('siphash')
|> :erlang.load_nif(0)
end
end

Expand Down
22 changes: 9 additions & 13 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ defmodule SipHash.Mixfile do
tool: ExCoveralls
],
preferred_cli_env: [
coveralls: :test
"coveralls": :test,
"coveralls.html": :test,
"coveralls.travis": :test
]
]
end
Expand All @@ -66,26 +68,20 @@ defmodule SipHash.Mixfile do
[
# documentation
{ :earmark, "~> 0.2.1", optional: true, only: :docs },
{ :ex_doc, "~> 0.11.3", optional: true, only: :docs },
{ :ex_doc, "~> 0.11.5", optional: true, only: :docs },
# testing
{ :benchfella, "~> 0.3.1", optional: true, only: :test },
{ :benchfella, "~> 0.3.2", optional: true, only: :test },
{ :benchwarmer, "~> 0.0.2", optional: true, only: :test },
{ :excoveralls, "~> 0.4.5", optional: true, only: :test },
{ :excoveralls, "~> 0.5.4", optional: true, only: :test },
{ :exprof, "~> 0.2.0", optional: true, only: :test }
]
end
end

# Custom clean for C source
defmodule Mix.Tasks.Clean.Make do
def run(_) do
{ _result, 0 } = System.cmd("make", ["clean"], stderr_to_stdout: true)
end
end

# Custom compile for C source
defmodule Mix.Tasks.Compile.Make do
def run(_) do
{ _result, 0 } = System.cmd("make", [], stderr_to_stdout: true)
{ _result, 0 } = System.cmd("make", ["priv/siphash.so"], stderr_to_stdout: true)
Mix.Project.build_structure()
:ok
end
end
28 changes: 15 additions & 13 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
%{"benchfella": {:hex, :benchfella, "0.3.1"},
"benchwarmer": {:hex, :benchwarmer, "0.0.2"},
"certifi": {:hex, :certifi, "0.3.0"},
"earmark": {:hex, :earmark, "0.2.1"},
"ex_doc": {:hex, :ex_doc, "0.11.3"},
"excoveralls": {:hex, :excoveralls, "0.4.5"},
"exjsx": {:hex, :exjsx, "3.2.0"},
"exprintf": {:hex, :exprintf, "0.1.6"},
"exprof": {:hex, :exprof, "0.2.0"},
"hackney": {:hex, :hackney, "1.4.8"},
"idna": {:hex, :idna, "1.0.3"},
"jsx": {:hex, :jsx, "2.6.2"},
"mimerl": {:hex, :mimerl, "1.0.2"},
%{"benchfella": {:hex, :benchfella, "0.3.2", "b9648e77fa8d8b8b9fe8f54293bee63f7de03909b3af6ab22a0e546716a396fb", [:mix], []},
"benchwarmer": {:hex, :benchwarmer, "0.0.2", "902e5c020608647b07c38b82103e4af6d2667dfd5d5d13c67382238de6943136", [:mix], []},
"certifi": {:hex, :certifi, "0.4.0", "a7966efb868b179023618d29a407548f70c52466bf1849b9e8ebd0e34b7ea11f", [:rebar3], []},
"earmark": {:hex, :earmark, "0.2.1", "ba6d26ceb16106d069b289df66751734802777a3cbb6787026dd800ffeb850f3", [:mix], []},
"ex_doc": {:hex, :ex_doc, "0.11.5", "0dc51cb84f8312162a2313d6c71573a9afa332333d8a332bb12540861b9834db", [:mix], [{:earmark, "~> 0.1.17 or ~> 0.2", [hex: :earmark, optional: true]}]},
"excoveralls": {:hex, :excoveralls, "0.5.4", "1a6e116bcf980da8b7fe33140c1d7e61aa0a4e51951cadbfacc420c12d2b9b8f", [:mix], [{:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}, {:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.0", "7136cc739ace295fc74c378f33699e5145bead4fdc1b4799822d0287489136fb", [:mix], [{:jsx, "~> 2.6.2", [hex: :jsx, optional: false]}]},
"exprintf": {:hex, :exprintf, "0.1.6", "b5b0a38bf78a357dbc61cdf7364fea004af6fdf5214be44021eb2ea7edf61f6e", [:mix], []},
"exprof": {:hex, :exprof, "0.2.0", "b03f50d0d33e2f18c8e047d9188ba765dc32daba0b553ed717a98a78561d5eaf", [:mix], [{:exprintf, "~> 0.1", [hex: :exprintf, optional: false]}]},
"hackney": {:hex, :hackney, "1.6.0", "8d1e9440c9edf23bf5e5e2fe0c71de03eb265103b72901337394c840eec679ac", [:rebar3], [{:ssl_verify_fun, "1.1.0", [hex: :ssl_verify_fun, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:certifi, "0.4.0", [hex: :certifi, optional: false]}]},
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []},
"jsx": {:hex, :jsx, "2.6.2", "213721e058da0587a4bce3cc8a00ff6684ced229c8f9223245c6ff2c88fbaa5a", [:mix, :rebar], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:rebar, :make], []},
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5"}}

0 comments on commit 40c0813

Please sign in to comment.