@@ -17,21 +17,39 @@ defmodule Rustler.Compiler do
1717 is_release = Mix . env ( ) in [ :prod , :bench ]
1818 entry = artifacts [ crate ]
1919
20- # Only a single file result per crate is supported right now
21- [ filename ] = entry [ :filenames ]
22- rel_filename = Path . basename ( filename )
20+ is_lib = :cargo_artifact . kind ( entry ) == :cdylib
21+ is_bin = :cargo_artifact . kind ( entry ) == :bin
2322
24- out_path = Path . join ( priv_dir ( entry , is_release ) , Path . basename ( filename ) )
25- dest = Path . join ( :code . priv_dir ( config . otp_app ) , out_path )
26- rel_dest = Path . relative_to_cwd ( dest )
23+ if ! is_lib and ! is_bin do
24+ Mix . raise ( "Crate #{ crate } is neither a 'bin' nor a 'cdylib' but #{ entry [ :kind ] } " )
25+ end
2726
28- shell . info ( " Copying #{ rel_filename } to #{ rel_dest } " )
29- File . mkdir_p! ( Path . dirname ( dest ) )
30- File . copy! ( filename , dest )
27+ priv_dir = priv_dir ( entry , is_release )
28+ dest_root = :code . priv_dir ( config . otp_app )
3129
32- is_lib = entry [ :kind ] == [ "cdylib" ]
30+ out_paths =
31+ for filename <- :cargo_artifact . filenames ( entry ) do
32+ out_path = Path . join ( priv_dir , Path . basename ( filename ) )
33+ dest = Path . join ( dest_root , out_path )
34+ rel_filename = Path . basename ( filename )
35+ rel_dest = Path . relative_to_cwd ( dest )
3336
34- % Config { config | lib: is_lib , load_path: Path . rootname ( out_path ) }
37+ shell . info ( " Copying #{ rel_filename } to #{ rel_dest } " )
38+ File . mkdir_p! ( Path . dirname ( dest ) )
39+ File . copy! ( filename , dest )
40+
41+ out_path
42+ end
43+
44+ [ load_path ] =
45+ if is_lib do
46+ out_paths |> Enum . filter ( & :cargo_util . is_dylib / 1 )
47+ else
48+ exec = :cargo_artifact . executable ( entry )
49+ [ Path . join ( priv_dir , Path . basename ( exec ) ) ]
50+ end
51+
52+ % Config { config | lib: is_lib , load_path: Path . rootname ( load_path ) }
3553 end
3654
3755 defp priv_dir ( entry , is_release ) do
@@ -42,7 +60,10 @@ defmodule Rustler.Compiler do
4260 "debug"
4361 end
4462
45- "crates/#{ entry [ :name ] } /#{ entry [ :version ] } /#{ type } "
63+ name = :cargo_artifact . name ( entry )
64+ version = :cargo_artifact . version ( entry )
65+
66+ "crates/#{ name } /#{ version } /#{ type } "
4667 end
4768
4869 defp ensure_string ( atom ) when is_atom ( atom ) do
0 commit comments