Skip to content

Commit e82ada6

Browse files
committed
doc/guide: Introduce a Guide Site
doc/guides: How to Doc fix: add starlight to base makefile
1 parent ec94a3c commit e82ada6

28 files changed

Lines changed: 8602 additions & 1 deletion

.github/workflows/deploy_docs.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Build Docs
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
paths:
8+
- 'doc/guides/**'
9+
- 'doc/starlight/**'
10+
11+
jobs:
12+
build-docs:
13+
runs-on: ubuntu-latest
14+
defaults:
15+
run:
16+
working-directory: doc/starlight
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
22+
- name: Build documentation
23+
run: make build
24+
# This step will probably need to be changed to use the actual service RIOT is using
25+
# This makes it more convenient to deploy while still in development though
26+
- name: Deploy documentation
27+
uses: peaceiris/actions-gh-pages@v3
28+
with:
29+
github_token: ${{ secrets.GITHUB_TOKEN }}
30+
publish_dir: doc/starlight/dist
31+
publish_branch: gh-pages
32+
cname: guide.riot-os.org
33+
commit_message: "Deploy documentation"

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.all:
22

3-
.PHONY: all doc doc-man doc-latex docclean print-versions welcome
3+
.PHONY: all doc doc-man doc-latex docclean doc-starlight print-versions welcome
44

55
all: welcome
66
@echo ""
@@ -12,8 +12,12 @@ doc doc-man doc-latex doc-ci:
1212
--output-md doc/doxygen/src/feature_list.md
1313
"$(MAKE)" -C doc/doxygen $@
1414

15+
doc-starlight:
16+
"$(MAKE)" -C doc/starlight dev
17+
1518
docclean:
1619
"$(MAKE)" -BC doc/doxygen clean
20+
"$(MAKE)" -C doc/starlight clean
1721

1822
pkg-clean:
1923
@echo "Cleaning all package sources"

