-
Notifications
You must be signed in to change notification settings - Fork 0
/
mix.exs
96 lines (85 loc) · 2.45 KB
/
mix.exs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
defmodule Mix.Tasks.Compile.TimSort do
def run(_) do
File.mkdir_p("priv/cpp-TimSort")
{result, _errcode} =
System.cmd(
"echo",
[
"************^^^^^^^^^^^^^^^^************\nCompiling NIFs with src/timsort.cpp\n************^^^^^^^^^^^^^^^^************"
],
stderr_to_stdout: true
)
IO.binwrite(result)
{result, _errcode} =
System.cmd(
"g++",
[
"--std=c++11",
"-O3",
"-fpic",
"-shared",
"-opriv/timsort.so",
# Include ERTS so we can find erl_nif.h at compile time.
# This will be unique to your system.
"-I$HOME/erlang/22.0/erts-10.4/include",
# Include the incatation `-dynamiclib -undefined dynamic_lookup` to the compiler,
# otherwise the the compilation works, but with an error about not being able to
# find the compiled erl_nif functions
"-dynamiclib",
"-undefined",
"dynamic_lookup",
"src/timsort.cpp"
],
stderr_to_stdout: true
)
# g++ --std=c++11 -O3 -fpic -shared -opriv/timsort.so -I/Users/christiankoch/erlang/22.0/erts-10.4/include src/timsort.cpp
IO.binwrite(result)
:ok
end
end
defmodule TimsortCppEx.MixProject do
use Mix.Project
def project do
[
app: :timsort_cpp_ex,
aliases: aliases(),
version: "0.1.0",
elixir: "~> 1.9",
start_permanent: Mix.env() == :prod,
compilers: [:tim_sort] ++ Mix.compilers(),
preferred_cli_env: [test_all: :test],
deps: deps()
]
end
# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
end
# Run "mix help deps" to learn about dependencies.
defp deps do
[{:stream_data, "~> 0.4"}]
end
defp aliases do
[
test_c: [
"cmd echo '*^*~_~*^*~_~*^*~_~*^*~_~*^*~_~*^*~_~*^*~_~*^'",
"cmd echo ",
"cmd echo 'Run TimSort C++ tests:'",
"cmd echo ",
"cmd echo '********************************************'",
"cmd cd priv/cpp-TimSort/build && CTest"
],
test_ex: [
"cmd echo '*^*~_~*^*~_~*^*~_~*^*~_~*^*~_~*^*~_~*^*~_~*^'",
"cmd echo ",
"cmd echo 'Run TimSortCppEx elixir tests:'",
"cmd echo ",
"cmd echo '********************************************'",
"test"
],
test_all: ["test_c", "test_ex"]
]
end
end