Skip to content

Commit 678d1e6

Browse files
committed
Initial commit
Signed-off-by: Miguel Ojeda <[email protected]>
0 parents  commit 678d1e6

24 files changed

+1334
-0
lines changed

.github/workflows/ci.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
ci:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
14+
- name: Install `mdbook`
15+
run: |
16+
curl --no-progress-meter --location --output mdbook.tar.gz https://github.com/rust-lang/mdBook/releases/download/v0.4.25/mdbook-v0.4.25-x86_64-unknown-linux-gnu.tar.gz
17+
echo "2d049e4d0a1ef739a1218cf209c99cdc0d1c66aa43a15e2183770f6e1d333324 mdbook.tar.gz" > mdbook.tar.gz.sha256
18+
sha256sum --check --strict mdbook.tar.gz.sha256
19+
tar --extract --file mdbook.tar.gz
20+
21+
- name: Build book
22+
run: |
23+
./pre.py
24+
./mdbook build
25+
./post.py
26+
27+
- name: Deploy to GitHub Pages
28+
run: |
29+
cd book
30+
git init
31+
git config user.name CI
32+
git config user.email ""
33+
git add .
34+
git commit -m "Deploy $GITHUB_SHA to branch `gh-pages`"
35+
git push --force "https://x-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY" HEAD:gh-pages

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
src/SUMMARY.md
2+
summary.json

Rust-for-Linux.svg

Lines changed: 357 additions & 0 deletions
Loading

