-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5976403
commit 21e4da9
Showing
13 changed files
with
962 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); |
Oops, something went wrong.