Repository navigation
Expand file tree
/
Copy path.make.lua
More file actions
95 lines (79 loc) · 3.21 KB
/
Copy path.make.lua
File metadata and controls
95 lines (79 loc) · 3.21 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
-- ondrive's build, as recipes. This replaced the Makefile; there is no other.
--
-- make the recipes, with what each of them says it does
-- make build the library
-- make test the suite
--
-- At an oslo prompt in this directory `make` is enough; everywhere else it is `oslo make`.
-- The dev shell's toolchain comes from `.env.lua`'s `nix_develop()`, so recipes call `cargo`
-- directly rather than wrapping every command in `nix develop -c`.
local make = oslo.make
local function need(tool, why)
assert(oslo.run{ "sh", "-c", "command -v " .. tool, capture = true }.ok, why)
end
-- name = ... from Cargo.toml — the one place every tool reads it from.
local function project_name()
local content = oslo.fs.read("Cargo.toml") or ""
local name = content:match('\nname%s*=%s*"([^"]+)"') or content:match('^name%s*=%s*"([^"]+)"')
assert(name, "Cargo.toml package name not found or invalid")
return name
end
local NAME = project_name()
make.recipe{ name = "build", desc = "the library",
run = function() sh.cargo("build", "--lib") end }
make.alias("b", "build")
make.recipe{ name = "compile", desc = "clean, then build", deps = { "clean", "build" } }
make.alias("c", "compile")
make.recipe{
name = "run",
desc = "run a development example (if examples exist)",
params = { { "--example", desc = "which example to run", default = "main" } },
run = function(a) sh.cargo("run", "--example", a.example or "main") end,
}
make.alias("r", "run")
make.recipe{ name = "test", desc = "run all tests",
run = function() sh.cargo("test", "--all-targets") end }
make.alias("t", "test")
make.recipe{ name = "check", desc = "cargo check on all targets",
run = function() sh.cargo("check", "--all-targets") end }
make.recipe{ name = "fmt", desc = "format the workspace",
run = function() sh.cargo("fmt", "--all") end }
make.recipe{ name = "clean", desc = "remove Cargo build artifacts",
run = function() sh.cargo("clean") end }
make.recipe{ name = "bind", desc = "generate both C and Python bindings",
deps = { "bind-c", "bind-py" } }
make.recipe{
name = "bind-c",
desc = "generate the C header",
run = function()
sh.cargo("build", "--lib")
sh.cbindgen("--config", "cbindgen.toml", "--crate", NAME, "--output", "include/" .. NAME .. ".h")
end,
}
make.recipe{
name = "bind-py",
desc = "generate the Python bindings",
run = function() sh.maturin("build", "--features", "python") end,
}
make.recipe{
name = "docs",
desc = "build the mdbook site into docs/, and commit it",
run = function()
need("mdbook", "mdbook is not installed; install it first")
local top = oslo.sys.pwd()
sh.mdbook("build", top .. "/book", "--dest-dir", top .. "/docs")
sh.git("add", "--all")
sh.git("commit", "-m", "docs: building website/mdbook")
end,
}
make.recipe{
name = "release",
desc = "cut a version: --type patch | minor | major | M.m.p",
params = { { "--type", desc = "patch | minor | major | M.m.p" } },
run = function(a)
need("git-rel", "git-rel is not installed; install it first")
assert(type(a.type) == "string",
"which release? make release --type patch|minor|major|M.m.p")
sh.git("rel", a.type)
end,
}