File tree Expand file tree Collapse file tree 3 files changed +63
-60
lines changed
Expand file tree Collapse file tree 3 files changed +63
-60
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,14 @@ defmodule Ortex.Native do
44
55 Stubs for `Rustler` NIFs. These should never be called directly.
66 """
7+
8+ # We have to compile the crate before `use Rustler` compiles the crate since
9+ # cargo downloads the onnxruntime shared libraries and they are not available
10+ # to load or copy into Elixir's during the on_load or Elixir compile steps.
11+ # In the future, this may be configurable in Rustler.
12+ Rustler.Compiler . compile_crate ( __MODULE__ , otp_app: :ortex , crate: :ortex )
13+ Ortex.Util . copy_ort_libs ( )
14+
715 use Rustler ,
816 otp_app: :ortex ,
917 crate: :ortex
Original file line number Diff line number Diff line change 1+ defmodule Ortex.Util do
2+ def copy_ort_libs ( ) do
3+ rust_env =
4+ case Mix . env ( ) do
5+ :prod -> "release"
6+ _ -> "debug"
7+ end
8+
9+ case :os . type ( ) do
10+ { :win32 , _ } ->
11+ Path . wildcard (
12+ Path . join ( [
13+ "./_build" ,
14+ Mix . env ( ) |> Atom . to_string ( ) ,
15+ "lib/ortex/native/ortex" ,
16+ rust_env ,
17+ "libonnxruntime*.dll*"
18+ ] )
19+ )
20+
21+ { :unix , :darwin } ->
22+ Path . wildcard (
23+ Path . join ( [
24+ "./_build/" ,
25+ Mix . env ( ) |> Atom . to_string ( ) ,
26+ "lib/ortex/native/ortex" ,
27+ rust_env ,
28+ "libonnxruntime*.dylib*"
29+ ] )
30+ )
31+
32+ { :unix , _ } ->
33+ Path . wildcard (
34+ Path . join ( [
35+ "./_build/" ,
36+ Mix . env ( ) |> Atom . to_string ( ) ,
37+ "lib/ortex/native/ortex" ,
38+ rust_env ,
39+ "libonnxruntime*.so*"
40+ ] )
41+ )
42+ end
43+ |> Enum . map ( fn x ->
44+ File . cp! (
45+ x ,
46+ Path . join ( [
47+ "./_build" ,
48+ Mix . env ( ) |> Atom . to_string ( ) ,
49+ "lib/ortex/priv/native/" ,
50+ Path . basename ( x )
51+ ] )
52+ )
53+ end )
54+ end
55+ end
Original file line number Diff line number Diff line change @@ -8,10 +8,6 @@ defmodule Ortex.MixProject do
88 elixir: "~> 1.14" ,
99 start_permanent: Mix . env ( ) == :prod ,
1010 deps: deps ( ) ,
11- compilers: [ :copy_ort_libs ] ++ Mix . compilers ( ) ,
12- aliases: [
13- "compile.copy_ort_libs": & copy_ort_libs / 1
14- ] ,
1511
1612 # Docs
1713 name: "Ortex" ,
@@ -54,60 +50,4 @@ defmodule Ortex.MixProject do
5450 description: "ONNX Runtime bindings for Elixir"
5551 ]
5652 end
57-
58- defp copy_ort_libs ( _ ) do
59- rust_env =
60- case Mix . env ( ) do
61- :prod -> "release"
62- _ -> "debug"
63- end
64-
65- case :os . type ( ) do
66- { :win32 , _ } ->
67- Path . wildcard (
68- Path . join ( [
69- "./_build" ,
70- Mix . env ( ) |> Atom . to_string ( ) ,
71- "lib/ortex/native/ortex" ,
72- rust_env ,
73- "libonnxruntime*.dll*"
74- ] )
75- )
76-
77- { :unix , :darwin } ->
78- Path . wildcard (
79- Path . join ( [
80- "./_build/" ,
81- Mix . env ( ) |> Atom . to_string ( ) ,
82- "lib/ortex/native/ortex" ,
83- rust_env ,
84- "libonnxruntime*.dylib*"
85- ] )
86- )
87-
88- { :unix , _ } ->
89- Path . wildcard (
90- Path . join ( [
91- "./_build/" ,
92- Mix . env ( ) |> Atom . to_string ( ) ,
93- "lib/ortex/native/ortex" ,
94- rust_env ,
95- "libonnxruntime*.so*"
96- ] )
97- )
98- end
99- |> Enum . map ( fn x ->
100- File . cp! (
101- x ,
102- Path . join ( [
103- "./_build" ,
104- Mix . env ( ) |> Atom . to_string ( ) ,
105- "lib/ortex/priv/native/" ,
106- Path . basename ( x )
107- ] )
108- )
109- end )
110-
111- { :ok , [ ] }
112- end
11353end
You can’t perform that action at this time.
0 commit comments