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

Add support for compiling WebAssembly wasm32-unknown-unknown target #92

Merged
merged 65 commits into from
Mar 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
7cfdb51
Add instruction to build with wasm32-unknown-unknown
iceiix Jan 12, 2019
d8d772f
Update to collision-rs git with num 0.2, without rustc-serialize
iceiix Jan 12, 2019
d658f7b
Build only for wasm on Travis CI for now
iceiix Jan 12, 2019
d64cdf5
Update to rust-clipboard fork to compile with emscripten
iceiix Jan 12, 2019
f4c9426
Exclude reqwest dependency in wasm32
iceiix Jan 12, 2019
d9cb6ac
Exclude compiling clipboard pasting on wasm32
iceiix Jan 12, 2019
5b58d7f
Exclude reqwest-using code from wasm32
iceiix Jan 12, 2019
903e6da
Install wasm target with rustup in Travis CI
iceiix Jan 13, 2019
cf39f27
Update to collision 0.19.0
iceiix Jan 13, 2019
bf8c442
Increase timeout to 45 minutes
iceiix Jan 13, 2019
44f9847
Add wasm-bindgen and crate type for wams-pack
iceiix Jan 13, 2019
dd117d4
Revert "Add wasm-bindgen and crate type for wams-pack"
iceiix Jan 13, 2019
9400d24
Copy emscripten shell.html from https://github.com/kripken/emscripten…
iceiix Jan 13, 2019
2222c4f
Update shell.html to load wasm32-unknown-emscripten/debug
iceiix Jan 13, 2019
c7e4ccf
Increase travis_wait time even further, try 120 minutes
iceiix Jan 13, 2019
90cf190
Guard against zero dpi_factor
iceiix Jan 13, 2019
ceebec6
Set RUST_BACKTRACE=1 in main
iceiix Jan 13, 2019
5b97bdd
Revert "Guard against zero dpi_factor"
iceiix Jan 13, 2019
601ed61
Remove unused unnecessary import
iceiix Jan 13, 2019
9f2533a
Reference .js without paths, must now copy to target/wasm32-unknown-e…
iceiix Jan 13, 2019
cbc6381
Add lots of logging to isolate where assertion failed: validate_hidpi…
iceiix Jan 13, 2019
8c3bb90
Revert "Add lots of logging to isolate where assertion failed: valida…
iceiix Jan 13, 2019
3ec551e
Merge branch 'master' into wasm
iceiix Jan 19, 2019
9353fc1
Fix duplicate collision Cargo.lock merge error
iceiix Jan 19, 2019
f1a38e6
Use patched winit to workaround is_normal emscripten/rustc bug
iceiix Jan 19, 2019
c67bc9d
Regenerate Cargo.lock
iceiix Jan 19, 2019
0603cf7
Remove glutin/winit (no graphics)
iceiix Jan 21, 2019
f1f2921
Remove unused unneeded bzip2 features in zip crate
iceiix Jan 21, 2019
92d3e23
flate2 use Rust backend
iceiix Jan 21, 2019
4112b13
Use miniz_oxide_c_api on git to workaround https://github.com/Frommi/…
iceiix Jan 21, 2019
5a5cef1
Replace shell.html with wasm loader example based on http://webassemb…
iceiix Jan 21, 2019
6cfa7c8
Add console_error_panic_hook module for wasm backtraces
iceiix Jan 21, 2019
52d47b6
Build using wasm-pack, wasm-bindgen, run with wasm-app
iceiix Jan 21, 2019
902f159
Update to miniz_oxide 0.2.1, remove patch for https://github.com/From…
iceiix Jan 24, 2019
118fd18
Merge branch 'master' into wasm
iceiix Mar 2, 2019
e7be5ba
Update Cargo.lock from master
iceiix Mar 2, 2019
4413dc0
Update to official clipboard crate since https://github.com/aweinstoc…
iceiix Mar 2, 2019
bc0404e
Initialize GL on native, not wasm
iceiix Mar 2, 2019
36ea9e3
Set DPI factor from native or 1.0 for wasm
iceiix Mar 2, 2019
60ebe93
Remove unneeded mut on dpi_factor since it is only set once, conditio…
iceiix Mar 2, 2019
8c56b5e
Compile out Game attributes last_mouse_ on non-wasm
iceiix Mar 2, 2019
5db9097
Revert "Compile out Game attributes last_mouse_ on non-wasm"
iceiix Mar 2, 2019
3b13c1b
Attempt to compile against winit stdweb-eventloop-2 branch
iceiix Mar 2, 2019
2df103b
Revert "Attempt to compile against winit stdweb-eventloop-2 branch"
iceiix Mar 2, 2019
e8e3552
Restore glutin for all platforms
iceiix Mar 2, 2019
9fa6827
Update to glutin unreleased post-0.19.0 git revision, current master
iceiix Mar 2, 2019
07aff8f
Update to branch of glutin attempting to build for wasm
iceiix Mar 2, 2019
a791000
Update winit dependency of glutin to git master
iceiix Mar 2, 2019
d630d96
Update to glutin branch with working (compiles, doesn't run) wasm_stub
iceiix Mar 2, 2019
89b1d1c
Update webpack to fix Module parse failed: Unexpected section: 0xfe
iceiix Mar 2, 2019
2be6d89
Add app name in title on web page
iceiix Mar 2, 2019
f6f1fa6
Simplify readme to npm start, instead of npm run start
iceiix Mar 2, 2019
b217566
Remove unnecessary differences
iceiix Mar 2, 2019
41dd293
Merge branch 'master' into wasm
iceiix Mar 2, 2019
f1735b6
Remove www/.bin/create-wasm-app.js from create-wasm-app template
iceiix Mar 2, 2019
eb662a7
Cleanup www npm package json
iceiix Mar 2, 2019
1e78848
Restore testing native in Travis-CI for now
iceiix Mar 2, 2019
2273692
Merge branch 'master' into wasm
iceiix Mar 3, 2019
c95477f
Add wasm to Travis-CI test matrix
iceiix Mar 3, 2019
33a522d
Move cargo test to non-wasm Travis-CI
iceiix Mar 3, 2019
e32b9fa
Add missing wasm-pack cargo installation to Travis-CI
iceiix Mar 3, 2019
0823af9
Update glutin to try to fix Windows EGL compilation on AppVeyor
iceiix Mar 3, 2019
2f2ff90
Move wasm instructions to www/
iceiix Mar 3, 2019
9fc3717
Merge branch 'master' into wasm
iceiix Mar 3, 2019
f8977b1
Increase cache upload timeout
iceiix Mar 3, 2019
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
target/
.rust/
working/
*.log
pkg

# IntelliJ
.idea
Expand Down
18 changes: 15 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,28 @@ matrix:
allow_failures:
- rust: nightly
fast_finish: true
cache: cargo
include:
- env: WASM=true
- env: WASM=false
cache:
cargo: true
timeout: 1000
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update ; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then sudo chown root:wheel /usr/local/bin/brew ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq ; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get install -y gcc libegl1-mesa-dev libgles2-mesa-dev ; fi
script:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/lib" ; fi
- travis_wait 30 cargo build --verbose
- cargo test --verbose
- if [[ "$WASM" == "true" ]]; then
rustup target add wasm32-unknown-unknown;
cargo install wasm-bindgen-cli;
cargo install wasm-pack;
travis_wait 120 wasm-pack build;
else
travis_wait 30 cargo build --verbose;
cargo test --verbose;
fi
os:
- linux
- osx
84 changes: 75 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ description = "Multi-protocol multi-platform Minecraft-compatible client"
repository = "https://github.com/iceiix/stevenarella"
license = "(MIT OR Apache-2.0)"

[lib]
crate-type = ["cdylib", "rlib"]
path = "src/main.rs"

[profile.dev]
# Steven runs horrendously slow with no optimizations, and often freezes.
# However, building with full -O3 optimizations takes too long for a debug build.
# Use an -O1 optimization level strikes a good compromise between build and program performance.
opt-level = 1

[dependencies]
cfg-if = "0.1.2"
wasm-bindgen = "0.2.33"
sha-1 = "0.8.1"
glutin = { git = "https://github.com/tomaka/glutin", rev = "23b3b101e554e521f38c1179f90d3d2f278b857c" }
glutin = { git = "https://github.com/iceiix/glutin", rev = "97797352b5242436cb82d8ecfb44242b69766e4c" }
byteorder = "1.2.7"
reqwest = "0.9.10"
serde = "1.0.89"
serde_json = "1.0.39"
flate2 = { version = "1.0.6", features = ["rust_backend"], default-features = false }
Expand All @@ -33,9 +38,15 @@ collision = "0.19.0"
aes = "0.3.2"
cfb8 = "0.3.1"
rsa_public_encrypt_pkcs1 = "0.2.0"
clipboard = "0.5.0"
clipboard = { git = "https://github.com/aweinstock314/rust-clipboard", rev = "07d080be58a361a5bbdb548fafe9449843d968be" }
# clippy = "*"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
reqwest = "0.9.10"

[target.'cfg(target_arch = "wasm32")'.dependencies]
console_error_panic_hook = "0.1.1"

[dependencies.steven_gl]
path = "./gl"
version = "0"
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ Just compile:
cargo build --release
```

For progress on web support, see [www/](./www).

## Running

### Standalone
Expand Down
28 changes: 26 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ pub mod auth;
pub mod model;
pub mod entity;

use cfg_if::cfg_if;
use wasm_bindgen::prelude::*;
use std::sync::{Arc, RwLock, Mutex};
use std::rc::Rc;
use std::marker::PhantomData;
Expand Down Expand Up @@ -166,7 +168,21 @@ impl Game {
}
}

fn main() {
cfg_if! {
if #[cfg(target_arch = "wasm32")] {
extern crate console_error_panic_hook;
pub use console_error_panic_hook::set_once as set_panic_hook;
} else {
#[inline]
pub fn set_panic_hook() {}
}
}

#[wasm_bindgen]
pub fn main() {
set_panic_hook();
std::env::set_var("RUST_BACKTRACE", "1");

let con = Arc::new(Mutex::new(console::Console::new()));
let (vars, vsync) = {
let mut vars = console::Vars::new();
Expand Down Expand Up @@ -215,7 +231,15 @@ fn main() {
let frame_time = 1e9f64 / 60.0;

let mut screen_sys = screen::ScreenSystem::new();
screen_sys.add_screen(Box::new(screen::Login::new(vars.clone())));
#[cfg(not(target_arch = "wasm32"))]
{
screen_sys.add_screen(Box::new(screen::Login::new(vars.clone())));
}

#[cfg(target_arch = "wasm32")]
{
screen_sys.add_screen(Box::new(screen::ServerList::new(None)));
}

let textures = renderer.get_textures();
let dpi_factor = window.get_current_monitor().get_hidpi_factor();
Expand Down
5 changes: 5 additions & 0 deletions src/protocol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
}

Expand All @@ -779,6 +781,7 @@ impl convert::From<serde_json::Error> for Error {
}
}

#[cfg(not(target_arch = "wasm32"))]
impl convert::From<reqwest::Error> for Error {
fn from(e: reqwest::Error) -> Error {
Error::Reqwest(e)
Expand All @@ -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(),
}
}
Expand All @@ -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),
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/protocol/mojang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use sha1::{self, Digest};
use serde_json::json;
#[cfg(not(target_arch = "wasm32"))]
use reqwest;

#[derive(Clone, Debug)]
Expand All @@ -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<Profile, super::Error> {
let req_msg = json!({
Expand Down
6 changes: 6 additions & 0 deletions src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,11 @@ impl TextureManager {
]);
}

#[cfg(target_arch = "wasm32")]
fn process_skins(recv: mpsc::Receiver<String>, reply: mpsc::Sender<(String, Option<image::DynamicImage>)>) {
}

#[cfg(not(target_arch = "wasm32"))]
fn process_skins(recv: mpsc::Receiver<String>, reply: mpsc::Sender<(String, Option<image::DynamicImage>)>) {
use reqwest;
let client = reqwest::Client::new();
Expand All @@ -857,6 +862,7 @@ impl TextureManager {
}
}

#[cfg(not(target_arch = "wasm32"))]
fn obtain_skin(client: &::reqwest::Client, hash: &str) -> Result<image::DynamicImage, ::std::io::Error> {
use std::io::Read;
use std::fs;
Expand Down
Loading