Skip to content

Commit

Permalink
Feature-gated selfinit
Browse files Browse the repository at this point in the history
  • Loading branch information
strawmelonjuice committed Sep 13, 2024
1 parent ca38354 commit 45fd67b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 27 deletions.
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ name = "cynthiaweb"
path = "./source/Main/main.rs"

[features]
default = ["js_runtime"]
default = ["js_runtime", "selfinit"]
selfinit = ["dep:rust-lzma"]
js_runtime = []


Expand All @@ -34,13 +35,14 @@ lto = true
panic = 'abort'

[dependencies]
rust-lzma = { version = "0.6.0", optional = true }
chrono = "0.4.38"
futures = "0.3.30"
actix-web = "4"
actix-files = "0.6"
serde = { version = "1.0.104", features = ["derive"] }
serde_yaml = "0.9.29"
# colored = "2.0.4" // No longer needed, Cynthia uses its own color module
chrono = "0.4.38"
simplelog = "0.12.2"
indicatif = "0.17.8"
log = "0.4.21"
Expand Down Expand Up @@ -75,8 +77,7 @@ reqwest = { version = "0.12.5" }
interactive_process = "0.1.3"
serde_dhall = "0.12.1"
regex = "1.10.3"
rust-lzma = "0.6.0"

[build-dependencies]
rust-lzma = "0.6.0"
rust-lzma = { version = "0.6.0", optional = true }
tar = "0.4.40"
3 changes: 2 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ Cynthia is currently in development, and is not yet ready for use. Cynthia is se
> [!WARNING]
> Windows support is not yet available. Cynthia is currently only supported on Linux and MacOS.
> As I don't run servers on Windows, it doesn't make sense for me to support it. If you want to run Cynthia on Windows, you can try using WSL2.
> This might be fixed in the future, but it's not something I'm actively working on.
>
>> UPDATE: If you _need_ Windows support timely, disable the `selfinit` feature while compiling Cynthia. This will remove the need for the lzma crate, which is not yet supported on Windows.
## usage

Expand Down
46 changes: 24 additions & 22 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,35 @@ const FILES: [&str; 1] = ["cleansheet"];

fn main() {
{
let packed_folder = {
let mut pkd = Vec::new();
let mut archive = tar::Builder::new(&mut pkd);
archive.append_dir_all("", "cleansheet").unwrap();
archive.finish().unwrap();
drop(archive);
pkd
};

let compressed_file = lzma::compress(&packed_folder, 9).unwrap();
std::fs::write("./target/cleansheet.tar.xz", compressed_file).unwrap();
#[cfg(feature = "selfinit")]
{
let mut filelist: String = String::new();
let paths = std::fs::read_dir("./cleansheet/").unwrap();
let packed_folder = {
let mut pkd = Vec::new();
let mut archive = tar::Builder::new(&mut pkd);
archive.append_dir_all("", "cleansheet").unwrap();
archive.finish().unwrap();
drop(archive);
pkd
};

let compressed_file = lzma::compress(&packed_folder, 9).unwrap();
std::fs::write("./target/cleansheet.tar.xz", compressed_file).unwrap();
{
let mut filelist: String = String::new();
let paths = std::fs::read_dir("./cleansheet/").unwrap();

for path in paths {
filelist.push_str(
format!("{}\n", path.unwrap().path().display())
.as_str()
.replace("./cleansheet/", "")
.as_str(),
);
for path in paths {
filelist.push_str(
format!("{}\n", path.unwrap().path().display())
.as_str()
.replace("./cleansheet/", "")
.as_str(),
);
}
std::fs::write("./target/cleansheet.filelist.txt", filelist).unwrap();
}
std::fs::write("./target/cleansheet.filelist.txt", filelist).unwrap();
}
}

#[cfg(not(feature = "js_runtime"))]
println!("cargo:warning=Node features are disabled. This means you won't need a node runtime to build or run Cynthia. It also means that some features are disabled.");

Expand Down
1 change: 1 addition & 0 deletions source/Main/helpers.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::PathBuf;

#[cfg(feature = "selfinit")]
/// Decompresses a folder from the bits of a .tar.xz file
pub(crate) fn decompress_folder(compressed_folder: &[u8], output_folder: PathBuf) {
let decompressed_folder = lzma::decompress(compressed_folder).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions source/Main/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ async fn main() {
.to_ascii_lowercase()
.as_str()
{
#[cfg(feature = "selfinit")]
"init" => {
interactive_initialiser().await;
}
Expand Down Expand Up @@ -201,6 +202,7 @@ async fn main() {
}
}

#[cfg(feature = "selfinit")]
async fn interactive_initialiser() {
// Steps for the initialiser:
// 1. Check if over a config already exists.
Expand Down
1 change: 1 addition & 0 deletions win.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cargo b --no-default-features --features js_runtime

0 comments on commit 45fd67b

Please sign in to comment.