Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for :natives key in bundlex #44

Merged
merged 7 commits into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions bundlex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 19 additions & 6 deletions lib/unifex/code_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion test_projects/cnode/bundlex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
]
Expand Down
2 changes: 1 addition & 1 deletion test_projects/nif/bundlex.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
]
Expand Down