Skip to content

Commit

Permalink
Merge branch 'feat/rename-namespace' of https://github.com/extism/dot…
Browse files Browse the repository at this point in the history
…net-pdk into feat/rename-namespace
  • Loading branch information
mhmd-azeez committed Oct 31, 2023
2 parents 84aa6c8 + 04ea861 commit fa3cf3c
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 42 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
on:
workflow_dispatch:
push:
tags:
- 'v*'

name: Release .NET PDK

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Create a new project and add this nuget package to your project:
```
dotnet new wasiconsole -o MyPlugin
cd MyPlugin
dotnet add package Extism.Pdk
dotnet add package Extism.Pdk --prerelease
```

Update your MyPlugin.csproj as follows:
Expand Down
6 changes: 0 additions & 6 deletions src/Extism.Pdk.MSBuild/FFIGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,8 @@ private FileEntry GenerateExports(string assemblyFileName, MethodDefinition[] ex
WASI_AFTER_RUNTIME_LOADED_DECLARATIONS
#endif
bool mono_runtime_initialized = false;
void initialize_runtime() {
if (mono_runtime_initialized) {
return;
}
mono_wasm_load_runtime("", 0);
mono_runtime_initialized = true;
}
// end of _initialize
Expand Down
4 changes: 2 additions & 2 deletions src/Extism.Pdk/Extism.Pdk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<PropertyGroup>
<PackageId>Extism.Pdk</PackageId>
<Version>1.0.0-rc1</Version>
<Version>1.0.0-rc3</Version>
<Authors>Extism Contributors</Authors>
<Description>Extism PDK that allows compiling .NET apps into wasm Extism plugins.</Description>
<Tags>extism, wasm, plugin</Tags>
Expand All @@ -28,4 +28,4 @@
</ItemGroup>
</Target>

</Project>
</Project>
3 changes: 1 addition & 2 deletions src/Extism.Pdk/Interop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,6 @@ public HttpRequest(Uri url)
public HttpRequest(string url)
{
Url = new Uri(url);
Pdk.Log(LogLevel.Error, url);
}

/// <summary>
Expand Down Expand Up @@ -577,4 +576,4 @@ public static MemoryBlock Find(ulong offset)
var length = Native.extism_length(offset);
return new MemoryBlock(offset, length);
}
}
}
3 changes: 3 additions & 0 deletions src/Extism.Pdk/build/Extism.Pdk.targets
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<!-- Wrap mono_runtime_run_main because we have to make sure at least one argument is passed in to Mono -->
<!-- See native/extism.c for the implementation -->
<_WasiSdkClangArgs Include="-Wl,--wrap=mono_runtime_run_main" />

<!-- Wrap mono_wasm_load_runtime to ensure mono is loaded only once when _start is called after an exported function -->
<_WasiSdkClangArgs Include="-Wl,--wrap=mono_wasm_load_runtime" />
</ItemGroup>
</Target>
</Project>
57 changes: 35 additions & 22 deletions src/Extism.Pdk/native/extism.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,147 +17,147 @@

typedef uint64_t ExtismPointer;

IMPORT("extism:env", "input_length")
IMPORT("extism:host/env", "input_length")
extern uint64_t extism_input_length_import();

uint64_t extism_input_length() {
return extism_input_length_import();
}

IMPORT("extism:env", "length")
IMPORT("extism:host/env", "length")
extern uint64_t extism_length_import(ExtismPointer);

uint64_t extism_length(ExtismPointer p) {
return extism_length_import(p);
}

IMPORT("extism:env", "alloc")
IMPORT("extism:host/env", "alloc")
extern ExtismPointer extism_alloc_import(uint64_t size);

ExtismPointer extism_alloc(uint64_t size) {
return extism_alloc_import(size);
}

IMPORT("extism:env", "free")
IMPORT("extism:host/env", "free")
extern void extism_free_import(ExtismPointer p);

void extism_free(ExtismPointer p) {
extism_free_import(p);
}

IMPORT("extism:env", "input_load_u8")
IMPORT("extism:host/env", "input_load_u8")
extern uint8_t extism_input_load_u8_import(ExtismPointer p);

uint8_t extism_input_load_u8(ExtismPointer p) {
return extism_input_load_u8_import(p);
}

IMPORT("extism:env", "input_load_u64")
IMPORT("extism:host/env", "input_load_u64")
extern uint64_t extism_input_load_u64_import(ExtismPointer p);

uint64_t extism_input_load_u64(ExtismPointer p) {
return extism_input_load_u64_import(p);
}

IMPORT("extism:env", "output_set")
IMPORT("extism:host/env", "output_set")
extern void extism_output_set_import(ExtismPointer p, uint64_t value);

void extism_output_set(ExtismPointer p, uint64_t value) {
extism_output_set_import(p, value);
}

IMPORT("extism:env", "error_set")
IMPORT("extism:host/env", "error_set")
extern void extism_error_set_import(ExtismPointer p);

void extism_error_set(ExtismPointer p) {
extism_error_set_import(p);
}

IMPORT("extism:env", "config_get")
IMPORT("extism:host/env", "config_get")
extern ExtismPointer extism_config_get_import(ExtismPointer p);

ExtismPointer extism_config_get(ExtismPointer p) {
return extism_config_get_import(p);
}

IMPORT("extism:env", "var_get")
IMPORT("extism:host/env", "var_get")
extern ExtismPointer extism_var_get_import(ExtismPointer p);

ExtismPointer extism_var_get(ExtismPointer p) {
return extism_var_get_import(p);
}

IMPORT("extism:env", "var_set")
IMPORT("extism:host/env", "var_set")
extern void extism_var_set_import(ExtismPointer p1, ExtismPointer p2);

void extism_var_set(ExtismPointer p1, ExtismPointer p2) {
extism_var_set_import(p1, p2);
}

IMPORT("extism:env", "store_u8")
IMPORT("extism:host/env", "store_u8")
extern void extism_store_u8_import(ExtismPointer p, uint8_t value);

void extism_store_u8(ExtismPointer p, uint8_t value) {
extism_store_u8_import(p, value);
}

IMPORT("extism:env", "load_u8")
IMPORT("extism:host/env", "load_u8")
extern uint8_t extism_load_u8_import(ExtismPointer p);

uint8_t extism_load_u8(ExtismPointer p) {
return extism_load_u8_import(p);
}

IMPORT("extism:env", "store_u64")
IMPORT("extism:host/env", "store_u64")
extern void extism_store_u64_import(ExtismPointer p, uint64_t value);

void extism_store_u64(ExtismPointer p, uint64_t value) {
extism_store_u64_import(p, value);
}

IMPORT("extism:env", "load_u64")
IMPORT("extism:host/env", "load_u64")
extern uint64_t extism_load_u64_import(ExtismPointer p);

uint64_t extism_load_u64(ExtismPointer p) {
return extism_load_u64_import(p);
}

IMPORT("extism:env", "http_request")
IMPORT("extism:host/env", "http_request")
extern ExtismPointer extism_http_request_import(ExtismPointer p1, ExtismPointer p2);

ExtismPointer extism_http_request(ExtismPointer p1, ExtismPointer p2) {
return extism_http_request_import(p1, p2);
}

IMPORT("extism:env", "http_status_code")
IMPORT("extism:host/env", "http_status_code")
extern int32_t extism_http_status_code_import();

int32_t extism_http_status_code() {
return extism_http_status_code_import();
}

IMPORT("extism:env", "log_info")
IMPORT("extism:host/env", "log_info")
extern void extism_log_info_import(ExtismPointer p);

void extism_log_info(ExtismPointer p) {
extism_log_info_import(p);
}

IMPORT("extism:env", "log_debug")
IMPORT("extism:host/env", "log_debug")
extern void extism_log_debug_import(ExtismPointer p);

void extism_log_debug(ExtismPointer p) {
extism_log_debug_import(p);
}

IMPORT("extism:env", "log_warn")
IMPORT("extism:host/env", "log_warn")
extern void extism_log_warn_import(ExtismPointer p);

void extism_log_warn(ExtismPointer p) {
extism_log_warn_import(p);
}

IMPORT("extism:env", "log_error")
IMPORT("extism:host/env", "log_error")
extern void extism_log_error_import(ExtismPointer p);

void extism_log_error(ExtismPointer p) {
Expand Down Expand Up @@ -232,4 +232,17 @@ int __wrap_mono_runtime_run_main(MonoMethod *method, int argc, char *argv[], Mon
}

return __real_mono_runtime_run_main(method, argc, argv, exc);
}
}

// Wrap mono_wasm_load_runtime to make sure we don't initialize mono more than once
void __real_mono_wasm_load_runtime(const char* unused, int debug_level);

bool mono_runtime_initialized = false;
void __wrap_mono_wasm_load_runtime(const char* unused, int debug_level) {
if (mono_runtime_initialized) {
return;
}

__real_mono_wasm_load_runtime(unused, debug_level);
mono_runtime_initialized = true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Mono.Cecil" Version="0.11.5" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit" Version="2.5.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down
6 changes: 0 additions & 6 deletions tests/Extism.Pdk.MsBuild.Tests/snapshots/exports.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,8 @@ void mono_wasm_load_runtime(const char* unused, int debug_level);
WASI_AFTER_RUNTIME_LOADED_DECLARATIONS
#endif

bool mono_runtime_initialized = false;
void initialize_runtime() {
if (mono_runtime_initialized) {
return;
}

mono_wasm_load_runtime("", 0);
mono_runtime_initialized = true;
}

// end of _initialize
Expand Down
2 changes: 1 addition & 1 deletion tests/Extism.Pdk.WasmTests/Extism.Pdk.WasmTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageReference Include="CliWrap" Version="3.6.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Shouldly" Version="4.2.1" />
<PackageReference Include="xunit" Version="2.5.1" />
<PackageReference Include="xunit" Version="2.5.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.1">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand Down

0 comments on commit fa3cf3c

Please sign in to comment.