           raise "calling `cargo metadata` failed.\n" <> output
       end
 
-    json = Jason.decode!(metadata)
+    Jason.decode!(metadata)
+  end
 
-    packages = json["packages"]
-
+  defp external_resources(crate_path, crate, metadata) do
+    crate_str = to_string(crate)
+    packages = Map.fetch!(metadata, "packages")
     crate_spec = get_spec(packages, crate_str)
 
     packages

  end

  defp build(opts) do
    crate = Keyword.fetch!(opts, :crate)

    resources =
      if opts[:skip_compilation?] do
        []
      else
        opts
        |> Keyword.get(:path)
        |> external_resources(crate)
      end

    opts = Keyword.put(opts, :external_resources, resources)

    struct!(Config, opts)
  end

  defp external_resources(crate_path, crate) do
    crate_str = to_string(crate)

    metadata =
      case System.cmd("cargo", ~w(metadata --format-version=1), cd: crate_path) do
        {metadata, 0} ->

            priv_dir: "",
            skip_compilation?: false,
            target: nil,
            target_dir: "",
            metadata: nil

  alias Rustler.Compiler.Config

