-
Notifications
You must be signed in to change notification settings - Fork 24
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
Major refactor and cleanup #14
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
e246f42
Add required dependencies to README
chemicstry a4b0153
Move javascript files into a subdir
chemicstry 35ea30d
Move utilities into a separate module
chemicstry dac94ea
Use spin locks to prevent main thread panics
chemicstry c7c5c88
Move scoped into a module
chemicstry b64d531
Add better formatting rules
chemicstry dc0bb62
Properly implement scoped thread join
chemicstry 1097fe7
Major refactor to properly implement join guards
chemicstry 3e032fb
Simplify examples without dummy main
chemicstry 9d50823
Remove unneeded flags in scripts
chemicstry 2b6105e
Use modules by default
chemicstry 28bc56f
Fix race condition in Signal
chemicstry 321f8e8
Add tests
chemicstry 15ee3e2
Fix tests
chemicstry a8897d2
Optimize CI
chemicstry 43f5398
Fix newlines
chemicstry ad02127
Add more scope tests
chemicstry bfc2658
Add async channel tests
chemicstry ff3628a
chrome driver seems broken at the moment
chemicstry 34e379a
Nightly is no longer needed
chemicstry e919f9b
Fix async channel test
chemicstry 71e6124
Revert "Nightly is no longer needed"
chemicstry b273e53
Update nightly
chemicstry 2ea79c4
Bump version
chemicstry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only problem I had with the PR, I needed to update { default-features = false }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought module support is now common enough to be default. I will bump the version of course.