Commit Graph

686 Commits

Author SHA1 Message Date
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
Benjamin Eckel
719462ba61 1.0.0-beta.0 (#587) v1.0.0-beta.0 2023-11-15 14:47:23 -06:00
Benjamin Eckel
bdb44f2e80 docs: fix readme for runtime rust sdk (#577) 2023-11-13 16:56:02 -06:00
Chris Dickinson
5afa658d10 v1.0.0-rc1 v1.0.0-rc1 2023-11-13 13:05:56 -08:00
Muhammad Azeez
2fb29025c9 fix: nuget packing in release-dotnet-native.yaml (#524)
Seems like there are some weird subtle differences between Windows and
Linux
v1.0.0-alpha.0
2023-11-09 10:00:35 +03:00
zach
91257f0a54 cleanup: simplify logging, include plugin ID in log messages (#573)
My initial goal was to make logging configurable for each plugin instead
of global but wasn't able to accomplish that in this PR (still looking
into it)

- Switches from `log4rs` to `fern` - this significantly simplifies the
logging code
  - Also considered `simplelog`
- Adds `plugin.id` to the logs whenever available
- Uses `extism::plugin::$id` target for functions logged from the PDK
2023-11-08 15:36:47 -08:00
Gavin Hayes
7636c87319 build: libextism/CMakeLists.txt add installing to support in-tree builds that use shared libraries (#575) 2023-11-08 17:17:38 -05:00
Gavin Hayes
6e18283ae6 feat: add add_subdirectory compatible cmake config (#574)
This enables cmake in-tree builds with libextism such as with the
cpp-sdk: https://github.com/extism/cpp-sdk/pull/7
2023-11-08 13:08:35 -05:00
Gavin Hayes
5eb8995347 fix: libextism - make fully static target no longer hardcoded to musl-gcc (#572)
I realized the glibc static build does actually work (though prints
warnings at compile time), so I made it no longer hard-coded to the
compiler. It's still a bad idea, so I added notes for why you shouldn't
do it with glibc.
2023-11-06 19:23:01 -05:00
Gavin Hayes
9992d34510 feat: add x86_64-unknown-linux-musl target, specifying target to make (#571)
The `x86_64-unknown-linux-musl` target does not build dynamic libraries
for now:
```
 warning: dropping unsupported crate type `cdylib` for target `x86_64-unknown-linux-musl`
```

A target may now be optionally specified to the root `Makefile`,
example:
`make RUST_TARGET=x86_64-unknown-linux-musl && sudo make
RUST_TARGET=x86_64-unknown-linux-musl install`

The new musl targets may be used to create entirely static binaries with
libextism. See the new `musl-static` target in `libextism/Makefile`
2023-11-06 17:06:44 -05:00
zach
3226060dd1 refactor!: allow Plugin::new to take raw wasm or Manifest (#569)
- Removes `Plugin::new_with_manifest` and updates `Plugin::new` to take
wasm bytes or `Manifest` using the new `WasmInput` trait
- Removes `PluginBuilder::new_with_module` in favor of a
`PluginBuilder::new` with a `WasmInput` argument
2023-11-06 13:31:24 -08:00
Benjamin Eckel
b0157efca4 chore: fix cargo resolver warning (#570)
```
warning: some crates are on edition 2021 which defaults to `resolver = "2"`, but virtual workspaces default to `resolver = "1"`
note: to keep the current resolver, specify `workspace.resolver = "1"` in the workspace root's manifest
note: to use the edition 2021 resolver, specify `workspace.resolver = "2"` in the workspace root's manifest
```
2023-11-06 14:41:39 -06:00
zach
b86ce1fec7 fix: improve handling of custom error messages (#568)
Fixes #567
2023-11-06 10:18:52 -08:00
zach
94e7722fbc test: add some http tests (#562) 2023-11-06 08:55:10 -08:00
zach
f36d0f60cc cleanup: update error message (#561) 2023-11-03 11:25:57 -07:00
zach
215d6838e9 cleanup: add PTR as an alias for I64 in C API (#560)
Similar to #558 but for libextism
2023-11-02 16:52:46 -07:00
Gavin Hayes
1aff1ce69c feat: pkg-config (#559)
Adds `pkg-config` configs for dynamic and static builds of libextism.
Example usage is shown in `libextism/Makefile`.

Added the `.in` versions of the `.pc` files to non-MSVC releases.
2023-11-02 19:38:50 -04:00
zach
ce5d43c9ae cleanup: add PTR as an alias for ValType::I64 (#558)
This will help simplify writing the types for host functions, `PTR` can
be used for any arguments that will point to Extism memory instead of
`ValType::I64`
2023-11-02 13:45:09 -07:00
zach
c5b3af2963 fix: set epoch deadline before each plugin call (#557)
We were updating the epoch deadline callback after the call has ended to
ignore any timeouts that might happen when reading output, which would
allow for the plugin to be cancelled successfully the first time a
plugin is called but would fail after the first call. This PR fixes
cancellation by resetting the epoch deadline and callback before each
plugin call.

I tested this against the dotnet sdk tests, where this was discovered,
and added a similar test to the runtime test suite,

Fixes #556
2023-11-01 13:05:08 -07:00
zach
f3447a538c refactor!: Use extism:host/env namespace for extism functions and extism:host/user for user-defined host functions (#511)
See #504 

Removes CI for the in-repo SDKs, we can remove the actual code closer to
the 1.0 release.

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: zshipko <zshipko@users.noreply.github.com>
2023-10-30 11:43:40 -07:00
Gavin Hayes
fab44c5db8 feat: build static libextism (#552)
* libextism is now built to crate-type `staticlib` as recommend by
@zshipko
* updated `Makefile` to install and uninstall the static library.
* updated c example to have `static` target to link libextism statically
* Compiler is no longer hardcoded to `clang`. Set `CC` to use a compiler
other than the system compiler. Tested with `gcc` and `clang`.
* added `static-artifact` to actions release. Untested as it's only ran
on push with tag.

---------

Co-authored-by: zach <zach@dylibso.com>
2023-10-27 19:10:57 -04:00
zach
0e65c3afae refactor!: Cleanup UserData implementation, update example in README (#550)
Fixes #545 

- Adds a type parameter to `UserData` type to avoid dynamic typing
issues
- Adds KV example from README to `examples/readme.rs` to make sure it
stays in-sync
- Implement `Default` for `UserData<T>` when `T` implements `Default`
- Make `UserData` argument non-optional in `Function::new`,
`UserData::default()` can be used instead.
2023-10-26 11:19:48 -07:00
Benjamin Eckel
fea4e6c293 docs: Add some documentation for plugin.call (#546)
We should go through some of the main ones people will be interacting
with and make sure there is a little more description of how to use it.
2023-10-26 12:42:55 -05:00
Chris Dickinson
c2910bdc60 fix(release): bump maturin manylinux floor for ring 0.17 dep (#548)
An update to `ring` broke the maturin-extism builds. Tracked this down
to [1]; the maintainers of `ring` don't intend to support linux sysroots
that old. This PR updates the ARM Linux builds in particular to pull in
a newer manylinux target. Tested on a [private
fork](https://github.com/extism/dev-extism/actions/runs/6644247344) of
the extism repo.

[1]: https://github.com/briansmith/ring/issues/1728
2023-10-25 13:34:34 -07:00
Benjamin Eckel
1f72c2a1ce docs: Point to readmes (#541)
Point everything to to new repos. We will eventually remove these
subrepos to clean everything up but leaving them for the next month at
least.

---------

Co-authored-by: zach <zach@dylibso.com>
2023-10-25 10:25:38 -05:00
zach
4bd0ed6d03 feat: add ability to dump extism kernel memory and generate coredumps, cleanup kernel memory layout (#539)
Fixes https://github.com/extism/extism/issues/537

- Requires wasmtime 14.0.0 or greater for coredump serialization
- Adds `EXTISM_COREDUMP` environment variable to write wasmtime coredump
to a file when an error occurs
- This will create a coredump from the main wasm module, which means it
doesn't give us too much insight into the kernel
- Adds `EXTISM_MEMDUMP` environment variable to write extism linear
memory to a file when an error occurs
  - This gives us access to the kernel memory  
- Adds some missing profiling options
- Converts timeouts to a Trap instead of a plain error, this helps us
get better information about where the timeout occured
- Some small improvements to error handling after a plugin call
- Adds a test for coredump and memdump generation
- Adds the ability to configure debug options using `PluginBuilder`
- Fixes memory layout and a wasted page of memory in the kernel, found
while debugging a memory dump

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: zshipko <zshipko@users.noreply.github.com>
2023-10-24 17:31:26 -07:00
Thomas Darimont
dba0b67cd3 chore: fix docstring for Manifest/allowed_paths (#531) 2023-10-24 17:48:40 -05:00