** (File.CopyError) could not copy from nil to "path_here": no such file or directory

I’m using burrito to create binaries, I need to copy nif from during pre patch phase, I’m getting the error.

** (File.CopyError) could not copy from nil to "/var/folders/6h/48xg2xzn50vb36qwpk_jqn9m0000gn/T/burrito_build_FF0728F3E343FB83/lib/svg_tracing/priv/native/libsvgtracing_tracer.so": no such file or directory
    (elixir 1.13.0) lib/file.ex:711: File.copy!/3
    (svg_tracing 0.1.4) lib/copy_nif.ex:18: SvgTracing.CopyNIF.execute/1
    (burrito 0.8.0) lib/builder/builder.ex:139: anonymous fn/3 in Burrito.Builder.run_phase/2
    (elixir 1.13.0) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
    (elixir 1.13.0) lib/enum.ex:937: Enum."-each/2-lists^foreach/1-0-"/2
    (burrito 0.8.0) lib/builder/builder.ex:88: Burrito.Builder.build/1
    (mix 1.13.0) lib/mix/tasks/release.ex:1048: Mix.Tasks.Release.run_steps/1
    (mix 1.13.0) lib/mix/task.ex:397: anonymous fn/3 in Mix.Task.run_task/3

Here is the nif path.
_build/prod/lib/svg_tracing/priv/native/libsvgtracing_tracer.so

and here is my mix.exs

  def releases do
    [
      svg_tracing: [
        steps: [:assemble, &Burrito.wrap/1],
        burrito: [
          targets: [
            macos_m1: [os: :darwin, cpu: :aarch64],
          ],
          extra_steps: [
            patch: [
              pre: [SvgTracing.CopyNIF],
            ]
          ]
        ]
      ]
    ]
  end

here is my copynif module.


defmodule SvgTracing.CopyNIF do
  alias Burrito.Builder.Step
  @behaviour Step

  @impl Step
  def execute(%Burrito.Builder.Context{} = context) do
    IO.inspect context, label: "context here"
    dir =
      Path.join(context.work_dir, [
        "lib",
        "/svg_tracing",
        "/priv",
        "/native"
      ])
    File.mkdir_p!(dir)
    case context.target.alias do
      :macos_m1 ->
        File.copy!(
          System.get_env("NIF_AARCH64_DARWIN"),
          Path.join(dir, "libsvgtracing_tracer.so")
        )
      alias ->
        raise "unknown target alias #{inspect(alias)}"
    end

    context
  end
end

File.copy! is failing because it’s getting nil as the first argument; where is this environment variable being set?

2 Likes

It’s nil, for now, and it is going on second option.

dir =
      Path.join(context.work_dir, [
        "lib",
        "/svg_tracing",
        "/priv",
        "/native"
      ])

Your answer is not shedding light. As @al2o3cr points out, your source file is nil – so make sure the env var is there. Put an IO.inspect before the File.copy! function call and check if indeed both values are what you expect.

1 Like