Commit Graph

612 Commits

Author SHA1 Message Date
Gavin Hayes
092eba5e2f feat: manifest wasm data without base64 (#657)
base64 support is retained. Now `data` can instead be `{"ptr":
ptr_value, "len": len_value}` where `ptr_value` points to a wasm module
and `len_value` is the size of bytes of it.
2024-01-12 16:48:25 -05:00
Benjamin Eckel
94b0b9a430 docs: fix rc version in docs (#656) 2024-01-09 18:56:08 -06:00
Steve Manuel
85cc72e832 docs: add .NET PDK link to table 2024-01-09 07:41:13 -07:00
Steve Manuel
9aee9d8ca5 feat: update README (#655)
Gives the README a bit of a refresh.

---------

Co-authored-by: Benjamin Eckel <bhelx@simst.im>
2024-01-09 07:30:30 -07:00
Gavin Hayes
4012dd22de chore: kernel add Handle and Offset types to differentiate from Pointer (#652)
This cosmetic change to the kernel adds two `u64` types for usage where
`Pointer` was used and it is actually something else or is more
restrictive (a pointer to the start of a data block (handle) or a
relative offset).

Instead of adding `Offset` to match `Length` I'd prefer to use `u64`
directly when referring to those scalars, but not sure if the those
types are preferred?
2024-01-08 12:31:24 -05:00
Steve Manuel
211d55337d feat: add rust-protobuf support to extism-convert (#653)
(code from @zshipko, thank you!)

---------

Co-authored-by: Zach Shipko <zach@dylibso.com>
v1.0.0
2024-01-05 16:36:40 -07:00
zach
431bc4d8af cleanup: improve wat detection (again) (#651)
Merged the other one too quickly, this PR is updated with some
additional feedback from @chrisdickinson:

              (Ooh, this could also start with `(;`)
https://github.com/extism/extism/pull/650#discussion_r1443419249

It's also updated to accommodate for modules that start with an open
paren followed by some whitespace. I doubt this covers all of the
permitted syntax but it should be good enough.
2024-01-05 14:58:47 -08:00
zach
cd4fc39655 cleanup: improve wat detection (#650)
- Update to ensure `is_wat` is only true when the input is a valid
string
- Update to allow leading whitespace in a wat file
2024-01-05 14:00:41 -08:00
zach
03e761908c feat: add Plugin::call_get_error_code to get Extism error code along with the error (#649)
- Adds `Plugin::call_get_error_code` to get the Extism error code when a
call fails
2024-01-05 12:52:31 -08:00
zach
26542d5740 feat(kernel): add extism_length_unsafe (#648)
- Adds `length_unsafe` function to the extism kernel, a more performant
`length` for known-valid memory handles

After this is merged I will update go-sdk and js-sdk too.

Closes #643
2024-01-03 09:29:05 -08:00
CosmicHorror
950a0f449f Toggle off default clap feature for cbindgen (#644)
The only feature for `cbindgen` is the `clap` feature for using it as a
standalone binary and isn't needed when using it as a library
2023-12-26 19:40:32 -08:00
zach
c8868c37d8 chore: update wasmtime bounds to include 16.0.0 (#642) 2023-12-20 14:37:43 -08:00
zach
ab812d9281 cleanup: remove default timeout (#641)
The default for `timeout_ms` is currently 30s which was an arbitrary
decision but it forces a user to set `timeout_ms` to null to avoid
having plugins cancelled which is a little strange.
2023-12-18 11:05:12 -08:00
Chris Dickinson
2087398513 v1.0.0-rc7 v1.0.0-rc7 2023-12-15 15:45:23 -08:00
Chris Dickinson
212e28bec3 fix: give extism_log_drain's param a named type (#638)
This fixes a test failure on the python-sdk [1]. (See also [2]). In
particular, while maturin creates bindings for `extism_log_drain` on
clang platforms, it seems that MSVC cannot generate the required binding
information for `ffi.py`. This results in an `extism_sys` wheel whose
shared object (in this case, a DLL) contains the `extism_log_drain`, but
whose Python FFI bindings don't contain a definition for that function.

Naming the function pointer type parameter resolves the issue. What a
strange issue!

[1]:
https://github.com/extism/python-sdk/actions/runs/7172934060/job/19669775001#step:9:35
[2]:
https://github.com/extism/python-sdk/pull/18#issuecomment-1850892835
2023-12-15 15:40:54 -08:00
zach
fd95729d8d fix(kernel): length function should return 0 for invalid offsets (#635)
Fixes #634 

- Updates `extism_length` to walks the allocation list to determine
valid offsets instead of assuming the provided offset is valid

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: zshipko <zshipko@users.noreply.github.com>
2023-12-14 16:55:13 -08:00
Muhammad Azeez
49e28892bc ci: release extism.dll.lib and extism.dll.a (#633)
Related to #141 and #584 
Follow up of #632
2023-12-13 22:29:29 +03:00
zach
a5edf58747 fix(kernel): improve performance after large allocations, add extism_plugin_reset to give users more control when dealing with large allocations (#627)
See https://github.com/extism/cpp-sdk/issues/15

- Limits a call to memset in the kernel to the size of the current
memory offset instead of the total size of memory.
- Adds `extism_plugin_reset` to the C API and `extism::Plugin::reset` to
Rust

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: zshipko <zshipko@users.noreply.github.com>
2023-12-12 13:56:34 -08:00
zach
e5ffabb975 feat: Add extism_convert::Raw to allow direct encoding using bytemuck (#626)
- Adds `extism_convert::Raw` to encode certain types using their direct
memory representations using https://github.com/Lokathor/bytemuck
- Only enabled on little-endian targets to prevent memory mismatch
issues
- Allows for certain types of structs to be encoded using their
in-memory representation
- Makes passing structs between Rust and C easier since none of the
other encodings are available in C by default.

## Usage
After making a bytemuck-compatible struct:
```rust
use bytemuck::{Zeroable, Pod};

#[derive(Debug, Clone, Copy, PartialEq, Pod, Zeroable)]
#[repr(C)]
struct Point {
  x: i32,
  y: i32,
}
```

It can be used in `call`:

```rust
let input = Point { x: 100, y: 50 };
let Raw(pt): Raw<Point> = plugin.call("transform", Raw(&input))?;
```
2023-12-11 11:14:33 -08:00
Gavin Hayes
0285f64ecf build: add c++ compat to extism.h (#625)
Before `extern "C"` was needed to include the header in C++ code. Now
that's included inside, so it's easier and cleaner to include in c++
projects like the `cpp-sdk`.
2023-12-06 15:34:09 -05:00
Muhammad Azeez
c7a68ed757 ci: bring back nuget packages for Extism runtime (#624)
Seems like these accidentally got removed in #583
2023-12-05 22:32:53 +03:00
zach
9bff8be915 refactor!: better scoping of arguments in host_fn macro, allow visibility in macros to be specified (#621)
Fixes #619  

- Also updates `host_fn`, `encoding`, and `typed_plugin` macros to allow
for visibility specifiers to manage the visibility of the defined types.
This means that `pub` will need to be added to existing invocations that
should remain public
2023-12-05 09:58:35 -08:00
zach
b1cb80fb47 fix: improve handling of 0 length blocks (#622)
Fixes #620 

- Returns `MemoryHandle::null()` instead of returning an error when the
offset is 0
2023-12-04 10:55:26 -08:00
neuronicnobody
03718edbfc fix manifest link (#617)
Fix link to Manifest in the Rust/Runtime README
2023-12-01 17:13:47 -08:00
zach
083b6db029 cleanup: implement Debug and PartialEq for manifest types (#618) 2023-12-01 15:23:01 -08:00
Chris Dickinson
c1b14e841a v1.0.0-rc6 v1.0.0-rc6 2023-12-01 11:52:18 -08:00
Chris Dickinson
528ae6f6a5 build: combine rust release workflows (#611)
Okay, phew.

The main bug from the [last
PR](https://github.com/extism/extism/pull/610) was that the rust
releases scramble to publish, but we have to publish them in a
particular order for the release to work since they depend on each
other.

There's a secondary bug: `cargo publish` is prone to 502'ing on publish.
I lean towards seeing how painful this is in practice; we should be able
to safely re-run the release flow on failure.
2023-12-01 11:51:18 -08:00
Chris Dickinson
75f2ea2efc doc: add example of linking modules in a plugin (#616)
Add an example of dynamically linking plugins and a benchmark that does
an apples-to-apples comparison of `reflect` using host functions vs.
`reflect` using a linked wasm module. (To my surprise, the host
functions are a _little bit faster_!)
2023-12-01 11:38:27 -08:00
Benjamin Eckel
895f82cf10 docs: Some readme changes on api status (#614)
Just moving this around and changing it up for the beta release.
2023-11-29 14:02:08 -06:00
zach
e4140fda9d cleanup: avoid matching meta.name twice (#613)
As pointed out by @mtb0x1 in
af4fd184e6 (r133737418)
2023-11-28 19:06:58 -08:00
zach
af4fd184e6 cleanup: simplify main module resolution (#612)
This PR simplifies the resolution of the `main` module when multiple
modules are provided. Before we would try to look at the path/URL when
the wasm was coming from disk or via HTTP, now any module missing a name
will be used as `main`. This is much nicer and more consistent since
this is what was being done when no filename was available (i.e. raw
data modules). It also make sense because non-main modules will need to
be named for the functions to be linked correctly.
2023-11-28 16:15:44 -08:00
zach
a517cd23be feat: enable wasmtime caching (#605)
Alternate to: #596 without support for manually compiling/loading native
code

- Enables wasmtime caching: https://docs.wasmtime.dev/cli-cache.html
- Adds `EXTISM_CACHE_CONFIG` and `PluginBuilder::with_cache_config` to
determine where to load a custom cache configuration from
- Adds `PluginBuilder::with_cache_disabled` to disable the cache when
initializing a plugin
  - Setting `EXTISM_CACHE_CONFIG=""` will also disable caching 

## Performance

With caching:
```
create/create_plugin    time:   [2.9079 ms 2.9139 ms 2.9200 ms]                                  
                        change: [+3.2677% +3.6399% +3.9766%] (p = 0.00 < 0.20)
                        Change within noise threshold.
```

Compared to `main`:
```
create/create_plugin    time:   [26.089 ms 26.498 ms 26.923 ms]                                 
                        change: [+0.1729% +2.0868% +4.1337%] (p = 0.04 < 0.20)
                        Change within noise threshold.
```
2023-11-28 11:50:21 -08:00
Chris Dickinson
938e3af7f0 v1.0.0-rc5 v1.0.0-rc5 2023-11-27 17:30:41 -08:00
Chris Dickinson
06706f07be build: drive cargo releases from git tag (#610)
Follow-up to f7d297f98f.

Update the release workflows for the dependent crates. The Cargo
workflows run on GitHub release publish to match the Python package
release workflow. This means all of our crates are versioned in lockstep
by the Git tag.

There are four changes:

1. Trigger the workflows on GitHub release publish
2. Add the `set version` step from `release.yml` to modify the version
tags in `Cargo.toml`.
3. Publish with `--allow-dirty` (to account for the edit in step 2)
4. In `extism-maturin`, do not inherit `authors` from the workspace
since [PyPI rejects the value we have
set](https://github.com/extism/extism/actions/runs/7012534645/job/19077216730#step:7:23).
2023-11-27 17:28:56 -08:00
Chris Dickinson
e75dd05c6c v1.0.0-rc4 v1.0.0-rc4 2023-11-27 16:25:46 -08:00
Chris Dickinson
f7d297f98f build: drive crate versions from workspace; drive workspace version from ci (#604)
This is an attempt to sand down [a sharp
edge](https://github.com/extism/extism/actions/runs/6949120346/job/18906546065#step:4:476)
around releases – keeping the `Cargo.toml` versions in-sync with the
release tag, & the versions of the workspace crates aligned with one
another.
2023-11-27 16:14:56 -08:00
zach
a94a0a7a15 cleanup: remove old SDKs (#583)
Removes all SDKs but the Rust SDK/runtime and the C SDK, which is
automatically generated from the Rust crate.

---------

Co-authored-by: Ben <ben@dylibso.com>
Co-authored-by: Steve <steve@dylibso.com>
Co-authored-by: Rob <rob@dylibso.com>
Co-authored-by: Muhammad <muhammad@dylibso.com>
Co-authored-by: Gavin <gavin@dylibso.com>
Co-authored-by: Chris <chris@dylibso.com>
Co-authored-by: Dom <dom@dylibso.com>
Co-authored-by: Charles <charles@dylibso.com>
2023-11-27 11:19:17 -08:00
Chris Dickinson
45b0749fe2 doc: add DEVELOPING.md with release workflow (#602)
Describe the release workflow as flowing from tag -> builds -> release.
2023-11-21 13:30:31 -08:00
Benjamin Eckel
15c30dfa8c fix: forgot to update the runtime version 2023-11-21 14:27:14 -06:00
Benjamin Eckel
7411eef7b0 release: 1.0.0-rc3 (#603) v1.0.0-rc3 2023-11-21 13:50:47 -06:00
zach
6e49548ca3 chore: support wasmtime 15 (#601) 2023-11-20 08:36:57 -08:00
George Hopkins
97f4dea8e6 Implement convenience traits for encoded types (#597)
Implement `From<T>` and `Debug` for `Base64<T>`, `Json<T>`, `Msgpack<T>`
and `Protobuf<T>`
2023-11-20 06:34:27 -08:00
George Hopkins
14248f8e17 ci: check formatting of all crates (#598)
Check formatting of all crates to ensure the whole codebase stays
formatted.
2023-11-20 06:34:04 -08:00
Muhammad Azeez
0f3b485813 Update release-dotnet-native.yaml to be resilient against file name changes (#589)
Seems like the assets now include version numbers in their name
2023-11-19 13:50:51 +03:00
Thomas Zahner
ecf5e3b9d4 Fix typo in README.md (#593) 2023-11-17 15:57:16 -08:00
Chris Dickinson
0aadf60272 build(bench): add "consume" and "echo" benchmarks (#595)
Further flesh out our runtime benchmarks: add benchmarks for sending
bytes one-way into Wasm linear memory, as well as testing copy-in then
copy-out. This compliments our `reflect` benchmark; we can get a sense
of how expensive the sub-operations are via `echo` and `consume`.
(Notably, we're missing a `produce` or `emit` that purely generates
output and sends it to the host!)

The source of these plugins is available in `extism/plugins` as
`echo.wat` and `consume.wat` [1].

[1]: https://github.com/extism/plugins/pull/4/files
2023-11-17 15:56:28 -08:00
Chris Dickinson
3eb454dd19 refactor(bench): Add throughput information to reflect function. (#592)
This parameterizes the `reflect` test and calls the `g.throughput` on
each data set to get an idea of our roundtrip throughput. (The changes
follow the "Throughput Measurements" [1] part of the Criterion guide
pretty much to the letter.)

Example output:

```
reflect/reflect 1       time:   [208.57 µs 209.05 µs 209.57 µs]
                        thrpt:  [298.23 MiB/s 298.97 MiB/s 299.66 MiB/s]
```

[1]:
https://bheisler.github.io/criterion.rs/book/user_guide/advanced_configuration.html#throughput-measurements
2023-11-16 17:23:39 -08:00
zach
2a24d13c9b refactor!: use tracing crate for logging, add extism_log_callback function (#578)
- Uses `tracing` instead of `log` crate
- Uses `tracing-subscriber` instead of `fern`
- This allows us to automatically capture `log` events using
`tracing-subscriber`
- Breaking: Makes `extism::set_log_file` private and only used through
the C API, Rust users should use `tracing-subscriber` to determine which
filters/levels to log.
- Adds `extism::set_log_callback` function to set a callback that can be
used for custom logging from Rust.
- Adds `bool extism_log_custom(const char *level)` and
`extism_log_drain(void (*fn)(const char *s, size_t length)` to the C API
to enable custom sinks in other SDKs
2023-11-16 10:35:22 -08:00
Benjamin Eckel
a1cf591de5 release 1.0.0-rc2 (#588) v1.0.0-rc2 2023-11-15 16:53:19 -06:00
Rob
d5c6ffb950 chore: loosen dependency requirements for base64 (#576)
Attempts to address an error seen when upgrading both Rust PDK & SDK to
latest:

```
    Updating git repository `https://github.com/extism/extism.git`
    Updating git repository `https://github.com/extism/rust-pdk.git`
    Updating crates.io index
error: failed to select a version for `base64`.
    ... required by package `extism-convert v0.2.0 (https://github.com/extism/extism.git?branch=main#7636c873)`
    ... which satisfies git dependency `extism-convert` of package `extism v1.0.0-alpha.0 (https://github.com/extism/extism.git?branch=main#7636c873)`
    ... which satisfies git dependency `extism` of package `proto_core v0.22.4 (/Users/miles/Projects/proto/crates/core)`
    ... which satisfies path dependency `proto_core` (locked to 0.22.4) of package `proto_cli v0.22.0 (/Users/miles/Projects/proto/crates/cli)`
versions that meet the requirements `^0.21.3` are: 0.21.5, 0.21.4, 0.21.3

all possible versions conflict with previously selected packages.

  previously selected package `base64 v0.21.0`
    ... which satisfies dependency `base64 = "^0.21.0"` (locked to 0.21.0) of package `extism-manifest v0.5.0`
    ... which satisfies dependency `extism-manifest = "^0.5.0"` (locked to 0.5.0) of package `extism-pdk v1.0.0-beta.0 (https://github.com/extism/rust-pdk.git?branch=main#009bf808)`
    ... which satisfies git dependency `extism-pdk` of package `proto_pdk v0.10.2 (/Users/miles/Projects/proto/crates/pdk)`

failed to select a version for `base64` which could resolve this conflict
```
2023-11-15 16:51:16 -06:00