silk.build.tasks.
The standard tasks a project's tasks.silk starts from: build, run, dev and plan.
silk init writes a tasks.silk whose Build, Run, Dev and Plan variants each call one
function here with the project's own compilation, so a setting the project makes once reaches
every command and the editor. Each variant embeds Options, which gives it --release,
--optimization none|speed|size, --target <triple> and --debug true|false. silk test
stays the toolchain's own command.
Examples#
import silk.build.graph { Compilation, Options, BuildError }
import silk.build.tasks { Standard, StandardError }
import silk.cli.command { Command, CommandLine, Opt }
import silk.cli.task { Task, TaskSet }
import silk.collections.list { List }
import silk.mem.allocator { Allocator }
import silk.system.child_process { ChildProcess }
import silk.system.filesystem { FileSystem }
import silk.system.host_input { HostInput }
import silk.text.string { String }
union Tasks {
Build { pub options: Options, pub out: String },
Run { pub options: Options, pub arguments: List<String> },
Dev { pub options: Options, pub arguments: List<String> },
Plan { pub options: Options },
}
impl CommandLine for Tasks {
static fn command() -> Command<Tasks> {
return Command<Tasks>.make("tasks", "Build and run the program")
|> Command.variant("Build", "Build the program (use --release to optimize)")
|> Command.variant("Run", "Build the program and run it")
|> Command.variant("Dev", "Run the program, and restart it when a source changes")
|> Command.variant("Plan", "Write the editor compilation requests")
|> Command.flatten("options")
|> Command.option("out", Opt.about("Also copy the program to this directory"))
|> Command.arg("arguments", Opt.about("Arguments for the program, after --"))
}
}
effect fn compilation(options: &Options) -> Compilation
! BuildError
? &mut Allocator | &mut FileSystem | &mut HostInput {
return run Compilation.fromPackage(options)
}
impl TaskSet for Tasks {
effect fn perform(self: Tasks) -> ()
! StandardError
? &mut HostInput | &mut Allocator | &mut ChildProcess | &mut FileSystem {
match move self {
Tasks.Build { options, out } => run Standard.build(run compilation(&options), out.view())
Tasks.Run { options, arguments } => {
run Standard.start(run compilation(&options), &options, &arguments)
}
Tasks.Dev { options, arguments } => run Standard.dev(&options, &arguments)
Tasks.Plan { options } => run Standard.plan(run compilation(&options))
}
}
}
pub effect fn main() -> i32 ? &mut HostInput {
return run Task.main<Tasks>()
}Import as Standard with import silk.build.tasks { Standard }.
Public declarations: 2.
StandardError#
pub type StandardError = BuildError
| TaskError
| ProcessError
| FileError
| HostInputError
| OutOfMemoryError
| WriterErrorEvery failure a standard task can end with, for the perform of a tasks program whose variants
call Standard: a failed build, a program that ended with a nonzero status, or a file,
process, environment, memory or output failure.
Standard#
pub struct StandardThe standard tasks. Each takes the project's compilation, made from the command's Options,
so that one function of the project configures every task.
Implementation Standard#
impl StandardAssociated function build#
pub effect fn build(compilation: Compilation, out: string) -> ()
! BuildError
? &mut Allocator | &mut FileSystem | &mut HostInputBuilds compilation. Its artifacts stay at build/<target>/<mode>/<name>. When out is not
empty, they are also copied to the directory out, relative to the package directory, keeping
their names and permissions.
Errors#
BuildError when the compilation or one of its steps fails.
Associated function start#
pub effect fn start(compilation: Compilation, options: &Options, arguments: &List<String>) -> ()
! BuildError | TaskError
? &mut Allocator | &mut FileSystem | &mut HostInputBuilds compilation and runs its program with arguments, sharing the task's terminal and
environment, and waits for it. options are the ones compilation was made from: a
--target this machine cannot run is refused before anything is built.
Errors#
BuildError when the build fails; TaskError with the program's status when it ends
with a nonzero one, or status 2 for a target this machine cannot run.
Associated function plan#
pub effect fn plan(compilation: Compilation) -> ()
! BuildError
? &mut Allocator | &mut FileSystem | &mut HostInputWrites the editor's compilation requests for compilation to build/requests/, without
compiling it.
Errors#
BuildError when a step the requests need fails.
Associated function dev#
pub effect fn dev(options: &Options, arguments: &List<String>) -> ()
! TaskError | FileError | HostInputError | OutOfMemoryError
? &mut Allocator | &mut FileSystem | &mut HostInputRuns the project as silk run does, with options and arguments, and restarts it each time
a file under the package's src/ or its silk.toml changes. A build that fails is reported
and the next change tries again. It ends when the task is stopped, such as with Control-C,
and stops the program first. It needs macOS or Linux.
Errors#
TaskError when SILK_COMPILER or SILK_PROJECT_ROOT is not set, as outside silk, on
another system, or when the program cannot be started.
Category: Build.
Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, aarch64-unknown-linux-gnu-no-libc, x86_64-unknown-linux-gnu, x86_64-unknown-linux-gnu-no-libc, wasm32-unknown-unknown, wasm32-wasip1, wasm32-wasip2, x86_64-pc-windows-msvc, wasm64-unknown-unknown.