Skip to main content

LuaSource

Struct LuaSource 

Source
pub struct LuaSource { /* private fields */ }
Expand description

Evaluates build files on the airsl embedded runtime, one fresh engine per file.

A build file runs on airsl’s minimal Lua surface with no grants, under limits. It sees the buildl module table as both buildl and airsstack.buildl, and the curated modules json, path, regex, hash and glob under airsstack.

buildl.use(name) loads the plugin the source was built with a directory for under that name, and refuses any other name. A plugin runs under its own environment, narrowed from the build file’s, and every declaration it makes carries the plugin as its origin.

buildl.discover declares a discovery target. buildl.discovered(label) returns, as a Lua string, the bytes the map handed to evaluate holds for that target, or nil; a relative label resolves against the build file’s directory.

buildl.sources never lists a file under a directory the source was built to skip. A source built with the workspace’s output and state directories therefore keeps a build file at the workspace root from seeing what the build wrote.

§Examples

use std::collections::BTreeMap;
use std::fs;
use std::path::PathBuf;

use buildl_core::{BuildFile, DeclarationSource, Directory, Discovered, Evaluated, Provenance};
use buildl_lua::{DeclarationLimits, LuaSource};

let workspace = tempfile::tempdir()?;
let root = fs::canonicalize(workspace.path())?;
fs::write(root.join("build.lua"), "buildl.alias('default', 'app')")?;

let skipped = [Directory::parse("out")?, Directory::parse(".buildl")?];
let source = LuaSource::new(&root, DeclarationLimits::default(), skipped, BTreeMap::new());
let file = BuildFile::new(Provenance::new(PathBuf::from("build.lua"), Directory::root()));
assert!(matches!(
    source.evaluate(&file, &Discovered::empty())?,
    Evaluated::Staged(staged) if staged.declarations.len() == 1
));

Implementations§

Source§

impl LuaSource

Source

pub fn new( root: impl Into<PathBuf>, limits: DeclarationLimits, skipped: impl IntoIterator<Item = Directory>, plugins: BTreeMap<PluginName, PathBuf>, ) -> Self

A source for the workspace at root, evaluating under limits, whose buildl.sources stays out of skipped and whose buildl.use loads the plugins in plugins.

root must be the workspace root’s canonical, absolute path. buildl.sources walks beneath it and refuses any directory that resolves outside it.

skipped names workspace-relative directories. The walk neither lists, enters nor counts anything inside one. Each is matched by its whole path from the workspace root, so out skips <root>/out and not <root>/lib/out. A build file whose own directory is a skipped directory, or lies inside one, gets an empty list from buildl.sources. An empty skipped skips nothing: the walk then lists the workspace’s own output and state directories too.

plugins maps each plugin name a build file may use to the directory holding its extension.toml. The caller has already checked the directories, so this source reads them as given. A plugin’s require stays inside its own directory, however that directory is reached.

Trait Implementations§

Source§

impl Clone for LuaSource

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LuaSource

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl DeclarationSource for LuaSource

Source§

fn evaluate( &self, file: &BuildFile, discovered: &Discovered, ) -> Result<Evaluated>

Evaluates file; buildl.discovered reads discovered.

A file that does not exist is Evaluated::Absent.

§Errors

Returns Error::Evaluation when the file cannot be read, is not UTF-8, does not parse, raises, is refused an operation, reaches a ceiling, calls a buildl primitive with arguments it does not accept, or uses a plugin that is unknown, cyclic, malformed or raises. A refusal from a primitive is reported even when the build file caught it with pcall and carried on.

Source§

impl Eq for LuaSource

Source§

impl PartialEq for LuaSource

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for LuaSource

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> MaybeSync for T
where T: Sync,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.