Skip to content

Commit

Permalink
Commit to work on PC
Browse files Browse the repository at this point in the history
  • Loading branch information
AverseABFun committed Dec 12, 2024
1 parent 5976403 commit 21e4da9
Show file tree
Hide file tree
Showing 13 changed files with 962 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "rust-pkg-gen"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.5.23", features = ["derive"]}
clap_complete = "4.5.38"
clap_mangen = "0.2.24"
rand = "0.8.5"
regex = "1.11.1"
rust-embed = "8.5.0"
serde = {version="1.0.215", features = ["derive"]}
toml = "0.8.19"
17 changes: 17 additions & 0 deletions rust-config.EXAMPLE.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[x64_package_linux_offline]
toolchains = [
{edition="2021", channel="nightly-2024-12-09", profile="complete", components=["rustfmt", "rustsrc"]}
]

[x64_package_linux_offline.meta]
offline = true
platforms = [
"x86_64-unknown-linux-gnu"
]
targets = [
"x86_64-unknown-linux-gnu",
"x86_64-pc-windows-gnu"
]

[x64_package_linux_offline.crates]
"*-nightly" = {"syn"="2.0.90"}
16 changes: 16 additions & 0 deletions rust-config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[x64_package_linux_rust_pkg_gen]
toolchains = [
{edition="2021", channel="1.83.0", profile="complete", components=["rustfmt", "rustc", "cargo"]}
]

[x64_package_linux_rust_pkg_gen.meta]
offline = true
platforms = [
"x86_64-unknown-linux-gnu"
]
targets = [
"x86_64-unknown-linux-gnu"
]

[x64_package_linux_rust_pkg_gen.crates]
"*-nightly" = {"rust-embed"="2.0.90"}
37 changes: 37 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use std::{collections::HashMap, fs, path::Path};
use serde::Deserialize;

pub mod resources;
mod tests;

#[derive(Deserialize, Debug)]
pub struct Toolchain {
pub edition: String,
pub channel: String,
pub profile: String,
pub components: Vec<String>
}

#[derive(Deserialize, Debug)]
pub struct Meta {
pub offline: bool,
pub platforms: Vec<String>,
pub targets: Vec<String>
}

pub type Crate = String;

pub type Crates = HashMap<String, HashMap<String, String>>;

#[derive(Deserialize, Debug)]
pub struct RustConfigInner {
pub toolchains: Vec<Toolchain>,
pub meta: Meta,
pub crates: Crates
}

pub type RustConfig = HashMap<String, RustConfigInner>;

pub fn parse_file(path: &Path) -> RustConfig {
toml::from_str(&fs::read_to_string(path).unwrap()).unwrap()
}
41 changes: 41 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::{env, path::PathBuf};
use rand::{Rng, SeedableRng};
use rust_pkg_gen::parse_file;
use rust_pkg_gen::resources::TemplateAssets;
use clap::Parser;

fn gen_char() -> u8 {
rand::rngs::StdRng::from_entropy().gen_range(65..90)
}

#[derive(Parser, Debug)]
struct Cli {
#[arg(long="temp-dir", default_value="InVaLiD!")]
temp_dir: PathBuf,
#[arg(default_value="rust-config.toml")]
path: PathBuf,
}

fn main() {
let args = Cli::parse();

let path = &PathBuf::from(args.path);
println!("{:#?}", parse_file(path));

let chars: &[u8; 6] = &[gen_char(), gen_char(), gen_char(), gen_char(), gen_char(), gen_char()];
let dir = if args.temp_dir != PathBuf::from("InVaLiD!") {
args.temp_dir
} else {
std::env::temp_dir().join(PathBuf::from(String::from_utf8_lossy(chars).as_ref()))
};
let _ = std::fs::create_dir(dir.clone());
for mut ele in TemplateAssets::iter() {
let file = TemplateAssets::get(&ele).unwrap();
ele = ele.split_once("/").unwrap().1.as_ref();
println!("{}", ele.as_ref());
for ele in PathBuf::from(ele.as_ref()).ancestors() {
let _ = std::fs::create_dir(PathBuf::from().join(ele));
}
std::fs::write(dir.join(PathBuf::from(ele.as_ref())), file.data).unwrap();
}
}
8 changes: 8 additions & 0 deletions src/resources.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use rust_embed::Embed;

#[derive(Embed)]
#[folder = "src/template/"]
#[prefix = "template/"]
pub struct TemplateAssets;

const RUSTUP_INIT_ASSET: &str = include_str!("rustup-init.sh");
Loading

0 comments on commit 21e4da9

Please sign in to comment.