Make helwasm compilable for wasm32-unknown-unknown target.
This commit is contained in:
+5
-1
@@ -23,9 +23,13 @@ shlex = "1.1.0"
|
|||||||
shellexpand = "3.0.0"
|
shellexpand = "3.0.0"
|
||||||
scopeguard = "1.1.0"
|
scopeguard = "1.1.0"
|
||||||
|
|
||||||
[target.'cfg(not(wasm))'.dependencies]
|
[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
|
||||||
chrono = "0.4.23"
|
chrono = "0.4.23"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
home = "0.5.4"
|
home = "0.5.4"
|
||||||
rustyline = "10.0.0"
|
rustyline = "10.0.0"
|
||||||
rpassword = "7.2.0"
|
rpassword = "7.2.0"
|
||||||
|
|
||||||
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
|
wasm-bindgen = "0.2.83"
|
||||||
|
chrono = { version = "0.4.23", features = ["wasmbind"] }
|
||||||
|
|||||||
+73
-2
@@ -5,7 +5,6 @@ use std::io;
|
|||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
|
|
||||||
#[cfg(not(wasm))]
|
|
||||||
pub mod date {
|
pub mod date {
|
||||||
use chrono::naive::NaiveDate;
|
use chrono::naive::NaiveDate;
|
||||||
use chrono::Local;
|
use chrono::Local;
|
||||||
@@ -43,7 +42,22 @@ pub mod date {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(wasm))]
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
pub mod rnd {
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
#[wasm_bindgen(js_name = rnd_range)]
|
||||||
|
fn extern_rnd_range(start: u32, end: u32) -> u32;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn range(start: u32, end: u32) -> u32 {
|
||||||
|
extern_rnd_range(start, end)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
pub mod rnd {
|
pub mod rnd {
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
@@ -52,6 +66,13 @@ pub mod rnd {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
pub mod home {
|
||||||
|
pub fn dir() -> std::path::PathBuf {
|
||||||
|
std::path::PathBuf::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
pub mod home {
|
pub mod home {
|
||||||
use home::home_dir;
|
use home::home_dir;
|
||||||
@@ -113,6 +134,56 @@ pub mod editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "wasm32")]
|
||||||
|
pub mod editor {
|
||||||
|
use crate::structs::LKErr;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
|
#[wasm_bindgen]
|
||||||
|
extern "C" {
|
||||||
|
#[wasm_bindgen(js_name = read_line)]
|
||||||
|
fn extern_readline(prompt: &str) -> String;
|
||||||
|
|
||||||
|
#[wasm_bindgen(js_name = read_password)]
|
||||||
|
fn extern_password(prompt: &str) -> String;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct Editor {
|
||||||
|
history: Vec<String>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Editor {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self { history: vec![] }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_history(&mut self) {
|
||||||
|
self.history.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_history_entry(&mut self, entry: &str) {
|
||||||
|
self.history.push(entry.to_string());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_history<'a>(&mut self, _fname: &str) -> Result<(), LKErr<'a>> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn save_history<'a>(&mut self, _fname: &str) -> Result<(), LKErr<'a>> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn readline<'a>(&mut self, prompt: &str) -> Result<String, LKErr<'a>> {
|
||||||
|
Ok(extern_readline(&prompt))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn password(prompt: String) -> std::io::Result<String> {
|
||||||
|
Ok(extern_password(&prompt))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn call_cmd_with_input(cmd: &str, args: &Vec<String>, input: &str) -> io::Result<String> {
|
pub fn call_cmd_with_input(cmd: &str, args: &Vec<String>, input: &str) -> io::Result<String> {
|
||||||
let mut cmd = Command::new(cmd).args(args).stdin(Stdio::piped()).stdout(Stdio::piped()).spawn()?;
|
let mut cmd = Command::new(cmd).args(args).stdin(Stdio::piped()).stdout(Stdio::piped()).spawn()?;
|
||||||
let mut stdin = cmd.stdin.take().unwrap();
|
let mut stdin = cmd.stdin.take().unwrap();
|
||||||
|
|||||||
+1
-1
@@ -4,10 +4,10 @@ version = "0.1.0"
|
|||||||
authors = ["ok2"]
|
authors = ["ok2"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[target.'cfg(wasm32)']
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "helwasm"
|
name = "helwasm"
|
||||||
path = "src/lib.rs"
|
path = "src/lib.rs"
|
||||||
|
crate-type = ["cdylib"]
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user