Commit Graph

585 Commits

Author SHA1 Message Date
Alex Crichton
e134505b90 Refactor the types.rs types and structures (#681)
* Refactor the `types.rs` types and structures

A few changes applied along the way:

* Documentation added to most methods and types.
* Limits are now stored with the maximum as optional rather than a
  sentinel u32 value for `None`.
* The `Name` type was removed in favor of just using a bare `String`.
* The `Extern` prefix in the varaints of `ExternType` has been removed
  since it was redundant.
* Accessors of `ExternType` variants no longer panic, and unwrapping
  versions were added with "unwrap" in the name.
* Fields and methods named `r#type` were renamed to `ty` to avoid
  requiring a raw identifier to use them.

* Remove `fail-fast: false`

This was left around since the development of GitHub Actions for
wasmtime, but they're no longer needed!

* Fix compilation of the test-programs code

* Fix compilation of wasmtime-py package

* Run rustfmt
2019-12-06 16:19:55 -06:00
Yury Delendik
cc6e8e1af2 Move cranelift dependencies to wasmtime-environ (#669)
Groups all CL data structures into single dependency to be used accross wasmtime project.
2019-12-05 16:07:34 -06:00
Dan Gohman
8a1b7965d8 Move command function invocation out of wasmtime-instance. (#585)
Previously, "_start" was run as part of module instantiation, which
meant it was always run, even for wasm modules that weren't being
loaded as commands. Now, just invoke it from the wasmtime driver,
which for now is the only place that runs wasm modules as actual
commands.

Also, stop recognizing the old "main" entry point, which tools have
stopped using a while ago, and switch to start recognizing the ""
entrypoint.
2019-12-05 14:03:17 -08:00
Josh Triplett
2635ccb742 Rename the wasmtime_api library to match the containing wasmtime crate (#594)
* Rename the `wasmtime_api` library to match the containing `wasmtime` crate

Commit d9ca508f80 renamed the
`wasmtime-api` crate to `wasmtime`, but left the name of the library it
contains as `wasmtime_api`.

It's fairly unusual for a crate to contain a library with a different
name, and it results in rather confusing error messages for a user; if
you list `wasmtime = "0.7"` in `Cargo.toml`, you can't `use
wasmtime::*`, you have to `use wasmtime_api::*;`.

Rename the `wasmtime_api` library to `wasmtime`.

* Stop renaming wasmtime to api on imports

Various users renamed the crate formerly known as wasmtime_api to api,
and then used api:: prefixes everywhere; change those all to wasmtime::
and drop the renaming.
2019-11-19 14:47:39 -08:00
Dan Gohman
58dd4c6c88 Replace more miscellaenous read_wasm utilities with wat::parse_file. (#601) 2019-11-19 09:34:17 -06:00
Dan Gohman
d645902620 Add support for wasi_snapshot_preview1. (#592)
* Add support for wasi_snapshot_preview1.

This adds support for the new ABI, while preserving compatibility
support for the old ABI.

* Fix compilation on platforms where nlink_t isn't 64-bit.

* rustfmt

* Fix Windows build errors.
2019-11-18 22:07:16 -08:00
Dan Gohman
7d47a04277 Remove unneded prefix argument from instantiate_wasi. (#584)
* Remove unneded prefix argument from `instantiate_wasi`.

This was an artifact of an earlier backwards-compatibility mechanism
which is no longer needed.

* Remove unneeded prefix arg from remaning uses
2019-11-16 11:40:14 -08:00
Daniel Bevenius
0753b1206b Use nested paths for use declarations (#576)
* Use nested paths for use declarations

This commit uses nested paths for cranelift_codegen and some of the
standard library use declarations.

The main motivation for this is that it seems to be consistent with
other use declarations in this file, and saves a few lines.

* squash: fix rustfmt issues
2019-11-16 10:26:45 -08:00
Yury Delendik
ea56118651 Add/use create_wasi_instance() instead of instantiate_wasi(). (#571)
* Add/use create_wasi_instance() instead of instantiate_wasi().

* rm Result from Instance::from_handle
2019-11-15 16:48:05 -08:00
Daniel Bevenius
a495418210 Correct minor typo in wasmtime.rs doc comment (#568) 2019-11-14 09:06:30 -06:00
Alex Crichton
fb60a21930 Reduce number of crates needed for Config usage
This commit is an attempt to reduce the number of crates necessary to
link to when using `wasmtime::Config` in "default mode" or with only one
or two tweaks. The change moves to a builder-style pattern for `Config`
to only require importing crates as necessary if you configure a
particular setting. This then also propagates that change to `Context`
as well by taking a `Config` instead of requiring that all arguments are
passed alone.
2019-11-13 08:32:13 -08:00
Yury Delendik
98266498af Use embedded API in the wasmtime-rust (#540) 2019-11-13 09:15:37 -06:00
Dan Gohman
061b453255 Remove unneeded extern crate, macro_use, and tidy uses. 2019-11-08 17:55:38 -08:00
Dan Gohman
e8f08193fc Reformat some long lines and macros. 2019-11-08 17:15:37 -08:00
Alex Crichton
5a5f241f98 Fix typo in warning message for --invoke (#530)
This was supposed to be `--invoke`, not `--render`
2019-11-08 17:41:05 -06:00
Dan Gohman
c3436ddcdf rustfmt 2019-11-08 09:06:55 -08:00
Dan Gohman
d9ca508f80 Rename wasmtime-api to wasmtime. 2019-11-08 06:43:07 -08:00
Yury Delendik
6632a7da37 [wasmtime-api] reduce examples complexity: hostref for store/engine (#489)
* reduce amount of store.clone()

* use HostRef Engine as ref / use Engine::default()
2019-11-07 11:39:23 -06:00
Andrew Brown
a8afdff972 Add error causes to failed WAST directives (#477) 2019-11-06 13:58:29 -06:00
Josh Triplett
56ce6e9c9f Migrate from failure to thiserror and anyhow (#436)
* Migrate from failure to thiserror and anyhow

The failure crate invents its own traits that don't use
std::error::Error (because failure predates certain features added to
Error); this prevents using ? on an error from failure in a function
using Error. The thiserror and anyhow crates integrate with the standard
Error trait instead.

This change does not attempt to semantically change or refactor the
approach to error-handling in any portion of the code, to ensure that
the change remains straightforward to review. Modules using specific
differentiated error types move from failure_derive and derive(Fail) to
thiserror and derive(Error). Modules boxing all errors opaquely move
from failure::Error to anyhow. Modules using String as an error type
continue to do so. Code using unwrap or expect continues to do so.

Drop Display implementations when thiserror can easily derive an
identical instance.

Drop manual traversal of iter_causes; anyhow's Debug instance prints the
chain of causes by default.

Use anyhow's type alias anyhow::Result<T> in place of
std::result::Result<T, anyhow::Error> whenever possible.

* wasm2obj: Simplify error handling using existing messages

handle_module in wasm2obj manually maps
cranelift_codegen::isa::LookupError values to strings, but LookupError
values already have strings that say almost exactly the same thing.
Rely on the strings from cranelift.

* wasmtime: Rely on question-mark-in-main

The main() wrapper around rmain() completely matches the behavior of
question-mark-in-main (print error to stderr and return 1), so switch to
question-mark-in-main.

* Update to walrus 0.13 and wasm-webidl-bindings 0.6

Both crates switched from failure to anyhow; updating lets us avoid a
translation from failure to anyhow within wasmtime-interface-types.
2019-11-04 20:43:25 -08:00
Alex Crichton
9947bc5209 Switch from wabt crate to wast (#434)
* Switch lightbeam from `wabt` to `wast`

Switch from a C++-based `*.wat` parser to a Rust-based parser

* Remove unneeded `wabt` dev-dependency from wasmtime-api

* Rewrite `wasmtime-wast` crate with `wast-parser`

This commit moves the `wasmtime-wast` crate off the `wabt` crate on to
the `wast-parser` crate which is a Rust implementation of a `*.wast` and
`*.wat` parser. The intention here is to continue to reduce the amount
of C++ required to build wasmtime!

* Use new `wat` and `wast` crate names
2019-10-18 13:25:48 -07:00
Dan Gohman
ebef2c6b57 Rename "always_lightbeam" to "lightbeam" in more places. (#404) 2019-10-17 17:15:31 -07:00
Nick Fitzgerald
842faf5aa6 Support for multi-value wasm (#399)
* deps: bump wasmparser to 0.39.2

This has a bug fix for multi-value Wasm validation that is required for getting
the spec tests passing.

https://github.com/yurydelendik/wasmparser.rs/pull/135

* Update cranelift to 0.46.1 to get multi-value Wasm support

The `cranelift_wasm` APIs had to change a little bit to maintain state necessary
when translating multi-value Wasm blocks. The `translate_module` function now
returns a `ModuleTranslationState` that is borrowed during each function's
translation.

* Enable multi-value proposal's spec tests

This enables all the Wasm multi-value proposal's spec tests other than the ones
that rely on functions having more return values than registers available on the
target. That is not supported by cranelift yet.

* wasmtime-interface-types: always use multi-value Wasm

And remove the return pointer hacks that work around the lack of multi-value.
2019-10-17 17:12:01 -07:00
Artur Jamro
872f6aa03d Fix opt_level builder flag (#411) 2019-10-10 12:14:45 -07:00
Dan Gohman
6ef46e0497 Use the Lightbeam cargo feature. 2019-10-04 18:12:06 -07:00
Dan Gohman
fb2a89a1b1 Fix compilation error by bringing in Lightbeam. 2019-10-04 17:36:14 -07:00
Dan Gohman
5ccdf13b11 Rename --always-cranelift to --cranelift.
Also, enable use of Lightbeam in wasm2obj.
2019-10-04 17:02:31 -07:00
Dan Gohman
8d89c3b479 Add options to wasmtime and wasm2obj to pick compilation strategy. 2019-10-02 13:59:49 -07:00
Dan Gohman
d4353f03cb Don't check assert_trap tests when Lightbeam is enabled.
Lightbeam doesn't yet produce trap metadata, so it can't yet match the
expected `assert_trap` messages. Disable them for now.
2019-10-02 13:42:26 -07:00
Dan Gohman
5bf2fc0ffa Don't enable Lightbeam tests if Lightbeam isn't enabled. 2019-10-02 12:06:00 -07:00
Dan Gohman
65b8afabe6 Make use of Lightbeam configurable.
This adds a `--always-lightbeam` option as well as an `--always-cranelift`
option, to allow the compilation strategy to be selected via the
command-line. This also enables regular testing for Lightbeam.
2019-10-02 11:54:06 -07:00
Jean-Bapiste Lepesme
e1b9c01d94 Fix opt_level setting passed to cranelift
With 92a19e9398 the optimisation levels of cranelift were renamed, without this change trying to use the -o flag on wasmtime runtime results in "error: Unexpected value for a setting, expected any among none, speed, speed_and_size".

"best" was renamed "speed_and_size", although I think "speed" is more adapted to wastime.

Bye,
JB.
2019-09-30 09:38:00 -07:00
Dan Gohman
053fb3433e Fix compilation error. 2019-09-26 17:22:41 -07:00
Dan Gohman
34766f64ea Recognize "wasi_unstable_preview0" in addition to "wasi_unstable". 2019-09-26 17:22:41 -07:00
Artur Jamro
286d2515f9 Check trap code in test suite assertions 2019-09-26 11:43:41 -07:00
Artur Jamro
fa9175f9e5 Trap registry 2019-09-25 17:56:08 -07:00
Artur Jamro
d1706117e5 Enable cache system by default 2019-09-25 16:48:18 -07:00
Artur Jamro
dde1c6ba58 Cache configuration documentation 2019-09-23 16:03:28 -07:00
Artur Jamro
1c22211d57 Refactor cache configuration 2019-09-23 12:48:36 -07:00
Marius Wachtler
c3a519d3a1 wasm2obj: add -O / --optimize command line option 2019-09-23 12:46:52 -07:00
Artur Jamro
febb0cb693 Cache worker 2019-09-18 16:43:27 -07:00
Yury Delendik
6a41417b52 Add examples; refactor HostRef 2019-09-18 09:15:14 -07:00
Artur Jamro
633dfa17ee Cache config as a file 2019-09-11 00:12:25 -07:00
Artur Jamro
479592f8c5 Cache compression (#234) 2019-08-23 16:39:46 -07:00
Yury Delendik
f88e92a57c Better Wasmtime API for embedder (#287)
* Migrate wasm-rust-api code to wasmtime.
2019-08-21 00:35:26 -07:00
Dan Gohman
4937dd0632 Fix the name of the wast command in its usage string. 2019-08-19 16:58:33 -07:00
Artur Jamro
3c33fe63a1 Add command line option for custom cache directory 2019-08-19 11:29:52 -07:00
Alex Crichton
af2b4e4946 Add initial support for WebAssembly Interface Types (#282)
This commit adds initial support for [WebAssembly Interface
Types][proposal] to wasmtime. This is all intended to be quite
experimental, so experimental in fact that even the name of the
[proposal] is still in flux. (this has otherwise been known as "host
bindings" or "webidl bindings" or "wasm bindings").

The goal of this commit is to start adding support the wasmtime set of
crates for WebAssembly Interface Types. A new `wasmtime-interface-types`
crate has been added with very basic support for dynamically invoking
and inspecting the various bindings of a module. This is in turn powered
by the `wasm-webidl-bindings` crate which is shared with the
`wasm-bindgen` CLI tool as a producer of this section.

Currently the only integration in `wasmtime`-the-binary itself is that
when passed the `--invoke` argument the CLI will now attempt to invoke
the target function with arguments as parsed from the command line
itself. For example if you export a function like:

    fn render(&str) -> String

Then passing `--invoke render` will require one argument on the command
line, which is the first argument as a string, and the return value is
printed to the console. This differs from today's interpretation of
`--invoke` where it is a failure if the invoked function takes more than
one argument and the return values are currently ignored.

This is intended to also be the basis of embedding wasmtime in other
contexts which also want to consume WebAssembly interface types. A
Python extension is also added to this repository which implements the
`wasmtime` package on PyPI. This Python extension is intended to make it
as easy as `pip3 install wasmtime` to load a WebAssembly file with
WebAssembly Interface Types into Python. Extensions for other languages
is of course possible as well!

One of the major missing pieces from this is handling imported functions
with interface bindings. Currently the embedding support doesn't have
much ability to support handling imports ergonomically, so it's intended
that this will be included in a follow-up patch.

[proposal]: https://github.com/webassembly/webidl-bindings

Co-authored-by: Yury Delendik <ydelendik@mozilla.com>
2019-08-19 13:32:13 +02:00
Alex Crichton
5fe550f533 Conform to Cargo's conventional file layout
Move `src/*.rs` to `src/bin/*.rs` which are automatically inferred as
binaries and move `src/utils.rs` to `src/lib.rs` which is compiled as a
reusable library for each of the binaries we're building.
2019-08-13 12:51:51 -07:00
Yury Delendik
4f04d7d873 Transform ranges and simple expressions (#63) 2019-08-08 20:44:45 -07:00