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 building with web-sys #961

Merged
merged 49 commits into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
6357834
Enable travis
jstarry Dec 24, 2019
0d29a28
`web-sys` general conversion (#826)
daxpedda Jan 8, 2020
05bb014
Move document creation to util convenience method (#855)
jstarry Jan 8, 2020
7adfef1
`web-sys` listener conversion (#813)
daxpedda Jan 9, 2020
2aa747e
`web-sys` html conversion (#817)
daxpedda Jan 9, 2020
d9235d9
`web-sys` agent conversion (#818)
daxpedda Jan 9, 2020
437db52
Merge branch 'master' into web-sys
jstarry Jan 12, 2020
3fde267
Merge branch 'master' into web-sys
jstarry Jan 15, 2020
8bb9d88
Add build guards for invalid build configs (#866)
jstarry Jan 15, 2020
3b3fa96
`web_sys` cfg conversion (#862)
daxpedda Jan 15, 2020
c1f621a
`web-sys` services conversion (#827)
daxpedda Jan 15, 2020
c85fd29
Merge branch 'master' into web-sys
jstarry Jan 19, 2020
74fbc2c
Fix CI builds (#877)
jstarry Jan 19, 2020
317376a
Merge branch 'master' into web-sys
jstarry Jan 24, 2020
ab2d91d
Fix derive_props_test
jstarry Jan 24, 2020
045f54d
Move tests (#897) (#898)
jstarry Jan 26, 2020
047ad2a
`web-sys` fetch service conversion (#867)
daxpedda Jan 27, 2020
e4762ca
`web-sys` reader service conversion (#868)
daxpedda Jan 27, 2020
1cc57ce
`web-sys` examples/tests conversion (#841)
daxpedda Jan 28, 2020
0ed0241
Fix spawning workers in combination with `wasm-bindgen`. (#901)
daxpedda Jan 29, 2020
ecf79b2
Fix component rendering process (#913)
jstarry Feb 2, 2020
9e603ce
Simplify yew-macro a bit (#902)
jplatte Jan 29, 2020
ac4b697
Fix clippy warnings (#912)
jstarry Feb 2, 2020
49d4f10
Import Task trait in dashboard example
jstarry Feb 10, 2020
e1f6768
Remove duplicate vtag tests
jstarry Feb 16, 2020
f6fe1e0
Fix prevent_default() by non-passive (#958)
jetli Feb 22, 2020
62a68ab
Merge commit 'Allow binary-only and text-only websocket connects (#38…
daxpedda Feb 23, 2020
da9e93e
Merge commit '5629f37b575c0c0468ad867975a09d07381710db' into web-sys-…
daxpedda Feb 25, 2020
e35d5e1
Remove `Option` from most services.
daxpedda Feb 25, 2020
bd43d37
Merge commit 'd1180c0369edfc6f19f539a448e6d9bdfeb1a077' into web-sys-…
daxpedda Feb 25, 2020
05a0854
Merge commit '063c25472efcc79c017eecd73da9fbd062aa3550' into web-sys-…
daxpedda Feb 25, 2020
a2152aa
Merge commit 'c422a5ed1b4f82f986b3293c465eb825ea72a656' into web-sys-…
daxpedda Feb 25, 2020
2c6e8c7
Merge commit '3dca0c775869f5bb28e00acbba2f97d5af1aa8f5' into web-sys-…
daxpedda Feb 25, 2020
86a4a77
Merge commit 'ee4792c7f6350962afd9e605b6c1c09731ed4c9c' into web-sys-…
daxpedda Feb 25, 2020
84e2802
Remove `Option` from resize service.
daxpedda Feb 25, 2020
b0639f4
Merge commit 'aedce8bfbcdaaadc815fd4c01a65d36eb43a6ce1' into web-sys-…
daxpedda Feb 25, 2020
07da4ed
Merge commit '87f76f7736cb8c063ff291e99d43d1941c4509e4' into web-sys-…
daxpedda Feb 25, 2020
05ff2ce
Merge commit '839b793b17241783d60d4bd25acb2c41599b2081' into web-sys-…
daxpedda Feb 25, 2020
2cb6ae9
Merge commit '1ede16795a8f08975708e1808c0d528f31d5c946' into web-sys-…
daxpedda Feb 25, 2020
7019d20
Merge commit '12da2b5119abbaa17e1b2ce88740f650d035284a' into web-sys-…
daxpedda Feb 25, 2020
2ce21b7
Apply fetch changes.
daxpedda Feb 25, 2020
c69c370
Merge commit 'df14a9fc3e74c697e1e5e201f35fd177b83065ae' into web-sys-…
daxpedda Feb 25, 2020
8b7ab86
Apply reader service changes.
daxpedda Feb 25, 2020
7ebf37e
Merge commit 'a5e74e7d1dd42362abb902b13498911c269841cc' into web-sys-…
daxpedda Feb 25, 2020
2a9fb99
Merge commit 'b534a4c83a3f4dabcfa39ddf582515091a6539dd' into web-sys-…
daxpedda Feb 25, 2020
8fddbab
Merge commit '6a759329d1a5a49d062e6265b1435f8dff54c6f4' into web-sys-…
daxpedda Feb 25, 2020
4790b33
Fix `node_refs` example.
daxpedda Feb 25, 2020
4b43e24
Merge pull request #966 from daxpedda/web-sys-fixes
jstarry Feb 26, 2020
42a5e7d
Remove web-sys travis branch
jstarry Feb 28, 2020
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
72 changes: 69 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ travis-ci = { repository = "yewstack/yew" }
anyhow = "1"
anymap = "0.12"
bincode = { version = "~1.2.1", optional = true }
cfg-if = "0.1"
cfg-match = "0.2"
console_error_panic_hook = { version = "0.1", optional = true }
futures = { version = "0.3", optional = true }
gloo = { version = "0.2", optional = true }
http = "0.2"
indexmap = "1.0.2"
js-sys = { version = "0.3", optional = true }
log = "0.4"
proc-macro-hack = "0.5"
proc-macro-nested = "0.1"
Expand All @@ -33,14 +39,73 @@ serde_cbor = { version = "0.11.1", optional = true }
serde_json = "1.0"
serde_yaml = { version = "0.8.3", optional = true }
slab = "0.4"
stdweb = "0.4.20"
stdweb = { version = "0.4.20", optional = true }
thiserror = "1"
toml = { version = "0.5", optional = true }
wasm-bindgen = { version = "0.2.58", optional = true }
wasm-bindgen-futures = { version = "0.4", optional = true }
yew-macro = { version = "0.12.0", path = "crates/macro" }

[dependencies.web-sys]
version = "0.3"
optional = true
features = [
"AbortController",
"AbortSignal",
"BinaryType",
"Blob",
"BlobPropertyBag",
"console",
"DedicatedWorkerGlobalScope",
"Document",
"DomException",
"DomTokenList",
"DragEvent",
"Element",
"Event",
"EventTarget",
"File",
"FileList",
"FileReader",
"FocusEvent",
"Headers",
"HtmlElement",
"HtmlInputElement",
"HtmlSelectElement",
"HtmlTextAreaElement",
"KeyboardEvent",
"Location",
"MessageEvent",
"MouseEvent",
"Node",
"ObserverCallback",
"PointerEvent",
"ReferrerPolicy",
"Request",
"RequestCache",
"RequestCredentials",
"RequestInit",
"RequestMode",
"RequestRedirect",
"Response",
"Storage",
"Text",
"TouchEvent",
"UiEvent",
"Url",
"WebSocket",
"WheelEvent",
"Window",
"Worker",
"WorkerGlobalScope",
"WorkerOptions",
]

# Changes here must be reflected in `build.rs`
[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dependencies]
wasm-bindgen = "0.2.58"

# Changes here must be reflected in `build.rs`
[target.'cfg(all(target_arch = "wasm32", not(target_os="wasi"), not(cargo_web)))'.dev-dependencies]
wasm-bindgen-test = "0.3.4"
base64 = "0.11.0"
Expand All @@ -57,9 +122,10 @@ rmp-serde = "0.14.0"
bincode = "~1.2.1"

[features]
default = ["services", "agent"]
default = []
std_web = ["stdweb"]
web_sys = ["console_error_panic_hook", "futures", "gloo", "js-sys", "web-sys", "wasm-bindgen", "wasm-bindgen-futures"]
doc_test = []
web_test = []
wasm_test = []
services = []
agent = ["bincode"]
Expand Down
25 changes: 22 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
use std::env;

pub fn main() {
let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
if cfg!(all(feature = "web_sys", feature = "std_web")) {
panic!("Yew does not allow the `web_sys` and `std_web` cargo features to be used simultaneously");
} else if cfg!(not(any(feature = "web_sys", feature = "std_web"))) {
panic!("Yew requires selecting either the `web_sys` or `std_web` cargo feature");
}

let target_os = env::var("CARGO_CFG_TARGET_OS").unwrap_or_default();
let using_wasi = target_os == "wasi";

let cargo_web = env::var("COMPILING_UNDER_CARGO_WEB").unwrap_or_default();
if target_arch == "wasm32" && cargo_web != "1" {
println!("cargo:rustc-cfg=feature=\"wasm_bindgen_test\"");
let using_cargo_web = cargo_web == "1";
if using_cargo_web && cfg!(feature = "web_sys") {
panic!("cargo-web is not compatible with web-sys");
}

let target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap_or_default();
let using_wasm_bindgen = target_arch == "wasm32" && !using_cargo_web && !using_wasi;
if !using_wasm_bindgen && cfg!(all(feature = "web_sys", not(feature = "doc_test"))) {
let target = env::var("TARGET").unwrap_or_default();
panic!(
"Selected target `{}` is not compatible with web-sys",
target
);
}
}
8 changes: 4 additions & 4 deletions ci/check_examples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ cd examples/showcase

if [ "$emscripten_supported" == "0" ]; then
# TODO - Emscripten builds are broken on rustc > 1.39.0
cargo web build --target asmjs-unknown-emscripten
cargo web build --target wasm32-unknown-emscripten
cargo web build --target asmjs-unknown-emscripten --features std_web
cargo web build --target wasm32-unknown-emscripten --features std_web
fi

# TODO showcase doesn't support wasm-bindgen yet
cargo web build --target wasm32-unknown-unknown
cargo web build --target wasm32-unknown-unknown --features std_web
cargo build --target wasm32-unknown-unknown --features web_sys

# Reset cwd
cd ../..
3 changes: 2 additions & 1 deletion ci/run_checks.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ fi

set -euxo pipefail
cargo fmt --all -- --check
cargo clippy -- --deny=warnings
cargo clippy --features std_web -- --deny=warnings
cargo clippy --target wasm32-unknown-unknown --features web_sys -- --deny=warnings
18 changes: 11 additions & 7 deletions ci/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ set -euxo pipefail # https://vaneyckt.io/posts/safer_bash_scripts_with_set_euxo_

if [ "$emscripten_supported" == "0" ]; then
# TODO - Emscripten builds are broken on rustc > 1.39.0
cargo web test --features web_test --target asmjs-unknown-emscripten
cargo web test --features web_test --target wasm32-unknown-emscripten
cargo web test --target asmjs-unknown-emscripten --features std_web
cargo web test --target wasm32-unknown-emscripten --features std_web
fi

cargo test --features wasm_test --target wasm32-unknown-unknown
cargo test --test macro_test
cargo test --test derive_props_test
cargo test --doc --all-features
(cd crates/macro && cargo test --doc)
cargo test --target wasm32-unknown-unknown --features wasm_test,std_web
cargo test --target wasm32-unknown-unknown --features wasm_test,web_sys
cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,std_web
cargo test --doc --features doc_test,wasm_test,yaml,msgpack,cbor,web_sys

(cd crates/macro \
&& cargo test --test macro_test \
&& cargo test --test derive_props_test \
&& cargo test --doc)
5 changes: 4 additions & 1 deletion crates/macro/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "1.0", features = ["full", "extra-traits"] }

# testing
[dev-dependencies]
yew = { path = "../.." }
rustversion = "1.0"
trybuild = "1.0"
yew = { path = "../..", features = ["std_web"] }

[build-dependencies]

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ error[E0599]: no method named `build` found for type `t3::PropsBuilder<t3::Props
...
35 | Props::builder().build();
| ^^^^^ method not found in `t3::PropsBuilder<t3::PropsBuilderStep_missing_required_prop_value>`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `build`, perhaps you need to implement it:
candidate #1: `proc_macro::bridge::server::TokenStreamBuilder`

error[E0599]: no method named `b` found for type `t4::PropsBuilder<t4::PropsBuilderStep_missing_required_prop_a>` in the current scope
--> $DIR/fail.rs:49:26
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[allow(dead_code)]
#[rustversion::attr(stable(1.41.0), cfg_attr(not(feature = "web_test"), test))]
#[rustversion::attr(stable(1.41.0), test)]
fn tests() {
let t = trybuild::TestCases::new();
t.pass("tests/derive_props/pass.rs");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ error[E0599]: no method named `string` found for type `ChildPropertiesBuilder<Ch
...
72 | html! { <Child string="abc" /> };
| ^^^^^^ method not found in `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `string`, perhaps you need to implement it:
candidate #1: `proc_macro::bridge::server::Literal`

error[E0599]: no method named `children` found for type `ChildPropertiesBuilder<ChildPropertiesBuilderStep_missing_required_prop_int>` in the current scope
--> $DIR/html-component-fail.rs:76:5
Expand All @@ -218,6 +222,9 @@ error[E0599]: no method named `build` found for type `ChildContainerPropertiesBu
78 | html! { <ChildContainer /> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `ChildContainerPropertiesBuilder<ChildContainerPropertiesBuilderStep_missing_required_prop_children>`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `build`, perhaps you need to implement it:
candidate #1: `proc_macro::bridge::server::TokenStreamBuilder`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0599]: no method named `build` found for type `ChildContainerPropertiesBuilder<ChildContainerPropertiesBuilderStep_missing_required_prop_children>` in the current scope
Expand All @@ -229,6 +236,9 @@ error[E0599]: no method named `build` found for type `ChildContainerPropertiesBu
79 | html! { <ChildContainer></ChildContainer> };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `ChildContainerPropertiesBuilder<ChildContainerPropertiesBuilderStep_missing_required_prop_children>`
|
= help: items from traits can only be used if the trait is implemented and in scope
= note: the following trait defines an item `build`, perhaps you need to implement it:
candidate #1: `proc_macro::bridge::server::TokenStreamBuilder`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0277]: the trait bound `yew::virtual_dom::vcomp::VChild<Child>: std::convert::From<&str>` is not satisfied
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/macro_test.rs → crates/macro/tests/macro_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[allow(dead_code)]
#[rustversion::attr(stable(1.41.0), cfg_attr(not(feature = "web_test"), test))]
#[rustversion::attr(stable(1.41.0), test)]
fn tests() {
let t = trybuild::TestCases::new();

Expand Down
34 changes: 22 additions & 12 deletions examples/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,28 +1,38 @@
[workspace]
members = [
"counter",
"crm",
"custom_components",
"dashboard",
"node_refs",
"file_upload",
"fragments",
"futures",
"game_of_life",
"inner_html",
"js_callback",
"large_table",
"minimal",
"mount_point",
"multi_thread",
"nested_list",
"npm_and_rest",
"pub_sub",
"server",
"showcase",
"textarea",
"timer",
"todomvc",
"two_apps",
"pub_sub",
"webgl"
"webgl",
"std_web/counter",
"std_web/file_upload",
"std_web/inner_html",
"std_web/js_callback",
"std_web/mount_point",
"std_web/multi_thread",
"std_web/node_refs",
"std_web/npm_and_rest",
"std_web/todomvc",
"std_web/two_apps",
"web_sys/counter",
"web_sys/file_upload",
"web_sys/inner_html",
"web_sys/js_callback",
"web_sys/mount_point",
"web_sys/multi_thread",
"web_sys/node_refs",
"web_sys/npm_and_rest",
"web_sys/todomvc",
"web_sys/two_apps",
]
Loading