This directory contains a test toolchain for MoonBit that can be used for development and testing when the real MoonBit compiler is not available.
-
Create the test toolchain (already done):
bazel run //:test_toolchain.sh
-
Update your WORKSPACE file to use the local toolchain:
# In your WORKSPACE file: local_repository( name = "moonbit_toolchain", path = "moonbit_toolchain", ) register_toolchains("@moonbit_toolchain//:moonbit_toolchain")
-
Build your project:
bazel build //your/target:here
When the real MoonBit compiler becomes available:
-
Update the checksum registry with correct URLs and checksums:
- Edit
moonbit/checksums/moonbit.json - Add the correct SHA256 checksums for each platform
- Verify the download URLs are correct
- Edit
-
Use the hermetic toolchain in WORKSPACE:
load("//moonbit/tools:hermetic_toolchain.bzl", "moonbit_toolchain_repository") moonbit_toolchain_repository( name = "moonbit_toolchain", version = "0.6.33", # or your desired version ) register_toolchains("@moonbit_toolchain//:moonbit_toolchain")
If you have MoonBit installed locally:
-
Create a custom toolchain BUILD file:
# In a custom BUILD file: exports_files(["path/to/your/moon"]) filegroup( name = "moonbit_toolchain", srcs = ["path/to/your/moon"], )
-
Register your custom toolchain:
local_repository( name = "custom_moonbit_toolchain", path = "path/to/your/build/file", ) register_toolchains("@custom_moonbit_toolchain//:moonbit_toolchain")
moon- Placeholder MoonBit compiler executableBUILD.bazel- Bazel build file defining the toolchainWORKSPACE- WORKSPACE file for the toolchainREADME.md- This file
If you see errors about the MoonBit compiler not being found:
- Check your toolchain registration in WORKSPACE
- Verify the repository exists with
bazel query @moonbit_toolchain//... - Ensure the toolchain is registered with
bazel query @moonbit_toolchain//:moonbit_toolchain
If the hermetic toolchain fails to download:
- Check your internet connectivity
- Verify the MoonBit release exists at the specified URL
- Check GitHub rate limits (you may be rate-limited)
- Use the test toolchain as a fallback
If your platform is not supported:
- Check the supported platforms in
moonbit/checksums/moonbit.json - Add your platform to the checksum registry if it should be supported
- Use the test toolchain for development
- Consider contributing platform support to the project
The test toolchain creates dummy output files that simulate MoonBit compilation. This allows you to:
- Test the build system without the real compiler
- Develop rules and build logic
- Verify toolchain resolution works
- Test cross-platform builds
When the real MoonBit compiler becomes available, simply switch to the hermetic toolchain or local installation method.
If you want to help improve the MoonBit toolchain:
- Update checksums when new MoonBit versions are released
- Add support for new platforms as they become available
- Improve error handling and user experience
- Add more comprehensive tests
- Document best practices for MoonBit development
This test toolchain is provided under the Apache License 2.0, same as the main rules_moonbit project.