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: on:
push: push:
branches: pull_request:
- master
jobs: jobs:
book: book:
@ -16,10 +15,23 @@ jobs:
toolchain: stable toolchain: stable
override: true 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 - name: Install mdbook
run: | run: |
(test -x $HOME/.cargo/bin/cargo-install-update || cargo install cargo-update) (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 cargo install-update -a
- name: Build book - name: Build book
@ -31,6 +43,7 @@ jobs:
- name: Deploy book - name: Deploy book
uses: JamesIves/github-pages-deploy-action@4.1.4 uses: JamesIves/github-pages-deploy-action@4.1.4
if: ${{ github.ref == 'refs/heads/master' }}
with: with:
branch: gh-pages branch: gh-pages
folder: docs folder: docs

103
Cargo.lock generated

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

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

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

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

@ -127,13 +127,13 @@ wasm-pack build examples/js-hello-world --mode no-install
## Extra options ## Extra options
The `build` command can pass extra options straight to `cargo build` even if they are not The `build` command can pass extra options straight to `cargo build` even if
supported in wasm-pack. To use them you should add standalone `--` argument at the very they are not supported in wasm-pack. To use them simply add the extra arguments
end of your command, and all the arguments you want to pass to cargo should go after. at the very end of your command, just as you would for `cargo build`. For
For example, to build the previous example using cargo's offline feature: 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"/> <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 The `test` command can pass extra options straight to `cargo test` even if they are not
supported in wasm-pack. supported in wasm-pack.
To use them you should add standalone `--` argument at the very To use them simply add the extra arguments at the very end of your command, just
end of your command, and all the arguments you want to pass to cargo should go after. as you would for `cargo test`.
`cargo test -h` for a list of all options that you can pass through. `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 # 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" # 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 # 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 # 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 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: 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`: 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::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use std::time::Instant; use std::time::Instant;
use structopt::clap::AppSettings;
use PBAR; use PBAR;
/// Everything required to configure and run the `wasm-pack build` command. /// 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. /// Everything required to configure and run the `wasm-pack build` command.
#[derive(Debug, StructOpt)] #[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 { pub struct BuildOptions {
/// The path to the Rust crate. If not set, searches up the path from the current directory. /// The path to the Rust crate. If not set, searches up the path from the current directory.
#[structopt(parse(from_os_str))] #[structopt(parse(from_os_str))]
@ -148,7 +156,7 @@ pub struct BuildOptions {
/// Sets the output file names. Defaults to package name. /// Sets the output file names. Defaults to package name.
pub out_name: Option<String>, pub out_name: Option<String>,
#[structopt(last = true)] #[structopt(allow_hyphen_values = true)]
/// List of extra options to pass to `cargo build` /// List of extra options to pass to `cargo build`
pub extra_options: Vec<String>, pub extra_options: Vec<String>,
} }
@ -176,7 +184,15 @@ type BuildStep = fn(&mut Build) -> Result<(), Error>;
impl Build { impl Build {
/// Construct a build command from the given options. /// 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_path = get_crate_path(build_opts.path)?;
let crate_data = manifest::CrateData::new(&crate_path, build_opts.out_name.clone())?; 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)); let out_dir = crate_path.join(PathBuf::from(build_opts.out_dir));

@ -3,7 +3,7 @@
use crate::child; use crate::child;
use crate::install::{self, Tool}; use crate::install::{self, Tool};
use crate::PBAR; use crate::PBAR;
use binary_install::Cache; use binary_install::{Cache, Download};
use std::path::Path; use std::path::Path;
use std::process::Command; use std::process::Command;
@ -58,6 +58,16 @@ pub fn find_wasm_opt(
cache: &Cache, cache: &Cache,
install_permitted: bool, install_permitted: bool,
) -> Result<install::Status, failure::Error> { ) -> 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"; let version = "version_78";
Ok(install::download_prebuilt( Ok(install::download_prebuilt(
&install::Tool::WasmOpt, &install::Tool::WasmOpt,

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

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

Loading…
Cancel
Save