Merge branch 'master' into fix-exe

master
Jesper Håkansson 4 years ago
commit d2e30a29ba
  1. 15
      .github/workflows/approve.yml
  2. 19
      .github/workflows/book.yml
  3. 103
      Cargo.lock
  4. 3
      Cargo.toml
  5. 14
      docs/_theme/header.hbs
  6. 1
      docs/src/SUMMARY.md
  7. 10
      docs/src/commands/build.md
  8. 12
      docs/src/commands/test.md
  9. 38
      docs/src/prerequisites/considerations.md
  10. 2
      docs/src/tutorials/npm-browser-packages/template-deep-dive/wee_alloc.md
  11. 20
      src/command/build.rs
  12. 12
      src/wasm_opt.rs
  13. 1
      tests/all/build.rs
  14. 2
      tests/all/main.rs

@ -0,0 +1,15 @@
name: Automatic Approve
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
automatic-approve:
name: Automatic Approve
runs-on: ubuntu-latest
steps:
- name: Automatic Approve
uses: mheap/automatic-approve-action@v1.1.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
workflows: "test.yml"

@ -2,8 +2,7 @@ name: Build and deploy documentation book
on:
push:
branches:
- master
pull_request:
jobs:
book:
@ -16,10 +15,23 @@ jobs:
toolchain: stable
override: true
- name: Cache dependencies
uses: actions/cache@v2
env:
cache-name: cache-mdbook
with:
path: |
~/.cargo/.crates.toml
~/.cargo/.crates2.json
~/.cargo/bin
~/.cargo/registry/index
~/.cargo/registry/cache
key: ${{ runner.os }}-build-${{ env.cache-name }}-0.3 }}
- name: Install mdbook
run: |
(test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update)
(test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.2" mdbook)
(test -x $HOME/.cargo/bin/mdbook || cargo install --vers "^0.3" mdbook)
cargo install-update -a
- name: Build book
@ -31,6 +43,7 @@ jobs:
- name: Deploy book
uses: JamesIves/github-pages-deploy-action@4.1.4
if: ${{ github.ref == 'refs/heads/master' }}
with:
branch: gh-pages
folder: docs

103
Cargo.lock generated

@ -537,9 +537,9 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aa4da3c766cd7a0db8242e326e9e4e081edd567072893ed320008189715366a4"
dependencies = [
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
"proc-macro2",
"quote",
"syn",
"synstructure",
]
@ -1323,9 +1323,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
"proc-macro2",
"quote",
"syn",
"version_check",
]
@ -1335,27 +1335,18 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2 1.0.29",
"quote 1.0.9",
"proc-macro2",
"quote",
"version_check",
]
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid 0.1.0",
]
[[package]]
name = "proc-macro2"
version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
dependencies = [
"unicode-xid 0.2.2",
"unicode-xid",
]
[[package]]
@ -1374,22 +1365,13 @@ version = "1.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0"
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2 1.0.29",
"proc-macro2",
]
[[package]]
@ -1787,9 +1769,9 @@ version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
dependencies = [
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -1826,21 +1808,24 @@ dependencies = [
[[package]]
name = "serial_test"
version = "0.2.0"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "50bfbc39343545618d97869d77f38ed43e48dd77432717dbc7ed39d797f3ecbe"
checksum = "f74862f16557830c73deefde614c906f8af0157e064b64f156e32a0b12d7114c"
dependencies = [
"lazy_static 1.4.0",
"parking_lot 0.9.0",
"serial_test_derive",
]
[[package]]
name = "serial_test_derive"
version = "0.2.0"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89dd85be2e2ad75b041c9df2892ac078fa6e0b90024028b2b9fb4125b7530f01"
checksum = "3c188479c8b700998829c168d7a4c21032660b0dd2ed87a0b166c85811750740"
dependencies = [
"quote 0.6.13",
"syn 0.15.44",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -1920,20 +1905,9 @@ checksum = "134d838a2c9943ac3125cf6df165eda53493451b719f3255b2a26b85f772d0ba"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
]
[[package]]
name = "syn"
version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid 0.1.0",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -1942,9 +1916,9 @@ version = "1.0.76"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6f107db402c2c2055242dbf4d2af0e69197202e9faacbef9571bbe47f5a1b84"
dependencies = [
"proc-macro2 1.0.29",
"quote 1.0.9",
"unicode-xid 0.2.2",
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
@ -1953,10 +1927,10 @@ version = "0.12.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "474aaa926faa1603c40b7885a9eaea29b444d1cb2850cb7c0e37bb1a4182f4fa"
dependencies = [
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
"unicode-xid 0.2.2",
"proc-macro2",
"quote",
"syn",
"unicode-xid",
]
[[package]]
@ -2049,9 +2023,9 @@ version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c"
dependencies = [
"proc-macro2 1.0.29",
"quote 1.0.9",
"syn 1.0.76",
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -2287,12 +2261,6 @@ version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "unicode-xid"
version = "0.2.2"
@ -2420,7 +2388,6 @@ dependencies = [
"serde_ignored",
"serde_json",
"serial_test",
"serial_test_derive",
"siphasher",
"strsim",
"structopt",

@ -41,8 +41,7 @@ chrono = "0.4.6"
assert_cmd = "0.11"
lazy_static = "1.1.0"
predicates = "1.0.0"
serial_test = "0.2"
serial_test_derive = "0.2"
serial_test = "0.3"
tempfile = "3"
[features]

@ -35,10 +35,12 @@
}
</style>
<header class='warning'>
This is the <strong>unpublished</strong> documentation of
<code>wasm-pack</code>, the published documentation is available
<a href="https://rustwasm.github.io/docs/wasm-pack/">
on the main Rust and WebAssembly documentation site
</a>. Features documented here may not be available in released versions of
<code>wasm-pack</code>.
<p>
This is the <strong>unpublished</strong> documentation of
<code>wasm-pack</code>, the published documentation is available
<a href="https://rustwasm.github.io/docs/wasm-pack/">
on the main Rust and WebAssembly documentation site
</a>. Features documented here may not be available in released versions of
<code>wasm-pack</code>.
</p>
</header>

@ -4,6 +4,7 @@
- [Quickstart](./quickstart.md)
- [Prerequisites](./prerequisites/index.md)
- [npm (optional)](./prerequisites/npm.md)
- [considerations](./prerequisites/considerations.md)
- [Non-`rustup` setups](./prerequisites/non-rustup-setups.md)
- [Commands](./commands/index.md)
- [`new`](./commands/new.md)

@ -127,13 +127,13 @@ wasm-pack build examples/js-hello-world --mode no-install
## Extra options
The `build` command can pass extra options straight to `cargo build` even if they are not
supported in wasm-pack. To use them you should add standalone `--` argument at the very
end of your command, and all the arguments you want to pass to cargo should go after.
For example, to build the previous example using cargo's offline feature:
The `build` command can pass extra options straight to `cargo build` even if
they are not supported in wasm-pack. To use them simply add the extra arguments
at the very end of your command, just as you would for `cargo build`. For
example, to build the previous example using cargo's offline feature:
```
wasm-pack build examples/js-hello-world --mode no-install -- --offline
wasm-pack build examples/js-hello-world --mode no-install --offline
```
<hr style="font-size: 1.5em; margin-top: 2.5em"/>

@ -44,8 +44,8 @@ wasm-pack test --node --firefox --chrome --safari --headless
The `test` command can pass extra options straight to `cargo test` even if they are not
supported in wasm-pack.
To use them you should add standalone `--` argument at the very
end of your command, and all the arguments you want to pass to cargo should go after.
To use them simply add the extra arguments at the very end of your command, just
as you would for `cargo test`.
`cargo test -h` for a list of all options that you can pass through.
@ -72,16 +72,16 @@ $ tree crates/foo
```
# Run all tests in tests/diff_patch.rs in Firefox
wasm-pack test crates/foo --firefox --headless -- --test diff_patch
wasm-pack test crates/foo --firefox --headless --test diff_patch
# Run all tests in tests/diff_patch.rs that contain the word "replace"
wasm-pack test crates/foo --firefox --headless -- --test diff_patch replace
wasm-pack test crates/foo --firefox --headless --test diff_patch replace
# Run all tests inside of a `tests` module inside of src/lib/diff.rs
wasm-pack test crates/foo --firefox --headless -- --lib diff::tests
wasm-pack test crates/foo --firefox --headless --lib diff::tests
# Same as the above, but only if they contain the word replace
wasm-pack test crates/foo --firefox --headless -- --lib diff::tests::replace
wasm-pack test crates/foo --firefox --headless --lib diff::tests::replace
```
Note that you can also filter tests by location in which they're supposed to

@ -0,0 +1,38 @@
# nodejs
Currently, `wasm-pack` generated npm modules require us to you have [fetch] polyfill in your node project.
If there is a module from `wasm-pack build --target nodejs` you may encounter some errors regarding global `Headers`, `Request`, `Response` and `fetch` Web APIs.
## Common errors:
```js
ReqwestError(reqwest::Error { kind: Builder, source: "JsValue(ReferenceError: Headers is not defined
ReqwestError(reqwest::Error { kind: Builder, source: "JsValue(ReferenceError: Request is not defined
var ret = getObject(arg0) instanceof Response;
ReferenceError: Response is not defined
```
## Workarround
Import or declare fetch and objects: Headers, Request, Response
```ts
// CommonJS
const fetch = require('node-fetch');
// ES Module
import fetch from 'node-fetch';
// @ts-ignore
global.fetch = fetch;
// @ts-ignore
global.Headers = fetch.Headers;
// @ts-ignore
global.Request = fetch.Request;
// @ts-ignore
global.Response = fetch.Response;
```
[fetch]: https://github.com/node-fetch/node-fetch

@ -40,7 +40,7 @@ allocator, but only if the `wee_alloc` feature is enabled at compile time. The
feature can be enabled by passing extra options while building:
```
$ wasm-pack build -- --features wee_alloc
$ wasm-pack build --features wee_alloc
```
or alternatively you could turn it on by default in `Cargo.toml`:

@ -18,6 +18,7 @@ use std::fmt;
use std::path::PathBuf;
use std::str::FromStr;
use std::time::Instant;
use structopt::clap::AppSettings;
use PBAR;
/// Everything required to configure and run the `wasm-pack build` command.
@ -101,6 +102,13 @@ pub enum BuildProfile {
/// Everything required to configure and run the `wasm-pack build` command.
#[derive(Debug, StructOpt)]
#[structopt(
// Allows unknown `--option`s to be parsed as positional arguments, so we can forward it to `cargo`.
setting = AppSettings::AllowLeadingHyphen,
// Allows `--` to be parsed as an argument, so we can forward it to `cargo`.
setting = AppSettings::TrailingVarArg,
)]
pub struct BuildOptions {
/// The path to the Rust crate. If not set, searches up the path from the current directory.
#[structopt(parse(from_os_str))]
@ -148,7 +156,7 @@ pub struct BuildOptions {
/// Sets the output file names. Defaults to package name.
pub out_name: Option<String>,
#[structopt(last = true)]
#[structopt(allow_hyphen_values = true)]
/// List of extra options to pass to `cargo build`
pub extra_options: Vec<String>,
}
@ -176,7 +184,15 @@ type BuildStep = fn(&mut Build) -> Result<(), Error>;
impl Build {
/// Construct a build command from the given options.
pub fn try_from_opts(build_opts: BuildOptions) -> Result<Self, Error> {
pub fn try_from_opts(mut build_opts: BuildOptions) -> Result<Self, Error> {
if let Some(path) = &build_opts.path {
if path.to_string_lossy().starts_with("--") {
let path = build_opts.path.take().unwrap();
build_opts
.extra_options
.insert(0, path.to_string_lossy().into_owned().to_string());
}
}
let crate_path = get_crate_path(build_opts.path)?;
let crate_data = manifest::CrateData::new(&crate_path, build_opts.out_name.clone())?;
let out_dir = crate_path.join(PathBuf::from(build_opts.out_dir));

@ -3,7 +3,7 @@
use crate::child;
use crate::install::{self, Tool};
use crate::PBAR;
use binary_install::Cache;
use binary_install::{Cache, Download};
use std::path::Path;
use std::process::Command;
@ -58,6 +58,16 @@ pub fn find_wasm_opt(
cache: &Cache,
install_permitted: bool,
) -> Result<install::Status, failure::Error> {
// First attempt to look up in PATH. If found assume it works.
if let Ok(path) = which::which("wasm-opt") {
PBAR.info(&format!("found wasm-opt at {:?}", path));
match path.as_path().parent() {
Some(path) => return Ok(install::Status::Found(Download::at(path))),
None => {}
}
}
let version = "version_78";
Ok(install::download_prebuilt(
&install::Tool::WasmOpt,

@ -264,7 +264,6 @@ fn build_with_arbitrary_cargo_options() {
fixture
.wasm_pack()
.arg("build")
.arg("--")
.arg("--no-default-features")
.assert()
.success();

@ -8,7 +8,7 @@ extern crate serde_derive;
extern crate binary_install;
extern crate serde_json;
#[macro_use]
extern crate serial_test_derive;
extern crate serial_test;
extern crate structopt;
extern crate tempfile;
extern crate wasm_pack;

Loading…
Cancel
Save