Skip to content
This repository was archived by the owner on Jun 14, 2023. It is now read-only.

Commit 3238fe1

Browse files
authored
Merge pull request #216 from john-sharratt/master
Added support for compiling against wasm32-wasi
2 parents d125632 + e1437ef commit 3238fe1

34 files changed

+1272
-458
lines changed

Cargo.lock

Lines changed: 864 additions & 318 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ description = "WebAssembly Package Manager CLI"
88
license = "MIT"
99

1010
[dependencies]
11-
atty = "0.2"
1211
billboard = { version = "0.1.0", optional = true }
1312
chrono = { version = "0.4", features = ["serde"] }
1413
colored = { version = "1.8", optional = true }
15-
dirs = "1"
14+
dirs = { version = "1", optional = true }
1615
anyhow = "1"
1716
thiserror = "1.0"
1817
fern = {version = "0.6", features = ["colored"]}
@@ -23,29 +22,40 @@ license-exprs = "1.4.0"
2322
log = "0.4"
2423
maplit = { version = "1", optional = true }
2524
minisign = "0.5"
26-
prettytable-rs = "0.8.0"
25+
prettytable-rs = { version = "0.8.0", optional = true }
2726
regex = "1"
28-
reqwest = { version = "0.11.0", features = ["native-tls-vendored", "blocking", "json", "gzip","socks","multipart"] }
29-
rpassword = "4"
30-
rusqlite = "0.24"
27+
rpassword-wasi = "5"
28+
rusqlite = { version = "0.24", optional = true }
3129
semver = { version = "0.11", features = ["serde"] }
3230
sentry = { version = "0.22.0", optional = true, features = ["anyhow", "panic", "backtrace"] }
3331
serde = "1.0"
3432
serde_derive = "1.0"
3533
serde_json = "1.0"
3634
structopt = { version = "0.3", features = ["color"] }
37-
tar = "0.4"
3835
tempfile = "3"
3936
time = "0.1"
4037
toml = "0.5.6"
4138
url = "2"
4239
wasmer-wasm-interface = { version = "0.1.0", path = "lib/wasm-interface" }
4340
wasmparser = "0.51.4"
44-
whoami = "1.1.5"
4541
dialoguer = "0.4.0"
4642
hex = { version = "0.4", optional = true }
4743
blake3 = { version = "0.3.1", optional = true }
4844

45+
[target.'cfg(not(target_os = "wasi"))'.dependencies]
46+
whoami = "1.1.5"
47+
atty = "0.2"
48+
reqwest = { version = "0.11.0", features = ["native-tls-vendored", "blocking", "json", "gzip","socks","multipart"], optional = true }
49+
tar = { version = "0.4" }
50+
51+
[target.'cfg(target_os = "wasi")'.dependencies]
52+
whoami = "0.5"
53+
wasm-bus-reqwest = { version = "1.0", path = "../ate/wasm-bus-reqwest" }
54+
wasm-bus-process = { version = "1.0", path = "../ate/wasm-bus-process" }
55+
getrandom = "0.2.3"
56+
tar = { package = "tar-wasi", version = "0.4" }
57+
serde_yaml = { version = "^0.8" }
58+
4959
[dev-dependencies]
5060
tempfile = "3"
5161

@@ -56,10 +66,11 @@ members = [
5666
]
5767

5868
[features]
59-
default = ["packagesigning", "sqlite-bundled"]
69+
default = ["full","packagesigning", "sqlite-bundled"]
6070
sqlite-bundled = ["rusqlite/bundled"]
6171
telemetry = ["sentry"]
6272
update-notifications= ["billboard", "colored"]
6373
prehash-module = ["hex", "blake3"]
64-
packagesigning = []
74+
packagesigning = []#[cfg(feature = "full")]
6575
integration_tests = ["maplit"]
76+
full = [ "dirs", "rusqlite", "prettytable-rs", "reqwest" ]

src/bin/wapm.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
#![cfg_attr(target_os = "wasi", allow(unused_variables))]
12
use std::{env, path};
23
use structopt::{clap::AppSettings, StructOpt};
34
#[cfg(feature = "update-notifications")]
45
use wapm_cli::update_notifier;
6+
#[allow(unused_imports)]
57
use wapm_cli::{commands, logging};
68