dist/tools/ci/static_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ run ./dist/tools/codespell/check.sh
131131
run ./dist/tools/cargo-checks/check.sh
132132
run ./dist/tools/examples_check/check_has_readme.sh
133133
run ./dist/tools/examples_check/check_in_readme.sh
134+
run ./dist/tools/code_in_guides_check/check_for_code.sh
134135
if [ -z "${GITHUB_RUN_ID}" ]; then
135136
run ./dist/tools/uncrustify/uncrustify.sh --check
136137
else
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
# This script checks if the code blocks in markdown files under the guides directory
3+
# are present in the corresponding source files. It looks for code blocks marked with
4+
# ```c and checks if the code exists in the source files defined by the code_folder
5+
# variable in the markdown file. If the code block is not found, it will print an error
6+
# message and exit with a non-zero status.
7+
8+
# Define the guides directory
9+
BASE_DIR="$(git rev-parse --show-toplevel)"
10+
GUIDES_DIR="$BASE_DIR/doc/guides"
11+
12+
# Check if directory exists
13+
if [ ! -d "$GUIDES_DIR" ]; then
14+
echo "Error: Guides directory not found at $GUIDES_DIR"
15+
exit 1
16+
fi
17+
18+
exit_code=0
19+
20+
# Parses code blocks from within a file
21+
# Args: $1 -> Line number of the code block
22+
# $2 -> The file path
23+
# Returns:
24+
# 0 -> On found or skipped block
25+
# 1 -> Not found
26+
parse_code_block() {
27+
start_line=$1
28+
file_path=$2
29+
# Check whether there is a <!--skip ci--> comment in the line before the code block
30+
skip_ci=$(sed -n "$((start_line - 1))p" "$file_path" | grep -c '<!--skip ci-->')
31+
if [ "$skip_ci" -gt 0 ]; then
32+
echo " ✔️ Line $start_line: Code block is skipped due to <!--skip ci--> comment"
33+
return 0
34+
fi
35+
36+
# Extract the code block content until the ending ```
37+
code_block=$(awk -v start="$start_line" 'NR>start{if(/^```$/){exit}; print}' "$file_path")
38+
39+
# Check if this code exists in any file in the source directory
40+
found=0
41+
for src_file in "$SOURCE_DIR"/*; do
42+
# Skip if not a regular file
43+
[ -f "$src_file" ] || continue
44+
45+
# Read the file content
46+
src_content=$(cat "$src_file")
47+
48+
# Check if the code block exists in the current source file
49+
if [[ "$src_content" == *"$code_block"* ]]; then
50+
found=1
51+
echo " ✔️ Found Line $start_line in $(basename "$src_file")"
52+
break
53+
fi
54+
done
55+
56+
if [ $found -eq 0 ]; then
57+
echo " ❌ Line $start_line: Code block not found in any source file"
58+
return 1
59+
fi
60+
}
61+
62+
markdown_files=$(find "$GUIDES_DIR" -type f \( -name "*.md" -o -name "*.mdx" \))
63+
64+
# Find and process all .md and .mdx files
65+
for file in $markdown_files; do
66+
echo "🧐 Processing file: $file"
67+
68+
# Check if there is a code_folder defined in the markdown file
69+
code_folder=$(grep -oP -m1 'code_folder:\s*\K.+' "$file")
70+
if [ -z "$code_folder" ]; then
71+
echo " ✔️ File does not specify code_folder, skipping ..."
72+
continue
73+
fi
74+
SOURCE_DIR="$BASE_DIR/$code_folder"
75+
76+
echo "🔍 Looking for code in $SOURCE_DIR"
77+
78+
# Get all code block start lines
79+
code_block_starts=$(grep -n '```[cC]' "$file" | cut -d':' -f1)
80+
81+
if [ -z "$code_block_starts" ]; then
82+
echo " ❌ No code blocks found in this file even though code_folder was specified."
83+
exit_code=1
84+
fi
85+
86+
# Process each code block
87+
for start_line in $code_block_starts; do
88+
parse_code_block "$start_line" "$file"
89+
if [ "$?" -eq "1" ]; then
90+
exit_code=1
91+
fi
92+
done
93+
done
94+
95+
if [ $exit_code -eq 0 ]; then
96+
echo "👍 All code blocks found in the source files."
97+
else
98+
echo "👎 Some code blocks were not found in the source files. See the output above."
99+
fi
100+
101+
exit $exit_code
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
title: Advanced Build System Tricks
3+
description: This page describes some build systems tricks that can help developers but are not part of the standard workflow.
4+
---
5+
6+
This page describes some build systems tricks that can help developers but are not part of the standard workflow.
7+
8+
They are low level commands that should not be taken as part of a stable API but better have a documentation than only having a description in the build system code.
9+
10+
## Customize the build system
11+
12+
- `RIOT_MAKEFILES_GLOBAL_PRE`: files parsed before the body of `$RIOTBASE/Makefile.include`
13+
- `RIOT_MAKEFILES_GLOBAL_POST`: files parsed after the body of `$RIOTBASE/Makefile.include`
14+
15+
The variables are a list of files that will be included by `$RIOTBASE/Makefile.include`. They will be handled as relative to the application directory if the path is relative.
16+
17+
## Usage
18+
19+
You can configure your own files that will be parsed by the build system main `Makefile.include` file before or after its main body, examples usages can be:
20+
21+
- Globally overwrite a variable, like `TERMPROG`
22+
- Specify a hard written `PORT` / `DEBUG_ADAPTER_ID` for some BOARD values
23+
- Define your custom targets
24+
- Override default targets
25+
26+
## Analyze dependency resolution
27+
28+
When refactoring dependency handling or modifying variables used for dependency resolution, one may want to evaluate the impact on the existing applications. This describe some debug targets to dump variables used during dependency resolution.
29+
30+
To analyze one board and application run the following commands in an application directory.
31+
32+
Generate the variables dump with the normal dependency resolution to a `dependencies_info_board_name` file:
33+
34+
```sh
35+
BOARD=board_name make dependency-debug
36+
```
37+
38+
Or with the "quick" version used by murdock to know supported boards (this is an incomplete resolution, details in `makefiles/dependencies_debug.inc.mk`) to a `dependencies_info-boards-supported_board_name` file:
39+
40+
```sh
41+
BOARDS=board_name DEPENDENCY_DEBUG=1 make info-boards-supported
42+
```
43+
44+
For more configuration and usage details, see in the file defining the targets `makefiles/dependencies_debug.inc.mk`.
45+
46+
To do a repository wide analysis, you can use the script `dist/tools/buildsystem_sanity_check/save_all_dependencies_resolution_variables.sh` that will generate the output for all boards and applications. It currently take around 2 hours on an 8 cores machine with ssd.
47+
48+
## Generate Makefile.ci content
49+
50+
Most applications and tests include a `Makefile.ci` to indicate which boards cannot compile the application or test. The content for these files can be generated via the script in:
51+
52+
```sh
53+
make -C $APPLICATION_DIRECTORY generate-Makefile.ci
54+
```
55+
56+
This will compile and link the application for every board available and record the result in the Makefile.ci. This requires the toolchain for every target to be available. The target supports using docker via the `BUILD_IN_DOCKER=1` variable.
57+
58+
## Out of Tree Cache Directory
59+
60+
By exporting the `BUILD_DIR` environment variable, a custom build / clone cache directory can be created. This can be particularly useful when working with multiple git work trees or clones of the RIOT repository.
61+
62+
## RIOT-aware Completion in zsh
63+
64+
For zsh users a RIOT-aware completion is provided in `dist/tools/zsh-completion`. Refer to the `README.md` in there for more details and installation instructions.
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
---
2+
title: Build in Docker
3+
description: Building RIOT in a Docker container
4+
---
5+
6+
Some parts of RIOT's build process can be performed inside a Docker container,
7+
which comes with the necessary compilers and toolchains and is fully managed by
8+
the build system. It can be enabled by passing `BUILD_IN_DOCKER=1` to make.
9+
10+
```shell
11+
$ BUILD_IN_DOCKER=1 make
12+
```
13+
14+
If your user does not have permissions to access the Docker daemon:
15+
16+
```shell
17+
$ BUILD_IN_DOCKER=1 DOCKER="sudo docker" make
18+
```
19+
20+
to always use Docker for building, set `BUILD_IN_DOCKER=1` (and if necessary
21+
`DOCKER="sudo docker"`) in the environment:
22+
23+
```console
24+
$ export BUILD_IN_DOCKER=1
25+
```
26+
27+
## Targets ran in Docker: DOCKER_MAKECMDGOALS_POSSIBLE
28+
29+
Currently only build related targets are ran in the docker container, the exact
30+
list is under `DOCKER_MAKECMDGOALS_POSSIBLE` variable.
31+
32+
## Environment Variables: DOCKER_ENV_VARS
33+
34+
When building in docker one might want for the command ran in docker to inherit
35+
variables that might have been set in the command line. e.g.:
36+
37+
```shell
38+
BOARD=samr21-xpro USEMODULE=xtimer make -C examples/hello-world
39+
```
40+
41+
In `docker.ink.mk` the origin of a variable listed in `DOCKER_ENV_VARS` is checked
42+
and if the origin is `environment` or `command` (for make command-line argument)
43+
then those variables will be passed to the docker container.
44+
45+
You can also set in `DOCKER_ENV_VARS` in the environment to add variables to the
46+
list, e.g.:
47+
48+
```shell
49+
DOCKER_ENV_VARS=BEER_TYPE BEER_TYPE="imperial stout" BUILD_IN_DOCKER=1 make -C examples/hello-world/
50+
docker run --rm -t -u "$(id -u)" \
51+
...
52+
-e 'BEER_TYPE=imperial stout' \
53+
-w '/data/riotbuild/riotbase/examples/hello-world/' \
54+
'riot/riotbuild:latest' make
55+
```
56+
57+
Your application Makefile can also extend `DOCKER_ENV_VARS`.
58+
59+
### Directly Define Environment Variables: DOCKER_ENVIRONMENT_CMDLINE
60+
61+
`DOCKER_ENVIRONMENT_CMDLINE` can be used to add variables directly to the environment
62+
but will need to be prefixed with `-e` (see [option-summary]).
63+
64+
e.g.:
65+
66+
```
67+
DOCKER_ENVIRONMENT_CMDLINE='-e BEER_TYPE="imperial stout"' BUILD_IN_DOCKER=1 make -C examples/hello-world/
68+
docker run --rm -t -u "$(id -u)" \
69+
...
70+
-e 'BEER_TYPE=imperial stout' \
71+
-w '/data/riotbuild/riotbase/examples/hello-world/' \
72+
'riot/riotbuild:latest' make
73+
```
74+
75+
## Command Line Variables: DOCKER_OVERRIDE_CMDLINE
76+
77+
Command line arguments are variables that are passed after `make` e.g.
78+
`make target FOO=bar`, but different to environment variables a variable defined
79+
through the command line will take precedence over all assignments of `FOO` within
80+
the makefile (same effect as adding `-e` for environment variables, see
81+
[option-summary] for more details.
82+
83+
To pass variables overriding the command-line to docker `DOCKER_OVERRIDE_CMDLINE`
84+
may be used:
85+
86+
```shell
87+
DOCKER_OVERRIDE_CMDLINE="BEER_TYPE='imperial stout'" BUILD_IN_DOCKER=1 make -C examples/hello-world/ RIOT_CI_BUILD=1
88+
Launching build container using image "riot/riotbuild:latest".
89+
sudo docker run --rm -t -u "$(id -u)" \
90+
...
91+
-w '/data/riotbuild/riotbase/examples/hello-world/' \
92+
'riot/riotbuild:latest' make BEER_TYPE='imperial stout' 'RIOT_CI_BUILD=1'
93+
```
94+
95+
### Redefined or Overridden Variables: DOCKER_ENV_VARS_ALWAYS
96+
97+
There is a corner case for the handling of `DOCKER_ENV_VARS`. If a variable is
98+
redefined (`+=`, `=`, `:=`) or overridden then the origin of the variable will be changed
99+
to `file` and there is no way of detecting in Make how it was set.
100+
101+
If this happens after `docker.ink.mk` this is not an issue, but for all variables
102+
susceptible to be defined in the application `Makefile` this is indeed the case.
103+
104+
A subset of these variables, namely variables relating to dependency resolution
105+
are therefore unconditionally passed to docker. The complete list can be found
106+
under `DOCKER_ENV_VARS_ALWAYS`.
107+
108+
#### CFLAGS
109+
110+
CFLAGS are not automatically passed to docker because they might contain spaces,
111+
'"' or other characters that will require escaping. The solution is to pass it with
112+
`DOCKER_ENVIRONMENT_CMDLINE` and escape every character as required.
113+
114+
e.g: if wanting to override STRING_WITH_SPACES
115+
116+
```
117+
# normal build
118+
CFLAGS=-DSTRING_WITH_SPACES='\"with space\" make
119+
# in docker
120+
DOCKER_ENVIRONMENT_CMDLINE='-e CFLAGS=-DSTRING_WITH_SPACES=\'\\\"with\ space\\\"\'' \
121+
BUILD_IN_DOCKER=1 make
122+
```
123+
124+
Alternatively, it is often easier to define the CFLAGS in the Makefile which gets
125+
evaluated inside the Docker image again), conditional on a less complex environment
126+
variable that gets added to `DOCKER_ENV_VARS` in the Makefile.
127+
128+
[option-summary]: https://www.gnu.org/software/make/manual/html_node/Options-Summary.html

0 commit comments

Comments
 (0)