SUMMARY.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
[Rust for Linux](https://rust-for-linux.com)
2+
3+
# The project
4+
5+
- [Contact](Contact.md)
6+
- [Contributing](Contributing.md)
7+
- [Branches](Branches.md)
8+
- [Rust version policy](Rust-version-policy.md)
9+
- [Unstable features](Unstable-features.md)
10+
- [Backporting and stable/LTS releases](Backporting-and-stable-LTS-releases.md)
11+
- [Industry and academia support](Industry-and-academia-support.md)
12+
- [Sponsors](Sponsors.md)
13+
14+
## Subprojects
15+
16+
- [`klint`](klint.md)
17+
- [`pinned-init`](pinned-init.md)
18+
- Hidden [The Safe Pinned Initialization Problem](The-Safe-Pinned-Initialization-Problem.md)
19+
- Hidden [Ksquirrel](Ksquirrel.md)
20+
21+
## Users
22+
23+
- [NVMe driver](NVMe-driver.md)
24+
25+
# Links
26+
27+
## Contact
28+
29+
- [Lore (mailing list archive)](https://lore.kernel.org/rust-for-linux/)
30+
- [Zulip (chat)](https://rust-for-linux.zulipchat.com)
31+
- [GitHub Organization](https://github.com/Rust-for-Linux)
32+
33+
## Security
34+
35+
- [Report a security bug](https://docs.kernel.org/admin-guide/security-bugs.html)
36+
37+
## Issue tracking
38+
39+
- [Issues](https://github.com/Rust-for-Linux/linux/issues)
40+
- [Unstable features](https://github.com/Rust-for-Linux/linux/issues/2)
41+
- [Good first issues](https://github.com/Rust-for-Linux/linux/contribute)
42+
43+
## Branches
44+
45+
- [`rust-next`](https://github.com/Rust-for-Linux/linux/tree/rust-next)
46+
- [`rust-fixes`](https://github.com/Rust-for-Linux/linux/tree/rust-fixes)
47+
- [`rust`](https://github.com/Rust-for-Linux/linux/tree/rust)
48+
49+
## Documentation
50+
51+
- [Kernel documentation (mainline)](https://docs.kernel.org/rust/index.html)
52+
- [Kernel documentation (next)](https://docs.kernel.org/next/rust/index.html)
53+
- [`rustdoc` code docs (v6.3-rc2)](https://rust-for-linux.github.io/docs/v6.3-rc2/kernel/)
54+
- [`rustdoc` code docs (`rust` 2023-03-13)](https://rust-for-linux.github.io/docs/rust/kernel/)
55+
- [`rustdoc` code docs (`pinned-init` v1)](https://rust-for-linux.github.io/docs/pinned-init/kernel/init/)
56+
- [`rustdoc` code docs (pre-merge v8 patch)](https://rust-for-linux.github.io/docs/kernel/)
57+
- [Out-of-tree module template](https://github.com/Rust-for-Linux/rust-out-of-tree-module)
58+
59+
## Conferences
60+
61+
- [Kangrejos](https://kangrejos.com)
62+
- [Linux Plumbers Conference (LPC)](https://lpc.events)
63+
- [Rust MC at LPC 2022](https://lpc.events/event/16/sessions/150/)
64+
65+
## LWN
66+
67+
- [Rust index](https://lwn.net/Kernel/Index/#Development_tools-Rust)
68+
- [Kangrejos index](https://lwn.net/Archives/ConferenceIndex/#Kangrejos)
69+
70+
## Toolchain projects
71+
72+
- [`rustc_codegen_gcc`](https://github.com/rust-lang/rustc_codegen_gcc)
73+
- [Rust GCC](https://rust-gcc.github.io)
74+
75+
## Other trees
76+
77+
- [Linus' tree](https://git.kernel.org/linus/)
78+
- [Stable tree](https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/)
79+
- [`linux-next` tree](https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git/)
80+
81+
## Other resources
82+
83+
- [Bootlin's Elixir](https://elixir.bootlin.com/linux/latest/source/rust)
84+
- [Compiler Explorer](https://godbolt.org/z/W4P36a9h9)
85+
- [Rust Playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021)
86+
- [Rust `core` docs](https://doc.rust-lang.org/1.62.0/core/)

book.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[book]
2+
title = "Rust for Linux"
3+
author = "Rust for Linux Contributors"
4+
description = "Adding support for the Rust language to the Linux kernel"
5+
language = "en"
6+
7+
[build]
8+
create-missing = false
9+
10+
[output.html]
11+
git-repository-url = ""
12+
edit-url-template = ""
13+
no-section-label = true
14+
15+
[output.html.fold]
16+
enable = true
17+
level = 0

post.py

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
"""Postprocesses the "book".
5+
"""
6+
7+
import json
8+
import os
9+
import pathlib
10+
import re
11+
import shutil
12+
13+
def handle_markdown(string):
14+
if string.count("`") % 2 != 0:
15+
raise RuntimeError("Unbalanced backticks.")
16+
17+
while True:
18+
if "`" not in string:
19+
return string
20+
21+
# Should use `code`, but it requires fixing the general CSS.
22+
string = string.replace("`", '<span class="rfl-mono-font">', 1)
23+
string = string.replace("`", "</span>", 1)
24+
25+
def process(path, content, html_menu, html_index_toc):
26+
# Fix index title (`index.html` and `Rust-for-Linux.html`).
27+
content = content.replace("<title>Rust for Linux - Rust for Linux</title>", "<title>Rust for Linux</title>")
28+
29+
# Fix header.
30+
content = content.replace('<link rel="icon" href="favicon.svg">', "")
31+
content = content.replace('<link rel="shortcut icon" href="favicon.png">', """
32+
<link rel="icon" href="Rust-for-Linux.svg">
33+
34+
<meta property="og:url" content="https://rust-for-linux.com">
35+
<meta property="og:type" content="website">
36+
<meta property="og:title" content="Rust for Linux">
37+
<meta property="og:description" content="Adding support for the Rust language to the Linux kernel">
38+
<meta property="og:image" content="https://rust-for-linux.com/Rust-for-Linux.svg">
39+
<script type="application/ld+json">
40+
{
41+
"@context": "http://schema.org",
42+
"@type": "CreativeWork",
43+
"name": "Rust for Linux",
44+
"description": "Adding support for the Rust language to the Linux kernel",
45+
"url": "https://rust-for-linux.com",
46+
"image": "https://rust-for-linux.com/Rust-for-Linux.svg"
47+
}
48+
</script>
49+
<style>
50+
#logo {
51+
display: block;
52+
margin-left: auto;
53+
margin-right: auto;
54+
}
55+
56+
.rfl-menu-block {
57+
text-align: center;
58+
font-size: 1.8rem;
59+
font-weight: bold;
60+
}
61+
62+
.rfl-mono-font {
63+
font-family: var(--mono-font);
64+
}
65+
66+
.rfl-mobile-links {
67+
display: none;
68+
}
69+
70+
@media only screen and (max-width: 1080px) {
71+
.rfl-mobile-links {
72+
display: block;
73+
}
74+
}
75+
76+
.chapter li.chapter-item {
77+
margin-top: 0.2em !important;
78+
margin-left: 1.5em !important;
79+
}
80+
81+
.chapter li.part-title {
82+
margin-bottom: -0.3em !important;
83+
margin-top: 1em !important;
84+
}
85+
</style>
86+
""")
87+
88+
# Provide custom menu.
89+
content = re.sub(r'<div class="sidebar-scrollbox">.*?</div>', html_menu, content, count=1, flags=re.DOTALL)
90+
91+
# Append Table of Contents in index (`index.html` and `Rust-for-Linux.html`), as well as
92+
# the links for mobile.
93+
content = content.replace("<!-- Generated TOC -->", html_index_toc)
94+
95+
return content
96+
97+
def main():
98+
# Read TOC generated by `pre.py`.
99+
with open("summary.json", "r", encoding="utf-8") as f:
100+
json_summary = json.load(f)
101+
102+
# Generate menu.
103+
html_menu = ""
104+
for block_name in json_summary:
105+
html_block = ""
106+
for section_name in json_summary[block_name]:
107+
if section_name != "":
108+
html_block += f'<li class="part-title">{section_name}</li>'
109+
for (text, link) in json_summary[block_name][section_name]:
110+
html_block += f'<li class="chapter-item"><a href="{link}" tabindex="0">{handle_markdown(text)}</a></li>'
111+
112+
html_menu += f"""
113+
<p class="rfl-menu-block">{block_name}</p>
114+
<ol class="chapter">{html_block}</ol>
115+
"""
116+
117+
html_menu = f"""
118+
<div class="sidebar-scrollbox">
119+
<a href="/"><img id="logo" src="Rust-for-Linux.svg" alt="Rust for Linux Logo"></a>
120+
{html_menu}
121+
</div>
122+
"""
123+
124+
# Generate TOC for index pages.
125+
html_index_toc = {}
126+
for block_name in json_summary:
127+
html_index_toc[block_name] = ""
128+
for section_name in json_summary[block_name]:
129+
section_links = ""
130+
for (text, link) in json_summary[block_name][section_name]:
131+
section_links += f'<li><a href="{link}" tabindex="0">{handle_markdown(text)}</a></li>'
132+
133+
if section_name != "":
134+
html_index_toc[block_name] += f"<h3>{section_name}</h3>\n"
135+
if section_links != "":
136+
html_index_toc[block_name] += f"<ul>{section_links}</ul>\n"
137+
138+
html_index_toc = f"""
139+
<h2><a class="header" href="#the-project">The project</a></h2>
140+
{html_index_toc["The project"]}
141+
<div class="rfl-mobile-links">
142+
<h2><a class="header" href="#links">Links</a></h2>
143+
{html_index_toc["Links"]}
144+
</div>
145+
"""
146+
147+
# Post-process each `mdbook`-generated file.
148+
for path in pathlib.Path().glob("book/**/*.html"):
149+
with path.open("r+", encoding="utf-8") as f:
150+
new_content = process(path, f.read(), html_menu, html_index_toc)
151+
f.seek(0)
152+
f.truncate()
153+
f.write(new_content)
154+
155+
# Remove unneeded files.
156+
os.remove("book/favicon.svg")
157+
os.remove("book/favicon.png")
158+
159+
# Copy logo.
160+
shutil.copyfile("Rust-for-Linux.svg", "book/Rust-for-Linux.svg")
161+
162+
if __name__ == "__main__":
163+
main()

pre.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/usr/bin/env python3
2+
# SPDX-License-Identifier: GPL-2.0
3+
4+
"""Preprocesses the "book".
5+
"""
6+
7+
import json
8+
import pathlib
9+
import re
10+
11+
def main():
12+
md_files_in_summary = set()
13+
mdbook_summary = ""
14+
json_summary = {}
15+
json_current_block = None
16+
json_current_section = None
17+
18+
with open("SUMMARY.md", "r", encoding="utf-8") as f:
19+
for line in f:
20+
# Blank lines.
21+
if line == "\n":
22+
continue
23+
24+
# The index/root link.
25+
if line == "[Rust for Linux](https://rust-for-linux.com)\n":
26+
md_files_in_summary.add("Rust-for-Linux.md")
27+
mdbook_summary += "[Rust for Linux](Rust-for-Linux.md)\n"
28+
continue
29+
30+
# Blocks.
31+
match = re.match(r"^# (.*)$", line)
32+
if match:
33+
json_current_block = match[1]
34+
json_current_section = ""
35+
json_summary[json_current_block] = {}
36+
json_summary[json_current_block][json_current_section] = []
37+
continue
38+
39+
# Titles.
40+
match = re.match(r"^## (.*)$", line)
41+
if match:
42+
json_current_section = match[1]
43+
json_summary[json_current_block][json_current_section] = []
44+
continue
45+
46+
# Hidden links.
47+
match = re.match(r"^ - Hidden \[(.*)\]\((.*)\.md\)$", line)
48+
if match:
49+
md_files_in_summary.add(f"{match[2]}.md")
50+
mdbook_summary += f" - [{match[1]}]({match[2]}.md)\n"
51+
continue
52+
53+
# Chapter links.
54+
match = re.match(r"^ - \[(.*)\]\((.*)\.md\)$", line)
55+
if match:
56+
md_files_in_summary.add(f"{match[2]}.md")
57+
mdbook_summary += line
58+
json_summary[json_current_block][json_current_section].append((match[1], f"{match[2]}.html"))
59+
continue
60+
61+
# External links.
62+
match = re.match(r"^ - \[(.*)\]\((.*)\)$", line)
63+
if match:
64+
json_summary[json_current_block][json_current_section].append((match[1], match[2]))
65+
continue
66+
67+
raise RuntimeError("Unknown syntax")
68+
69+
md_files_in_src = set(str(path.relative_to("src")) for path in pathlib.Path("src").glob("**/*.md"))
70+
md_files_in_src.discard("SUMMARY.md")
71+
if md_files_in_summary != md_files_in_src:
72+
raise AssertionError("Unmatched files in generated `SUMMARY.md` vs. `src` folder")
73+
74+
with open("src/SUMMARY.md", "w", encoding="utf-8") as f:
75+
f.write(mdbook_summary)
76+
77+
with open("summary.json", "w", encoding="utf-8") as f:
78+
json.dump(json_summary, f)
79+
80+
if __name__ == "__main__":
81+
main()

0 commit comments

Comments
 (0)