Commit Graph

64 Commits

Author SHA1 Message Date
Peter Huene
a6ec8f85a6 Loop the array of strings only once.
Remove unnecessary loop when marshaling lists of strings as pointers to UTF-8
bytes.
2020-02-24 18:26:26 -08:00
Peter Huene
78ee043524 Ensure marshaled UTF-8 string arrays are null terminated. 2020-02-24 18:20:27 -08:00
Peter Huene
8dff0fc121 Fix unit tests on Windows.
Close the file descriptors before attempting to reopen the files.
2020-02-24 17:56:55 -08:00
Peter Huene
11dec4d788 Add WASI unit tests for the C# API. 2020-02-24 17:42:49 -08:00
Peter Huene
ae0b4090ce Implement WASI C API.
This commit implements an initial WASI C API that can be used to instantiate
and configure a WASI instance from C.

This also implements a `WasiBuilder` for the C# API enabling .NET hosts to bind
to Wasmtime's WASI implementation.
2020-02-24 17:42:44 -08:00
Nick Fitzgerald
de4ad31cbd Update cranelift to 0.59.0 2020-02-24 15:21:27 -08:00
Alex Crichton
9dffaf9d57 Update wasmparser dependency (#912)
* Update wasmparser dependency

Closes #905

* Fix lightbeam compilation
2020-02-06 12:25:32 -06:00
Alex Crichton
3dd5a3cb3f Reimplement wasmtime-wasi on top of wasmtime (#899)
* Reimplement `wasmtime-wasi` on top of `wasmtime`

This commit reimplements the `wasmtime-wasi` crate on top of the
`wasmtime` API crate, instead of being placed on top of the `wasmtime-*`
family of internal crates. The purpose here is to continue to exercise
the API as well as avoid usage of internals wherever possible and
instead use the safe API as much as possible.

The `wasmtime-wasi` crate's API has been updated as part of this PR as
well. The general outline of it is now:

* Each module snapshot has a `WasiCtxBuilder`, `WasiCtx`, and `Wasi`
  type.
  * The `WasiCtx*` types are reexported from `wasi-common`.
  * The `Wasi` type is synthesized by the `wig` crate's procedural macro
* The `Wasi` type exposes one constructor which takes a `Store` and a
  `WasiCtx`, and produces a `Wasi`
* Each `Wasi` struct fields for all the exported functions in that wasi
  module. They're all public an they all have type `wasmtime::Func`
* The `Wasi` type has a `get_export` method to fetch an struct field by
  name.

The intention here is that we can continue to make progress on #727 by
integrating WASI construction into the `Instance::new` experience, but
it requires everything to be part of the same system!

The main oddity required by the `wasmtime-wasi` crate is that it needs
access to the caller's `memory` export, if any. This is currently done
with a bit of a hack and is expected to go away once interface types are
more fully baked in.

* Remove now no-longer-necessary APIs from `wasmtime`

* rustfmt

* Rename to from_abi
2020-02-06 09:23:06 -06:00
Julian Popescu
5d7635c351 Replaces load_file with load_bytes in rust macro (#750)
* Replaces `load_file` with `load_bytes` in macro

Loading an `AsRef<[u8]>` object is just more flexible than a filestring.
In the end you can just do `std::fs::read(&str)?` as the argument to get
the same behavior, but the reverse is a lot harder.

* updates markdown rust macro test example with new macro syntax

* Adds the `load_file` method back to rust macro

`load_file` was removed preferring `load_bytes`, but then later readded
with the `load_bytes` method as backend
2020-01-22 12:11:24 -06:00
Dan Gohman
9a88d3d894 Replace the global-exports mechanism with a caller-vmctx mechanism. (#789)
* Replace the global-exports mechanism with a caller-vmctx mechanism.

This eliminates the global exports mechanism, and instead adds a
caller-vmctx argument to wasm functions so that WASI can obtain the
memory and other things from the caller rather than looking them up in a
global registry.

This replaces #390.

* Fixup some merge conflicts

* Rustfmt

* Ensure VMContext is aligned to 16 bytes

With the removal of `global_exports` it "just so happens" that this
isn't happening naturally any more.

* Fixup some bugs with double vmctx in wasmtime crate

* Trampoline stub needed adjusting
* Use pointer type instead of always using I64 for caller vmctx
* Don't store `ir::Signature` in `Func` since we don't know the pointer
  size at creation time.
* Skip the first 2 arguments in IR signatures since that's the two vmctx
  parameters.

* Update cranelift to 0.56.0

* Handle more merge conflicts

* Rustfmt

Co-authored-by: Alex Crichton <alex@alexcrichton.com>
2020-01-21 14:50:59 -08:00
Alex Crichton
e5afdd2ede Document the wasmtime::Instance APIs (#814)
* Document the `wasmtime::Instance` APIs

This documents oddities like the import list and export list and how to
match them all up. Addtionally this largely just expands all the docs
related to `Instance` to get filled out.

This also moves the `set_signal_handler` functions into
platform-specific modules in order to follow Rust idioms about how to
expose platform-specific information. Additionally the methods are
marked `unsafe` because I figure anything having to do with signal
handling is `unsafe` inherently. I don't actually know what these
functions do, so they're currently still undocumented.

* Fix build of python bindings

* Fix some rebase conflicts
2020-01-16 17:58:44 -06:00
Alex Crichton
364fa994ed Move the C API to a separate crate (#818)
* Move the C API to a separate crate

This commit moves the C API from `crates/api/src/wasm.rs` to
`crates/capi/src/lib.rs` to be located in a separate crate. There's a
number of reasons for this:

* When a Rust program depends on the `wasmtime` crate, there's no need
  to compile in the C API.
* This should improve compile times of the `wasmtime` crate since it's
  not producing artifacts which aren't always used.
* The development of the C API can be guaranteed to only use the public
  API of the `wasmtime` crate itself.

Some CI pieces are tweaked and this overall shouldn't have much impact
on users, it's intended that it's a cleanup/speedup for developers!

* Disable rustdoc/tests for capi

* Review feedback

* Add back in accidentally deleted comment

* More renamings

* Try to fix dotnet build
2020-01-14 11:36:57 -08:00
Alex Crichton
420dcd76fd Don't require Store in Instance constructor (#810)
* Don't require `Store` in `Instance` constructor

This can be inferred from the `Module` argument. Additionally add a
`store` accessor to an `Instance` in case it's needed to instantiate
another `Module`.

cc #708

* Update more constructors

* Fix a doctest

* Don't ignore store in `wasm_instance_new`

* Run rustfmt
2020-01-13 17:50:57 -06:00
Dan Gohman
ef2177ed3a Update to the latest spec_testsuite and dependencies. (#803)
* Update to the latest spec_testsuite and dependencies.

Update to target-lexicon 0.10, cranelift 0.54, wast 0.6, faerie 0.14,
and the latest spec_testsuite.

For wast and cranelift-wasm, update the code for API changes.

* Factor out the code for matching f32, f64, and v128.

This takes the idea from #802 to split out `f32_matches`, `f64_matches`,
and `v128_matches` functions, which better factor out the matching
functionality between scalar and vector.
2020-01-10 13:57:38 -08:00
Alex Crichton
28a938a62f Remove allow(improper_ctypes) (#797)
This was a bug on nightly a month or so ago but has since been fixed!
2020-01-10 14:41:49 -06:00
Alex Crichton
6571fb8f4f Remove HostRef from the wasmtime public API (#788)
* Remove `HostRef` from the `wasmtime` public API

This commit removes all remaining usages of `HostRef` in the public API
of the `wasmtime` crate. This involved a number of API decisions such
as:

* None of `Func`, `Global`, `Table`, or `Memory` are wrapped in `HostRef`
* All of `Func`, `Global`, `Table`, and `Memory` implement `Clone` now.
* Methods called `type` are renamed to `ty` to avoid typing `r#type`.
* Methods requiring mutability for external items now no longer require
  mutability. The mutable reference here is sort of a lie anyway since
  the internals are aliased by the underlying module anyway. This
  affects:
  * `Table::set`
  * `Table::grow`
  * `Memory::grow`
  * `Instance::set_signal_handler`
* The `Val::FuncRef` type is now no longer automatically coerced to
  `AnyRef`. This is technically a breaking change which is pretty bad,
  but I'm hoping that we can live with this interim state while we sort
  out the `AnyRef` story in general.
* The implementation of the C API was refactored and updated in a few
  locations to account for these changes:
  * Accessing the exports of an instance are now cached to ensure we
    always hand out the same `HostRef` values.
  * `wasm_*_t` for external values no longer have internal cache,
    instead they all wrap `wasm_external_t` and have an unchecked
    accessor for the underlying variant (since the type is proof that
    it's there). This makes casting back and forth much more trivial.

This is all related to #708 and while there's still more work to be done
in terms of documentation, this is the major bulk of the rest of the
implementation work on #708 I believe.

* More API updates

* Run rustfmt

* Fix a doc test

* More test updates
2020-01-10 10:42:14 -06:00
Dan Gohman
336ee94c89 Bump version to 0.9.0 (#790) 2020-01-09 21:57:40 -08:00
Alex Crichton
1fe76ef9e3 Remove the need for HostRef<Module>
This commit continues previous work and also #708 by removing the need
to use `HostRef<Module>` in the API of the `wasmtime` crate. The API
changes performed here are:

* The `Module` type is now itself internally reference counted.
* The `Module::store` function now returns the `Store` that was used to
  create a `Module`
* Documentation for `Module` and its methods have been expanded.
2020-01-08 12:46:18 -08:00
Alex Crichton
eb1991c579 Revert "Remove the need for HostRef<Module> (#778)"
This reverts commit 7b33f1c619.

Pushed a few extra commits by accident, so reverting this.
2020-01-08 12:44:59 -08:00
Alex Crichton
7b33f1c619 Remove the need for HostRef<Module> (#778)
* Remove the need for `HostRef<Module>`

This commit continues previous work and also #708 by removing the need
to use `HostRef<Module>` in the API of the `wasmtime` crate. The API
changes performed here are:

* The `Module` type is now itself internally reference counted.
* The `Module::store` function now returns the `Store` that was used to
  create a `Module`
* Documentation for `Module` and its methods have been expanded.

* Fix compliation of test programs harness

* Fix the python extension

* Update `CodeMemory` to be `Send + Sync`

This commit updates the `CodeMemory` type in wasmtime to be both `Send`
and `Sync` by updating the implementation of `Mmap` to not store raw
pointers. This avoids the need for an `unsafe impl` and leaves the
unsafety as it is currently.

* Fix a typo
2020-01-08 14:42:37 -06:00
Alex Crichton
045d6a7310 Remove the need for HostRef<Store> (#771)
* Remove the need for `HostRef<Store>`

This commit goes through the public API of the `wasmtime` crate and
removes the need for `HostRef<Store>`, as discussed in #708. This commit
is accompanied with a few changes:

* The `Store` type now also implements `Default`, creating a new
  `Engine` with default settings and returning that.

* The `Store` type now implements `Clone`, and is documented as being a
  "cheap clone" aka being reference counted. As before there is no
  supported way to create a deep clone of a `Store`.

* All APIs take/return `&Store` or `Store` instead of `HostRef<Store>`,
  and `HostRef<T>` is left as purely a detail of the C API.

* The `global_exports` function is tagged as `#[doc(hidden)]` for now
  while we await its removal.

* The `Store` type is not yet `Send` nor `Sync` due to the usage of
  `global_exports`, but it is intended to become so eventually.

* Touch up comments on some examples

* Run rustfmt
2020-01-07 16:29:44 -06:00
Andrew Brown
296ebc46fd Update wasmparser to 0.45.1 (#776) 2020-01-07 16:21:50 -06:00
Alex Crichton
d142a39113 Tweak some API doc generation (#772)
* Build docs with the nightly toolchain so [foo::bar] links work by
  default. This is a relatively new feature of rustdoc and I thought it
  was stabilized at this point but apparently it's not!

* Tweak some API docs on `wasmtime::Strategy`

* Use `--all` to build all local crate documentation instead of trying
  to list the number of local crates

* Tweak some documentation configuration to avoid warnings generated by
  Cargo.
2020-01-07 14:42:35 -06:00
Alex Crichton
787f50e107 Remove usage of Features from wasmtime::Config API (#763)
Instead expose a number of boolean accessors which doesn't require users
to construct a foreign `Features` type and allows us to decouple the API
of the `wasmtime` crate from the underlying implementation detail.
2020-01-06 17:34:48 -06:00
Alex Crichton
b9dc38f4e1 Remove need for HostRef<Engine> (#762)
This commit removes the need to use `HostRef<Engine>` in the Rust API.
Usage is retained in the C API in one location, but otherwise `Engine`
can always be used directly.

This is the first step of progress on #708 for the `Engine` type.
Changes here include:

* `Engine` is now `Clone`, and is documented as being cheap. It's not
  intended that cloning an engine creates a deep copy.
* `Engine` is now both `Send` and `Sync`, and asserted to be so.
* Usage of `Engine` in APIs no longer requires or uses `HostRef`.
2020-01-06 15:17:03 -06:00
Yury Delendik
681445b18b Fail with Trap in Instance::new() instead of Error (#683) 2019-12-30 16:25:16 -06:00
Andrew Brown
086ff63e6b Update wasmparser to 0.45.0 (#733) 2019-12-18 10:24:01 -06:00
Alex Crichton
5d399d48ab Disable some tests for crates in their manifest (#725)
Instead of passing `--exclude` in CI disable them in the manifest so
`--all` can work with fewer flags locally as well.
2019-12-16 11:00:50 -06:00
Austin Wise
50d0aa939c Add tests calling function imports. 2019-12-13 18:50:57 -08:00
Austin Wise
df0f0e3c44 Remove trailing null bytes from trap messages.
It appears there are two trailing null bytes at the end of the string.
This does not seem right. But it might be a good idea generally to remove
any null bytes that get into error messages.
2019-12-13 18:48:32 -08:00
Austin Wise
e11056345a Add a Visual Studio solution. 2019-12-13 17:25:12 -08:00
Austin Wise
96d6a16ce9 Remove unneed dynamic binding in MemoryBinding.
The Validate function already checks that the field type is Memory.
2019-12-13 17:25:08 -08:00
Austin Wise
7f05a2e6a5 Use DoNotWrapExceptions to avoid exception wrapping. 2019-12-13 17:22:26 -08:00
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
Austin Wise
1d01779b2e Root bindings so the delegate in FunctionBinding is not GCed. 2019-12-05 18:58:09 -08: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
Peter Huene
b7c8408978 Merge pull request #676 from peterhuene/fix-dotnet-interop
Fix .NET interop issue for Windows release builds.
2019-12-05 13:32:46 -08:00
Peter Huene
cc02214084 Fix .NET interop issue for Windows release builds.
For Windows release builds, the `wasm_valtype_kind` C API return value
is being returned as a single byte.

The .NET interop signature for this function was expecting an
integer-sized return, resulting in three extra bytes being used on
Windows.

The fix is to limit the corresponding C# enum to a byte representation,
which will properly mask the return value from `wasm_valtype_kind`.

CI has also been updated to test both debug and release configurations
(previously it was only testing debug, hence why this was missed).

Also fixed a cast bug in the `declare_vec!` macro in the C API when the
element types were pointers to values.  The `as_slice` implementation
was incorrectly casting away a level of pointer indirection, resulting
in corrupted data when accessing the slice's elements.
2019-12-05 12:44:47 -08:00
Nick Fitzgerald
0fce2ac288 deps: Update wasmparser in most places (#670)
Doesn't update it in lightbeam.
2019-12-05 13:51:47 -06:00
Peter Huene
3e7bc745a2 Merge pull request #624 from peterhuene/wasmtime-for-dotnet
Move Wasmtime for .NET to the Wasmtime repo.
2019-11-26 12:47:04 -08:00
Peter Huene
a3bc464e47 Add LLVM exception for Wasmtime for .NET license. 2019-11-26 11:34:44 -08:00
Luiz Irber
5cdae1d394 use setuptools_scm for python version management (#627)
* use setuptools_scm for python version management

* add git dep for python wheel building

* if no tag is defined, default to dev

* any untagged version default to 0.0.1
2019-11-26 08:56:51 -06:00
Peter Huene
9fdf5bce8e Move Wasmtime for .NET to the Wasmtime repo.
This moves the Wasmtime for .NET implementation to the Wasmtime repo.

Wasmtime for .NET is a binding of the Wasmtime API for use in .NET.
2019-11-22 18:26:33 -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
Alex Crichton
39e57e3e9a Migrate back to std:: stylistically (#554)
* Migrate back to `std::` stylistically

This commit moves away from idioms such as `alloc::` and `core::` as
imports of standard data structures and types. Instead it migrates all
crates to uniformly use `std::` for importing standard data structures
and types. This also removes the `std` and `core` features from all
crates to and removes any conditional checking for `feature = "std"`

All of this support was previously added in #407 in an effort to make
wasmtime/cranelift "`no_std` compatible". Unfortunately though this
change comes at a cost:

* The usage of `alloc` and `core` isn't idiomatic. Especially trying to
  dual between types like `HashMap` from `std` as well as from
  `hashbrown` causes imports to be surprising in some cases.
* Unfortunately there was no CI check that crates were `no_std`, so none
  of them actually were. Many crates still imported from `std` or
  depended on crates that used `std`.

It's important to note, however, that **this does not mean that wasmtime
will not run in embedded environments**. The style of the code today and
idioms aren't ready in Rust to support this degree of multiplexing and
makes it somewhat difficult to keep up with the style of `wasmtime`.
Instead it's intended that embedded runtime support will be added as
necessary. Currently only `std` is necessary to build `wasmtime`, and
platforms that natively need to execute `wasmtime` will need to use a
Rust target that supports `std`. Note though that not all of `std` needs
to be supported, but instead much of it could be configured off to
return errors, and `wasmtime` would be configured to gracefully handle
errors.

The goal of this PR is to move `wasmtime` back to idiomatic usage of
features/`std`/imports/etc and help development in the short-term.
Long-term when platform concerns arise (if any) they can be addressed by
moving back to `no_std` crates (but fixing the issues mentioned above)
or ensuring that the target in Rust has `std` available.

* Start filling out platform support doc
2019-11-18 22:04:06 -08:00
Jakub Konka
9182971697 Add missing import to wasmtime-rust macro (#589)
This commit does two things: 1) it fixes `wasmtime_rust::wasmtime` proc macro by
adding the missing import to the `__rt` module, and fixing the scoping inside
the macro itself; and 2) it augments the `wasmtime_rust::wasmtime` proc macro with
custom error messages in case the implementor forgets the `self` argument in the
trait methods.
2019-11-18 10:39:40 -06: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
Dan Gohman
c5f998add2 Update the crates.io publishing scripts (#580)
* Fix fuzz target compilation.

* Bump version to 0.7.0

* Temporarily disable fuzz tests

Temporarily disable fuzz tests until https://github.com/bytecodealliance/cranelift/issues/1216 is resolved.

* Fix publish-all.sh to not modify the witx crate.

* Remove the "publish = false" attribute from Lightbeam.

* Add a README.md for wasmtime-interface-types.

* Remove the "rust" category.

This fixes the following warning:

warning: the following are not valid category slugs and were ignored: rust. Please see https://crates.io/category_slugs for the list of all category slugs.

* Mark wasmtime-cli as "publish = false".

* Sort the publishing rules in topological order.

Also, publish nightly-only crates with cargo +nightly.
2019-11-15 12:17:19 -08:00
Ben Brittain
b0f558aa10 Mark functions as pub if trait is public (#574) 2019-11-14 19:20:45 -06:00
Yury Delendik
36cb806c54 Use embedding api in python extension (#569)
Now embedding API is used in the Python extension, this allows us to remove ModuleData::invoke() from wasmtime-interface-types
2019-11-14 10:40:04 -06:00