/*!
* Project definitions & configurations.
*/
import '@cargo' as Rust;
import pkg '@github' as GitHub;
/// Cargo.toml definition.
Cargo cargo: {
package: {
name: 'stof'
authors: [
'CJ Cummings <cj@formata.io>'
]
description: 'Data that carries its own logic.'
license: 'Apache-2.0'
repository: 'https://github.com/dev-formata-io/stof'
homepage: 'https://docs.stof.dev'
keywords: [
'format',
'runtime',
'async',
'validation',
'embedded',
]
categories: [
'compilers',
'data-structures',
'development-tools',
'template-engine',
'asynchronous',
]
}
Target lib: {
crate-type: ['cdylib', 'lib']
bench: false
doctest: false
#[init]
fn init_name() {
// Set the lib name to "pystof" when building for python (default features contains "py" feature).
if (super.features.default.contains('py')) self.name = 'pystof';
}
}
features: {
default: ['basic']
basic: ['stof_std', 'system', 'pkg', 'log']
full: ['stof_std', 'system', 'pkg', 'log', 'image', 'docx', 'pdf', 'http', 'tokio', 'age_encrypt']
stof_std: []
system: []
pkg: ['dep:zip', 'dep:regex', 'dep:walkdir']
log: ['dep:log']
image: ['dep:image']
docx: ['dep:docx-rs']
pdf: ['dep:lopdf', 'image']
http: ['dep:reqwest']
tokio: ['dep:tokio']
age_encrypt: ['dep:age']
/// python bindings for stof with full functionality (TODO min/sandboxing)
/// when building for python, set this as the only "default" feature
py: [
'full',
'dep:pyo3',
]
/// wasm/js version of the runtime
/// should be the only feature enabled when building for the wasm target
js: [
'stof_std',
'age_encrypt',
'dep:js-sys',
'dep:wasm-bindgen',
'dep:serde-wasm-bindgen',
'dep:getrandom',
'dep:wasm-bindgen-futures',
'dep:web-sys',
'dep:console_error_panic_hook',
]
}
dependencies: {
base64: 0.22.1
bincode: 1.3.3
indexmap: {
version: 2.12.1
features: ['serde']
}
bytes: {
version: 1.11.0
features: ['serde']
}
colored: 3.0.0
docx-rs: {
version: 0.4.18
optional: true
}
image: {
version: 0.25.6
features: ['serde']
optional: true
}
lazy_static: 1.5.0
markdown: {
version: 1.0.0
features: ['serde']
}
nanoid: 0.4.0
lopdf: {
version: 0.37.0
features: ['serde']
optional: true
}
regex: {
version: 1.12.2
optional: true
}
serde: {
version: 1.0.228
features: ['derive', 'rc']
}
serde_json: {
version: 1.0.145
features: ['preserve_order']
}
serde_yaml: 0.9.34
toml: {
version: 0.9.8
features: ['preserve_order']
}
typetag: 0.2.21
urlencoding: 2.1.3
walkdir: {
version: 2.5.0
optional: true
}
zip: {
version: 4.5.0
optional: true
}
chrono: 0.4.42
tokio: {
version: 1.48.0
features: ['full']
optional: true
}
reqwest: {
version: 0.12.25
optional: true
features: ['blocking']
}
rustc-hash: 2.1.1
imbl: {
version: 6.1.0
features: ['serde', 'triomphe']
}
arcstr: {
version: 1.2.0
features: ['serde']
}
nom: 8.0.0
parking_lot: {
version: 0.12.5
features: ['serde']
}
age: {
version: 0.11.2
optional: true
features: ['web-sys'] // use web_sys::SystemTime when wasm target
}
log: {
version: 0.4.29
optional: true
}
web-time: {
version: 1.1.0
features: ['serde']
}
/*****************************************************************************
* Python features.
*****************************************************************************/
pyo3: {
version: 0.27.2
optional: true
features: [
'macros',
'chrono',
'chrono-tz',
'hashbrown',
'indexmap',
'generate-import-lib',
'extension-module',
]
}
/*****************************************************************************
* JS features.
*****************************************************************************/
wasm-bindgen: {
version: 0.2.106
optional: true
}
wasm-bindgen-futures: {
version: 0.4.56
optional: true
}
serde-wasm-bindgen: {
version: 0.6.5
optional: true
}
js-sys: {
version: 0.3.83
optional: true
}
getrandom: {
version: 0.2.15
optional: true
features: ['js']
}
web-sys: {
version: 0.3.83
optional: true
features: ['console', 'Window']
}
console_error_panic_hook: {
version: 0.1.7
optional: true
}
}
}
/// GitHub.
github: {
funding: 'dev-formata-io'
#[run]
workflows: [
{
name: 'Rust'
on: {
push: {
branches: ['main']
}
pull_request: {
branches: ['main']
}
}
env: {
CARGO_TERM_COLOR: 'always'
}
jobs: {
build: {
runs-on: 'ubuntu-latest'
steps: [
{
uses: 'actions/checkout@v4'
},
{
name: 'Build'
run: 'cargo build --verbose'
},
{
name: 'Run tests'
run: 'cargo test --verbose -- --nocapture'
}
]
}
}
} as GitHub.Workflow
]
#[run]
/// Generate GitHub FUNDING.yml.
fn generate_funding_yaml() {
const object = new { github: self.funding };
const yaml = stringify('yaml', object);
drop(object);
fs.write('.github/FUNDING.yml', yaml);
}
}
/// pyproject.toml definition.
pyproject: {
project: {
name: 'stof'
description: 'Data that carries its own logic.'
license: 'Apache-2.0'
authors: [
{
name: 'CJ Cummings'
email: 'cj@stof.dev'
}
]
readme: 'README.md'
requires-python: '>=3.7'
classifiers: [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
keywords: [
'format',
'runtime',
'validation',
'embedded',
]
urls: {
Documentation: 'https://docs.stof.dev'
Playground: 'https://play.stof.dev'
Repository: 'https://github.com/dev-formata-io/stof'
}
}
build-system: {
requires: ['maturin>=1,<2']
build-backend: 'maturin'
}
}
/*****************************************************************************
* Generate functions.
*****************************************************************************/
/// Generate Cargo.toml file.
async fn generate_cargo_toml() {
const out = await Rust.Cargo.generate(self.cargo, 0.9.2, update = false);
fs.write('Cargo.toml', out);
pln('Cargo .. ok');
}
/// Generate python project toml.
async fn generate_pyproject_toml() {
const out = stringify('toml', self.pyproject);
fs.write('pyproject.toml', out);
pln('pyproject .. ok');
}
/// Generate GitHub configurations.
async fn generate_github() {
self.github.run();
pln('GitHub .. ok');
}
/*****************************************************************************
* Main functions.
*****************************************************************************/
#[main]
/// `stof run project.stof`
fn main() {
await [
self.generate_cargo_toml(),
self.generate_github(),
];
pln('done');
}
#[javascript]
/// `stof run project.stof -a javascript`
fn javascript_main() {
// set js features
self.cargo.features.default = ['js'];
await [
self.generate_cargo_toml(),
self.generate_github(),
];
pln('javascript config done');
}
#[python]
/// `stof run project.stof -a python`
fn python_main() {
// set py features and name
self.cargo.features.default = ['py'];
self.cargo.lib.name = 'pystof';
await [
self.generate_cargo_toml(),
self.generate_github(),
self.generate_pyproject_toml(),
];
pln('python config done');
}