-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from chemicstry/refactor
Major refactor and cleanup
- Loading branch information
Showing
30 changed files
with
1,164 additions
and
589 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
# Prevent running double CI when pull request is on the same repository | ||
if: | | ||
(github.event_name != 'pull_request') | ||
|| (github.event.pull_request.head.repo.id != github.event.pull_request.base.repo.id) | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Install | ||
run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh | ||
|
||
- name: Rustfmt | ||
run: cargo fmt --all --check | ||
|
||
- name: Test native | ||
run: cargo test | ||
|
||
- name: Test wasm | ||
run: ./test_wasm.sh | ||
|
||
- name: Build docs | ||
env: | ||
RUSTDOCFLAGS: "-Dwarnings" | ||
run: cargo doc --no-deps --lib --target wasm32-unknown-unknown |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ Cargo.lock | |
/examples/target | ||
/examples-wasm-pack/target | ||
.vscode/ | ||
!.vscode/settings.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "wasm_thread" | ||
version = "0.2.0" | ||
version = "0.3.0" | ||
authors = ["Jurgis Balciunas <[email protected]>"] | ||
edition = "2018" | ||
description = "An std thread replacement for wasm32 target" | ||
|
@@ -13,19 +13,36 @@ categories = ["concurrency", "wasm"] | |
readme = "README.md" | ||
|
||
[features] | ||
default = ["es_modules"] | ||
es_modules = [] | ||
|
||
[dependencies] | ||
wasm-bindgen = "0.2" | ||
web-sys = { version = "0.3", features = ["Blob", "DedicatedWorkerGlobalScope", "MessageEvent", "Url", "Worker", "WorkerType", "WorkerOptions"]} | ||
web-sys = { version = "0.3", features = [ | ||
"Blob", | ||
"DedicatedWorkerGlobalScope", | ||
"MessageEvent", | ||
"Url", | ||
"Worker", | ||
"WorkerType", | ||
"WorkerOptions", | ||
"Window", | ||
"Navigator", | ||
"WorkerNavigator", | ||
] } | ||
js-sys = "0.3" | ||
futures = "0.3" | ||
async-channel = "1.4" | ||
|
||
[dev-dependencies] | ||
log = "0.4" | ||
env_logger = "0.7" | ||
env_logger = "0.10" | ||
wasm-bindgen-test = "0.3" | ||
async-channel = "2.2" | ||
wasm-bindgen-futures = "0.4" | ||
|
||
[target.'cfg(target_arch = "wasm32")'.dev-dependencies] | ||
console_log = { version = "0.2", features = ["color"] } | ||
console_log = { version = "1.0", features = ["color"] } | ||
console_error_panic_hook = "0.1" | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["wasm32-unknown-unknown"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
<body> | ||
<script type="module"> | ||
import init, {run} from "./target/simple.js"; | ||
init() | ||
.then(() => { | ||
run() | ||
}); | ||
</script> | ||
</body> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
|
||
<body> | ||
<script type="module"> | ||
import init from "./target/simple.js"; | ||
init(); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
<body> | ||
<script src="./target/simple.js"></script> | ||
<script type="text/javascript"> | ||
wasm_bindgen('./target/simple_bg.wasm').then((wasm) => { | ||
wasm.run(); | ||
}); | ||
</script> | ||
</body> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
|
||
<body> | ||
<script src="./target/simple.js"></script> | ||
<script type="text/javascript"> | ||
wasm_bindgen('./target/simple_bg.wasm'); | ||
</script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,23 @@ | ||
use std::time::Duration; | ||
|
||
#[cfg(not(target_arch = "wasm32"))] | ||
use std::thread; | ||
#[cfg(target_arch = "wasm32")] | ||
use wasm_bindgen::prelude::*; | ||
use wasm_thread as thread; | ||
|
||
#[cfg(target_arch = "wasm32")] | ||
mod wasm { | ||
use crate::main; | ||
use wasm_bindgen::prelude::*; | ||
|
||
// Prevent `wasm_bindgen` from autostarting main on all spawned threads | ||
#[wasm_bindgen(start)] | ||
pub fn dummy_main() {} | ||
|
||
// Export explicit run function to start main | ||
#[wasm_bindgen] | ||
pub fn run() { | ||
console_log::init().unwrap(); | ||
console_error_panic_hook::set_once(); | ||
main(); | ||
} | ||
} | ||
|
||
#[wasm_bindgen(start)] | ||
fn main() { | ||
#[cfg(not(target_arch = "wasm32"))] | ||
env_logger::init_from_env( | ||
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"), | ||
); | ||
console_log::init().unwrap(); | ||
console_error_panic_hook::set_once(); | ||
|
||
for _ in 0..2 { | ||
thread::spawn(|| { | ||
for i in 1..3 { | ||
log::info!( | ||
"hi number {} from the spawned thread {:?}!", | ||
i, | ||
thread::current().id() | ||
); | ||
log::info!("hi number {} from the spawned thread {:?}!", i, thread::current().id()); | ||
thread::sleep(Duration::from_millis(1)); | ||
} | ||
}); | ||
} | ||
|
||
for i in 1..3 { | ||
log::info!( | ||
"hi number {} from the main thread {:?}!", | ||
i, | ||
thread::current().id() | ||
); | ||
log::info!("hi number {} from the main thread {:?}!", i, thread::current().id()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
$env:RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals" | ||
wasm-pack build --dev --out-dir ./no-module/target --target no-modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/bin/sh | ||
|
||
RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals" \ | ||
wasm-pack build --dev --out-dir ./no-module/target --target no-modules | ||
wasm-pack build --dev --out-dir ./no-module/target --target no-modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
$env:RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals" | ||
wasm-pack build --dev --out-dir ./module/target --target web --features wasm_thread/es_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
#!/bin/sh | ||
|
||
RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals" \ | ||
wasm-pack build --dev --out-dir ./module/target --target web --features wasm_thread/es_modules | ||
wasm-pack build --dev --out-dir ./module/target --target web --features wasm_thread/es_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
<body> | ||
<script src="./target/simple.js"></script> | ||
<script type="text/javascript"> | ||
wasm_bindgen('./target/simple_bg.wasm').then((wasm) => { | ||
wasm.run(); | ||
}); | ||
</script> | ||
</body> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
</head> | ||
|
||
<body> | ||
<script type="module"> | ||
import init from "./target/simple.js"; | ||
init(); | ||
</script> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.