silk.core.compilation.
Build choices of the current compilation, such as safety, threading, and artifact kind, for use in static evaluation.
When to use#
Use Compilation to select code for the build request, for example with static if. Use
Compilation.safety to select checked or unchecked library code, and
Compilation.threading to select single-thread or multi-thread code. Use silk.core.target for
facts about the machine, such as the architecture and the pointer width.
Details#
Each value comes from the compilation profile, which is fixed before specialization. The values
describe logical requests. They do not find SDKs, load runtime packages, or change the ownership
rules. Each operation in this module is static, so the selection adds no runtime cost.
Examples#
Select code for the safety policy#
import silk.core.compilation { Compilation, Safety }
fn boundsChecked() -> bool {
static if Compilation.safety() == Safety.Checked {
return true
}
return false
}
pub fn main() -> i32 {
let checked = boundsChecked()
return 0
}Import as Compilation with import silk.core.compilation { Compilation }.
Public declarations: 13.
Libc#
pub enum LibcThe C library that the build requests.
Details#
Read the selected value with Compilation.libc.
None#
NoneNo C library. The program uses only Silk code and direct system calls.
System#
SystemThe C library of the platform, such as the libc of macOS.
Gnu#
GnuThe GNU C library (glibc).
Artifact#
pub enum ArtifactThe kind of output file that the build requests.
Details#
Read the selected value with Compilation.artifact.
Executable#
ExecutableA program that the operating system can start.
LoadableModule#
LoadableModuleA module that a host program loads at runtime, such as a shared library or a WebAssembly module.
StaticArchive#
StaticArchiveA static library archive for a later link step.
Object#
ObjectOne relocatable object file.
Link#
pub enum LinkThe link mode that the build requests.
Details#
Read the selected value with Compilation.link.
Static#
StaticStatic linking. The artifact includes its dependencies.
Dynamic#
DynamicDynamic linking. The artifact loads shared libraries at startup.
CodeModel#
pub enum CodeModelThe code model that the build requests.
Details#
Read the selected value with Compilation.codeModel.
Small#
SmallThe small code model. Code and static data must be in a limited address range.
Large#
LargeThe large code model. Code and static data can be at any address.
Relocation#
pub enum RelocationThe relocation model that the build requests.
Details#
Read the selected value with Compilation.relocation.
Static#
StaticCode for a fixed load address.
Pic#
PicPosition-independent code, which can load at any address.
Optimization#
pub enum OptimizationThe optimization level that the build requests.
Details#
Read the selected value with Compilation.optimization.
None#
NoneNo optimization.
Speed#
SpeedOptimization for speed.
Size#
SizeOptimization for code size.
Safety#
pub enum SafetyThe library safety policy that the build requests.
Details#
Read the selected value with Compilation.safety.
Checked#
CheckedThe library does its runtime checks.
Unchecked#
UncheckedLibrary code can omit runtime checks. The caller is responsible for valid inputs.
Threading#
pub enum ThreadingThe library threading policy that the build requests.
Details#
Read the selected value with Compilation.threading.
Single#
SingleThe program has one thread. The library can use code without synchronization.
Multi#
MultiThe program can have more than one thread. The library uses synchronized code.
Unwind#
pub enum UnwindThe unwind mode that the build requests.
Details#
Read the selected value with Compilation.unwind.
None#
NoneNo unwind tables.
Native#
NativeUnwind tables for the native platform.
Selection#
pub union SelectionAn entry or runtime request: the platform default, none, or a named symbol or package.
Details#
Compilation.entry and Compilation.runtime return this type. A name is a logical
identity, not a file path.
Default#
DefaultThe default of the platform.
None#
NoneNo entry point or no runtime.
Named#
NamedA named symbol or package.
Field name#
pub name: string<'static>The logical name of the symbol or package.
Sanitizer#
pub enum SanitizerA sanitizer that a build can request.
Details#
Test a sanitizer with Compilation.hasSanitizer. A build can request more than one sanitizer.
Address#
AddressAddress checks for instrumented memory operations.
Thread#
ThreadData-race checks for instrumented concurrent operations.
Undefined#
UndefinedChecks for instrumented undefined behavior.
debug#
pub const debug: booltrue if the build requests debug information.
Compilation#
pub struct CompilationThe owner type of the compilation queries. It has no fields and is never constructed.
Details#
Each operation is static. Use it in a static if, a static fn, or a const initializer.
Implementation Compilation#
impl CompilationAssociated function libc#
pub static fn libc() -> LibcReturns the C library that the build requests.
Associated function artifact#
pub static fn artifact() -> ArtifactReturns the kind of output file that the build requests.
Associated function link#
pub static fn link() -> LinkReturns the link mode that the build requests.
Associated function codeModel#
pub static fn codeModel() -> CodeModelReturns the code model that the build requests.
Associated function relocation#
pub static fn relocation() -> RelocationReturns the relocation model that the build requests.
Associated function optimization#
pub static fn optimization() -> OptimizationReturns the optimization level that the build requests.
Associated function safety#
pub static fn safety() -> SafetyReturns the library safety policy that the build requests.
When to use#
Use safety to select between checked and unchecked library code, for example to omit bounds
checks in an unchecked build.
Associated function threading#
pub static fn threading() -> ThreadingReturns the library threading policy that the build requests.
When to use#
Use threading to select between code with and without synchronization.
Associated function unwind#
pub static fn unwind() -> UnwindReturns the unwind mode that the build requests.
Associated function entry#
pub static fn entry() -> SelectionReturns the entry point request of the build.
Details#
The result is a logical request. This function does not find a startup symbol.
Associated function runtime#
pub static fn runtime() -> SelectionReturns the runtime request of the build.
Details#
The result is a logical request. This function does not load a runtime package.
Associated function hasSanitizer#
pub static fn hasSanitizer(value: Sanitizer) -> boolReturns true if the build requests the sanitizer value.
Category: Core.
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.