local M = {} function M.build(opts, pristine) local a = { "build", "-d", opts.build_dir, vim.fn.getcwd(), "--board", opts.board } if opts.sysbuild then table.insert(a, "--sysbuild") end if pristine then table.insert(a, "--pristine") end table.insert(a, "--") table.insert(a, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON") if opts.conf_file then table.insert(a, "-DCONF_FILE=" .. opts.conf_file) end if #opts.overlays > 0 then table.insert(a, "-DDTC_OVERLAY_FILE=" .. table.concat(opts.overlays, ";")) end for _, e in ipairs(opts.extra_cmake or {}) do table.insert(a, e) end local exec = require("hego.exec") local cmd = exec.ncs(opts, vim.list_extend({ "west" }, a)) return exec.run_async(cmd, { title = "hego://build", on_exit = function(obj) if obj.code == 0 then require("hego.lsp").link(opts) end end, }) end return M