-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.lua
More file actions
114 lines (93 loc) · 2.58 KB
/
build.lua
File metadata and controls
114 lines (93 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
local function notify(msg, level)
-- print("notified: ", msg)
coroutine.yield({
msg = msg,
level = level or vim.log.levels.INFO,
})
end
local to_notify = {}
local function notify_add(msg, level)
table.insert(to_notify, { msg = msg, level = level or vim.log.levels.INFO })
end
local function notify_all()
local tab
to_notify, tab = {}, to_notify
for _, msg in pairs(tab) do
-- print("notifiying all: msg = ", msg.msg)
notify(msg.msg, msg.level)
end
-- print("notified all")
end
local function lib_names()
local os_name = vim.uv.os_uname().sysname
if os_name == "Linux" then
return "libbight.so", "bight.so"
elseif os_name == "Darwin" then
return "libbight.dylib", "bight.so"
elseif os_name:match("Windows") then
return "bight.dll", "bight.dll"
else
notify("Unsupported OS: " ..
os_name .. ". If you want to add support, open a PR at https://github.com/WASDetchan/bight.nvim",
vim.log.levels.ERROR)
end
end
local function build()
local root = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h")
local src_name, dst_name = lib_names()
if not src_name then return end
notify("Building (cargo build --release --locked)…")
local uv = vim.uv
local stderr = uv.new_pipe()
local return_code = nil
local handle, _ = uv.spawn(
"cargo",
{
cwd = root,
args = { "build", "--release", "--locked" },
stdio = { nil, nil, stderr }
},
function(code, _)
-- notify_add("Finished building with code " .. code)
return_code = code
end
)
if not stderr or not handle then
notify("Failed to spawn build process!", vim.log.levels.ERROR)
return
end
stderr:read_start(function(_, chunk)
-- print("got chunk of stderr: ", chunk)
if chunk then
notify_add(chunk)
end
end)
while not return_code do
if (#to_notify > 0) then
notify_all()
-- print("notified all")
end
-- vim.wait(100)
coroutine.yield()
end
notify_all()
if return_code ~= 0 then
notify("Build failed with exit code " .. return_code, vim.log.levels.ERROR)
return
else
notify("Built " .. dst_name)
end
local src = root .. "/target/release/" .. src_name
local dst_dir = root .. "/lua"
local dst = dst_dir .. "/" .. dst_name
if vim.fn.filereadable(src) == 0 then
notify("Build succeeded but output not found: " .. src, vim.log.levels.ERROR)
return
end
-- print("dst_dir: ", dst_dir)
vim.fn.mkdir(dst_dir, "p")
vim.fn.delete(dst)
vim.fn.writefile(vim.fn.readfile(src, "b"), dst, "b")
notify("Installed " .. dst_name)
end
build()