Skip to content

Commit 674ca66

Browse files
committed
feat(guides): add extra.rockspec guide
1 parent 5c54751 commit 674ca66

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

docs/guides/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Want to get better at using Lux? Look no further than this set of guides.
1111
## Maintenance
1212
- [How to publish a Lua project](/guides/publishing)
1313
- [How to publish a new release of your project](/guides/project-updating)
14+
- [How to use Lux with a rockspec file](/guides/rockspec)
1415

1516
## Code Hygiene
1617
- [How to test a Lua project](/guides/testing)

docs/guides/rockspec.md

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
id: rockspec
3+
title: How to use Lux with a rockspec file
4+
---
5+
6+
In this guide, we'll learn how to use rockspec files with Lux.
7+
8+
:::note
9+
Using TOML is highly recommended due to ease-of-use. We recommend only following this guide
10+
if you have an existing, complex rockspec and do not want to waste the effort porting it.
11+
:::
12+
13+
## Create a Project
14+
15+
Various functions related to rockspecs (e.g. uploading, building and testing) require that you have made a project.
16+
17+
If you haven't, be sure to run:
18+
19+
```sh
20+
lx new .
21+
```
22+
23+
In the directory containing your code.
24+
25+
## `extra.rockspec`
26+
27+
Lux expects a rockspec to exist in an `extra.rockspec` file. Create that file in your project's root and paste the content
28+
of your rockspec there:
29+
30+
```lua title="extra.rockspec"
31+
package = "say"
32+
version = "0.1.0-1"
33+
34+
source = {
35+
url = "git+https://github.com/my/project",
36+
}
37+
38+
build = {
39+
type = "builtin",
40+
modules = {
41+
say = "src/my-project/init.lua"
42+
}
43+
}
44+
```
45+
46+
This is all that's required - Lux will now pull information from the rockspec file whenever it needs.
47+
48+
## Important Behaviour
49+
50+
Lux will **always prioritize the rockspec's data** over the TOML. Lux does not deeply merge content from both
51+
files, but simply prioritizes data found in the rockspec.
52+
53+
For example, if you specify a project version in the TOML and a project version in the rockspec, Lux will
54+
use the version defined in the rockspec. If you specify a `source` table in the TOML and a `source` table in the rockspec,
55+
Lux will completely ignore all content in the TOML and use only the `source` table from the rockspec.
56+
57+
## Cleaning up the Rockspec
58+
59+
For the reasons above, you'll want to clean up the rockspec and only keep the data you really need (the more
60+
data coming from the TOML the better). In the case of `extra.rockspec`, Lux allows you to omit any fields, including ones
61+
that would generally be considered required fields.
62+
63+
Following the previous section, here's an example of a cleaned up rockspec:
64+
65+
```lua title="extra.rockspec"
66+
build = {
67+
type = "builtin",
68+
modules = {
69+
say = "src/my-project/init.lua"
70+
}
71+
}
72+
```
73+
74+
Notice how we removed all the fields apart from the ones we are interested in overriding.
75+
In this case, we were only interested in overriding the `build` table.
76+
77+
After cleanup, feel free to continue using Lux as if nothing ever happened.

0 commit comments

Comments
 (0)