Skip to content

Commit 68f0fe0

Browse files
author
Wodann
committed
feat(book): add book to main repository
this allows testing of listings in the book with the latest source code
1 parent 6ab5300 commit 68f0fe0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1830
-49
lines changed

.github/workflows/ci.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,25 @@ jobs:
5959
- name: Install LLVM
6060
uses: ./.github/actions/install-llvm
6161

62-
- name: Cargo check
62+
- name: Cargo build
63+
uses: actions-rs/cargo@v1
64+
continue-on-error: ${{ matrix.config.toolchain == 'nightly' }}
65+
with:
66+
command: build
67+
68+
- name: Install mdbook
69+
if: ${{ matrix.config.os == 'ubuntu-latest' && matrix.config.toolchain == 'stable' }}
70+
uses: actions-rs/install@v0.1
71+
with:
72+
crate: mdbook
73+
version: latest
74+
use-tool-cache: true
75+
76+
- name: mdbook test
77+
if: ${{ matrix.config.os == 'ubuntu-latest' && matrix.config.toolchain == 'stable' }}
78+
run: mdbook test book -L target/debug/deps
79+
80+
- name: Cargo test
6381
uses: actions-rs/cargo@v1
6482
continue-on-error: ${{ matrix.config.toolchain == 'nightly' }}
6583
with:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ Cargo.lock
2929

