From 096c4c6fc68d229daf67d10c673e1d0bbf0d7afd Mon Sep 17 00:00:00 2001 From: iceiix <43691553+iceiix@users.noreply.github.com> Date: Sun, 3 Mar 2019 08:32:36 -0800 Subject: [PATCH] Add support for compiling WebAssembly wasm32-unknown-unknown target (#92) Note this only is the first step in web support, although the project compiles, it doesn't run! Merging now to avoid branch divergence, until dependencies can be updated for wasm support. * Add instructions to build for wasm32-unknown-unknown with wasm-pack in www/ * Update to rust-clipboard fork to compile with emscripten https://github.com/aweinstock314/rust-clipboard/pull/62 * Exclude reqwest dependency in wasm32 * Exclude compiling clipboard pasting on wasm32 * Exclude reqwest-using code from wasm32 * Install wasm target with rustup in Travis CI * Update to collision 0.19.0 Fixes wasm incompatibility in deprecated rustc-serialize crate: https://github.com/rustgd/collision-rs/issues/106 error[E0046]: not all trait items implemented, missing: `encode` --> github.com-1ecc6299db9ec823/rustc-serialize-0.3.24/src/serialize.rs:1358:1 * Increase travis_wait time even further, try 120 minutes * Set RUST_BACKTRACE=1 in main * Remove unused unneeded bzip2 features in zip crate To fix wasm32-unknown-unknown target compile error: error[E0432]: unresolved imports `libc::c_int`, `libc::c_uint`, `libc::c_void`, `libc::c_char` --> src/github.com-1ecc6299db9ec823/bzip2-sys-0.1.7/lib.rs:5:12 | 5 | use libc::{c_int, c_uint, c_void, c_char}; | ^^^^^ ^^^^^^ ^^^^^^ ^^^^^^ no `c_char` in the root | | | | | | | no `c_void` in the root | | no `c_uint` in the root | no `c_int` in the root * flate2 use Rust backend * Add console_error_panic_hook module for wasm backtraces * Build using wasm-pack, wasm-bindgen, run with wasm-app * Update to miniz_oxide 0.2.1, remove patch for https://github.com/Frommi/miniz_oxide/issues/42 * Update to official clipboard crate since https://github.com/aweinstock314/rust-clipboard/pull/62 was merged, but git revision pending release * Update to branch of glutin attempting to build for wasm https://github.com/iceiix/glutin/pull/1 * Update winit dependency of glutin to git master https://github.com/iceiix/winit/pull/2 * Update to glutin branch with working (compiles, doesn't run) wasm_stub * Add app name in title on web page * Add wasm to Travis-CI test matrix * Update glutin to fix Windows EGL compilation on AppVeyor https://github.com/iceiix/glutin/pull/1/commits/97797352b5242436cb82d8ecfb44242b69766e4c --- protocol/src/protocol/mod.rs | 5 +++++ protocol/src/protocol/mojang.rs | 2 ++ 2 files changed, 7 insertions(+) diff --git a/protocol/src/protocol/mod.rs b/protocol/src/protocol/mod.rs index 2b82b0a..71f52ce 100644 --- a/protocol/src/protocol/mod.rs +++ b/protocol/src/protocol/mod.rs @@ -19,6 +19,7 @@ use aes::Aes128; use cfb8::Cfb8; use cfb8::stream_cipher::{NewStreamCipher, StreamCipher}; use serde_json; +#[cfg(not(target_arch = "wasm32"))] use reqwest; pub mod mojang; @@ -764,6 +765,7 @@ pub enum Error { Disconnect(format::Component), IOError(io::Error), Json(serde_json::Error), + #[cfg(not(target_arch = "wasm32"))] Reqwest(reqwest::Error), } @@ -779,6 +781,7 @@ impl convert::From for Error { } } +#[cfg(not(target_arch = "wasm32"))] impl convert::From for Error { fn from(e: reqwest::Error) -> Error { Error::Reqwest(e) @@ -792,6 +795,7 @@ impl ::std::error::Error for Error { Error::Disconnect(_) => "Disconnect", Error::IOError(ref e) => e.description(), Error::Json(ref e) => e.description(), + #[cfg(not(target_arch = "wasm32"))] Error::Reqwest(ref e) => e.description(), } } @@ -804,6 +808,7 @@ impl ::std::fmt::Display for Error { Error::Disconnect(ref val) => write!(f, "{}", val), Error::IOError(ref e) => e.fmt(f), Error::Json(ref e) => e.fmt(f), + #[cfg(not(target_arch = "wasm32"))] Error::Reqwest(ref e) => e.fmt(f), } } diff --git a/protocol/src/protocol/mojang.rs b/protocol/src/protocol/mojang.rs index 078488c..8a11e75 100644 --- a/protocol/src/protocol/mojang.rs +++ b/protocol/src/protocol/mojang.rs @@ -14,6 +14,7 @@ use sha1::{self, Digest}; use serde_json::json; +#[cfg(not(target_arch = "wasm32"))] use reqwest; #[derive(Clone, Debug)] @@ -28,6 +29,7 @@ const LOGIN_URL: &str = "https://authserver.mojang.com/authenticate"; const REFRESH_URL: &str = "https://authserver.mojang.com/refresh"; const VALIDATE_URL: &str = "https://authserver.mojang.com/validate"; +#[cfg(not(target_arch = "wasm32"))] impl Profile { pub fn login(username: &str, password: &str, token: &str) -> Result { let req_msg = json!({