sun::cli
namespace · Source (opens in a new tab)
Parses command-line options and runs the selected compiler command.
Classes
- sun::cli::DependencyPathVariables (public)
- sun::cli::ProgramArguments (public)
Structs
- sun::cli::CompileJob (public)
- sun::cli::EarlyExit (public)
- sun::cli::SharedOptions (public)
- sun::cli::BuildRunOptions (public)
- sun::cli::TestOptions (public)
- sun::cli::FmtOptions (public)
Functions
- applyBuildRunSettings
- applySharedSettings
- buildMoonBundle
- compileEntrypoint
- compileTestBinary
- deriveOutputName
- isConfigInput
- isNoTestsError
- loadConfigInput
- makeCompileJob
- parseBuildRunArguments
- parseFmtArguments
- parseTestArguments
- renderUsage
- renderVersionLine
- reportEarlyExit
- reportSunError
- reportUnexpectedError
- runBundleCommand
- runCompileCommand
- runConfigBuildCommand
- runDefaultCommand
- runFmtCommand
- runJitCommand
- runTestCommand
- validateBuildRunOptions
applyBuildRunSettings
public · function · Source (opens in a new tab)
void sun::cli::applyBuildRunSettings(const BuildRunOptions &options)Put the default command's options into effect: the GitHub token, the target the library search is for, and the shared settings.
Applies the build and execution settings selected on the command line.
Related: BuildRunOptions
applySharedSettings
public · function · Source (opens in a new tab)
void sun::cli::applySharedSettings(const SharedOptions &shared)Put the shared options into effect: define the path variables, then set up the library search from the environment and the lib-path folders.
Applies command-line settings shared by compiler commands.
Related: SharedOptions
buildMoonBundle
public · function · Source (opens in a new tab)
int sun::cli::buildMoonBundle(const std::string &entrypoint, const std::filesystem::path &outputPath, const sun::moon_bundling::MoonBuildOptions &buildOptions)Build one .moon bundle from an entrypoint with a manifest, printing what went into it.
Builds a compiled Moon library from an entrypoint and bundle settings.
A bundle already built from the same inputs is left alone and reported as up to date unless buildOptions.forceRebuild is set. Returns the exit code.
Related: sun::moon_bundling::MoonBuildOptions
compileEntrypoint
public · function · Source (opens in a new tab)
int sun::cli::compileEntrypoint(const CompileJob &job)Compile one entrypoint: the production executable (when there is a main, or when there are no tests to build instead) plus the test binary (when the program has tests and no-test was not given).
Compiles and links a program entrypoint using the prepared job settings.
Prints errors and returns the exit code.
Related: CompileJob
compileTestBinary
public · function · Source (opens in a new tab)
int sun::cli::compileTestBinary(const CompileJob &job, bool hasExecutable=true)Compile only the job's test binary: tests kept, the runner synthesized, linked to the job's test binary name.
Builds the executable used to run the selected Sun tests.
hasExecutable says whether the program also yields an executable, which the test binary records for later runs. Throws SunError like any compile — including "no test functions
found" when the program has no tests; the caller decides what that means for it.
Related: CompileJob, SunError
deriveOutputName
public · function · Source (opens in a new tab)
std::string sun::cli::deriveOutputName(const std::string &entrypoint)The default artifact name for an entrypoint: its path without the .sun extension.
Derives the default output filename from the input entrypoint.
isConfigInput
public · function · Source (opens in a new tab)
bool sun::cli::isConfigInput(const std::string &input)True when the input argument is a sun-config.json rather than a .sun entrypoint.
Reports whether the input names a project configuration file.
A config with an entrypoints list stands in for its entrypoints on the command line.
isNoTestsError
public · function · Source (opens in a new tab)
bool sun::cli::isNoTestsError(const sun::support::SunError &error)True when the error says the program declares no test functions.
Recognizes the diagnostic produced when no tests are available.
Config runs treat that as "nothing to do" rather than a failure, since a library may simply have no tests yet.
Related: sun::support::SunError, Config
loadConfigInput
public · function · Source (opens in a new tab)
SunConfig sun::cli::loadConfigInput(const std::string &input, const std::string &targetTriple="", bool refreshSources=false)Parse the config named on the command line and insist it declares entrypoints — without them there is nothing to stand in for.
Loads project configuration for the selected compilation target.
Resolves Git sources and applies project paths to builds outside the project directory. refreshSources fetches a fresh revision even when a checkout is cached.
Related: sun::driver::SunConfig
makeCompileJob
public · function · Source (opens in a new tab)
CompileJob sun::cli::makeCompileJob(const BuildRunOptions &options)Fill a job from the command-line options.
Resolves command options into the inputs and outputs of a compilation job.
The output names are copied as given, so the caller still has to settle them.
Related: CompileJob, BuildRunOptions
parseBuildRunArguments
public · function · Source (opens in a new tab)
std::optional< EarlyExit > sun::cli::parseBuildRunArguments(const std::string &programName, const std::vector< std::string > &args, BuildRunOptions &options)Parse the default command (run, compile or bundle) and check the result with validateBuildRunOptions.
Parses command-line arguments into build run options and reports early exits.
programName appears in the help text.
Related: EarlyExit, BuildRunOptions
parseFmtArguments
public · function · Source (opens in a new tab)
std::optional< EarlyExit > sun::cli::parseFmtArguments(const std::vector< std::string > &args, FmtOptions &options)Parse sun fmt.
Parses command-line arguments into fmt options and reports early exits.
Related: EarlyExit, FmtOptions
parseTestArguments
public · function · Source (opens in a new tab)
std::optional< EarlyExit > sun::cli::parseTestArguments(const std::vector< std::string > &args, TestOptions &options)Parse sun test.
Parses command-line arguments into test options and reports early exits.
Related: EarlyExit, TestOptions
renderUsage
public · function · Source (opens in a new tab)
std::string sun::cli::renderUsage(const std::string &programName)The full help text.
Returns the command-line help text for the supplied program name.
programName is how the user invoked the compiler.
renderVersionLine
public · function · Source (opens in a new tab)
std::string sun::cli::renderVersionLine()The line sun --version prints: version number and git commit hash.
Returns the compiler version text displayed by the command line.
reportEarlyExit
public · function · Source (opens in a new tab)
int sun::cli::reportEarlyExit(const EarlyExit &earlyExit)Print an early exit's text on its stream and return its exit code.
Prints an early-exit message to its selected output stream.
Related: EarlyExit
reportSunError
public · function · Source (opens in a new tab)
int sun::cli::reportSunError(const sun::support::SunError &error)Print a compile error and return the failing exit code.
Prints a compiler diagnostic for the command-line user.
Related: sun::support::SunError
reportUnexpectedError
public · function · Source (opens in a new tab)
int sun::cli::reportUnexpectedError(const std::exception &error)Print any other exception, marked as an error, and return the failing exit code.
Prints an unexpected exception as a command-line failure.
runBundleCommand
public · function · Source (opens in a new tab)
int sun::cli::runBundleCommand(const BuildRunOptions &options)sun emit-moon [-o <file>] <entrypoint.sun> Bundles the first input file, to the -o path or a default next to it.
Runs the bundle command and returns its process exit status.
Related: BuildRunOptions
runCompileCommand
public · function · Source (opens in a new tab)
int sun::cli::runCompileCommand(const BuildRunOptions &options)sun -c [-o <file>] <script.sun>... and sun emit-obj ... Compiles the input files, naming the output after the first one unless -o says otherwise.
Runs the compile command and returns its process exit status.
Related: BuildRunOptions
runConfigBuildCommand
public · function · Source (opens in a new tab)
int sun::cli::runConfigBuildCommand(const BuildRunOptions &options)sun -c sun-config.json Builds every declared entrypoint, stopping at the first failure.
Runs the config build command and returns its process exit status.
A binary becomes an executable plus its test binary. A library becomes a .moon bundle plus, when it has tests, its test binary.
Related: BuildRunOptions
runDefaultCommand
public · function · static · Source (opens in a new tab)
static int sun::cli::runDefaultCommand(const std::string &programName, const std::vector< std::string > &args)The default command: bundle, compile or run, depending on the flags.
runFmtCommand
public · function · Source (opens in a new tab)
int sun::cli::runFmtCommand(const std::vector< std::string > &args)sun fmt [check] <file.sun|directory>... Formats files in place; directories are searched recursively for .sun files.
Runs the fmt command and returns its process exit status.
With check nothing is rewritten and files that would change are listed instead. Every file is processed before exiting. Exit codes: 0 = clean/formatted, 1 = check found differences, 2 = parse or I/O error. args are the arguments after fmt.
runJitCommand
public · function · Source (opens in a new tab)
int sun::cli::runJitCommand(const BuildRunOptions &options)sun [options] <script.sun>... [ args...] Compiles the input files in memory and runs main with the JIT.
Runs the jit command and returns its process exit status.
The arguments after reach main(argc, argv), and main's i32 result becomes the exit code. A sun-config.json input runs its single binary entrypoint.
Related: BuildRunOptions
runTestCommand
public · function · Source (opens in a new tab)
int sun::cli::runTestCommand(const std::vector< std::string > &args)sun test [options] <script.sun> [ args...] Compiles the entrypoint with tests enabled and JIT-runs the synthesized runner.
Runs the test command and returns its process exit status.
test-sequential, test-filter <pattern> and everything after are forwarded to the runner's main. A sun-config.json as the entrypoint runs every configured entrypoint's tests in turn. Returns 0 only when every test passed. args are the arguments after test.
validateBuildRunOptions
public · function · Source (opens in a new tab)
std::optional< EarlyExit > sun::cli::validateBuildRunOptions(const BuildRunOptions &options, const std::string &programName)Find the first combination of flags that makes no sense, such as static without -c.
Checks for incompatible or incomplete build and execution options.
Returns nothing when the options are consistent.
Related: EarlyExit, BuildRunOptions
Variables
kFmtUsage
public · variable · Source (opens in a new tab)
const char *const sun::cli::kFmtUsage =
"Usage: sun fmt [--check] <file.sun|directory>...\n"No documentation comment.
kTestUsageBrief
public · variable · Source (opens in a new tab)
const char *const sun::cli::kTestUsageBrief =
"Usage: sun test [--test-sequential] "
"[--test-filter <pattern>] <script.sun> [-- args...]\n"No documentation comment.
kTestUsageFull
public · variable · Source (opens in a new tab)
const char *const sun::cli::kTestUsageFull =
"Usage: sun test [--test-sequential] "
"[--test-filter <pattern>] [--debug] [-g] [-O0] "
"[--emit-ir] [--moon <spec>] [--lib-path <dir>] "
"<script.sun> [-- args...]\n"No documentation comment.
Related: debug