-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #332 from moonbitlang/update-docs
docs: update
- Loading branch information
Showing
27 changed files
with
407 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
```json | ||
{ | ||
"name": "example", | ||
"version": "1.0.0", | ||
"version": "0.1.0", | ||
... | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Module Configuration | ||
|
||
moon uses the `moon.mod.json` file to identify and describe a module. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Deps | ||
|
||
The `deps` field is used to specify the dependencies of the module. | ||
|
||
It is automatically managed by commands like `moon add` and `moon remove`. | ||
|
||
```json | ||
{ | ||
"name": "username/hello", | ||
"deps": { | ||
"moonbitlang/x": "0.4.6" | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Description | ||
|
||
The `description` field is used to specify the description of the module. | ||
|
||
```json | ||
{ | ||
"description": "This is a description of the module." | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Keywords | ||
|
||
The `keywords` field is used to specify the keywords for the module. | ||
|
||
```json | ||
{ | ||
"keywords": ["example", "test"] | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# License | ||
|
||
The `license` field is used to specify the license of the module. The license type must comply with the [SPDX License List](https://spdx.org/licenses/). | ||
|
||
```json | ||
{ | ||
"license": "MIT" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Module Name | ||
|
||
The `name` field is used to specify the name of the module, and it is required. | ||
|
||
```json | ||
{ | ||
"name": "example", | ||
... | ||
} | ||
``` | ||
|
||
The module name can contain letters, numbers, `_`, `-`, and `/`. | ||
|
||
For modules published to [mooncakes.io](https://mooncakes.io), the module name must begin with the username. For example: | ||
|
||
```json | ||
{ | ||
"name": "moonbitlang/core", | ||
... | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# README | ||
|
||
The `readme` field is used to specify the path to the module's README file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Repository | ||
|
||
The `repository` field is used to specify the URL of the module's repository. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Source directory | ||
|
||
The `source` field is used to specify the source directory of the module. | ||
|
||
It must be a subdirectory of the directory where the `moon.mod.json` file is located and must be a relative path. | ||
|
||
When creating a module using the `moon new` command, a `src` directory will be automatically generated, and the default value of the `source` field will be `src`. | ||
|
||
```json | ||
{ | ||
"source": "src" | ||
} | ||
``` | ||
|
||
When the `source` field does not exist, or its value is `null` or an empty string `""`, it is equivalent to setting `"source": "."`. This means that the source directory is the same as the directory where the `moon.mod.json` file is located. | ||
|
||
```json | ||
{ | ||
"source": null | ||
} | ||
{ | ||
"source": "" | ||
} | ||
{ | ||
"source": "." | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Version | ||
|
||
The `version` field is used to specify the version of the module. | ||
|
||
This field is optional. For modules published to [mooncakes.io](https://mooncakes.io), the version number must follow the [Semantic Versioning 2.0.0](https://semver.org/spec/v2.0.0.html) specification. | ||
|
||
```json | ||
{ | ||
"name": "example", | ||
"version": "0.1.0", | ||
... | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Package Configuration | ||
|
||
moon uses the `moon.pkg.json` file to identify and describe a package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Alert List | ||
|
||
Disable user preset alerts. | ||
|
||
```json | ||
{ | ||
"alert-list": "-alert_1-alert_2" | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Conditional Compilation | ||
|
||
The smallest unit of conditional compilation is a file. | ||
|
||
In a conditional compilation expression, three logical operators are supported: `and`, `or`, and `not`, where the `or` operator can be omitted. | ||
|
||
For example, `["or", "wasm", "wasm-gc"]` can be simplified to `["wasm", "wasm-gc"]`. | ||
|
||
Conditions in the expression can be categorized into backends and optimization levels: | ||
|
||
- **Backend conditions**: `"wasm"`, `"wasm-gc"`, and `"js"` | ||
- **Optimization level conditions**: `"debug"` and `"release"` | ||
|
||
Conditional expressions support nesting. | ||
|
||
If a file is not listed in `"targets"`, it will be compiled under all conditions by default. | ||
|
||
Example: | ||
|
||
```json | ||
{ | ||
"targets": { | ||
"only_js.mbt": ["js"], | ||
"only_wasm.mbt": ["wasm"], | ||
"only_wasm_gc.mbt": ["wasm-gc"], | ||
"all_wasm.mbt": ["wasm", "wasm-gc"], | ||
"not_js.mbt": ["not", "js"], | ||
"only_debug.mbt": ["debug"], | ||
"js_and_release.mbt": ["and", ["js"], ["release"]], | ||
"js_only_test.mbt": ["js"], | ||
"js_or_wasm.mbt": ["js", "wasm"], | ||
"wasm_release_or_js_debug.mbt": ["or", ["and", "wasm", "release"], ["and", "js", "debug"]] | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# import | ||
|
||
The `import` field is used to specify other packages that a package depends on. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# is-main | ||
|
||
The `is-main` field is used to specify whether a package needs to be linked into an executable file. | ||
|
||
The output of the linking process depends on the backend. When this field is set to `true`: | ||
|
||
- For the `wasm` and `wasm-gc` backends, a standalone WebAssembly module will be generated. | ||
- For the `js` backend, a standalone JavaScript file will be generated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Link Options | ||
|
||
By default, moon only links packages where `is-main` is set to `true`. If you need to link other packages, you can specify this with the `link` option. | ||
|
||
The `link` option is used to specify link options, and its value can be either a boolean or an object. | ||
|
||
- When the `link` value is `true`, it indicates that the package should be linked. The output will vary depending on the backend specified during the build. | ||
|
||
```json | ||
{ | ||
"link": true | ||
} | ||
``` | ||
|
||
- When the `link` value is an object, it indicates that the package should be linked, and you can specify link options. For detailed configuration, please refer to the subpage for the corresponding backend. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# JS Backend Link Options | ||
|
||
#### Configurable Options | ||
|
||
- The `exports` option is used to specify the function names to export in the JavaScript module. | ||
|
||
For example, in the following configuration, the `hello` function from the current package is exported as the `hello` function in the JavaScript module. In the JavaScript host, the `hello` function can be called to invoke the `hello` function from the current package. | ||
|
||
```json | ||
{ | ||
"link": { | ||
"js": { | ||
"exports": [ | ||
"hello" | ||
] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
- The `format` option is used to specify the output format of the JavaScript module. | ||
|
||
The currently supported formats are: | ||
- `esm` | ||
- `cjs` | ||
- `iife` | ||
|
||
For example, the following configuration sets the output format of the current package to ES Module. | ||
|
||
```json | ||
{ | ||
"link": { | ||
"js": { | ||
"format": "esm" | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# wasm-gc Backend Link Options | ||
|
||
The link options for the `wasm-gc` backend are similar to those for the `wasm` backend, except there is no `heap-start-address` option. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# wasm Backend Link Options | ||
|
||
#### Configurable Options | ||
|
||
- The `exports` option is used to specify the function names exported by the `wasm` backend. | ||
|
||
For example, in the following configuration, the `hello` function from the current package is exported as the `hello` function in the `wasm` module, and the `foo` function is exported as the `bar` function in the `wasm` module. In the `wasm` host, the `hello` and `bar` functions can be called to invoke the `hello` and `foo` functions from the current package. | ||
|
||
```json | ||
{ | ||
"link": { | ||
"wasm": { | ||
"exports": [ | ||
"hello", | ||
"foo:bar" | ||
] | ||
} | ||
} | ||
} | ||
``` | ||
|
||
- The `heap-start-address` option is used to specify the starting address of the linear memory that can be used when compiling to the `wasm` backend. | ||
|
||
For example, the following configuration sets the starting address of the linear memory to 1024. | ||
|
||
```json | ||
{ | ||
"link": { | ||
"wasm": { | ||
"heap-start-address": 1024 | ||
} | ||
} | ||
} | ||
``` | ||
|
||
- The `import-memory` option is used to specify the linear memory imported by the `wasm` module. | ||
|
||
For example, the following configuration specifies that the linear memory imported by the `wasm` module is the `memory` variable from the `env` module. | ||
|
||
```json | ||
{ | ||
"link": { | ||
"wasm": { | ||
"import-memory": { | ||
"module": "env", | ||
"name": "memory" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
- The `export-memory-name` option is used to specify the name of the linear memory exported by the `wasm` module. | ||
|
||
```json | ||
{ | ||
"link": { | ||
"wasm": { | ||
"export-memory-name": "memory" | ||
} | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Name | ||
|
||
The package name is not configurable; it is determined by the directory name of the package. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Pre-build | ||
|
||
The `"pre-build"` field is used to specify pre-build commands, which will be executed before build commands such as `moon check|build|test`. | ||
|
||
`"pre-build"` is an array, where each element is an object containing `input`, `output`, and `command` fields. The `input` and `output` fields can be strings or arrays of strings, while the `command` field is a string. In the `command`, you can use any shell commands, as well as the `$input` and `$output` variables, which represent the input and output files, respectively. If these fields are arrays, they will be joined with spaces by default. | ||
|
||
Currently, there is a built-in special command `:embed`, which converts files into MoonBit source code. The `--text` parameter is used to embed text files, and `--binary` is used for binary files. `--text` is the default and can be omitted. The `--name` parameter is used to specify the generated variable name, with `resource` being the default. The command is executed in the directory where the `moon.pkg.json` file is located. | ||
|
||
```json | ||
{ | ||
"pre-build": [ | ||
{ | ||
"input": "a.txt", | ||
"output": "a.mbt", | ||
"command": ":embed -i $input -o $output" | ||
} | ||
] | ||
} | ||
``` | ||
|
||
If the content of `a.txt` in the current package directory is: | ||
``` | ||
hello, | ||
world | ||
``` | ||
|
||
After running `moon build`, the following `a.mbt` file will be generated in the directory where the `moon.pkg.json` is located: | ||
|
||
``` | ||
let resource : String = | ||
#|hello, | ||
#|world | ||
#| | ||
``` |
Oops, something went wrong.