Add web-example to test wasm backend (based on druid's setups), make smol compile by making none of it compile ;-)

This commit is contained in:
James Laver 2020-05-09 21:54:43 +02:00
parent bc3293203f
commit 9cfed4ec0c
12 changed files with 6031 additions and 2 deletions

View File

@ -32,7 +32,6 @@ once_cell = "1.3.1"
piper = "0.1.1"
scoped-tls-hkt = "0.1.2"
slab = "0.4.2"
socket2 = { version = "0.3.12", features = ["pair", "unix"] }
[dependencies.tokio]
version = "0.2.19"
@ -40,6 +39,9 @@ default-features = false
features = ["rt-threaded"]
optional = true
[target.'cfg(not(target_arch="wasm32"))'.dependencies]
socket2 = { version = "0.3.12", features = ["pair", "unix"] }
[target.'cfg(unix)'.dependencies]
nix = "0.17.0"
@ -54,7 +56,7 @@ criterion = "0.3"
[workspace]
members = [
".",
"examples",
"examples"
]
[[bench]]

View File

@ -115,22 +115,40 @@
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
#[cfg(not(target_arch = "wasm32"))]
mod async_io;
#[cfg(not(target_arch = "wasm32"))]
mod block_on;
#[cfg(not(target_arch = "wasm32"))]
mod blocking;
#[cfg(not(target_arch = "wasm32"))]
mod context;
#[cfg(not(target_arch = "wasm32"))]
mod io_event;
#[cfg(not(target_arch = "wasm32"))]
mod reactor;
#[cfg(not(target_arch = "wasm32"))]
mod run;
#[cfg(not(target_arch = "wasm32"))]
mod task;
#[cfg(not(target_arch = "wasm32"))]
mod thread_local;
#[cfg(not(target_arch = "wasm32"))]
mod throttle;
#[cfg(not(target_arch = "wasm32"))]
mod timer;
#[cfg(not(target_arch = "wasm32"))]
mod work_stealing;
#[cfg(not(target_arch = "wasm32"))]
pub use async_io::Async;
#[cfg(not(target_arch = "wasm32"))]
pub use block_on::block_on;
#[cfg(not(target_arch = "wasm32"))]
pub use blocking::{iter, reader, writer};
#[cfg(not(target_arch = "wasm32"))]
pub use run::run;
#[cfg(not(target_arch = "wasm32"))]
pub use task::Task;
#[cfg(not(target_arch = "wasm32"))]
pub use timer::Timer;

2
web-example/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
/out/node_modules

19
web-example/Cargo.toml Normal file
View File

@ -0,0 +1,19 @@
[package]
name = "web"
version = "0.1.0"
edition = "2018"
[lib]
crate-type = ["cdylib"]
[workspace]
[dependencies]
wasm-bindgen = "0.2.38"
[dependencies.smol]
path = ".."
[dependencies.web-sys]
version = "0.3.15"
features = ["console"]

12
web-example/build.sh Normal file
View File

@ -0,0 +1,12 @@
#!/bin/sh
set -ex
# Run the `wasm-pack` CLI tool to build and process the Rust wasm file
wasm-pack build -d out/dist
# Finally, package everything up using Webpack and start a server so we can
# browse the result
cd out
npm install
npm run serve

View File

@ -0,0 +1,20 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>smol demo</title>
<style>
html, body, canvas {
margin: 0px;
padding: 0px;
width: 100%;
height: 100%;
overflow: hidden;
background-color: black;
}
</style>
</head>
<body>
<script src="index.js"></script>
</body>
</html>

1
web-example/out/index.js Normal file
View File

@ -0,0 +1 @@
import('./dist/web').then(m => m.run()).catch(console.error);

5895
web-example/out/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,13 @@
{
"scripts": {
"build": "webpack",
"serve": "webpack-dev-server"
},
"devDependencies": {
"text-encoding": "^0.7.0",
"html-webpack-plugin": "^3.2.0",
"webpack": "^4.11.1",
"webpack-cli": "^3.1.1",
"webpack-dev-server": "^3.1.0"
}
}

View File

@ -0,0 +1,20 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname),
filename: 'index.js',
},
plugins: [
// Have this example work in Edge which doesn't ship `TextEncoder` or
// `TextDecoder` at this time.
new webpack.ProvidePlugin({
TextDecoder: ['text-encoding', 'TextDecoder'],
TextEncoder: ['text-encoding', 'TextEncoder']
})
],
mode: 'development'
};

7
web-example/src/lib.rs Normal file
View File

@ -0,0 +1,7 @@
use wasm_bindgen::prelude::*;
use smol;
#[wasm_bindgen]
pub fn run() {
}

View File

@ -0,0 +1,20 @@
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
module.exports = {
entry: './index.js',
output: {
path: path.resolve(__dirname),
filename: 'index.js',
},
plugins: [
// Have this example work in Edge which doesn't ship `TextEncoder` or
// `TextDecoder` at this time.
new webpack.ProvidePlugin({
TextDecoder: ['text-encoding', 'TextDecoder'],
TextEncoder: ['text-encoding', 'TextEncoder']
})
],
mode: 'development'
};