From 4aab03c67869ff4ecc473794f62e35e4565a01d6 Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Fri, 29 May 2020 22:22:30 +0100 Subject: Make reqwest build on wasm --- dhall/src/semantics/resolve/resolve.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'dhall/src/semantics/resolve/resolve.rs') diff --git a/dhall/src/semantics/resolve/resolve.rs b/dhall/src/semantics/resolve/resolve.rs index 3b72b9e..fb770db 100644 --- a/dhall/src/semantics/resolve/resolve.rs +++ b/dhall/src/semantics/resolve/resolve.rs @@ -159,9 +159,7 @@ impl ImportLocation { fn fetch_text(self) -> Result { Ok(match self { ImportLocation::Local(path) => std::fs::read_to_string(&path)?, - ImportLocation::Remote(url) => { - reqwest::blocking::get(url).unwrap().text().unwrap() - } + ImportLocation::Remote(url) => download_http_text(url)?, ImportLocation::Env(var_name) => match env::var(var_name) { Ok(val) => val, Err(_) => return Err(ImportError::MissingEnvVar.into()), @@ -197,6 +195,18 @@ fn mkexpr(kind: UnspannedExpr) -> Expr { Expr::new(kind, Span::Artificial) } +// TODO: error handling +#[cfg(not(target_arch = "wasm32"))] +pub(crate) fn download_http_text(url: Url) -> Result { + Ok(reqwest::blocking::get(url).unwrap().text().unwrap()) +} +#[cfg(target_arch = "wasm32")] +pub(crate) fn download_http_text(url: Url) -> Result { + blocking::block_on(async { + Ok(reqwest::get(url).await.unwrap().text().await.unwrap()) + }) +} + fn make_aslocation_uniontype() -> Expr { let text_type = mkexpr(ExprKind::Builtin(Builtin::Text)); let mut union = BTreeMap::default(); -- cgit v1.2.3