diff --git a/bundlex.exs b/bundlex.exs index 172fd5be..d84c23ea 100644 --- a/bundlex.exs +++ b/bundlex.exs @@ -9,14 +9,16 @@ defmodule Unifex.BundlexProject do defp libs do [ - unifex_nif: [ + unifex: [ deps: [shmex: :lib_nif], src_base: "unifex/nif/unifex", - sources: ["unifex.c", "payload.c"] + sources: ["unifex.c", "payload.c"], + interface: :nif ], - unifex_cnode: [ + unifex: [ src_base: "unifex/cnode/unifex", - sources: ["unifex.c", "cnode.c", "payload.c"] + sources: ["unifex.c", "cnode.c", "payload.c"], + interface: :cnode ] ] end diff --git a/lib/unifex/code_generator.ex b/lib/unifex/code_generator.ex index 9682ad16..4a0441d0 100644 --- a/lib/unifex/code_generator.ex +++ b/lib/unifex/code_generator.ex @@ -22,16 +22,29 @@ defmodule Unifex.CodeGenerator do defp get_generator(%Specs{name: name, interface: nil}) do {:ok, bundlex_project} = Bundlex.Project.get() + config = bundlex_project.config - [:nifs, :cnodes] - |> Enum.find(&(bundlex_project.config |> Keyword.get(&1, []) |> Keyword.has_key?(name))) - |> case do - :nifs -> Unifex.CodeGenerators.NIF - :cnodes -> Unifex.CodeGenerators.CNode + interfaces = [:natives, :libs] |> Enum.find_value(&get_in(config, [&1, name, :interface])) + + case interfaces do + [] -> raise "Interface for native #{name} is not specified. + Please specify it in your *.spec.exs or bundlex.exs file." + _ -> get_generator_module_name(List.first(interfaces)) end end defp get_generator(%Specs{interface: interface}) do - Module.concat(Unifex.CodeGenerators, interface) + get_generator_module_name(interface) + end + + defp get_generator_module_name(interface) do + module_name = + case interface do + :nif -> :NIF + :cnode -> :CNode + other -> other + end + + Module.concat(Unifex.CodeGenerators, module_name) end end diff --git a/mix.exs b/mix.exs index 4c6f9dfe..0fe905af 100644 --- a/mix.exs +++ b/mix.exs @@ -60,7 +60,8 @@ defmodule Unifex.MixProject do {:ex_doc, "~> 0.19", only: :dev, runtime: false}, {:bunch, "~> 1.0"}, {:shmex, "~> 0.2.0"}, - {:bundlex, "~> 0.2.0"}, + {:bundlex, + git: "https://github.com/membraneframework/bundlex.git", branch: "master", override: true}, {:dialyxir, "~> 1.0.0-rc.7", only: [:dev], runtime: false} ] end diff --git a/mix.lock b/mix.lock index 242693bc..b7fe5da6 100644 --- a/mix.lock +++ b/mix.lock @@ -8,13 +8,8 @@ [{:bundlex, "~> 0.2.7", [hex: :bundlex, repo: "hexpm", optional: false]}], "hexpm", "f0819b2f9f78086447ac7459a8e7b6e25ad535b9d3a4f9469253c552137de6b4"}, bundlex: - {:hex, :bundlex, "0.2.8", "0f4530bf24a2ebb92f2e360111319aae6fc6eb03c6ec5054b529d9ffb78811fa", - [:mix], - [ - {:bunch, "~> 1.0", [hex: :bunch, repo: "hexpm", optional: false]}, - {:qex, "~> 0.5", [hex: :qex, repo: "hexpm", optional: false]}, - {:secure_random, "~> 0.5", [hex: :secure_random, repo: "hexpm", optional: false]} - ], "hexpm", "d583b04ea679297aa08ad2b31866c4848fd99feea036bf5af59df71e2408b096"}, + {:git, "https://github.com/membraneframework/bundlex.git", + "0c0e94394b8564f6ffa4f5c5355a0fcaff8f4a68", [branch: "master"]}, dialyxir: {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", diff --git a/test_projects/cnode/bundlex.exs b/test_projects/cnode/bundlex.exs index 4a2feac3..0b475c37 100644 --- a/test_projects/cnode/bundlex.exs +++ b/test_projects/cnode/bundlex.exs @@ -10,7 +10,7 @@ defmodule Example.BundlexProject do def cnodes(_platform) do [ example: [ - deps: [unifex: :unifex_cnode], + deps: [unifex: :unifex], src_base: "example", sources: ["_generated/example.c", "example.c"] ] diff --git a/test_projects/nif/bundlex.exs b/test_projects/nif/bundlex.exs index f3a54385..51d963e0 100644 --- a/test_projects/nif/bundlex.exs +++ b/test_projects/nif/bundlex.exs @@ -10,7 +10,7 @@ defmodule Example.BundlexProject do def nifs(_platform) do [ example: [ - deps: [unifex: :unifex_nif], + deps: [unifex: :unifex], src_base: "example", sources: ["_generated/example.c", "example.c"] ]