native-toolchain

    Deterministic native compiler and linker discovery for MoonBit tools

    moonbit
    native
    toolchain
    compiler
    ffi
    Download zip
    Author
    Version
    0.1.1
    License
    MIT
    Last updated
    17 days ago
    Downloads
    161

    #unmbt/native-toolchain

    Deterministic native compiler and linker discovery for MoonBit build tools.

    The package centralizes the host and environment handling shared by native CLI, HTTP, and Node-API build scripts. It discovers the compiler, linker, archiver, symbol tool, and SDK while keeping explicit MOON_CC, MOON_LINK, MOON_AR, and MOON_NM overrides authoritative. Missing explicit tools are reported as diagnostics instead of silently falling back to another tool.

    #Install

    moon add unmbt/native-toolchain

    Then import the package from MoonBit:

    import "unmbt/native-toolchain"

    #Example

    let toolchain = @native_toolchain.discover()
    match toolchain.compiler {
    Some(tool) => println("native compiler: " + tool.path)
    None => for diagnostic in toolchain.diagnostics { println(diagnostic) }
    }

    discover(builder~="auto") selects cl/link/lib/dumpbin on Windows and cc/ar/nm on POSIX hosts. Set an explicit builder name when a project uses a non-default compiler. Toolchain::is_usable requires a compiler and linker and no diagnostics; the optional archiver, symbol tool, SDK, and tool paths remain available to callers that need to construct a native build.

    #Supported targets

    The package targets native and is intended for host-side build and release tools. It does not embed a compiler or ship platform binaries.

    #License

    MIT

    Host

    pub(all) enum Host {
    Windows
    Posix
    } derive(Eq,
    Debug
    )

    Tool

    pub struct Tool {
    name : String
    path : String
    } derive(Eq,
    Debug
    )

    Toolchain

    pub struct Toolchain {
    host : Host
    compiler : Tool?
    linker : Tool?
    archiver : Tool?
    symbol_tool : Tool?
    sdk : String?
    diagnostics : Array[String]
    } derive(
    Debug
    )

    Toolchain::is_usable

    fn Toolchain::is_usable(self : Toolchain) -> Bool

    discover

    async fn discover(builder? : String) -> Toolchain

    Resolve the native tools used by HTTP and Node-API builds.

    Explicit MOON_CC, MOON_CXX, MOON_AR, and MOON_NM values are authoritative. An explicit path that does not exist is reported as an error rather than silently replaced by another compiler.

    Source Files