Initial Commit

This commit is contained in:
SoraKatadzuma committed 2026-10-29 07:37:29 -05:00
commit bb5dd0f9dd
27 files changed
+5466

No files matched your search

+139
View File
@@ -0,0 +1,139 @@
#! @file project.sakura
#! @author John Christman (sorakatadzuma@gmail.com)
#! @copyright Malunal Studios, LLC.
#! @license MIT
#!
#! Contains what a blossomfile says of a project: who it is, its options, what
#! it requires, its targets and tests, what it exports, how it installs, and how
#! it is packaged.
import std::io;
module blossom::models;
#! An option of a project, and the value it has, as the text written.
pub struct setting {
pub var name: string;
pub var value: string;
}
#! What a target is.
pub enum target_kind: u8 {
program, #! A program, built into an executable.
library, #! A folder of modules, which programs read through `--lib`.
}
#! Where a test runs.
pub enum runner: u8 {
machine, #! On the machine, by `sakura run`.
native, #! Built into an executable, which is then run.
}
#! A target or a test of a project.
pub struct target {
pub var name: string;
pub var kind: target_kind;
pub var level: u32 = 2; #! `-O`, from 0 to 2.
pub var petal: bool; #! Whether it's built with `-g`.
pub var system: string; #! What it's built for, as `windows-x86_64`, or empty for the system blossom runs on.
pub var deps: vector<string>; #! The libraries it reads, by name, `std` among them or not.
pub var srcs: vector<string>; #! Its files, folders, and globs, relative to the project.
pub var opts: vector<string>; #! What's given to `sakura` as written.
pub var root: string; #! A library's folder, relative to the project.
pub var runs: runner; #! Where a test runs.
pub var checks: bool; #! Whether a test's memory is checked as it runs.
pub var args: vector<string>; #! What a test is given.
pub var line: u32; #! Where it's written.
}
#! A project another requires.
pub struct requirement {
pub var remote: string; #! A remote's address, or a folder relative to the blossomfile.
pub var branch: string; #! The branch or tag cloned, `main` unless written.
pub var local: bool; #! Whether it's a folder rather than a remote.
pub var options: vector<setting>; #! The values it's given for its options.
pub var line: u32; #! Where it's written.
}
#! A step of installing, beside what's installed by default.
pub struct step {
pub var tag: string; #! What it does, as `!include`.
pub var source: string; #! What it takes, relative to the project.
pub var dest: string; #! Where it goes under the prefix, or empty for the source's own place.
pub var line: u32; #! Where it's written.
}
#! How a project is described in its packages.
pub struct package_info {
pub var lic: string; #! Its license, as `MIT`.
pub var desc: string; #! What it is, in a line.
pub var auth: string; #! Who made it, as `Name <mail>`.
pub var url: string; #! Where it lives.
}
#! A project, as its blossomfile says it.
pub struct project {
pub var name: string;
pub var gpid: string;
pub var semv: string;
pub var folder: path; #! The folder holding its blossomfile, absolute.
pub var file: path; #! Its blossomfile.
pub var options: vector<setting>; #! Its options' values, in the order declared.
pub var requires: vector<requirement>;
pub var targets: vector<target>;
pub var tests: vector<target>;
pub var exports: vector<string>; #! The libraries other projects may read.
pub var install: vector<step>;
pub var package: package_info;
pub var key: string; #! Its output folder's name in `.blossom`.
}
#! Who the project is, as `malunal/hello@1.0.0`.
#! @param this The project.
#! @returns Its group, name, and version.
pub val project::identity: string {
get => $"{this.gpid}/{this.name}@{this.semv}";
}
#! The folder its outputs for these option values go to.
#! @param this The project.
#! @returns `.blossom/<key>` within its folder.
pub val project::output: path {
get => this.folder.join(".blossom").join(this.key.view());
}
#! Finds a target or test by its name.
#! @param this The project.
#! @param name The name.
#! @returns Where it is among the targets, then the tests after them, or
#! `nothing` where neither has it.
pub def project::find(&this, name: strview): maybe<u64> {
for k in 0..this.targets.length {
return k if this.targets[k].name.view() == name;
}
for k in 0..this.tests.length {
return this.targets.length + k if this.tests[k].name.view() == name;
}
return nothing {};
}
#! A target, or a test after the targets, by where `find` says it is.
#! @param this The project.
#! @param index Where it is.
#! @returns It.
pub def project::at(&this, index: u64): &target {
if index < this.targets.length {
return &this.targets[index];
}
return &this.tests[index - this.targets.length];
}
#! Whether the project lets others read a library.
#! @param this The project.
#! @param name The library's name.
#! @returns Whether `exports` names it.
pub def project::exported(&this, name: strview): bool {
for &each in this.exports {
return true if each.view() == name;
}
return false;
}