Skip to content

Commit

Permalink
Ensure not to call Mix.target in runtime (#119)
Browse files Browse the repository at this point in the history
* Ensure not to call Mix.target in runtime

* remove invalid target check

* bump version to 1.4.3
  • Loading branch information
mat-hek authored Jan 2, 2024
1 parent 3541af8 commit 7474285
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
1 change: 1 addition & 0 deletions lib/bundlex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ defmodule Bundlex do
"""
@type target ::
%{architecture: String.t(), vendor: String.t(), os: String.t(), abi: String.t() | nil}

@doc """
A function returning a target triplet for the environment on which it is run.
"""
Expand Down
4 changes: 1 addition & 3 deletions lib/bundlex/loader.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ defmodule Bundlex.Loader do
@moduledoc false
require unquote(__MODULE__)

if unquote(Mix.target() == :host) do
@on_load :load_nif
end
@on_load :load_nif

@spec load_nif() :: :ok | no_return()
def load_nif() do
Expand Down
19 changes: 8 additions & 11 deletions lib/bundlex/platform.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,14 @@ defmodule Bundlex.Platform do
Otherwise raises Mix error.
"""
@spec get_target!() :: name_t
def get_target!() do
case {Mix.target(), System.fetch_env("NERVES_APP")} do
{:host, _app} ->
get_host!()

{_target, {:ok, _app}} ->
:nerves

{_target, :error} ->
IO.warn("Crosscompilation supported only for Nerves systems, assuming host's platform")
get_host!()
if Mix.target() == :host do
def get_target!(), do: get_host!()
else
def get_target!() do
case System.fetch_env("NERVES_APP") do
{:ok, _app} -> :nerves
:error -> get_host!()
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Bundlex.Mixfile do
use Mix.Project

@version "1.4.2"
@version "1.4.3"
@github_url "https://github.com/membraneframework/bundlex"

def project do
Expand Down

0 comments on commit 7474285

Please sign in to comment.