Skip to content

Commit

Permalink
port to other os
Browse files Browse the repository at this point in the history
  • Loading branch information
Cr0a3 committed Mar 10, 2024
1 parent 1f5c228 commit 0913dc5
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 43 deletions.
95 changes: 95 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ reqwest = { version = "0.11.25", features=["json"] }
serde = { version = "1.0.197", features=["derive"] }
serde_json = "1.0.114"
struct_iterable = "0.1.1"
tokio = { version = "1.36.0", features=["full"] }
toml = "0.8.10"
zip = "0.6.6"
8 changes: 0 additions & 8 deletions app/cpack.toml

This file was deleted.

1 change: 0 additions & 1 deletion app/include/lib.hpp

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main.cpp

This file was deleted.

33 changes: 21 additions & 12 deletions src/api.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use reqwest::*;
use serde_json::{json, Value};
use reqwest::{self, Client};
use serde::{Serialize, Deserialize};
use crate::print;

Expand All @@ -10,7 +11,7 @@ struct ApiCall {
}

pub struct Api {
pub domain: String,
pub domain: String,
}

impl Api {
Expand All @@ -20,27 +21,35 @@ impl Api {
}
}

pub async fn call(&self, json: ApiCall) -> Result<ApiCall, reqwest::Error> {
let res = Client::new().post(&self.domain).json(&json).send().await?;
res.json().await?
pub async fn call(&self, json: Value) -> Result<Value, reqwest::Error> {
let client = Client::new();
let res = client.post(&self.domain).json(&json).send().await?;
let answer: Value = res.json().await?;

Ok(answer)
}

pub async fn get_download_link(&self, name: &String, version: &String) -> String {
let result = self.call(ApiCall {
func: "getlink".into(),
opt1: Some(name.into()),
opt2: Some(version.into()),
}).await;
let result = self.call(json!({
"func": "download",
"name": name,
"version": version,
})).await;

let json: ApiCall = match result {
let json: Value = match result {
Ok(j) => j,
Err(e) => {
print::error("E", &format!("error while calling the api: {}", e));
return "none".into();
},
};

let link = json.opt1.expect("error while unwraping download link");
let link = json["link"].to_string();

if link == "error" {
return json["error"].to_string()
}

link

}
Expand Down
17 changes: 16 additions & 1 deletion src/consts.rs
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
pub static DOMAIN: &str = "localhost";
pub static DOMAIN: &str = "localhost";

#[cfg(windows)]
pub static BINARY_EXT: &str = "exe";
#[cfg(unix)]
pub static BINARY_EXT: &str = "out";

#[cfg(windows)]
pub static LIBARY_EXT: &str = "dll";
#[cfg(unix)]
pub static LIBARY_EXT: &str = "lib";

#[cfg(windows)]
pub static LIBARY_LD_FLAG: &str = "--dll";
#[cfg(unix)]
pub static LIBARY_LD_FLAG: &str = "--lib";
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ mod consts;

use crate::runner::*;

pub fn main() {
#[tokio::main]
async fn main() {
let mut args: Vec<String> = env::args().collect();

let mut options: Vec<String> = vec!();
Expand Down Expand Up @@ -36,7 +37,7 @@ pub fn main() {
}

"build" => {
let _ = build::build("debug", options.contains(&"--noout".to_string()));
let _ = build::build("debug", options.contains(&"--noout".to_string())).await;
}

"clean" => {
Expand All @@ -48,7 +49,7 @@ pub fn main() {
}

"run" => {
run::run("debug", options.contains(&"--noout".to_string()) );
run::run("debug", options.contains(&"--noout".to_string())).await;
}

"publish" => {
Expand Down Expand Up @@ -79,7 +80,7 @@ pub fn main() {
}

"build" => {
let _ = build::build(opt.as_str(), options.contains(&"--noout".to_string()));
let _ = build::build(opt.as_str(), options.contains(&"--noout".to_string())).await;
}

"new" => {
Expand All @@ -101,7 +102,7 @@ pub fn main() {
}

"run" => {
run::run(opt.as_str(), options.contains(&"--noout".to_string()) );
run::run(opt.as_str(), options.contains(&"--noout".to_string()) ).await;
}

"add" => {
Expand Down
10 changes: 5 additions & 5 deletions src/runner/build.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{conf::{self, parse_dependencys, Data}, dependencys::*, print};
use crate::{conf::{self, parse_dependencys, Data}, consts, dependencys::*, print};
use std::{fs, process::Command};
use PrintLib::colorize::Colorize;

Expand Down Expand Up @@ -103,7 +103,7 @@ pub async fn build(target: &str, noout: bool) -> Result<bool, std::io::Error> {
// link together
let lib = conf::load_tml_cfg::<Data>("cpack.toml").package.lib.unwrap_or(false);

let ext = match lib {false => "exe", true => "dll" };
let ext = match lib {false => consts::BINARY_EXT, true => consts::LIBARY_EXT };
let prog = match lib {false => "g++", true => "ld" };

if sucess {
Expand Down Expand Up @@ -131,11 +131,11 @@ pub async fn build(target: &str, noout: bool) -> Result<bool, std::io::Error> {
);

if lib {
cmd.arg("--dll");
cmd.arg(consts::LIBARY_LD_FLAG);
} else {
cmd.arg("-lstdc++");
}

cmd.arg("-lstdc++");

let status = cmd.status();

match status {
Expand Down
4 changes: 2 additions & 2 deletions src/runner/run.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{conf::{self, Data}, print};
use crate::{conf::{self, Data}, consts, print};
use std::{path::Path, process::Command};
use PrintLib::colorize::Colorize;
use crate::runner::build::build;
Expand All @@ -21,7 +21,7 @@ pub async fn run(target: &str, noout: bool) -> Option<bool> {
}

// now there are no compile errors
let fmt_path = format!("target/{target}/{}.exe", name);
let fmt_path = format!("target/{target}/{}.{}", name, consts::BINARY_EXT);
let bin = Path::new( &fmt_path );

if !bin.exists() {
Expand Down

0 comments on commit 0913dc5

Please sign in to comment.