Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- defmodule RustCompile do
- @rust_path "D:/var/Rust/hello"
- @rust_target "D:/var/Rust/hello/bin"
- def get_files(path_name) do
- with {:ok, files} <- File.ls(path_name) do
- files
- else
- {:error, reason} ->
- reason
- end
- end
- def run do
- error_file = Path.expand(".") <> "/list_error_compile.txt"
- if File.exists?(error_file) do
- File.rm(error_file)
- end
- files =
- Enum.filter(get_files(@rust_path), fn x ->
- fullpath = Path.join([@rust_path, x])
- !File.dir?(fullpath)
- end)
- Enum.each(files, fn file ->
- if Path.extname(file) == ".rs" do
- IO.puts("Compiling '#{file}'..")
- t = Task.async(fn -> compile_rust(@rust_path <> "/" <> file, @rust_target) end)
- Task.await(t)
- end
- end)
- delete_debug_files(@rust_target)
- end
- def compile_rust(file_name, target) do
- {result, exit_code} = System.cmd("rustc", ["-v", "-O", "--out-dir=" <> target, file_name], stderr_to_stdout: true)
- if exit_code > 0 do
- {:ok, file} = File.open(Path.expand(".") <> "/list_error_compile.txt", [:append])
- IO.binwrite(file, file_name <> "\n")
- IO.binwrite(file, result <> "\n--------------------------------------------------\n")
- File.close(file)
- end
- end
- def delete_debug_files(path) do
- files = Enum.filter(get_files(path), fn x ->
- fullpath = Path.join([@rust_target, x])
- !File.dir?(fullpath)
- end)
- Enum.each(files, fn file ->
- if Path.extname(file) == ".pdb" do
- IO.puts("Menghapus '#{file}'..")
- File.rm!(@rust_target <> "/" <> file)
- end
- end)
- end
- end
- RustCompile.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement