feat(crates): prebuilt binaries (#473)

* feat(crates): prebuilt binaries

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

* chore: update name

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

* chore: build on PR

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

* chore: only build for lua51 and luajit

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

* feat: build stuff

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

* chore: only build if changes in Rust

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

* fix: remove deadcode

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>

---------

Signed-off-by: Aaron Pham <contact@aarnphm.xyz>
This commit is contained in:
Aaron Pham
2024-09-03 06:20:53 -04:00
committed by GitHub
parent 9765eaca21
commit a5726bd2bf
8 changed files with 223 additions and 62 deletions

View File

@@ -10,7 +10,7 @@ local Utils = require("avante.utils")
---@field ask fun(question:string?): boolean
---@field edit fun(question:string?): nil
---@field refresh fun(): nil
---@field build fun(): boolean
---@field build fun(opts: {source: boolean}): boolean
---@field switch_provider fun(target: string): nil
---@field toggle avante.ApiToggle
---@field get_suggestion fun(): avante.Suggestion | nil
@@ -20,6 +20,57 @@ local M = {}
---@param target Provider
M.switch_provider = function(target) require("avante.providers").refresh(target) end
---@param path string
local function to_windows_path(path)
local winpath = path:gsub("/", "\\")
if winpath:match("^%a:") then winpath = winpath:sub(1, 2):upper() .. winpath:sub(3) end
winpath = winpath:gsub("\\$", "")
return winpath
end
---@param opts {source: boolean}
M.build = function(opts)
local dirname = Utils.trim(string.sub(debug.getinfo(1).source, 2, #"/init.lua" * -1), { suffix = "/" })
local git_root = vim.fs.find(".git", { path = dirname, upward = true })[1]
local build_directory = git_root and vim.fn.fnamemodify(git_root, ":h") or (dirname .. "/../../")
if opts.source and not vim.fn.executable("cargo") then
error("Building avante.nvim requires cargo to be installed.", 2)
end
---@type string[]
local cmd
local os_name = Utils.get_os_name()
if vim.tbl_contains({ "linux", "darwin" }, os_name) then
cmd = {
"sh",
"-c",
string.format("make BUILD_FROM_SOURCE=%s -C %s", opts.source == true and "true" or "false", build_directory),
}
elseif os_name == "windows" then
build_directory = to_windows_path(build_directory)
cmd = {
"powershell",
"-ExecutionPolicy",
"Bypass",
"-File",
string.format("%s\\Build.ps1", build_directory),
"-WorkingDirectory",
build_directory,
}
else
error("Unsupported operating system: " .. os_name, 2)
end
local job = vim.system(cmd, { text = true }):wait()
return vim.tbl_contains({ 0 }, job.code) and true or false
end
---@param question? string
M.ask = function(question)
if not require("avante").toggle() then return false end