Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove wasi conditional compilation from wasmer-registry #3368

Merged
merged 2 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions lib/registry/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@ use graphql_client::GraphQLQuery;
use serde::Deserialize;
use serde::Serialize;
use std::collections::BTreeMap;
#[cfg(not(test))]
use std::env;
use std::path::{Path, PathBuf};

pub static GLOBAL_CONFIG_FILE_NAME: &str = if cfg!(target_os = "wasi") {
"/.private/wapm.toml"
} else {
"wapm.toml"
};

#[derive(Deserialize, Default, Serialize, Debug, PartialEq, Eq)]
pub struct PartialWapmConfig {
/// The number of seconds to wait before checking the registry for a new
Expand All @@ -23,12 +15,10 @@ pub struct PartialWapmConfig {
pub registry: Registries,

/// Whether or not telemetry is enabled.
#[cfg(feature = "telemetry")]
#[serde(default)]
pub telemetry: Telemetry,

/// Whether or not updated notifications are enabled.
#[cfg(feature = "update-notifications")]
#[serde(default)]
pub update_notifications: UpdateNotifications,

Expand All @@ -51,8 +41,7 @@ pub struct UpdateNotifications {
pub enabled: String,
}

#[cfg(feature = "telemetry")]
#[derive(Deserialize, Serialize, Debug, PartialEq)]
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Default)]
pub struct Telemetry {
pub enabled: String,
}
Expand Down Expand Up @@ -284,7 +273,7 @@ impl PartialWapmConfig {
#[cfg(not(test))]
pub fn get_folder() -> Result<PathBuf, String> {
Ok(
if let Some(folder_str) = env::var("WASMER_DIR").ok().filter(|s| !s.is_empty()) {
if let Some(folder_str) = std::env::var("WASMER_DIR").ok().filter(|s| !s.is_empty()) {
let folder = PathBuf::from(folder_str);
std::fs::create_dir_all(folder.clone())
.map_err(|e| format!("cannot create config directory: {e}"))?;
Expand All @@ -307,12 +296,12 @@ impl PartialWapmConfig {

#[cfg(test)]
pub fn get_file_location(test_name: &str) -> Result<PathBuf, String> {
Ok(Self::get_folder(test_name)?.join(GLOBAL_CONFIG_FILE_NAME))
Ok(Self::get_folder(test_name)?.join(crate::GLOBAL_CONFIG_FILE_NAME))
}

#[cfg(not(test))]
pub fn get_file_location() -> Result<PathBuf, String> {
Ok(Self::get_folder()?.join(GLOBAL_CONFIG_FILE_NAME))
Ok(Self::get_folder()?.join(crate::GLOBAL_CONFIG_FILE_NAME))
}
}

Expand Down
13 changes: 0 additions & 13 deletions lib/registry/src/graphql.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
use graphql_client::*;
#[cfg(not(target_os = "wasi"))]
use reqwest::{
blocking::{multipart::Form, Client},
header::USER_AGENT,
};
use std::env;
use std::time::Duration;
#[cfg(target_os = "wasi")]
use {wasm_bus_reqwest::prelude::header::*, wasm_bus_reqwest::prelude::*};

pub(crate) mod proxy {
//! Code for dealing with setting things up to proxy network requests
Expand All @@ -28,9 +25,7 @@ pub(crate) mod proxy {
pub fn maybe_set_up_proxy_blocking(
builder: reqwest::blocking::ClientBuilder,
) -> anyhow::Result<reqwest::blocking::ClientBuilder> {
#[cfg(not(target_os = "wasi"))]
use anyhow::Context;
#[cfg(not(target_os = "wasi"))]
if let Some(proxy) = maybe_set_up_proxy_inner()
.map_err(|e| anyhow::anyhow!("{e}"))
.context("install_webc_package: failed to setup proxy for reqwest Client")?
Expand All @@ -43,9 +38,7 @@ pub(crate) mod proxy {
pub fn maybe_set_up_proxy(
builder: reqwest::ClientBuilder,
) -> anyhow::Result<reqwest::ClientBuilder> {
#[cfg(not(target_os = "wasi"))]
use anyhow::Context;
#[cfg(not(target_os = "wasi"))]
if let Some(proxy) = maybe_set_up_proxy_inner()
.map_err(|e| anyhow::anyhow!("{e}"))
.context("install_webc_package: failed to setup proxy for reqwest Client")?
Expand Down Expand Up @@ -106,12 +99,6 @@ pub(crate) mod proxy {
}
}

#[cfg(target_os = "wasi")]
pub fn whoami_distro() -> String {
whoami::os().to_lowercase()
}

#[cfg(not(target_os = "wasi"))]
pub fn whoami_distro() -> String {
whoami::distro().to_lowercase()
}
Expand Down
6 changes: 1 addition & 5 deletions lib/registry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,7 @@ pub use crate::{
queries::get_bindings_query::ProgrammingLanguage,
};

pub static GLOBAL_CONFIG_FILE_NAME: &str = if cfg!(target_os = "wasi") {
"/.private/wapm.toml"
} else {
"wapm.toml"
};
pub static GLOBAL_CONFIG_FILE_NAME: &str = "wapm.toml";

#[derive(Debug, Clone, PartialEq, PartialOrd, Eq, Ord)]
pub struct PackageDownloadInfo {
Expand Down