Before submitting your changes to the moon project, you must sign Contributor Copyright Assignment Agreement (CCAA), depending on who owns the copyright to your work:
- For individual contributors, you can sign it online by visiting https://moonbitlang.com/cla/moon.
- For corporate contributors, please download the CCAA from CCAA-IDEA_IDEA Legal_20240712_IDEA Legal20240722.pdf, sign it, and send it to us at jichuruanjian@idea.edu.cn.
The first thing is to install Rust toolchain and MoonBit toolchain, if you have not setup, referring to:
cargo build
cargo test
The tests for moon
depend on
expect-test. If your changes
affect the output of the tests, you can update the expected output:
env UPDATE_EXPECT=1 cargo test
cargo build
cargo test
$env:UPDATE_EXPECT=1; cargo test; Remove-Item Env:\UPDATE_EXPECT
The following command will install moon
from source code, it will be installed at ~/.cargo/bin/
.(note that the original moon
install via MoonBit CLI Tools is at ~/.moon/bin/
)
cargo install --path ./crates/moon
cargo install --path ./crates/moon --debug
# more faster
cargo install --path ./crates/moon --debug --offline
The following content is based on a28d2f1a, which may outdated as the project develops.
-
crates/moon
src/cli
: the command line interface ofmoon
src/cli/mooncake_adapter.rs
: forwards to themooncake
binarysrc/cli/generate_test_driver.rs
: as the name suggests
tests/test_cases/mod.rs
: all end-to-end tests are located in this file
-
crates/moonbuild
src/{check, gen, build, bundle, entry, runtest}
: generate commands and n2 state according tomoon.mod.json
andmoon.pkg.json
src/bundle.rs
: only formoonbitlang/core
, not visible to userssrc/bench.rs
: generates a project for benchmarking, will be moved tomoon new
src/dry_run.rs
: prints commands without executing them, mainly used by end-to-end tests.src/expect.rs
: the implementation of expect tests inmoon
src/upgrade.rs
: formoon upgrade
. We hope to move it to another binary crate, not mooncake, since depending on network in moonbuild does not make sense.
-
crates/mooncake
: package managersrc/pkg/add
:moon add
src/pkg/{install, sync}
:moon install
src/pkg/remove
:moon remove
src/pkg/tree
:moon tree
src/registry/online.rs
: downloads packages from mooncakes.iosrc/resolver/mvs.rs
: Go-like minimal version selection algorithm.
-
crates/moonutil
: currently not well organized, needs cleanupsrc/common.rs
: common definitions shared by other cratessrc/scan.rs
: scans the project directory to gather all structural informationsrc/moon_dir.rs
: gets the.moon
,core
, etc. directory paths and handles related environment variablessrc/build.rs
: formoon version
It's recommended to run the following command before you submit a PR, which may help discover some potential CI failure ASAP
cargo fmt
cargo clippy --all-targets --all-features -- -D warnings
cargo test
We use typos to avoid potential typos, you can also download and run it locally before PR.
To keep a clean and readable Git history, we follow a semi-linear history pattern. A semi-linear history looks like this:
$ git log --oneline --graph
*
|\
| *
|/
*
|\
| *
| *
|/
*
A semi-linear history improves readability, simplifies bug tracking.
Until GitHub supports this natively (see discussion: Support semi-linear history), we use rebase workflow and create a merge commit when merging a pull request to achieve a semi-linear history.
There are two ways to update branches: locally and on the GitHub Pull Request page.
- Fetch the latest changes:
git fetch
- Rebase your branch:
git rebase origin/main
When updating a branch on the GitHub Pull Request page, always use the "Update with Rebase" option instead of "Update with merge commit." This helps in maintaining the desired semi-linear history.