79
#[derive(StructOpt, Debug)]
@@ -27,6 +29,7 @@ enum Command {
2729
/// Install a package
2830
Install(commands::InstallOpt),
2931

32+
#[cfg(feature = "full")]
3033
#[structopt(name = "publish")]
3134
/// Publish a package
3235
Publish(commands::PublishOpt),
@@ -38,12 +41,13 @@ enum Command {
3841
/// Run a command from the package or one of the dependencies
3942
Run(commands::RunOpt),
4043

44+
#[cfg(feature = "full")]
4145
#[structopt(name = "search")]
4246
/// Search packages
4347
Search(commands::SearchOpt),
4448

4549
#[cfg(feature = "package")]
46-
#[structopt(name = "package", raw(aliases = r#"&["p", "pkg"]"#))]
50+
#[structopt(name = "package", aliases = r#"&["p", "pkg"]"#)]
4751
/// Create a wasm package with bundled assets
4852
Package(commands::PackageOpt),
4953

@@ -59,10 +63,12 @@ enum Command {
5963
/// Set up current directory for use with wapm
6064
Init(commands::InitOpt),
6165

66+
#[cfg(feature = "full")]
6267
#[structopt(name = "list")]
6368
/// List the currently installed packages and their commands
6469
List(commands::ListOpt),
6570

71+
#[cfg(feature = "full")]
6672
#[cfg(feature = "packagesigning")]
6773
#[structopt(name = "keys")]
6874
/// Manage minisign keys for verifying packages
@@ -72,6 +78,7 @@ enum Command {
7278
/// Uninstall a package
7379
Uninstall(commands::UninstallOpt),
7480

81+
#[cfg(feature = "full")]
7582
#[structopt(name = "bin")]
7683
/// Get the .bin dir path
7784
Bin(commands::BinOpt),
@@ -89,14 +96,25 @@ enum Command {
8996
/// Remove packages from the manifest
9097
Remove(commands::RemoveOpt),
9198

99+
#[cfg(feature = "full")]
92100
/// Execute a command, installing it temporarily if necessary
93101
Execute(commands::ExecuteOpt),
94102
}
95103

96104
fn main() {
97-
let is_atty = atty::is(atty::Stream::Stdout);
98-
if let Err(e) = logging::set_up_logging(is_atty) {
99-
eprintln!("Error: {}", e);
105+
#[cfg(not(target_os = "wasi"))]
106+
{
107+
let is_atty = atty::is(atty::Stream::Stdout);
108+
if let Err(e) = logging::set_up_logging(is_atty) {
109+
eprintln!("Error: {}", e);
110+
}
111+
}
112+
113+
//#[cfg(target_os = "wasi")]
114+
{
115+
if let Err(e) = logging::set_up_logging(true) {
116+
eprintln!("Error: {}", e);
117+
}
100118
}
101119

102120
#[cfg(feature = "telemetry")]
@@ -121,6 +139,7 @@ fn main() {
121139
.expect("Could not parse argv[0] as a path")
122140
.to_string_lossy();
123141

142+
#[cfg(feature = "full")]
124143
let args = if prog_name == "wax" {
125144
Command::Execute(commands::ExecuteOpt::ExecArgs(
126145
env::args().skip(1).collect(),
@@ -133,6 +152,9 @@ fn main() {
133152
Command::from_args()
134153
};
135154

155+
#[cfg(not(feature = "full"))]
156+
let args = Command::from_args();
157+
136158
#[cfg(feature = "update-notifications")]
137159
// Only show the async check on certain commands
138160
let maybe_show_update_notification = match args {
@@ -158,15 +180,20 @@ fn main() {
158180
Command::Install(install_options) => commands::install(install_options),
159181
Command::Add(add_options) => commands::add(add_options),
160182
Command::Remove(remove_options) => commands::remove(remove_options),
183+
#[cfg(feature = "full")]
161184
Command::Publish(publish_options) => commands::publish(publish_options),
162185
Command::Run(run_options) => commands::run(run_options),
186+
#[cfg(feature = "full")]
163187
Command::Execute(execute_options) => commands::execute(execute_options),
188+
#[cfg(feature = "full")]
164189
Command::Search(search_options) => commands::search(search_options),
165190
#[cfg(feature = "package")]
166191
Command::Package(package_options) => commands::package(package_options),
167192
Command::Validate(validate_options) => commands::validate(validate_options),
168193
Command::Init(init_options) => commands::init(init_options),
194+
#[cfg(feature = "full")]
169195
Command::List(list_options) => commands::list(list_options),
196+
#[cfg(feature = "full")]
170197
#[cfg(feature = "packagesigning")]
171198
Command::Keys(key_options) => commands::keys(key_options),
172199
Command::Completions(completion_options) => {
@@ -178,6 +205,7 @@ fn main() {
178205
Ok(())
179206
}
180207
Command::Uninstall(uninstall_options) => commands::uninstall(uninstall_options),
208+
#[cfg(feature = "full")]
181209
Command::Bin(bin_options) => commands::bin(bin_options),
182210
#[cfg(feature = "update-notifications")]
183211
Command::BackgroundUpdateCheck => {

src/commands/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ enum AddError {
3636
pub fn add(options: AddOpt) -> anyhow::Result<()> {
3737
let mut error = false;
3838
let mut manifest: Manifest = {
39-
let cur_dir = std::env::current_dir()?;
39+
let cur_dir = crate::config::Config::get_current_dir()?;
4040
Manifest::find_in_directory(cur_dir).map_err(|_| AddError::NoManifest)?
4141
};
4242

src/commands/bin.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::config::Config;
22
use crate::data::manifest::PACKAGES_DIR_NAME;
33
use crate::dataflow::bin_script::BIN_DIR_NAME;
4-
use std::env;
54
use structopt::StructOpt;
65
use thiserror::Error;
76

@@ -21,7 +20,7 @@ pub enum BinError {
2120
pub fn bin(options: BinOpt) -> anyhow::Result<()> {
2221
let mut root_dir = match options.global {
2322
true => Config::get_globals_directory()?,
24-
false => env::current_dir()?,
23+
false => Config::get_current_dir()?,
2524
};
2625
root_dir.push(PACKAGES_DIR_NAME);
2726

src/commands/execute.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use thiserror::Error;
1818
use graphql_client::*;
1919

2020
use std::convert::From;
21-
use std::env;
2221
use std::ffi::OsString;
2322
use std::path::PathBuf;
2423
use std::str::FromStr;
@@ -228,7 +227,7 @@ pub fn execute(opt: ExecuteOpt) -> anyhow::Result<()> {
228227
}
229228
let opt = opt;
230229
trace!("Execute {:?}", &opt);
231-
let current_dir = env::current_dir()?;
230+
let current_dir = crate::config::Config::get_current_dir()?;
232231
if let Some(which) = opt.which {
233232
let mut wax_index = wax_index::WaxIndex::open()?;
234233
let dir = if let Ok((package_name, version, _)) = wax_index.search_for_entry(which.clone())

src/commands/init.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::init;
2-
use std::env;
32
use structopt::StructOpt;
43

54
#[derive(StructOpt, Debug)]
@@ -10,7 +9,7 @@ pub struct InitOpt {
109
}
1110

1211
pub fn init(opt: InitOpt) -> anyhow::Result<()> {
13-
let current_directory = env::current_dir()?;
12+
let current_directory = crate::config::Config::get_current_dir()?;
1413
init::init(current_directory, opt.force_yes)
1514
}
1615

src/commands/install.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::config::Config;
88
use crate::dataflow;
99
use crate::util;
1010
use std::borrow::Cow;
11-
use std::env;
1211
use std::path::Path;
1312
use structopt::StructOpt;
1413
use thiserror::Error;
@@ -36,6 +35,9 @@ enum InstallError {
3635
#[error("Failed to install packages. {0}")]
3736
CannotRegenLockFile(dataflow::Error),
3837

38+
#[error("Failed to create the install directory. {0}")]
39+
CannotCreateInstallDirectory(std::io::Error),
40+
3941
#[error("Failed to install packages in manifest. {0}")]
4042
FailureInstallingPackages(dataflow::Error),
4143

@@ -69,7 +71,7 @@ mod package_args {
6971

7072
/// Run the install command
7173
pub fn install(options: InstallOpt) -> anyhow::Result<()> {
72-
let current_directory = env::current_dir()?;
74+
let current_directory = crate::config::Config::get_current_dir()?;
7375
let _value = util::set_wapm_should_accept_all_prompts(options.force_yes);
7476
debug_assert!(
7577
_value.is_some(),
@@ -137,9 +139,12 @@ pub fn install(options: InstallOpt) -> anyhow::Result<()> {
137139
}
138140
false => Cow::Borrowed(&current_directory),
139141
};
142+
std::fs::create_dir_all(install_directory.clone())
143+
.map_err(|err| InstallError::CannotCreateInstallDirectory(err))?;
140144

141-
let changes_applied = dataflow::update(installed_packages, vec![], install_directory)
142-
.map_err(|err| InstallError::CannotRegenLockFile(err))?;
145+
let changes_applied =
146+
dataflow::update(installed_packages.clone(), vec![], install_directory)
147+
.map_err(|err| InstallError::CannotRegenLockFile(err))?;
143148

144149
if changes_applied {
145150
if options.global {

src/commands/list.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::config;
44
use crate::data::lock::lockfile::{CommandMap, ModuleMap};
55
use crate::dataflow::lockfile_packages::LockfileResult;
66
use prettytable::{format, Table};
7-
use std::{env, fmt::Write as _};
7+
use std::{fmt::Write as _};
88
use structopt::StructOpt;
99

1010
#[derive(StructOpt, Debug)]
@@ -37,7 +37,7 @@ pub fn list(options: ListOpt) -> anyhow::Result<()> {
3737

3838
let mut handle = String::new();
3939
if local {
40-
let cwd = env::current_dir()?;
40+
let cwd = crate::config::Config::get_current_dir()?;
4141
match LockfileResult::find_in_directory(cwd) {
4242
LockfileResult::Lockfile(lockfile) => {
4343
let has_modules = !lockfile.modules.is_empty();

src/commands/login.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::config::Config;
22
use crate::graphql::execute_query;
3+
use rpassword_wasi as rpassword;
34
use std::io::prelude::*;
45
use std::io::{stdin, stdout};
56

@@ -21,8 +22,7 @@ pub fn login() -> anyhow::Result<()> {
2122
stdin().read_line(buffer)?;
2223
let username = buffer.trim_end();
2324

24-
let password =
25-
rpassword::read_password_from_tty(Some("Password: ")).expect("Can't get password");
25+
let password = rpassword::prompt_password("Password: ").expect("Can't get password");
2626

2727
let q = LoginMutation::build_query(login_mutation::Variables {
2828
username: username.to_string(),

0 commit comments

Comments
 (0)