From b0b085a2afc8600469d252a3cb23f0b2d17f3a21 Mon Sep 17 00:00:00 2001 From: Graham McInitre Date: Thu, 16 Jul 2026 09:42:40 -0500 Subject: [PATCH] =?UTF-8?q?fix:=20skip=20NIF=20compilation=20in=20prod=20?= =?UTF-8?q?=E2=80=94=20NIF=20is=20pre-built=20by=20Nix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The prod build runs MIX_ENV=prod without make/gcc/net-snmp. The NIF is pre-built by the towerops-nif Nix package and injected via build.nix preBuild. Skip the mix compiler task in prod to avoid 'could not be found' CI errors. --- lib/mix/tasks/compile.towerops_nif.ex | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/lib/mix/tasks/compile.towerops_nif.ex b/lib/mix/tasks/compile.towerops_nif.ex index 32f852ea..bf1378ce 100644 --- a/lib/mix/tasks/compile.towerops_nif.ex +++ b/lib/mix/tasks/compile.towerops_nif.ex @@ -1,12 +1,28 @@ defmodule Mix.Tasks.Compile.ToweropsNif do @moduledoc """ Compiles the towerops_nif C NIF. + + In dev/test, runs `make -C c_src` to build `priv/towerops_nif.so`. + In prod, the NIF is pre-built by Nix and injected via build.nix preBuild, + so this task is a no-op. """ use Mix.Task.Compiler @impl true def run(_args) do + if skip_compilation?() do + {:ok, []} + else + do_compile() + end + end + + defp skip_compilation? do + Mix.env() == :prod or is_nil(System.find_executable("make")) + end + + defp do_compile do {result, _exit_code} = System.cmd("make", [], cd: "c_src", stderr_to_stdout: true, into: IO.stream()) case result do @@ -25,8 +41,12 @@ defmodule Mix.Tasks.Compile.ToweropsNif do @impl true def clean do - {_result, _exit_code} = System.cmd("make", ["clean"], cd: "c_src", stderr_to_stdout: true) - :ok + if skip_compilation?() do + :ok + else + {_result, _exit_code} = System.cmd("make", ["clean"], cd: "c_src", stderr_to_stdout: true) + :ok + end rescue _ -> :ok end