3030
# Build artifacts
3131
*.munlib
32-
**/target/*
32+
**/target/*

.gitmodules

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[submodule "crates/mun_abi/c"]
22
path = crates/mun_abi/c
3-
url = ../../mun-lang/abi-c
3+
url = https://github.com/mun-lang/abi-c.git
44
[submodule "crates/mun_runtime_capi/ffi"]
55
path = crates/mun_runtime_capi/ffi
6-
url = ../../mun-lang/runtime-ffi.git
6+
url = https://github.com/mun-lang/runtime-ffi.git
7+
[submodule "book/vendor/highlight.js"]
8+
path = book/vendor/highlight.js
9+
url = https://github.com/mun-lang/highlight.js.git
10+
branch = add-mun

README.md

Lines changed: 110 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,31 +32,35 @@
3232

3333
## Features
3434

35-
- **Ahead of time compilation** - Mun is compiled ahead of time (AOT), as opposed to being
36-
interpreted or compiled just in time (JIT). By detecting errors in the code during AOT
37-
compilation, an entire class of runtime errors is eliminated. This allows developers to stay
38-
within the comfort of their IDE instead of having to switch between the IDE and target application
39-
to debug runtime errors.
40-
41-
- **Statically typed** - Mun resolves types at compilation time instead of at runtime, resulting in
42-
immediate feedback when writing code and opening the door for powerful refactoring tools.
43-
44-
- **First class hot-reloading** - Every aspect of Mun is designed with hot reloading in mind. Hot
45-
reloading is the process of changing code and resources of a live application, removing the need
46-
to start, stop and recompile an application whenever a function or value is changed.
47-
48-
- **Performance** - AOT compilation combined with static typing ensure that Mun is compiled to
49-
machine code that can be natively executed on any target platform. LLVM is used for compilation
50-
and optimization, guaranteeing the best possible performance. Hot reloading does introduce a
51-
slight runtime overhead, but it can be disabled for production builds to ensure the best possible
35+
- **Ahead of time compilation** - Mun is compiled ahead of time (AOT), as
36+
opposed to being interpreted or compiled just in time (JIT). By detecting
37+
errors in the code during AOT compilation, an entire class of runtime errors
38+
is eliminated. This allows developers to stay within the comfort of their IDE
39+
instead of having to switch between the IDE and target application to debug
40+
runtime errors.
41+
42+
- **Statically typed** - Mun resolves types at compilation time instead of at
43+
runtime, resulting in immediate feedback when writing code and opening the
44+
door for powerful refactoring tools.
45+
46+
- **First class hot-reloading** - Every aspect of Mun is designed with hot
47+
reloading in mind. Hot reloading is the process of changing code and resources
48+
of a live application, removing the need to start, stop and recompile an
49+
application whenever a function or value is changed.
50+
51+
- **Performance** - AOT compilation combined with static typing ensure that Mun
52+
is compiled to machine code that can be natively executed on any target
53+
platform. LLVM is used for compilation and optimization, guaranteeing the best
54+
possible performance. Hot reloading does introduce a slight runtime overhead,
55+
but it can be disabled for production builds to ensure the best possible
5256
runtime performance.
5357

54-
- **Cross compilation** - The Mun compiler is able to compile to all supported target platforms from
55-
any supported compiler platform.
58+
- **Cross compilation** - The Mun compiler is able to compile to all supported
59+
target platforms from any supported compiler platform.
5660

57-
- **Powerful IDE integration** *not implemented yet* - The Mun language and compiler framework are
58-
designed to support source code queries, allowing for powerful IDE integrations such as code
59-
completion and refactoring tools.
61+
- **Powerful IDE integration** *not implemented yet* - The Mun language and
62+
compiler framework are designed to support source code queries, allowing for
63+
powerful IDE integrations such as code completion and refactoring tools.
6064

6165
## Example
6266

@@ -119,14 +123,16 @@ fn on_heap() -> GC {
119123

120124
## Documentation
121125

122-
[The Mun Programming Language Book](https://docs.mun-lang.org/)
126+
[The Mun Programming Language Book](https://docs.mun-lang.org/) is hosted on
127+
[netlify](https://www.netlify.com/).
123128

124129
## Pre-Built Binaries
125130

126131
**[NOTE] We do not provide support for milestone releases**
127132

128-
Download pre-built binaries of [milestone releases](https://github.com/mun-lang/mun/releases) for
129-
macOS, Linux, and Windows (64-bit only).
133+
Download pre-built binaries of [milestone
134+
releases](https://github.com/mun-lang/mun/releases) for macOS, Linux, and
135+
Windows (64-bit only).
130136

131137
## Building from Source
132138

@@ -141,16 +147,18 @@ rustup](https://www.rust-lang.org/tools/install).
141147

142148
#### LLVM
143149

144-
Mun targets LLVM 7.1.0. Installing LLVM is platform dependant and as such can be a pain. The
145-
following steps are how we install LLVM on [our CI
150+
Mun targets LLVM 7.1.0. Installing LLVM is platform dependant and as such can be
151+
a pain. The following steps are how we install LLVM on [our CI
146152
runners](.github/actions/install-llvm/index.js):
147153

148-
* ***nix**: Package managers of recent *nix distros can install binary versions of LLVM, e.g.:
154+
* ***nix**: Package managers of recent *nix distros can install binary versions
155+
of LLVM, e.g.:
149156
```bash
150157
# Ubuntu 18.04
151158
sudo apt install llvm-7 llvm-7-* liblld-7*
152159
```
153-
* **Arch Linux** The binary version of LLVM can currently only be installed using an AUR helper, such as `yay`:
160+
* **Arch Linux** The binary version of LLVM can currently only be installed
161+
using an AUR helper, such as `yay`:
154162
```bash
155163
yay -Syu lld7-headers lld7-libs-static
156164
```
@@ -162,26 +170,29 @@ runners](.github/actions/install-llvm/index.js):
162170
cd lld7
163171
makepkg -si
164172
```
165-
When running `llvm-config`, an error can occur signalling that `/usr/lib/libtinfo.so.5` is
166-
missing. If a newer version is present, create a symlink; e.g. `ln -s /usr/lib/libtinfo.so.6
167-
/usr/lib/libtinfo.so.5`), otherwise download the library.
168-
* **macOS**: [Brew](https://brew.sh/) contains a binary distribution of LLVM 7.1.0. However, as it's
169-
not the latest version, it won't be added to the path. We are using
170-
[llvm-sys](https://crates.io/crates/llvm-sys) to manage version, but another option is to export
171-
the `LLVM_SYS_70_PREFIX` variable, which will not clutter your `PATH`. To install:
173+
When running `llvm-config`, an error can occur signalling that
174+
`/usr/lib/libtinfo.so.5` is missing. If a newer version is present, create a
175+
symlink; e.g. `ln -s /usr/lib/libtinfo.so.6 /usr/lib/libtinfo.so.5`),
176+
otherwise download the library.
177+
* **macOS**: [Brew](https://brew.sh/) contains a binary distribution of LLVM
178+
7.1.0. However, as it's not the latest version, it won't be added to the path.
179+
We are using [llvm-sys](https://crates.io/crates/llvm-sys) to manage version,
180+
but another option is to export the `LLVM_SYS_70_PREFIX` variable, which will
181+
not clutter your `PATH`. To install:
172182
```bash
173183
brew install llvm@7
174184
# Export LLVM_SYS_PREFIX to not clubber PATH
175185
export LLVM_SYS_PREFIX=$(brew --prefix llvm@7)
176186
```
177-
* **windows**: Binary distrubutions are available for Windows on the LLVM website, but they
178-
do not contain a number of libraries that are required by Mun. To avoid having to go to the
179-
trouble of compiling LLVM yourself, we created a
180-
[repository](https://github.com/mun-lang/llvm-package-windows) that automatically compiles the
181-
required binaries. It also contains a
187+
* **windows**: Binary distrubutions are available for Windows on the LLVM
188+
website, but they do not contain a number of libraries that are required by
189+
Mun. To avoid having to go to the trouble of compiling LLVM yourself, we
190+
created a [repository](https://github.com/mun-lang/llvm-package-windows) that
191+
automatically compiles the required binaries. It also contains a
182192
[release](https://github.com/mun-lang/llvm-package-windows/releases/download/v7.1.0/llvm-7.1.0-windows-x64-msvc15.7z)
183-
that you can download and extract to your machine. Once downloaded and extracted, add the `<extract_dir>/bin`
184-
folder to the `PATH` environment variable.
193+
that you can download and extract to your machine. Once downloaded and
194+
extracted, add the `<extract_dir>/bin` folder to the `PATH` environment
195+
variable.
185196

186197
### Clone source
187198

@@ -197,12 +208,66 @@ git submodule update --init --recursive
197208
cargo build --release
198209
```
199210

211+
## Building Documentation
212+
213+
Building the book requires
214+
[mdBook](https://github.com/rust-lang-nursery/mdBook), ideally version 0.3.x. To
215+
install it, run:
216+
217+
```
218+
$ cargo install mdbook --vers [version-num]
219+
```
220+
221+
The Mun book uses a [custom version of
222+
Highlight.js](https://github.com/mun-lang/highlight.js) to enable highlighting
223+
of Mun code. The build version of Highlight.js is required by mdbook in the
224+
`theme/` folder but it is not distributed with the source. Instead, it can be
225+
build by invoking the build script:
226+
227+
```bash
228+
cd book
229+
./ci/build-highlight-js
230+
```
231+
232+
Every time you change something in the custom version of highlight.js you have
233+
to call the above script to ensure you locally use the latest version.
234+
235+
After generating the custom minified Highlight.js, to build the book, type:
236+
237+
```
238+
$ mdbook build
239+
```
240+
241+
The output will be in the book subdirectory. To view the book, open it in your
242+
web browser.
243+
244+
For local development use `mdbook serve` instead of `mdbook build`. This will
245+
start a local webserver on port `3000` that serves the book and rebuilds the
246+
content when changes are detected.
247+
248+
All of the above is also combined in a single shell script that can be invoked
249+
by simply running:
250+
251+
```bash
252+
./ci/build
253+
```
254+
255+
To test the `rust` source code in the book, run:
256+
257+
```bash
258+
mdbook test -L path/to/target/debug/deps
259+
```
260+
261+
For this to work, there can only be one `libmun_runtime-{HASH}.rlib` file in the
262+
provided library path.
263+
200264
## License
201265

202266
The Mun Runtime is licensed under either of
203267

204-
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
268+
* Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
205269
http://www.apache.org/licenses/LICENSE-2.0)
206-
* MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
270+
* MIT license ([LICENSE-MIT](LICENSE-MIT) or
271+
http://opensource.org/licenses/MIT)
207272

208273
at your option.

book/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/book
2+
/theme/highlight.js

book/book.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[book]
2+
authors = ["The Mun Team <team@mun-lang.org>"]
3+
language = "en"
4+
multilingual = false
5+
src = "src"
6+
title = "The Mun Programming Language"
7+
8+
[output.html]
9+
additional-css = ["theme/mun.css"]

book/ci/build

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
# First build our custom highlight.js
6+
./ci/build-highlight-js
7+
8+
# Check if mdbook is installed, otherwise download the binaries
9+
mdbook="mdbook"
10+
if ! [ -x "$(command -v $mdbook)" ]; then
11+
echo "Installing mdbook.."
12+
curl -sL https://github.com/rust-lang-nursery/mdBook/releases/download/v0.3.1/mdbook-v0.3.1-x86_64-unknown-linux-gnu.tar.gz | tar zxv
13+
mdbook="./mdbook"
14+
fi
15+
16+
# Actually build the book
17+
echo 'Building book..'
18+
$mdbook build

book/ci/build-highlight-js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
main() {
5+
# prepare the git submodule, if it hasn't been already
6+
git submodule init
7+
8+
# build the minified highlight.js source
9+
pushd vendor/highlight.js
10+
npm install
11+
node tools/build.js rust bash mun cpp c typescript
12+
popd
13+
14+
# copy the minified sources to the theme directory
15+
mkdir -p theme
16+
cp vendor/highlight.js/build/highlight.pack.js theme/highlight.js
17+
}
18+
19+
main
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub fn fibonacci_n() -> i64 {
2+
let n = arg();
3+
fibonacci(n);
4+
}
5+
6+
fn arg() -> i64 {
7+
5
8+
}
9+
10+
fn fibonacci(n: i64) -> i64 {
11+
if n <= 1 {
12+
n
13+
} else {
14+
fibonacci(n - 1) + fibonacci(n - 2)
15+
}
16+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pub fn arg() -> i64 {
2+
5
3+
}
4+
5+
pub fn fibonacci(n: i64) -> i64 {
6+
if n <= 1 {
7+
n
8+
} else {
9+
fibonacci(n - 1) + fibonacci(n - 2)
10+
}
11+
}

0 commit comments

Comments
 (0)