Skip to content

Conversation

@cocoa-xu
Copy link
Contributor

@cocoa-xu cocoa-xu commented Dec 10, 2022

Adding support for specifying how to recover from unavailable targets using the make_precompiler_unavailable_target config key (probably needs a shorter name for this). Allowed values are :compile and :ignore. Defaults to :compile.

It is also possible to pass in a 2-arity function to make_precompiler_unavailable_target: the first argument is the triplet of the unavailable target, and the second argument is a list that contains all available targets provided by the precompiler.

One use case is the dll_loader_helper, which only needs to be compiled on windows and ignores the compilation process for all other targets.

For instance (cocoa-xu/dll_loader_helper #8):

  def project do
    [
      ...,
      make_precompiler_unavailable_target: &unavailable_target/2,
      cc_precompiler: [
        only_listed_compilers: true,
        compilers: %{
          {:win32, :nt} => %{
            "x86_64-windows-msvc" => {"cl", "cl"}
          }
        }
      ]
    ]
  end

  defp unavailable_target("x86_64-windows-msvc", _), do: :compile
  defp unavailable_target(_, _), do: :ignore

make_precompiler_filename: "nif",
make_precompiler_priv_paths: ["nif.*"]
make_precompiler_priv_paths: ["nif.*"],
make_precompiler_unavailable_target: :compile,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we make it a callback in the Precompiler that returns either :compile or :ignore. If no callback is specified, we use :compile?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree! I'll update the code soon. :)

@josevalim josevalim merged commit f9443b8 into elixir-lang:master Dec 11, 2022
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@josevalim
Copy link
Member

@cocoa-xu please let me know if it works in DLL helpers and, if it does, I will ship a new version!

@cocoa-xu
Copy link
Contributor Author

cocoa-xu commented Dec 11, 2022

Thanks @josevalim! I tested it with the dll_loader_helper on an x86_64 Windows machine, and it works as expected. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants