Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ts pdk #473

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/codegen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ fn main() {

generator
.generate(
PathBuf::from("package/src/api-types.ts"),
PathBuf::from("package/src/internal/raw-api-types.ts"),
TypeScriptRenderer::default(),
)
.unwrap();
Expand Down
22 changes: 19 additions & 3 deletions crates/pdk-api/src/api/build_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@ api_struct!(

api_enum!(
/// The location in which source code can be acquired.
#[serde(tag = "type", rename_all = "kebab-case")]
#[serde(tag = "type")]
pub enum SourceLocation {
/// Downloaded from an archive.
#[cfg_attr(feature = "schematic", schema(nested))]
#[serde(rename = "kebab-case")]
Archive(ArchiveSource),

/// Cloned from a Git repository.
#[cfg_attr(feature = "schematic", schema(nested))]
#[serde(rename = "kebab-case")]
Git(GitSource),
}
);
Expand Down Expand Up @@ -80,42 +82,56 @@ impl CommandInstruction {

api_enum!(
/// An instruction to execute.
#[serde(tag = "type", content = "instruction", rename_all = "kebab-case")]
#[serde(tag = "type", content = "instruction")]
pub enum BuildInstruction {
/// Update a file and make it executable.
#[serde(rename = "kebab-case")]
MakeExecutable(PathBuf),

/// Move a file from source to destination.
#[serde(rename = "kebab-case")]
MoveFile(PathBuf, PathBuf),

/// Remove a directory.
#[serde(rename = "kebab-case")]
RemoveDir(PathBuf),

/// Remove a file.
#[serde(rename = "kebab-case")]
RemoveFile(PathBuf),

/// Request (curl, wget, etc) a script and download to the host.
#[serde(rename = "kebab-case")]
RequestScript(String),

/// Execute a command as a child process.
#[cfg_attr(feature = "schematic", schema(nested))]
#[serde(rename = "kebab-case")]
RunCommand(Box<CommandInstruction>),
}
);

api_enum!(
/// Is required and must exist in the current environment.
#[serde(tag = "type", content = "requirement", rename_all = "kebab-case")]
#[serde(tag = "type", content = "requirement")]
pub enum BuildRequirement {
#[serde(rename = "kebab-case")]
CommandExistsOnPath(String),
#[serde(rename = "kebab-case")]
ManualIntercept(String), // url
#[serde(rename = "kebab-case")]
GitConfigSetting(String, String),
#[serde(rename = "kebab-case")]
GitVersion(VersionReq),
#[serde(rename = "kebab-case")]
PythonVersion(VersionReq),
#[serde(rename = "kebab-case")]
RubyVersion(VersionReq),
// macOS
#[serde(rename = "kebab-case")]
XcodeCommandLineTools,
// Windows
#[serde(rename = "kebab-case")]
WindowsDeveloperMode,
}
);
Expand Down
1 change: 1 addition & 0 deletions crates/pdk-api/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ api_enum!(
#[default]
Language,
DependencyManager,
#[serde(rename = "CLI")]
CLI,
}
);
Expand Down
4 changes: 3 additions & 1 deletion crates/warpgate-api/src/host_funcs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ use rustc_hash::FxHashMap;
api_enum!(
/// Target where host logs should be written to.
#[derive(Default)]
#[serde(rename_all = "lowercase")]
pub enum HostLogTarget {
#[serde(rename = "stderr")]
Stderr,
#[serde(rename = "stdout")]
Stdout,
#[default]
#[serde(rename = "tracing")]
Tracing,
}
);
Expand Down
2 changes: 2 additions & 0 deletions crates/warpgate-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ macro_rules! api_struct {
#[derive(Clone, Debug, Default, serde::Deserialize, PartialEq, serde::Serialize)]
#[cfg_attr(feature = "schematic", derive(schematic::Schematic))]
#[serde(default)]
#[serde(rename_all = "snake_case")]
$struct
};
}
Expand All @@ -26,6 +27,7 @@ macro_rules! api_enum {
($struct:item) => {
#[derive(Clone, Debug, serde::Deserialize, PartialEq, serde::Serialize)]
#[cfg_attr(feature = "schematic", derive(schematic::Schematic))]
#[serde(rename_all = "PascalCase")]
$struct
};
}
Expand Down
1 change: 1 addition & 0 deletions package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lib
9 changes: 9 additions & 0 deletions package/.prototools
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
node = "20.12.1"
npm = "10.5.0"
extism-js = "1.0.0-rc9"

[plugins]
extism-js = "source:./extism-js.toml"

# silly workaround for root .prototools potentially pointing at non-existing plugin
wasm-test = "source:./extism-js.toml"
26 changes: 26 additions & 0 deletions package/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Contributing to @moonrepo/proto-pdk

## Prerequisites

Everything except [binaryen](https://github.com/WebAssembly/binaryen) is currently
managed via the .prototools.

## Building

```shell
npm run build
```

## Testing

```shell
# run tests and watch for changes
npm test

# run tests and exit
npm test run
```

## E2E tests

Refer to [the test plugin](./test/README.md).
36 changes: 36 additions & 0 deletions package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# @moonrepo/proto-pdk

A plugin development kit for creating proto WASM plugins using JS/TS.

> [!IMPORTANT]
> The Extism JavaScript PDK does not currently provide filesystem APIs, hence
> some functionality, such as custom checksumming, is difficult to achieve using
> this PDK.
>
> If you need this you're better off using the [Rust PDK](../crates/pdk) for now.

## Prerequisites

You will need:

- [extism-js >=v1.0.0-rc9](https://github.com/extism/js-pdk)

## Installation

Not yet published, please check back later.

<!--
```shell
npm i -D @moonrepo/proto-pdk binaryen
```
-->

## Usage

[The test plugin](./test) is currently the best reference for a complete TypeScript-based example,
until we get the PDK properly documented.

Neither TypeScript or ESBuild is a requirement. A bundler (like ESBuild) is however, and the bundled output
should target at ES2020 or below, while using CommonJS as the format.

It is strongly recommended to minify your bundled JavaScript, as it greatly affects the final WASM file size.
24 changes: 24 additions & 0 deletions package/extism-js.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name = "extism-js"
type = "cli"

[resolve]
git-url = "https://github.com/extism/js-pdk"

[platform.linux]
archs = ["x86_64", "aarch64"]
download-file = "extism-js-{arch}-linux-v{version}.gz"
checksum-file = "extism-js-{arch}-linux-v{version}.gz.sha256"
bin-path = "extism-js-{arch}-linux-v{version}"

[platform.macos]
archs = ["x86_64", "aarch64"]
download-file = "extism-js-{arch}-macos-v{version}.gz"
checksum-file = "extism-js-{arch}-macos-v{version}.gz.sha256"
bin-path = "extism-js-{arch}-macos-v{version}"

[platform.windows]
archs = []

[install]
download-url = "https://github.com/extism/js-pdk/releases/download/v{version}/{download_file}"
checksum-url = "https://github.com/extism/js-pdk/releases/download/v{version}/{checksum_file}"
Loading