Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
CryZe committed Nov 20, 2019
1 parent 8be6a05 commit 90dfd57
Show file tree
Hide file tree
Showing 15 changed files with 570 additions and 57 deletions.
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ smallvec = { version = "1.0.0", default-features = false, optional = true }
euc = { version = "0.4.2", default-features = false, optional = true }
vek = { version = "0.9.8", default-features = false, optional = true }

# WebAssembly in the Web
web-sys = { version = "0.3.28", default-features = false, features = ["Performance", "Window"], optional = true }

[dev-dependencies]
memmem = "0.1.1"
criterion = "0.3.0"
Expand All @@ -83,6 +86,7 @@ more-image-formats = ["image/webp", "image/pnm", "image/ico", "image/jpeg", "ima
image-shrinking = ["more-image-formats"]
rendering = ["std", "more-image-formats", "euclid", "livesplit-title-abbreviations", "lyon", "rusttype", "smallvec"]
software-rendering = ["rendering", "euc", "vek", "derive_more/mul"]
wasm-web = ["web-sys", "chrono/wasmbind", "livesplit-hotkey/wasm-web"]

# FIXME: Some targets don't have atomics, but we can't test for this properly
# yet. So there's a feature you explicitly have to opt into to deactivate the
Expand Down
25 changes: 24 additions & 1 deletion capi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ unsafe fn str(s: *const c_char) -> &'static str {
}
}

//raw file descriptor handling
// raw file descriptor handling
#[cfg(unix)]
unsafe fn get_file(fd: i64) -> File {
use std::os::unix::io::FromRawFd;
Expand Down Expand Up @@ -153,3 +153,26 @@ unsafe fn release_file(file: File) {

#[cfg(not(any(windows, unix)))]
unsafe fn release_file(_: File) {}

#[cfg(all(
target_arch = "wasm32",
not(any(target_os = "emscripten", target_os = "wasi",)),
))]
#[no_mangle]
pub extern "C" fn alloc(size: usize) -> *mut u8 {
let mut buf = Vec::with_capacity(size);
let ptr = buf.as_mut_ptr();
core::mem::forget(buf);
ptr
}

#[cfg(all(
target_arch = "wasm32",
not(any(target_os = "emscripten", target_os = "wasi",)),
))]
#[no_mangle]
pub extern "C" fn dealloc(ptr: *mut u8, cap: usize) {
unsafe {
let _buf = Vec::from_raw_parts(ptr, 0, cap);
}
}
7 changes: 6 additions & 1 deletion crates/livesplit-hotkey/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,16 @@ promising-future = { version = "0.2.4", optional = true }
stdweb = { version = "0.3.0", optional = true }
parking_lot = { version = "0.9.0", optional = true }

[target.'cfg(all(target_arch = "wasm32", target_os = "unknown"))'.dependencies]
wasm-bindgen = { version = "0.2.54", optional = true }
web-sys = { version = "0.3.28", default-features = false, features = ["KeyboardEvent", "EventTarget", "Window"], optional = true }

[dependencies]
cfg-if = "0.1.10"
snafu = { version = "0.6.0", default-features = false }
serde = { version = "1.0.98", default-features = false, features = ["derive", "alloc"] }
snafu = { version = "0.6.0", default-features = false }

[features]
default = ["std"]
std = ["snafu/std", "serde/std", "stdweb", "parking_lot", "x11-dl", "mio", "promising-future", "winapi", "parking_lot"]
wasm-web = ["wasm-bindgen", "web-sys"]
11 changes: 9 additions & 2 deletions crates/livesplit-hotkey/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,15 @@ cfg_if::cfg_if! {
#[macro_use]
extern crate stdweb;
} else if #[cfg(all(target_arch = "wasm32", target_os = "unknown"))] {
pub mod wasm;
pub use crate::wasm::*;
cfg_if::cfg_if! {
if #[cfg(feature = "wasm-web")] {
mod wasm_web;
pub use self::wasm_web::*;
} else {
mod wasm_unknown;
pub use self::wasm_unknown::*;
}
}
} else {
pub mod other;
pub use crate::other::*;
Expand Down
File renamed without changes.
Loading

0 comments on commit 90dfd57

Please sign in to comment.