diff --git a/.cargo/config b/.cargo/config deleted file mode 100644 index d8c2032b..00000000 --- a/.cargo/config +++ /dev/null @@ -1,2 +0,0 @@ -[alias] -xtask = "run --manifest-path ./xtask/Cargo.toml --" diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 2c4e0673..8d4a17fd 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,11 +1,11 @@ version: 2 updates: - - package-ecosystem: github-actions + - package-ecosystem: cargo directory: / schedule: interval: daily - - package-ecosystem: cargo - directory: /xtask + - package-ecosystem: github-actions + directory: / schedule: interval: daily - package-ecosystem: cargo @@ -13,26 +13,18 @@ updates: schedule: interval: daily - package-ecosystem: cargo - directory: /crates/compilers + directory: /core schedule: interval: daily - package-ecosystem: cargo - directory: /crates/conduits + directory: /derive schedule: interval: daily - package-ecosystem: cargo - directory: /crates/core + directory: /macros schedule: interval: daily - package-ecosystem: cargo - directory: /crates/gateways + directory: /net schedule: interval: daily - - package-ecosystem: cargo - directory: /crates/net - schedule: - interval: daily - - package-ecosystem: cargo - directory: /crates/pipelines - schedule: - interval: daily \ No newline at end of file diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index bfe65aa8..a69bb803 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -10,6 +10,8 @@ on: push: branches: [ "main", "master", "prod" ] tags: [ "prod-*", "v*.*.*" ] + release: + types: [ published ] schedule: - cron: "30 9 * * *" workflow_dispatch: @@ -33,20 +35,19 @@ jobs: - uses: actions/checkout@v3 - run: rustup update ${{ matrix.toolchain }} && rustup default ${{ matrix.toolchain }} - run: cargo build --release -v --workspace - - run: cargo test --all --all-features --release -v + - run: cargo test --all -F full --release -v features: if: ${{ github.event.inputs.publish }} name: Publish + needs: [ build ] runs-on: ubuntu-latest strategy: matrix: package: - - acme-compilers - - acme-conduits - acme-core - - acme-gateways + - acme-derive + - acme-macros - acme-net - - acme-pipelines steps: - uses: actions/checkout@v3 - name: Publish (${{matrix.package}}) diff --git a/.gitpod.yml b/.gitpod.yml index 42fad13c..b6598339 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -3,5 +3,5 @@ tasks: rustup default nightly rustup target add wasm32-unknown-unknown wasm32-wasi --toolchain nightly rustup component add clippy rustfmt --toolchain nightly - cargo build --workspace --release + cargo build -F full --workspace --release command: cargo watch -x test --all \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index f95f7201..3723fbb1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,7 +5,8 @@ edition = "2021" homepage = "https://github.com/FL03/acme/wikis" license = "Apache-2.0" repository = "https://github.com/FL03/acme" -version = "0.2.4" # TODO - Update cargo package version +readme = "README.md" +version = "0.2.5" # TODO - Update cargo package version [workspace] default-members = [ @@ -14,9 +15,17 @@ default-members = [ exclude = [ "xtask" ] members = [ "acme", - "crates/*", + "core", + "derive", + "macros", + "net", ] +[workspace.dependencies] +scsys = { features = ["full"], version = "0.1.41" } +serde = { features = ["derive"], version = "1" } +serde_json = "1" + [profile.dev] codegen-units = 256 debug = true diff --git a/README.md b/README.md index cb6edb9d..7d9bb3d1 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ [![Clippy](https://github.com/FL03/acme/actions/workflows/clippy.yml/badge.svg)](https://github.com/FL03/acme/actions/workflows/clippy.yml) [![Rust](https://github.com/FL03/acme/actions/workflows/rust.yml/badge.svg)](https://github.com/FL03/acme/actions/workflows/rust.yml) +[![crates.io](https://img.shields.io/crates/v/acme.svg)](https://crates.io/crates/acme) +[![docs.rs](https://docs.rs/acme/badge.svg)](https://docs.rs/acme) *** diff --git a/acme/Cargo.toml b/acme/Cargo.toml index 2c6e6c1a..1ca40cb0 100644 --- a/acme/Cargo.toml +++ b/acme/Cargo.toml @@ -1,16 +1,17 @@ [package] -authors = ["FL03 (https://github.com)"] categories = [] -description = "Acme is a complete development toolkit for extending platform functionality" -edition = "2021" -homepage = "https://github.com/scattered-systems/acme/wikis" keywords = ["async", "scsys"] -license = "Apache-2.0" name = "acme" publish = true -readme = "README.md" -repository = "https://github.com/scattered-systems/acme" -version = "0.2.4" # TODO - Update cargo package version + +authors.workspace = true +description.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +version.workspace = true [lib] crate-type = ["cdylib", "rlib"] @@ -18,26 +19,28 @@ test = true [features] default = ["core"] -full = ["conduits", "core", "compilers", "extras", "gateways", "net", "pipelines",] +full = [ + "core", + "derive", + "extras", + "macros", + "net", +] core = ["acme-core"] +derive = ["acme-derive/default"] +macros = ["acme-macros/default"] extras = [] net = ["acme-net"] -conduits = ["acme-conduits"] -compilers = ["acme-compilers"] -gateways = ["acme-gateways"] -pipelines = ["acme-pipelines"] [build-dependencies] [dependencies] -acme-conduits = { features = [], optional = true, path = "../crates/conduits", version = "0.2.4" } -acme-core = { features = [], optional = true, path = "../crates/core", version = "0.2.4" } -acme-compilers = { features = [], optional = true, path = "../crates/compilers", version = "0.2.4" } -acme-gateways = { features = [], optional = true, path = "../crates/gateways", version = "0.2.4" } -acme-net = { features = [], optional = true, path = "../crates/net", version = "0.2.4" } -acme-pipelines = { features = [], optional = true, path = "../crates/pipelines", version = "0.2.4" } +acme-core = { features = [], optional = true, path = "../core", version = "0.2.5" } +acme-derive = { features = [], optional = true, path = "../derive", version = "0.2.5" } +acme-macros = { features = [], optional = true, path = "../macros", version = "0.2.5" } +acme-net = { features = [], optional = true, path = "../net", version = "0.2.5" } [package.metadata.docs.rs] all-features = true diff --git a/acme/src/lib.rs b/acme/src/lib.rs index be374fe0..5d9a9a86 100644 --- a/acme/src/lib.rs +++ b/acme/src/lib.rs @@ -5,32 +5,20 @@ Acme was inspired by projects like Python's FastAPI, seeking to simplify the creation of powerful Rust-native applications targeting WebAssembly runtime's. Additionally, Acme services the ecosystem by forming the basis of our composable runtime environment facilitated by the tandem between Proton, Flow, and Reaction. */ -#[cfg(feature = "compilers")] -pub use acme_compilers as compilers; -#[cfg(feature = "conduits")] -pub use acme_conduits as conduits; #[cfg(feature = "core")] pub use acme_core::*; -#[cfg(feature = "gateways")] -pub use acme_gateways as gateways; +#[cfg(feature = "derive")] +pub use acme_derive::*; +#[cfg(feature = "macros")] +pub use acme_macros::*; #[cfg(feature = "net")] pub use acme_net as net; -#[cfg(feature = "pipelines")] -pub use acme_pipelines as pipelines; pub mod prelude { + pub use super::*; - #[cfg(feature = "compilers")] - pub use super::compilers::*; - #[cfg(feature = "conduits")] - pub use super::conduits::*; - #[cfg(feature = "gateways")] - pub use super::gateways::*; #[cfg(feature = "net")] pub use super::net::*; - #[cfg(feature = "pipelines")] - pub use super::pipelines::*; - pub use super::*; #[cfg(feature = "core")] - pub use super::{events::*, sessions::*}; + pub use super::{events::*, handlers::*, sessions::*}; } diff --git a/core/Cargo.toml b/core/Cargo.toml new file mode 100644 index 00000000..965d0490 --- /dev/null +++ b/core/Cargo.toml @@ -0,0 +1,43 @@ +[package] +description = "acme" +name = "acme-core" + +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +version.workspace = true + +[features] +default = [ "cli"] +full = [ "cli" ] + +cli = [ "clap/cargo", "clap/derive", "clap/default", "clap/env"] + +[lib] +crate-type = ["cdylib", "rlib"] +test = true + +[build-dependencies] + +[dev-dependencies] + +[dependencies] +scsys.workspace = true +serde.workspace = true +serde_json.workspace = true + +async-trait = "0.1" +axum-core = "0.3" +clap = { features = ["cargo", "derive", "env"], optional = true, version = "4" } +decanter = { features = ["derive"], version = "0.1.3" } +futures = "0.3" +strum = { features = ["derive"], version = "0.24" } +tokio = { features = ["macros", "process", "signal", "sync"], version = "1" } +tracing-subscriber = "0.3" + +[package.metadata.docs.rs] +all-features = true +rustc-args = ["--cfg", "docsrs"] diff --git a/crates/core/src/events/event.rs b/core/src/events/event.rs similarity index 83% rename from crates/core/src/events/event.rs rename to core/src/events/event.rs index 6acace02..0951cc54 100644 --- a/crates/core/src/events/event.rs +++ b/core/src/events/event.rs @@ -3,21 +3,25 @@ Contrib: FL03 Description: ... Summary ... */ -use super::{EventSpec, Eventful}; -use scsys::prelude::Message; +use crate::{EventSpec, Eventful}; +use decanter::prelude::{Hash, Hashable}; +use scsys::prelude::{Message, Timestamp}; use serde::{Deserialize, Serialize}; -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] pub struct Event { pub event: E, pub message: Message, + pub timestamp: i64, } impl Event { pub fn new(event: E, message: Option) -> Self { + let timestamp = Timestamp::default().into(); Self { event, message: message.unwrap_or_default(), + timestamp, } } } @@ -80,6 +84,7 @@ mod tests { #[test] fn test_events_default() { let a = Event::::default(); + a.hash(); assert_eq!(a.event(), crate::events::Events::None); } } diff --git a/crates/core/src/events/mod.rs b/core/src/events/mod.rs similarity index 95% rename from crates/core/src/events/mod.rs rename to core/src/events/mod.rs index a1d1491f..78aaecbf 100644 --- a/crates/core/src/events/mod.rs +++ b/core/src/events/mod.rs @@ -3,7 +3,7 @@ Contrib: FL03 Description: ... Summary ... */ -pub use self::{event::*, opts::*, specs::*}; +pub use self::{event::*, opts::*}; pub(crate) mod event; pub(crate) mod opts; diff --git a/crates/core/src/events/opts.rs b/core/src/events/opts.rs similarity index 95% rename from crates/core/src/events/opts.rs rename to core/src/events/opts.rs index 379e5db9..b240cbc2 100644 --- a/crates/core/src/events/opts.rs +++ b/core/src/events/opts.rs @@ -3,7 +3,7 @@ Contrib: FL03 Description: ... Summary ... */ -use super::{Event, Eventful}; +use crate::{events::Event, Eventful}; use scsys::prelude::Message; use serde::{Deserialize, Serialize}; diff --git a/core/src/handlers/handler.rs b/core/src/handlers/handler.rs new file mode 100644 index 00000000..44d19bde --- /dev/null +++ b/core/src/handlers/handler.rs @@ -0,0 +1,20 @@ +/* + Appellation: handler + Contrib: FL03 + Description: ... summary ... +*/ +use serde::{Deserialize, Serialize}; + +pub type TransitionFunction = dyn Fn(S) -> T; + +pub trait Transition { + type Output; + + fn data(&self) -> S; + fn transition(&self, dirac: &TransitionFunction) -> Self::Output { + dirac(self.data()) + } +} + +#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] +pub struct Handler; diff --git a/core/src/handlers/mod.rs b/core/src/handlers/mod.rs new file mode 100644 index 00000000..c9c05a22 --- /dev/null +++ b/core/src/handlers/mod.rs @@ -0,0 +1,30 @@ +/* + Appellation: handlers + Contrib: FL03 + Description: ... summary ... +*/ +pub use self::handler::*; + +pub(crate) mod handler; + +pub(crate) mod specs { + use async_trait::async_trait; + + /// + #[async_trait] + pub trait AsyncHandle: Clone + Send + Sync { + type Error: std::error::Error + Send + Sync; + + async fn handler(&self) -> Result<&Self, Self::Error> + where + Self: Sized; + } + /// + pub trait Handle: Clone { + type Error: std::error::Error + 'static; + + fn handler(&self) -> Result<&Self, Self::Error> + where + Self: Sized; + } +} diff --git a/core/src/lib.rs b/core/src/lib.rs new file mode 100644 index 00000000..b63c4a98 --- /dev/null +++ b/core/src/lib.rs @@ -0,0 +1,65 @@ +/* + Appellation: acme-core + Contrib: FL03 + Description: ... Summary ... +*/ +pub use self::{primitives::*, specs::*, utils::*}; + +pub mod events; +pub mod handlers; +pub mod sessions; + +pub(crate) mod primitives; +pub(crate) mod utils; + +pub(crate) mod specs; + +pub use crate::events::specs::*; +pub use crate::handlers::specs::*; + +use async_trait::async_trait; +use scsys::prelude::{AsyncResult, Logger, Result}; + +/// +#[async_trait] +pub trait AsyncSpawnable { + async fn spawn(&mut self) -> AsyncResult<&Self>; +} +/// +pub trait BaseApplication: BaseObject + Versionable { + fn application(&self) -> &Self { + self + } + fn namespace(&self) -> String; +} + +/// +pub trait BaseObject { + fn count(&self) -> usize; + fn name(&self) -> String; + fn slug(&self) -> String { + self.name().to_ascii_lowercase() + } + fn symbol(&self) -> String; +} +/// +pub trait Spawnable { + fn spawn(&mut self) -> Result<&Self>; +} +/// +pub trait Traceable { + fn with_tracing(&self, level: Option<&str>) -> AsyncResult<&Self> { + // TODO: Introduce a more refined system of tracing logged events + let mut logger = Logger::new(level.unwrap_or("info").to_string()); + logger.setup(None); + tracing_subscriber::fmt::init(); + Ok(self) + } +} +/// +pub trait Versionable { + type Error; + + fn update(&mut self) -> Result<()>; + fn version(&self) -> String; +} diff --git a/crates/core/src/primitives.rs b/core/src/primitives.rs similarity index 100% rename from crates/core/src/primitives.rs rename to core/src/primitives.rs diff --git a/crates/core/src/sessions/mod.rs b/core/src/sessions/mod.rs similarity index 100% rename from crates/core/src/sessions/mod.rs rename to core/src/sessions/mod.rs diff --git a/crates/core/src/sessions/session.rs b/core/src/sessions/session.rs similarity index 88% rename from crates/core/src/sessions/session.rs rename to core/src/sessions/session.rs index 668bc64c..d4235823 100644 --- a/crates/core/src/sessions/session.rs +++ b/core/src/sessions/session.rs @@ -3,11 +3,12 @@ Contrib: FL03 Description: ... summary ... */ -use scsys::prelude::{Event, Timestamp}; +use crate::events::Event; +use scsys::prelude::Timestamp; use serde::{Deserialize, Serialize}; use std::convert::From; -#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] +#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] pub struct Session { pub events: Vec, pub timestamp: i64, diff --git a/core/src/specs/apps.rs b/core/src/specs/apps.rs new file mode 100644 index 00000000..82826b5e --- /dev/null +++ b/core/src/specs/apps.rs @@ -0,0 +1,30 @@ +/* + Appellation: application + Contrib: FL03 + Description: ... summary ... +*/ +use crate::AsyncSpawnable; +use scsys::prelude::{AsyncResult, Configurable, Contextual, Locked}; + +/// Implements the base interface for creating compatible platform applications +pub trait AppSpec: Default + AsyncSpawnable { + type Ctx: Contextual; + type State; + fn init() -> Self; + fn context(&self) -> Self::Ctx; + fn name(&self) -> String; + fn settings(&self) -> Cnf; + fn setup(&mut self) -> AsyncResult<&Self>; + fn slug(&self) -> String { + self.name().to_ascii_lowercase() + } + fn state(&self) -> &Locked; +} + +pub struct Application(Ctx); + +impl Application { + pub fn new() -> Self { + Self(Default::default()) + } +} diff --git a/crates/core/src/specs/cli.rs b/core/src/specs/cli.rs similarity index 67% rename from crates/core/src/specs/cli.rs rename to core/src/specs/cli.rs index f1bd0c36..1daecb49 100644 --- a/crates/core/src/specs/cli.rs +++ b/core/src/specs/cli.rs @@ -3,9 +3,13 @@ Contrib: FL03 Description: ... summary ... */ -use super::{AsyncHandler, Handler}; use clap::{Parser, Subcommand}; +pub trait CLIAction { + type Action: clap::FromArgMatches; +} + +/// pub trait Commands: Clone + Default + Subcommand { fn command(&self) -> Self where @@ -15,9 +19,8 @@ pub trait Commands: Clone + Default + Subcommand { } } -pub trait AsyncCommands: Commands + AsyncHandler {} - -pub trait CliSpec: Parser { +/// +pub trait CLISpec: Parser { type Cmds: Commands; fn new() -> Self { @@ -27,7 +30,3 @@ pub trait CliSpec: Parser { where Self: Sized; } - -pub trait CliSpecExt: CliSpec + Handler {} - -pub trait AsyncCliSpec: CliSpec + AsyncHandler {} diff --git a/core/src/specs/mod.rs b/core/src/specs/mod.rs new file mode 100644 index 00000000..88d77ed4 --- /dev/null +++ b/core/src/specs/mod.rs @@ -0,0 +1,10 @@ +/* + Appellation: specs + Contrib: FL03 + Description: ... summary ... +*/ +pub use self::{apps::*, cli::*}; + +pub(crate) mod apps; +#[cfg(feature = "cli")] +pub(crate) mod cli; diff --git a/core/src/utils.rs b/core/src/utils.rs new file mode 100644 index 00000000..ff4beefa --- /dev/null +++ b/core/src/utils.rs @@ -0,0 +1,12 @@ +/* + Appellation: utils + Contrib: FL03 + Description: ... Summary ... +*/ +use crate::{Host, Port}; +use std::net::SocketAddr; + +/// Simple function wrapper for creating [SocketAddr] from its pieces: ([Host], [Port]) +pub fn socket_address(host: Host, port: Port) -> SocketAddr { + SocketAddr::from((host, port)) +} diff --git a/crates/compilers/tests/default.rs b/core/tests/default.rs similarity index 100% rename from crates/compilers/tests/default.rs rename to core/tests/default.rs diff --git a/crates/compilers/Cargo.toml b/crates/compilers/Cargo.toml deleted file mode 100644 index b40b2151..00000000 --- a/crates/compilers/Cargo.toml +++ /dev/null @@ -1,37 +0,0 @@ -[package] -authors = ["FL03 (https://github.com/FL03)"] -categories = [] -description = "acme" -edition = "2021" -homepage = "https://github.com/FL03/acme/wiki" -keywords = ["scsys"] -license = "Apache-2.0" -name = "acme-compilers" -repository = "https://github.com/FL03/acme" -version = "0.2.4" - -[lib] -crate-type = ["cdylib", "rlib"] -test = true - -[build-dependencies] - -[dev-dependencies] - -[dependencies] -async-trait = "0.1.59" -axum = "0.6.1" -hyper = { features = ["full"], version = "0.14.23" } -http = "0.2.8" -http-body = "0.4.5" -scsys = { features = ["full"], version = "0.1.38" } -serde = { features = ["derive"], version = "1" } -serde_json = "1" -strum = { features = ["derive"], version = "0.24.1" } -tokio = { features = ["macros"], version = "1.23.0" } -tracing = { features = [], version = "0.1.37" } -wasmer = { features = [], version = "3.0.2" } - -[package.metadata.docs.rs] -all-features = true -rustc-args = ["--cfg", "docsrs"] diff --git a/crates/compilers/src/compiler.rs b/crates/compilers/src/compiler.rs deleted file mode 100644 index 595f670b..00000000 --- a/crates/compilers/src/compiler.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* - Appellation: compiler - Contrib: FL03 - Description: ... Summary ... -*/ -use crate::states::{CompilerState, CompilerStates}; -use std::sync::Arc; - -#[derive(Clone, Debug, Eq, PartialEq)] -pub struct Compiler { - state: Arc, -} - -impl Compiler { - pub fn set_state(&mut self, state: CompilerStates) -> &Self { - self.state = Arc::new(CompilerState::new(None, None, Some(state))); - self - } - pub fn init(&mut self) -> &Self { - self.set_state(CompilerStates::init()); - self - } - - pub fn read_input(&mut self) -> &Self { - self.set_state(CompilerStates::read()); - // read the input WebAssembly code - // ... - // return the next state - self - } - - pub fn compile(&mut self) -> &Self { - self.set_state(CompilerStates::compile()); - // compile the input WebAssembly code using Wasmer - // ... - // return the next state - self - } - - pub fn write_output(&mut self) -> &Self { - self.set_state(CompilerStates::write()); - // write the compiled WebAssembly code to the output - // ... - // return the next state - self - } - - pub fn finish(&mut self) -> &Self { - self.set_state(CompilerStates::complete()); - // clean up and finalize the compilation process - // ... - // return the final state - self - } - - pub fn run(&mut self) { - // update the current state of the state-machine - // by calling the appropriate state method based - // on the current state - } -} diff --git a/crates/compilers/src/lib.rs b/crates/compilers/src/lib.rs deleted file mode 100644 index a218fa5b..00000000 --- a/crates/compilers/src/lib.rs +++ /dev/null @@ -1,9 +0,0 @@ -/* - Appellation: pzzld-compilers - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::compiler::*; - -pub(crate) mod compiler; -pub mod states; diff --git a/crates/compilers/src/states/compiler.rs b/crates/compilers/src/states/compiler.rs deleted file mode 100644 index 5ac31736..00000000 --- a/crates/compilers/src/states/compiler.rs +++ /dev/null @@ -1,108 +0,0 @@ -/* - Appellation: compiler - Contrib: FL03 - Description: ... Summary ... -*/ -use scsys::prelude::{fnl_remove, StatePack}; -use serde::{Deserialize, Serialize}; -use std::convert::From; -use strum::{EnumString, EnumVariantNames}; - -#[derive( - Clone, Copy, Debug, Deserialize, EnumString, EnumVariantNames, Eq, Hash, PartialEq, Serialize, -)] -#[strum(serialize_all = "snake_case")] -pub enum CompilerStates { - Idle = 0, - Init = 1, - Read = 2, - Compile = 3, - Write = 4, - Complete = 5, - Invalid = 6, -} - -impl CompilerStates { - pub fn idle() -> Self { - Self::Idle - } - pub fn init() -> Self { - Self::Init - } - pub fn invalid() -> Self { - Self::Invalid - } - pub fn read() -> Self { - Self::Read - } - pub fn write() -> Self { - Self::Write - } - pub fn compile() -> Self { - Self::Compile - } - pub fn complete() -> Self { - Self::Complete - } -} - -impl StatePack for CompilerStates {} - -impl std::fmt::Display for CompilerStates { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!( - f, - "{}", - fnl_remove(serde_json::to_string(self).unwrap()).to_ascii_lowercase() - ) - } -} - -impl Default for CompilerStates { - fn default() -> Self { - Self::Idle - } -} - -impl From for CompilerStates { - fn from(data: i64) -> Self { - match data { - 0 => Self::idle(), - 1 => Self::init(), - 2 => Self::read(), - 3 => Self::compile(), - 4 => Self::write(), - 5 => Self::complete(), - _ => Self::invalid(), - } - } -} - -impl From for i64 { - fn from(data: CompilerStates) -> Self { - match data { - CompilerStates::Idle => 0, - CompilerStates::Init => 1, - CompilerStates::Read => 2, - CompilerStates::Compile => 3, - CompilerStates::Write => 4, - CompilerStates::Complete => 5, - CompilerStates::Invalid => 6, - } - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_compiler_state() { - let a: i64 = CompilerStates::default().into(); - assert_eq!(a, 0i64); - assert_eq!( - CompilerStates::try_from("idle").ok().unwrap(), - CompilerStates::from(a) - ) - } -} diff --git a/crates/compilers/src/states/mod.rs b/crates/compilers/src/states/mod.rs deleted file mode 100644 index 7837ce0a..00000000 --- a/crates/compilers/src/states/mod.rs +++ /dev/null @@ -1,10 +0,0 @@ -/* - Appellation: states - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::compiler::*; - -pub(crate) mod compiler; - -pub type CompilerState = scsys::prelude::State; diff --git a/crates/conduits/Cargo.toml b/crates/conduits/Cargo.toml deleted file mode 100644 index 4b589702..00000000 --- a/crates/conduits/Cargo.toml +++ /dev/null @@ -1,30 +0,0 @@ -[package] -authors = ["FL03 (https://github.com/FL03)"] -categories = [] -description = "acme" -edition = "2021" -homepage = "https://github.com/FL03/acme/wiki" -keywords = ["scsys"] -license = "Apache-2.0" -name = "acme-conduits" -repository = "https://github.com/FL03/acme" -version = "0.2.4" - -[lib] -crate-type = ["cdylib", "rlib"] -test = true - -[build-dependencies] - -[dependencies] -mio = "0.8.4" -scsys = { features = ["full"], version = "0.1.38" } -serde = { features = ["derive"], version = "1" } -serde_json = "1" -strum = { features = ["derive"], version = "0.24.1" } -tokio = { features = ["macros"], version = "1.21.2" } - -[dev-dependencies] -acme-core = { path = "../core" } - -[target.wasm32-unknown-unknown] diff --git a/crates/conduits/src/lib.rs b/crates/conduits/src/lib.rs deleted file mode 100644 index f3b4f653..00000000 --- a/crates/conduits/src/lib.rs +++ /dev/null @@ -1,15 +0,0 @@ -/* - Appellation: acme-conduits - Contrib: FL03 - Description: - A conduit describes a viable surface which facilitates at least one, if not all, of the four possible types of interactions. - Those interactions describe the different engagements the system may undergo and follow the logic below - I Peer-to-Peer (P -> P) - II Peer-to-Machine (P -> M) - III Machine-to-Machine (M -> M) - IV Machine-to-Peer (M -> P) -*/ - -pub mod api; -pub mod cli; -pub mod rpc; diff --git a/crates/conduits/src/rpc/mod.rs b/crates/conduits/src/rpc/mod.rs deleted file mode 100644 index 8b137891..00000000 --- a/crates/conduits/src/rpc/mod.rs +++ /dev/null @@ -1 +0,0 @@ - diff --git a/crates/core/Cargo.toml b/crates/core/Cargo.toml deleted file mode 100644 index bc19c6a2..00000000 --- a/crates/core/Cargo.toml +++ /dev/null @@ -1,42 +0,0 @@ -[package] -authors = ["FL03 (https://github.com/FL03)"] -categories = [] -description = "acme" -edition = "2021" -homepage = "https://github.com/FL03/acme/wiki" -keywords = ["scsys"] -license = "Apache-2.0" -name = "acme-core" -repository = "https://github.com/FL03/acme" -version = "0.2.4" - -[features] -default = [ "cli"] -full = [ "cli" ] - -cli = [ "clap/cargo", "clap/derive", "clap/default", "clap/env"] - -[lib] -crate-type = ["cdylib", "rlib"] -test = true - -[build-dependencies] - -[dev-dependencies] - -[dependencies] -async-trait = "0.1.60" -axum-core = "0.3.0" -clap = { features = ["cargo", "derive", "env"], optional = true, version = "4.0.29" } -config = "0.13.3" -futures = "0.3.25" -scsys = { features = ["full"], version = "0.1.38" } -serde = { features = ["derive"], version = "1" } -serde_json = "1" -strum = { features = ["derive"], version = "0.24.1" } -tokio = { features = ["full"], version = "1.23.0" } -tracing-subscriber = "0.3.16" - -[package.metadata.docs.rs] -all-features = true -rustc-args = ["--cfg", "docsrs"] diff --git a/crates/core/src/lib.rs b/crates/core/src/lib.rs deleted file mode 100644 index f4a8db5b..00000000 --- a/crates/core/src/lib.rs +++ /dev/null @@ -1,16 +0,0 @@ -/* - Appellation: acme-core - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::{primitives::*, specs::*, utils::*}; - -pub mod events; -pub mod sessions; - -pub(crate) mod primitives; -pub(crate) mod utils; - -pub(crate) mod specs; - -pub trait Tracable {} diff --git a/crates/core/src/specs/apps.rs b/crates/core/src/specs/apps.rs deleted file mode 100644 index 441665ec..00000000 --- a/crates/core/src/specs/apps.rs +++ /dev/null @@ -1,35 +0,0 @@ -/* - Appellation: application - Contrib: FL03 - Description: ... summary ... -*/ -use super::AsyncSpawable; -use scsys::prelude::{BoxResult, Locked, Logger}; - -/// Implements the base interface for creating compatible platform applications -pub trait AppSpec: Default + AsyncSpawable { - type Cnf; - type Ctx; - type State; - fn init() -> Self; - fn context(&self) -> Self::Ctx; - fn name(&self) -> String; - fn settings(&self) -> Self::Cnf; - fn setup(&mut self) -> BoxResult<&Self>; - fn slug(&self) -> String { - self.name().to_ascii_lowercase() - } - fn state(&self) -> &Locked; -} - -/// Extends the core interface to include logging capabilities -pub trait ApplicationLoggerSpec: AppSpec { - /// Creates a service handle for toggling the tracing systems implemented - fn with_tracing(&self, level: Option<&str>) -> BoxResult<&Self> { - // TODO: Introduce a more refined system of tracing logged events - let mut logger = Logger::new(level.unwrap_or("info").to_string()); - logger.setup(None); - tracing_subscriber::fmt::init(); - Ok(self) - } -} diff --git a/crates/core/src/specs/mod.rs b/crates/core/src/specs/mod.rs deleted file mode 100644 index 0ef117e6..00000000 --- a/crates/core/src/specs/mod.rs +++ /dev/null @@ -1,62 +0,0 @@ -/* - Appellation: specs - Contrib: FL03 - Description: ... summary ... -*/ -pub use self::{apps::*, cli::*}; - -pub(crate) mod apps; -#[cfg(feature = "cli")] -pub(crate) mod cli; - -use async_trait::async_trait; - -/// -#[async_trait] -pub trait AsyncHandler: Clone + Send + Sync { - type Error: std::error::Error + Send + Sync + 'static; - - async fn handler(&self) -> Result<&Self, Self::Error> - where - Self: Sized; -} -/// -#[async_trait] -pub trait AsyncSpawable { - async fn spawn(&mut self) -> scsys::AsyncResult<&Self>; -} -/// -pub trait BaseApplication: BaseObject + Versionable { - fn application(&self) -> &Self { - self - } - fn namespace(&self) -> String; -} -/// -pub trait BaseObject { - fn count(&self) -> usize; - fn name(&self) -> String; - fn slug(&self) -> String { - self.name().to_ascii_lowercase() - } - fn symbol(&self) -> String; -} -/// -pub trait Handler: Clone { - type Error: std::error::Error + 'static; - - fn handler(&self) -> Result<&Self, Self::Error> - where - Self: Sized; -} -/// -pub trait Spawnable { - fn spawn(&mut self) -> scsys::Result<&Self>; -} -/// -pub trait Versionable { - type Error; - - fn update(&mut self) -> Result<(), Box>; - fn version(&self) -> String; -} diff --git a/crates/core/src/utils.rs b/crates/core/src/utils.rs deleted file mode 100644 index 5a7b9ed6..00000000 --- a/crates/core/src/utils.rs +++ /dev/null @@ -1,5 +0,0 @@ -/* - Appellation: utils - Contrib: FL03 - Description: ... Summary ... -*/ diff --git a/crates/core/tests/default.rs b/crates/core/tests/default.rs deleted file mode 100644 index 5a2a8993..00000000 --- a/crates/core/tests/default.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -#[test] -fn lib_compiles() { - let f = |l: usize, r: usize| l + r; - let result = f(2, 2); - assert_eq!(result, 4); -} diff --git a/crates/gateways/Cargo.toml b/crates/gateways/Cargo.toml deleted file mode 100644 index 12b9cdb0..00000000 --- a/crates/gateways/Cargo.toml +++ /dev/null @@ -1,32 +0,0 @@ -[package] -authors = ["FL03 (https://github.com/FL03)"] -categories = [] -description = "acme" -edition = "2021" -homepage = "https://github.com/FL03/acme/wiki" -keywords = ["scsys"] -license = "Apache-2.0" -name = "acme-gateways" -repository = "https://github.com/FL03/acme" -version = "0.2.4" - -[lib] -crate-type = ["cdylib", "rlib"] -test = true - -[dependencies] -async-trait = "0.1" -axum = { features =["headers", "http2", "macros", "ws"], version = "0.6.0" } -clap = { features = ["derive"], version = "4.0.29" } -http = "0.2.8" -hyper = { features = ["full"], version = "0.14.23" } -lru = "0.8.1" -rust-s3 = {features = ["with-tokio"], version = "0.32.3" } -scsys = { features = ["full"], version = "0.1.38" } -serde = { features = ["derive"], version = "1" } -serde_json = "1" -tokio = { features = ["full"], version = "1.22.0" } -tower = "0.4.13" -tower-http = { features = ["full"], version = "0.3.4" } -tracing = "0.1.37" -tracing-subscriber = { features = ["env-filter"], version = "0.3.16" } diff --git a/crates/gateways/src/api/mod.rs b/crates/gateways/src/api/mod.rs deleted file mode 100644 index ba89b2b7..00000000 --- a/crates/gateways/src/api/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* - Appellation: api - Contrib: FL03 - Description: ... Summary ... -*/ - -pub mod routes; diff --git a/crates/gateways/src/api/routes/mod.rs b/crates/gateways/src/api/routes/mod.rs deleted file mode 100644 index b1d89d95..00000000 --- a/crates/gateways/src/api/routes/mod.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* - Appellation: routes - Contrib: FL03 - Description: ... Summary ... -*/ - -pub mod s3; diff --git a/crates/gateways/src/api/routes/s3/buckets.rs b/crates/gateways/src/api/routes/s3/buckets.rs deleted file mode 100644 index 38abde22..00000000 --- a/crates/gateways/src/api/routes/s3/buckets.rs +++ /dev/null @@ -1,63 +0,0 @@ -/* - Appellation: buckets - Contrib: FL03 - Description: ... Summary ... -*/ -use crate::{collect_obj_names, contexts::Context, fetch_bucket_contents}; -use axum::{ - extract::{Path, Query}, - routing::get, - Extension, Json, Router, -}; -use scsys::prelude::Message; -use serde::{Deserialize, Serialize}; -use serde_json::{json, Value}; - -pub fn router() -> Router { - Router::new() - .route("/bucket", get(landing)) - .route("/bucket/:name", get(fetch_bucket_object_names)) -} - -// Base path for the S3 Gateway -pub async fn landing(Extension(ctx): Extension) -> Json { - let mut auth = false; - if ctx.credentials().access_key.is_some() && ctx.credentials().secret_key.is_some() { - auth = true - } - let msg = Message::from(json!({ - "auth": auth, - "message": "S3 Gateway" - })); - Json(msg) -} - -#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub struct BucketParams { - pub delim: Option, - pub name: String, - pub path: Vec, - pub prefix: Option, -} - -// Given -pub async fn fetch_bucket_object_names( - Extension(ctx): Extension, - Path(name): Path, - Query(params): Query, -) -> Json { - let delim = Some(params.delim.unwrap_or_else(|| "/".to_string())); - let prefix = params.prefix.unwrap_or_else(|| "/".to_string()); - let bucket = ctx.bucket(params.name.as_str()).expect(""); - let objects = fetch_bucket_contents(bucket, prefix.as_str(), delim) - .await - .unwrap_or_default(); - let names = collect_obj_names(objects).await; - let payload = json!({"name": name, "data": names}); - Json(payload) -} - -pub async fn list_bucket_contents() -> Json { - let payload = json!({"": ""}); - Json(payload) -} diff --git a/crates/gateways/src/api/routes/s3/mod.rs b/crates/gateways/src/api/routes/s3/mod.rs deleted file mode 100644 index 260ed31c..00000000 --- a/crates/gateways/src/api/routes/s3/mod.rs +++ /dev/null @@ -1,11 +0,0 @@ -/* - Appellation: s3 - Contrib: FL03 - Description: ... Summary ... -*/ - -pub mod buckets; - -pub fn buckets() -> axum::Router { - buckets::router() -} diff --git a/crates/gateways/src/config/creds.rs b/crates/gateways/src/config/creds.rs deleted file mode 100644 index 0e7520e6..00000000 --- a/crates/gateways/src/config/creds.rs +++ /dev/null @@ -1,62 +0,0 @@ -/* - Appellation: creds - Contrib: FL03 - Description: ... Summary ... -*/ -use s3::creds::Credentials; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub struct GatewayCreds { - pub access_key: String, - pub(crate) secret_key: String, -} - -impl GatewayCreds { - pub fn new(access_key: String, secret_key: String) -> Self { - Self { - access_key, - secret_key, - } - } - pub fn from_env( - &mut self, - access_key: Option<&str>, - secret_key: Option<&str>, - ) -> scsys::BoxResult<&Self> { - self.access_key = std::env::var(access_key.unwrap_or("S3_ACCESS_KEY"))?; - self.secret_key = std::env::var(secret_key.unwrap_or("S3_SECRET_KEY"))?; - Ok(self) - } -} - -impl std::fmt::Display for GatewayCreds { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", serde_json::json!({"access_key": &self.access_key})) - } -} - -impl std::convert::TryFrom for GatewayCreds { - type Error = Box; - fn try_from(data: Credentials) -> Result { - if data.access_key.is_some() & data.secret_key.is_some() { - let res = Self::new(data.access_key.unwrap(), data.secret_key.unwrap()); - Ok(res) - } else { - panic!("Failed to find any credentials") - } - } -} - -impl std::convert::TryFrom for Credentials { - type Error = s3::creds::error::CredentialsError; - fn try_from(data: GatewayCreds) -> Result { - Credentials::new( - Some(data.access_key.as_str()), - Some(data.secret_key.as_str()), - None, - None, - None, - ) - } -} diff --git a/crates/gateways/src/config/mod.rs b/crates/gateways/src/config/mod.rs deleted file mode 100644 index 80342585..00000000 --- a/crates/gateways/src/config/mod.rs +++ /dev/null @@ -1,120 +0,0 @@ -/* - Appellation: config - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::{creds::*, regions::*, settings::*}; - -pub(crate) mod creds; -pub(crate) mod regions; - -pub(crate) mod settings { - use super::*; - use s3::{creds::Credentials, Region}; - use scsys::prelude::{ - config::{Config, Environment}, - try_collect_config_files, AsyncResult, ConfigResult, - }; - use serde::{Deserialize, Serialize}; - - #[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] - pub struct GatewayConfig { - pub access_key: String, - pub(crate) secret_key: String, - pub endpoint: String, - pub region: String, - } - - impl GatewayConfig { - pub fn new( - access_key: String, - secret_key: String, - endpoint: String, - region: String, - ) -> Self { - Self { - access_key, - secret_key, - endpoint, - region, - } - } - pub fn build() -> ConfigResult { - let mut builder = Config::builder() - .add_source(Environment::default().prefix("S3").separator("_")) - .set_default("access_key", "")? - .set_default("secret_key", "")? - .set_default("endpoint", "https://gateway.storjshare.io")? - .set_default("region", "us-east-1")?; - - if let Ok(v) = try_collect_config_files("**/*.config.*", false) { - builder = builder.add_source(v); - }; - if let Ok(v) = std::env::var("S3_ACCESS_KEY") { - builder = builder.set_override("access_key", v)?; - } - if let Ok(v) = std::env::var("S3_SECRET_KEY") { - builder = builder.set_override("secret_key", v)?; - } - - builder.build()?.try_deserialize() - } - pub fn partial_env( - access_key: Option<&str>, - secret_key: Option<&str>, - endpoint: String, - region: String, - ) -> AsyncResult { - let access_key = std::env::var(access_key.unwrap_or("S3_ACCESS_KEY"))?; - let secret_key = std::env::var(secret_key.unwrap_or("S3_SECRET_KEY"))?; - Ok(Self::new(access_key, secret_key, endpoint, region)) - } - pub fn credentials(&self) -> Credentials { - let cred = GatewayCreds::new(self.access_key.clone(), self.secret_key.clone()); - cred.try_into().ok().unwrap() - } - pub fn region(&self) -> Region { - Region::Custom { - endpoint: self.endpoint.clone(), - region: self.region.clone(), - } - } - } - - impl std::convert::From<&GatewayCreds> for GatewayConfig { - fn from(data: &GatewayCreds) -> Self { - let region = S3Region::default(); - Self::new( - data.access_key.clone(), - data.secret_key.clone(), - region.endpoint(), - region.region(), - ) - } - } - - impl std::convert::From<&S3Region> for GatewayConfig { - fn from(data: &S3Region) -> Self { - let cred = GatewayCreds::default(); - Self::new( - cred.access_key.clone(), - cred.secret_key, - data.endpoint(), - data.region(), - ) - } - } - - impl Default for GatewayConfig { - fn default() -> Self { - Self::partial_env( - None, - None, - "https://gateway.storjshare.io".to_string(), - "us-east-1".to_string(), - ) - .ok() - .unwrap() - } - } -} diff --git a/crates/gateways/src/config/regions.rs b/crates/gateways/src/config/regions.rs deleted file mode 100644 index eb611fff..00000000 --- a/crates/gateways/src/config/regions.rs +++ /dev/null @@ -1,68 +0,0 @@ -/* - Appellation: regions - Contrib: FL03 - Description: ... Summary ... -*/ -use s3::Region; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub struct S3Region { - pub endpoint: String, - pub region: String, -} - -impl S3Region { - pub fn new(endpoint: String, region: String) -> Self { - Self { endpoint, region } - } - pub fn endpoint(&self) -> String { - self.endpoint.clone() - } - pub fn region(&self) -> String { - self.region.clone() - } - pub fn update_endpoint(&mut self, endpoint: String) -> &Self { - self.endpoint = endpoint; - self - } - pub fn update_region(&mut self, region: String) -> &Self { - self.region = region; - self - } -} - -impl Default for S3Region { - fn default() -> Self { - Self::new( - "https://gateway.storjshare.io".to_string(), - "us-east-1".to_string(), - ) - } -} - -impl std::fmt::Display for S3Region { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", serde_json::to_string(&self).unwrap()) - } -} - -impl std::convert::From<(&str, &str)> for S3Region { - fn from(data: (&str, &str)) -> Self { - Self::new(data.0.to_string(), data.1.to_string()) - } -} -impl std::convert::From<&Region> for S3Region { - fn from(data: &Region) -> Self { - Self::new(data.clone().endpoint(), data.clone().host()) - } -} - -impl std::convert::From<&S3Region> for Region { - fn from(data: &S3Region) -> Self { - Self::Custom { - endpoint: data.clone().endpoint, - region: data.clone().region, - } - } -} diff --git a/crates/gateways/src/contexts/context.rs b/crates/gateways/src/contexts/context.rs deleted file mode 100644 index a83ff95e..00000000 --- a/crates/gateways/src/contexts/context.rs +++ /dev/null @@ -1,28 +0,0 @@ -/* - Appellation: context - Contrib: FL03 - Description: ... Summary ... -*/ -use crate::config::GatewayConfig; -use s3::{error::S3Error, Bucket}; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub struct Context { - pub cnf: GatewayConfig, -} - -impl Context { - pub fn new(cnf: GatewayConfig) -> Self { - Self { cnf } - } - pub fn credentials(&self) -> s3::creds::Credentials { - self.cnf.credentials() - } - pub fn region(&self) -> s3::Region { - self.cnf.region() - } - pub fn bucket(&self, name: &str) -> Result { - Bucket::new(name, self.region(), self.credentials()) - } -} diff --git a/crates/gateways/src/contexts/mod.rs b/crates/gateways/src/contexts/mod.rs deleted file mode 100644 index ae87d178..00000000 --- a/crates/gateways/src/contexts/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -/* - Appellation: contexts - Contrib: FL03 - Description: ... Summary ... -*/ -#[doc(inline)] -pub use self::context::*; - -pub(crate) mod context; diff --git a/crates/gateways/src/gateway.rs b/crates/gateways/src/gateway.rs deleted file mode 100644 index 9106dcba..00000000 --- a/crates/gateways/src/gateway.rs +++ /dev/null @@ -1,57 +0,0 @@ -/* - Appellation: gateway - Contrib: FL03 - Description: ... Summary ... -*/ -use crate::config::{GatewayConfig, GatewayCreds, S3Region}; -use s3::{creds::Credentials, error::S3Error, Bucket, Region}; -use serde::{Deserialize, Serialize}; -use std::convert::From; - -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct Gateway { - pub cnf: GatewayConfig, -} - -impl Gateway { - pub fn new(creds: GatewayCreds, region: S3Region) -> Self { - let cnf = GatewayConfig::new( - creds.access_key.clone(), - creds.secret_key, - region.endpoint(), - region.region(), - ); - Self { cnf } - } - pub fn credentials(&self) -> Credentials { - let cred = GatewayCreds::new(self.cnf.access_key.clone(), self.cnf.secret_key.clone()); - cred.try_into().ok().unwrap() - } - pub fn region(&self) -> Region { - Region::Custom { - endpoint: self.cnf.endpoint.clone(), - region: self.cnf.region.clone(), - } - } - pub fn bucket(&self, name: &str) -> Result { - Bucket::new(name, self.region(), self.credentials()) - } -} - -impl From<&S3Region> for Gateway { - fn from(value: &S3Region) -> Self { - Self::new(Default::default(), value.clone()) - } -} - -impl From<&Gateway> for Credentials { - fn from(value: &Gateway) -> Self { - value.credentials() - } -} - -impl From<&Gateway> for Region { - fn from(value: &Gateway) -> Self { - value.region() - } -} diff --git a/crates/gateways/src/lib.rs b/crates/gateways/src/lib.rs deleted file mode 100644 index 24cc9f2a..00000000 --- a/crates/gateways/src/lib.rs +++ /dev/null @@ -1,18 +0,0 @@ -/* - Appellation: pzzld-gateway - Contrib: FL03 - Description: ... Summary ... -*/ -#[doc(inline)] -pub use self::{gateway::*, primitives::*, utils::*}; - -pub mod api; -pub mod config; -pub mod contexts; -pub mod middleware; -pub mod sessions; -pub mod states; - -pub(crate) mod gateway; -pub(crate) mod primitives; -pub(crate) mod utils; diff --git a/crates/gateways/src/middleware/gateway.rs b/crates/gateways/src/middleware/gateway.rs deleted file mode 100644 index da87ced9..00000000 --- a/crates/gateways/src/middleware/gateway.rs +++ /dev/null @@ -1,23 +0,0 @@ -/* - Appellation: gateway - Contrib: FL03 - Description: ... Summary ... -*/ -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize)] -pub struct GatewayMiddleware { - pub handle: String, -} - -impl GatewayMiddleware { - pub fn new(handle: String) -> Self { - Self { handle } - } -} - -impl Default for GatewayMiddleware { - fn default() -> Self { - Self::new(Default::default()) - } -} diff --git a/crates/gateways/src/middleware/mod.rs b/crates/gateways/src/middleware/mod.rs deleted file mode 100644 index 096b46a8..00000000 --- a/crates/gateways/src/middleware/mod.rs +++ /dev/null @@ -1,27 +0,0 @@ -/* - Appellation: middleware - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::{gateway::*, specs::*}; - -pub(crate) mod gateway; - -pub(crate) mod specs { - use async_trait::async_trait; - use scsys::AsyncResult; - use tower::layer::Layer; - - #[async_trait] - pub trait GatewayService { - fn handle(&self) -> String; - fn service(&self) -> &Self { - self - } - async fn start(&mut self) -> AsyncResult<&Self>; - } - - pub trait GatewayServiceLayer: Layer {} - - pub trait IntoGatewayService {} -} diff --git a/crates/gateways/src/primitives.rs b/crates/gateways/src/primitives.rs deleted file mode 100644 index 84350d0c..00000000 --- a/crates/gateways/src/primitives.rs +++ /dev/null @@ -1,14 +0,0 @@ -/* - Appellation: primitives - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::{constants::*, statics::*, types::*}; - -pub(crate) mod constants { - pub const STORJ_GATEWAY_ENDPOINT: &str = "https://gatway.storjshare.io"; -} - -pub(crate) mod statics {} - -pub(crate) mod types {} diff --git a/crates/gateways/src/sessions.rs b/crates/gateways/src/sessions.rs deleted file mode 100644 index 26855f04..00000000 --- a/crates/gateways/src/sessions.rs +++ /dev/null @@ -1,14 +0,0 @@ -/* - Appellation: sessions - Contrib: FL03 - Description: ... Summary ... -*/ -use scsys::prelude::{Id, Timestamp}; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub struct Session { - pub id: Id, - pub timestamp: Timestamp, - pub data: Vec, -} diff --git a/crates/gateways/src/states.rs b/crates/gateways/src/states.rs deleted file mode 100644 index 6d801fcf..00000000 --- a/crates/gateways/src/states.rs +++ /dev/null @@ -1,45 +0,0 @@ -/* - Appellation: states - Contrib: FL03 - Description: ... Summary ... -*/ -use scsys::prelude::{Id, Message, Timestamp}; -use serde::{Deserialize, Serialize}; -use std::sync::Arc; - -#[derive(Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub struct Session { - pub id: Id, - pub timestamp: Timestamp, - pub data: Vec, -} - -#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub enum State { - Connect { name: String, endpoint: String }, - Idle, -} - -impl State { - pub fn into_message(&self) -> Message { - self.clone().into() - } - pub fn boxed(&self) -> Box<&Self> { - Box::new(self) - } - pub fn shared(&self) -> Arc { - Arc::new(self.clone()) - } -} - -impl Default for State { - fn default() -> Self { - Self::Idle - } -} - -impl std::fmt::Display for State { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", serde_json::to_string(&self).unwrap()) - } -} diff --git a/crates/gateways/src/utils.rs b/crates/gateways/src/utils.rs deleted file mode 100644 index bc6fc1c5..00000000 --- a/crates/gateways/src/utils.rs +++ /dev/null @@ -1,52 +0,0 @@ -/* - Appellation: utils - Contrib: FL03 - Description: ... Summary ... -*/ -use crate::Gateway; -use s3::{creds::Credentials, serde_types::ListBucketResult, Region}; -use scsys::prelude::{BoxResult, S3Credential}; - -/// -pub fn convert_credentials(cred: S3Credential) -> Credentials { - Credentials { - access_key: Some(cred.access_key), - secret_key: Some(cred.secret_key), - security_token: None, - session_token: None, - expiration: None, - } -} -/// -pub fn simple_creds(access_key: &str, secret_key: &str) -> Credentials { - Credentials::new(Some(access_key), Some(secret_key), None, None, None).expect("msg") -} -/// -pub fn simple_region(endpoint: T, region: T) -> Region { - Region::Custom { - endpoint: endpoint.to_string(), - region: region.to_string(), - } -} - -/// -pub async fn collect_obj_names(objects: Vec) -> Vec { - tracing::info!("Collecting information on the given data..."); - objects - .iter() - .map(|i| i.clone().name) - .collect::>() -} -/// -pub async fn fetch_bucket_contents( - bucket: s3::Bucket, - prefix: &str, - delim: Option, -) -> BoxResult> { - let res = bucket.list(prefix.to_string(), delim).await?; - Ok(res) -} -/// -pub async fn fetch_bucket(gateway: &Gateway, name: &str) -> BoxResult { - Ok(gateway.bucket(name)?) -} diff --git a/crates/net/tests/default.rs b/crates/net/tests/default.rs deleted file mode 100644 index c26d18f3..00000000 --- a/crates/net/tests/default.rs +++ /dev/null @@ -1,10 +0,0 @@ -#[cfg(test)] -mod tests { - - #[test] - fn lib_compiles() { - let f = |i: usize, j: usize| i * j; - - assert_eq!(f(10, 2), 20); - } -} diff --git a/crates/pipelines/Cargo.toml b/crates/pipelines/Cargo.toml deleted file mode 100644 index 822aadac..00000000 --- a/crates/pipelines/Cargo.toml +++ /dev/null @@ -1,37 +0,0 @@ -[package] -authors = ["FL03 (https://github.com/FL03)"] -categories = [] -description = "acme" -edition = "2021" -homepage = "https://github.com/FL03/acme/wiki" -keywords = ["scsys"] -license = "Apache-2.0" -name = "acme-pipelines" -repository = "https://github.com/FL03/acme" -version = "0.2.4" - -[lib] -crate-type = ["cdylib", "rlib"] -test = true - -[build-dependencies] - -[dev-dependencies] - -[dependencies] -async-trait = "0.1.59" -axum = "0.6.1" -hyper = { features = ["full"], version = "0.14.23" } -http = "0.2.8" -http-body = "0.4.5" -scsys = { features = ["full"], version = "0.1.38" } -serde = { features = ["derive"], version = "1" } -serde_json = "1" -strum = { features = ["derive"], version = "0.24.1" } -tokio = { features = ["macros"], version = "1.23.0" } -tracing = { features = [], version = "0.1.37" } - - -[package.metadata.docs.rs] -all-features = true -rustc-args = ["--cfg", "docsrs"] diff --git a/crates/pipelines/src/lib.rs b/crates/pipelines/src/lib.rs deleted file mode 100644 index dd89d951..00000000 --- a/crates/pipelines/src/lib.rs +++ /dev/null @@ -1,14 +0,0 @@ -/* - Appellation: pzzld-pipelines - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::{pipeline::*, primitives::*, stages::*, utils::*}; - -pub(crate) mod pipeline; -pub(crate) mod stages; -pub(crate) mod utils; - -pub(crate) mod primitives { - pub const DEFAULT_WORKDIR: &str = "."; -} diff --git a/crates/pipelines/src/pipeline.rs b/crates/pipelines/src/pipeline.rs deleted file mode 100644 index b02df354..00000000 --- a/crates/pipelines/src/pipeline.rs +++ /dev/null @@ -1,33 +0,0 @@ -/* - Appellation: pipeline - Contrib: FL03 - Description: - PipelineStage: - Stages in the build process which specify when a particular hook will execute -*/ -use crate::PipelineStage; - -use scsys::prelude::{Message, Timestamp}; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] -pub struct Pipeline { - pub message: Message, - pub name: String, - pub stage: PipelineStage, - pub timestamp: i64, -} - -impl Pipeline { - pub fn new(message: Option, name: String) -> Self { - let message = message.unwrap_or_default(); - let stage = PipelineStage::PreBuild; - let timestamp = Timestamp::default().into(); - Self { - message, - name, - stage, - timestamp, - } - } -} diff --git a/crates/pipelines/src/stages.rs b/crates/pipelines/src/stages.rs deleted file mode 100644 index 38cc3d0f..00000000 --- a/crates/pipelines/src/stages.rs +++ /dev/null @@ -1,21 +0,0 @@ -/* - Appellation: pipeline - Contrib: FL03 - Description: - Stages - - -*/ -use serde::{Deserialize, Serialize}; - -#[allow(clippy::enum_variant_names)] -#[derive( - Clone, Copy, Debug, Default, Deserialize, Eq, Hash, Ord, PartialEq, PartialOrd, Serialize, -)] -#[serde(rename_all = "snake_case")] -pub enum PipelineStage { - PreBuild = 0, - #[default] - Build = 1, - - PostBuild = -1, -} diff --git a/crates/pipelines/src/utils.rs b/crates/pipelines/src/utils.rs deleted file mode 100644 index fb8b2f29..00000000 --- a/crates/pipelines/src/utils.rs +++ /dev/null @@ -1,7 +0,0 @@ -/* - Appellation: utils - Contrib: FL03 - Description: ... Summary ... -*/ - -pub fn remove_dir_all() {} diff --git a/crates/pipelines/tests/default.rs b/crates/pipelines/tests/default.rs deleted file mode 100644 index 5a2a8993..00000000 --- a/crates/pipelines/tests/default.rs +++ /dev/null @@ -1,7 +0,0 @@ -#[cfg(test)] -#[test] -fn lib_compiles() { - let f = |l: usize, r: usize| l + r; - let result = f(2, 2); - assert_eq!(result, 4); -} diff --git a/derive/Cargo.toml b/derive/Cargo.toml new file mode 100644 index 00000000..6ce6d5b0 --- /dev/null +++ b/derive/Cargo.toml @@ -0,0 +1,34 @@ +[package] +description = "Acme is a complete development toolkit for extending platform functionality" +name = "acme-derive" + +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +version.workspace = true + +[features] +default = [] + +[lib] +proc-macro = true +test = true + +[build-dependencies] + +[dependencies] +syn = { features = [], version = "1" } +proc-macro2 = "1" + +[dev-dependencies] + +[package.metadata.docs.rs] +all-features = true +rustc-args = ["--cfg", "docsrs"] + +[target.wasm32-unknown-unknown] + +[target.wasm32-wasi] diff --git a/crates/conduits/src/api/mod.rs b/derive/src/lib.rs similarity index 100% rename from crates/conduits/src/api/mod.rs rename to derive/src/lib.rs diff --git a/macros/Cargo.toml b/macros/Cargo.toml new file mode 100644 index 00000000..f2f6ccb2 --- /dev/null +++ b/macros/Cargo.toml @@ -0,0 +1,33 @@ +[package] +description = "Acme is a complete development toolkit for extending platform functionality" +name = "acme-macros" + +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +version.workspace = true + +[features] +default = [] + +[lib] +crate-type = ["cdylib", "rlib"] +test = true + +[build-dependencies] + +[dependencies] +syn = { features = [], version = "1" } + +[dev-dependencies] + +[package.metadata.docs.rs] +all-features = true +rustc-args = ["--cfg", "docsrs"] + +[target.wasm32-unknown-unknown] + +[target.wasm32-wasi] diff --git a/crates/conduits/src/cli/mod.rs b/macros/src/lib.rs similarity index 100% rename from crates/conduits/src/cli/mod.rs rename to macros/src/lib.rs diff --git a/crates/net/Cargo.toml b/net/Cargo.toml similarity index 60% rename from crates/net/Cargo.toml rename to net/Cargo.toml index 83f4409e..da59eeeb 100644 --- a/crates/net/Cargo.toml +++ b/net/Cargo.toml @@ -1,14 +1,14 @@ [package] -authors = ["FL03 (https://github.com/FL03)"] -categories = [] description = "acme" -edition = "2021" -homepage = "https://github.com/FL03/acme/wiki" -keywords = ["scsys"] -license = "Apache-2.0" name = "acme-net" -repository = "https://github.com/FL03/acme" -version = "0.2.4" + +authors.workspace = true +edition.workspace = true +homepage.workspace = true +license.workspace = true +readme.workspace = true +repository.workspace = true +version.workspace = true [lib] crate-type = ["cdylib", "rlib"] @@ -23,9 +23,9 @@ http = "0.2.8" http-body = "0.4.5" hyper = { features = ["full"], version = "0.14.23" } mio = "0.8.4" -scsys = { features = ["full"], version = "0.1.38" } -serde = { features = ["derive"], version = "1" } -serde_json = "1" +scsys.workspace = true +serde.workspace = true +serde_json.workspace = true strum = { features = ["derive"], version = "0.24.1" } tokio = { features = ["macros", "signal"], version = "1.23.0" } tower = "0.4.13" @@ -34,6 +34,6 @@ tracing = { features = [], version = "0.1.37" } tracing-subscriber = { features = [], version = "0.3.16" } [dev-dependencies] -acme-core = { path = "../core" } + [target.wasm32-unknown-unknown] diff --git a/crates/net/src/lib.rs b/net/src/lib.rs similarity index 99% rename from crates/net/src/lib.rs rename to net/src/lib.rs index c17c460e..bc42da25 100644 --- a/crates/net/src/lib.rs +++ b/net/src/lib.rs @@ -25,4 +25,4 @@ pub trait WebBackend { async fn serve(&self) -> AsyncResult { self.server().serve(self.client().await).await } -} \ No newline at end of file +} diff --git a/crates/net/src/middleware/mod.rs b/net/src/middleware/mod.rs similarity index 100% rename from crates/net/src/middleware/mod.rs rename to net/src/middleware/mod.rs diff --git a/crates/net/src/proxies/mod.rs b/net/src/proxies/mod.rs similarity index 100% rename from crates/net/src/proxies/mod.rs rename to net/src/proxies/mod.rs diff --git a/crates/net/src/proxies/proxy.rs b/net/src/proxies/proxy.rs similarity index 100% rename from crates/net/src/proxies/proxy.rs rename to net/src/proxies/proxy.rs diff --git a/crates/net/src/servers/mod.rs b/net/src/servers/mod.rs similarity index 100% rename from crates/net/src/servers/mod.rs rename to net/src/servers/mod.rs diff --git a/crates/net/src/servers/server.rs b/net/src/servers/server.rs similarity index 89% rename from crates/net/src/servers/server.rs rename to net/src/servers/server.rs index 2b881563..f6151bb7 100644 --- a/crates/net/src/servers/server.rs +++ b/net/src/servers/server.rs @@ -16,7 +16,7 @@ pub struct Server { impl Server { pub fn new(host: Option<[u8; 4]>, port: Option) -> Self { Self { - host: host.unwrap_or([127, 0, 0, 1]), + host: host.unwrap_or([0, 0, 0, 0]), port: port.unwrap_or(8080), } } @@ -40,7 +40,7 @@ impl ServerSpec for Server { impl Default for Server { fn default() -> Self { - Self::new(Some([127, 0, 0, 1]), Some(8080)) + Self::new(Some([0, 0, 0, 0]), Some(8080)) } } @@ -63,7 +63,7 @@ mod tests { #[tokio::test] async fn test_server() { let server = Server::default(); - assert_eq!(server.host, [127, 0, 0, 1]); + assert_eq!(server.host, [0, 0, 0, 0]); assert_eq!(server.port, 8080); } } diff --git a/crates/net/src/signals/mod.rs b/net/src/signals/mod.rs similarity index 100% rename from crates/net/src/signals/mod.rs rename to net/src/signals/mod.rs diff --git a/crates/net/src/signals/shutdown.rs b/net/src/signals/shutdown.rs similarity index 100% rename from crates/net/src/signals/shutdown.rs rename to net/src/signals/shutdown.rs diff --git a/crates/conduits/tests/default.rs b/net/tests/default.rs similarity index 100% rename from crates/conduits/tests/default.rs rename to net/tests/default.rs diff --git a/scripts/cargo/test.sh b/scripts/cargo/test.sh deleted file mode 100644 index 06fb6bca..00000000 --- a/scripts/cargo/test.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env bash -cargo fmt --all -cargo test --all --all-features --color always --verbose - \ No newline at end of file diff --git a/scripts/publish.sh b/scripts/publish.sh deleted file mode 100644 index ee361cd9..00000000 --- a/scripts/publish.sh +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash -cargo publish --all-features --color always --jobs 1 --token ${'$'}CARGO_REGISTRY_TOKEN --verbose -p acme-minis -cargo publish --all-features --color always --jobs 1 --token ${'$'}CARGO_REGISTRY_TOKEN --verbose -p acme \ No newline at end of file diff --git a/scripts/rustup.sh b/scripts/rustup.sh new file mode 100644 index 00000000..7fb2cbc0 --- /dev/null +++ b/scripts/rustup.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +rustup default nightly +rustup target add wasm32-unknown-unknown wasm32-wasi --toolchain nightly +rustup component add clippy rustfmt --toolchain nightly \ No newline at end of file diff --git a/scripts/setup.sh b/scripts/setup.sh index 20405f8e..242a4275 100644 --- a/scripts/setup.sh +++ b/scripts/setup.sh @@ -1,7 +1,4 @@ #!/usr/bin/env bash - sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y sudo apt install -y protobuf-compiler -rustup install nightly -rustup component add clippy rustfmt --toolchain nightly -rustup target add wasm32-unknown-unknown --toolchain nightly +sh scripts/rustup.sh \ No newline at end of file diff --git a/xtask/Cargo.toml b/xtask/Cargo.toml deleted file mode 100644 index 0fdab48f..00000000 --- a/xtask/Cargo.toml +++ /dev/null @@ -1,38 +0,0 @@ -[package] -authors = ["FL03 (https://github.com/FL03)"] -description = "xtask" -edition = "2021" -license = "Apache-2.0" -name = "xtask" -publish = false -version = "0.1.0" - -[[bin]] -bench = false -name = "xtask" -path = "src/main.rs" -test = false - -[build-dependencies] - -[dependencies] -anyhow = "1.0.66" -clap = { features = ["cargo", "derive", "env"], version = "4.0.29" } -config = "0.13.3" -devx-cmd = "0.5.0" -devx-pre-commit = "0.5.0" -duct = "0.13.6" -serde = { features = ["derive"], version = "1" } -serde_json = "1" -tracing = "0.1.37" -tracing-subscriber = "0.3.16" - -[dev-dependencies] - -[package.metadata.docs.rs] -all-features = true -rustc-args = ["--cfg", "docsrs"] - -[target.wasm32-unknown-unknown] - -[target.wasm32-wasi] diff --git a/xtask/src/cli/args/builder.rs b/xtask/src/cli/args/builder.rs deleted file mode 100644 index 451f9187..00000000 --- a/xtask/src/cli/args/builder.rs +++ /dev/null @@ -1,46 +0,0 @@ -/* - Appellation: builder - Contrib: FL03 - Description: ... Summary ... -*/ -use crate::command; -use anyhow::Result; -use clap::Args; -use serde::{Deserialize, Serialize}; - -#[derive(Args, Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub struct Builder { - #[arg(action = clap::ArgAction::SetTrue, long, short)] - release: bool, - #[arg(action = clap::ArgAction::SetFalse, long, short)] - workspace: bool, -} - -impl Builder { - pub fn new(release: bool, workspace: bool) -> Self { - Self { release, workspace } - } - fn commands(&self) -> Result<&Self> { - let mut args = vec!["build"]; - - if self.release { - args.push("--release"); - } - if self.workspace { - args.push("--workspace"); - } - command("cargo", args)?; - Ok(self) - } - pub fn handler(&self) -> Result<&Self> { - tracing::info!("Building the workspace..."); - self.commands()?; - Ok(self) - } -} - -impl Default for Builder { - fn default() -> Self { - Self::new(false, true) - } -} \ No newline at end of file diff --git a/xtask/src/cli/args/mod.rs b/xtask/src/cli/args/mod.rs deleted file mode 100644 index ba872b4f..00000000 --- a/xtask/src/cli/args/mod.rs +++ /dev/null @@ -1,57 +0,0 @@ -/* - Appellation: args - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::{auto::*, builder::*, runner::*, setup::*}; - -pub(crate) mod builder; -pub(crate) mod runner; -pub(crate) mod setup; - -pub(crate) mod auto { - use crate::command; - use anyhow::Result; - use clap::Args; - use serde::{Deserialize, Serialize}; - - #[derive(Args, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] - pub struct Auto { - #[arg(action = clap::ArgAction::SetFalse, long, short)] - clippy: bool, - #[arg(action = clap::ArgAction::SetTrue, long, short)] - bench: bool, - #[arg(action = clap::ArgAction::SetFalse, long, short)] - rustfmt: bool, - #[arg(action = clap::ArgAction::SetFalse, long, short)] - test: bool, - } - - impl Auto { - fn clippy(&self) -> Result<&Self> { - tracing::info!("Analyzing the codespace..."); - command("cargo", vec!["clippy", "--all", "--allow-dirty", "--fix"])?; - Ok(self) - } - fn rustfmt(&self) -> Result<&Self> { - tracing::info!("Formatting the codespace..."); - command("cargo", vec!["fmt", "--all"])?; - Ok(self) - } - fn testing(&self) -> Result<&Self> { - tracing::info!("Testing the workspace..."); - - command( - "cargo", - vec!["test", "--all", "--all-features", "--release"], - )?; - Ok(self) - } - pub fn handler(&self) -> Result<&Self> { - self.clippy()?.rustfmt()?; - super::Builder::default().handler()?; - self.testing()?; - Ok(self) - } - } -} diff --git a/xtask/src/cli/args/runner.rs b/xtask/src/cli/args/runner.rs deleted file mode 100644 index eb1a1aaf..00000000 --- a/xtask/src/cli/args/runner.rs +++ /dev/null @@ -1,38 +0,0 @@ -/* - Appellation: runner - Contrib: FL03 - Description: ... Summary ... -*/ -use crate::command; -use anyhow::Result; -use clap::Args; -use serde::{Deserialize, Serialize}; - -#[derive(Args, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub struct Runner { - #[clap(long, short, value_parser)] - package: Option, - #[arg(action = clap::ArgAction::SetTrue, long, short)] - release: bool, -} - -impl Runner { - pub fn new(package: Option, release: bool) -> Self { - Self { package, release } - } - fn commands(&self) -> Result<&Self> { - let mut args = vec!["run"]; - if self.release { - args.push("--release"); - } - args.push("--"); - args.push("--h"); - command("cargo", args.clone())?; - Ok(self) - } - pub fn handler(&self) -> Result<&Self> { - tracing::info!("Initializing the application..."); - self.commands()?; - Ok(self) - } -} diff --git a/xtask/src/cli/args/setup.rs b/xtask/src/cli/args/setup.rs deleted file mode 100644 index 67fb160d..00000000 --- a/xtask/src/cli/args/setup.rs +++ /dev/null @@ -1,63 +0,0 @@ -/* - Appellation: setup - Contrib: FL03 - Description: ... Summary ... -*/ -use crate::{command, dist_dir}; -use anyhow::Result; -use clap::Args; -use serde::{Deserialize, Serialize}; - -#[derive(Args, Clone, Debug, Default, Deserialize, Eq, Hash, PartialEq, Serialize)] -pub struct Setup { - #[arg(action = clap::ArgAction::SetTrue, long, short)] - extras: bool, -} - -impl Setup { - pub fn new(extras: bool) -> Self { - Self { extras } - } - fn setup_artifacts(&self) -> Result<&Self> { - if std::fs::create_dir_all(&dist_dir()).is_err() { - tracing::info!("Clearing out the previous build"); - std::fs::remove_dir_all(&dist_dir())?; - std::fs::create_dir_all(&dist_dir())?; - }; - Ok(self) - } - fn commands(&self) -> Result<&Self> { - command("rustup", vec!["default", "nightly"])?; - command( - "rustup", - vec![ - "target", - "add", - "wasm32-unknown-unknown", - "wasm32-wasi", - "--toolchain", - "nightly", - ], - )?; - if self.extras { - command( - "rustup", - vec![ - "component", - "add", - "clippy", - "rustfmt", - "--toolchain", - "nightly", - ], - )?; - command("npm", vec!["install", "-g", "wasm-pack"])?; - }; - Ok(self) - } - pub fn handler(&self) -> Result<&Self> { - tracing::info!("Setting up the workspace..."); - self.setup_artifacts()?.commands()?; - Ok(self) - } -} diff --git a/xtask/src/cli/commands.rs b/xtask/src/cli/commands.rs deleted file mode 100644 index 004aa0a7..00000000 --- a/xtask/src/cli/commands.rs +++ /dev/null @@ -1,47 +0,0 @@ -/* - Appellation: commands - Contrib: FL03 - Description: ... Summary ... -*/ -use super::{Auto, Builder, Runner, Setup}; -use anyhow::Result; -use clap::Subcommand; -use serde::{Deserialize, Serialize}; - -#[derive(Clone, Debug, Deserialize, Hash, PartialEq, Serialize, Subcommand)] -pub enum Commands { - Auto(Auto), - Build(Builder), - Run(Runner), - Setup(Setup), -} - -impl Commands { - pub fn handler(&self) -> Result<&Self> { - tracing::info!("Processing commands issued to the cli..."); - match self { - Self::Auto(auto) => { - tracing::info!("Initializing the CI/CD pipeline"); - auto.handler()?; - } - Self::Build(build) => { - tracing::info!("Compiling the codebase..."); - build.handler()?; - } - Self::Run(runner) => { - runner.handler()?; - } - Self::Setup(setup) => { - tracing::info!("Setting up the environment..."); - setup.handler()?; - } - }; - Ok(self) - } -} - -impl Default for Commands { - fn default() -> Self { - Self::Setup(Default::default()) - } -} diff --git a/xtask/src/cli/mod.rs b/xtask/src/cli/mod.rs deleted file mode 100644 index 1b393acc..00000000 --- a/xtask/src/cli/mod.rs +++ /dev/null @@ -1,61 +0,0 @@ -/* - Appellation: cli - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::{args::*, commands::*, context::*}; - -pub(crate) mod args; -pub(crate) mod commands; - -use std::{sync::Arc, thread::JoinHandle}; - -/// -pub fn new() -> CommandLineInterface { - CommandLineInterface::default() -} -/// -pub fn handle() -> JoinHandle> { - let tmp = Arc::new(new()); - std::thread::spawn(move || { - tmp.handler().expect(""); - tmp - }) -} - -pub(crate) mod context { - use super::Commands; - use anyhow::Result; - use clap::Parser; - - #[derive(Clone, Debug, Hash, Parser, PartialEq)] - #[clap(about, author, version)] - #[clap(long_about = None)] - pub struct CommandLineInterface { - #[clap(subcommand)] - pub command: Option, - #[arg(action = clap::ArgAction::SetTrue, long, short)] - pub debug: bool, - #[arg(action = clap::ArgAction::SetTrue, long, short)] - pub update: bool, - } - - impl CommandLineInterface { - pub fn new() -> Self { - Self::parse() - } - pub fn handler(&self) -> Result<&Self> { - if self.debug {} - if let Some(cmds) = &self.command { - cmds.handler()?; - } - Ok(self) - } - } - - impl Default for CommandLineInterface { - fn default() -> Self { - Self::parse() - } - } -} diff --git a/xtask/src/main.rs b/xtask/src/main.rs deleted file mode 100644 index 94cf0833..00000000 --- a/xtask/src/main.rs +++ /dev/null @@ -1,46 +0,0 @@ -/* - Appellation: xtask - Contrib: FL03 - Description: ... Summary ... -*/ -pub use self::utils::*; - -pub(crate) mod utils; - -pub mod cli; - -fn main() -> anyhow::Result<()> { - tracing_subscriber::fmt::init(); - tracing::info!("Welcome to xtask..."); - - let handle = std::thread::spawn(move || { - cli::handle().join().unwrap(); - }); - handle.join().ok().unwrap(); - - Ok(()) -} - -/// -pub type Bundle = std::collections::HashMap>>; - -/// -#[macro_export] -macro_rules! cmd { - ($( - $x:expr; - [ $( $y:expr ),* ] - );*) => { - { - $( - let mut cmd = std::process::Command::new($x); - cmd.current_dir(scsys_xtask::project_root()); - let mut tmp = Vec::new(); - $( - tmp.push($y); - )* - cmd.args(tmp.as_slice()).status().expect(""); - )* - } - }; -} \ No newline at end of file diff --git a/xtask/src/utils.rs b/xtask/src/utils.rs deleted file mode 100644 index 8b72a60c..00000000 --- a/xtask/src/utils.rs +++ /dev/null @@ -1,54 +0,0 @@ -/* - Appellation: utils - Contrib: FL03 - Description: ... Summary ... -*/ -use anyhow::Result; -use std::path::{Path, PathBuf}; -use std::{collections::HashMap, fs, io, process::Command}; - -/// -pub fn command(program: &str, args: Vec<&str>) -> Result<()> { - let mut cmd = Command::new(program); - cmd.current_dir(project_root()); - cmd.args(args.as_slice()).status()?; - Ok(()) -} -/// -pub fn copy_dir_all(src: impl AsRef, dst: impl AsRef) -> io::Result<()> { - fs::create_dir_all(&dst)?; - for entry in fs::read_dir(src)? { - let entry = entry?; - let ty = entry.file_type()?; - if ty.is_dir() { - copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?; - } else { - fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; - } - } - Ok(()) -} -/// -pub fn dist_dir() -> PathBuf { - project_root().join(".artifacts/dist") -} -/// -pub fn execute_bundle(bundle: HashMap<&str, Vec>>) -> Result<()> { - for k in bundle.keys() { - // Step 1: Rustup - for i in 0..bundle[k].len() { - let mut cmd = Command::new(k); - cmd.current_dir(project_root()); - cmd.args(bundle[k][i].clone().as_slice()).status()?; - } - } - Ok(()) -} -/// Fetch the project root unless specified otherwise with a CARGO_MANIFEST_DIR env variable -pub fn project_root() -> PathBuf { - Path::new(&env!("CARGO_MANIFEST_DIR")) - .ancestors() - .nth(1) - .unwrap() - .to_path_buf() -}